From 0f9ef005f063198ea2e16ca36beaead4bd5e3824 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 14 Apr 2016 21:12:07 +0100 Subject: Add .NET output --- .gitignore | 4 +- couscous.json | 17 ++-- dotnet/Mammoth.sln | 17 ++++ dotnet/Mammoth/Couscous/Adapters.cs | 86 ++++++++++++++++ dotnet/Mammoth/Couscous/HorribleHacks.cs | 21 ++++ dotnet/Mammoth/Couscous/IterableExtensions.cs | 13 +++ dotnet/Mammoth/Couscous/JavaStringExtensions.cs | 17 ++++ dotnet/Mammoth/Couscous/java/io/Closeable.cs | 9 ++ dotnet/Mammoth/Couscous/java/io/IOException.cs | 17 ++++ dotnet/Mammoth/Couscous/java/io/InputStream.cs | 5 + .../java/lang/IndexOutOfBoundsException.cs | 7 ++ .../Mammoth/Couscous/java/lang/RuntimeException.cs | 13 +++ dotnet/Mammoth/Couscous/java/lang/String.cs | 7 ++ dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs | 14 +++ .../java/lang/UnsupportedOperationException.cs | 7 ++ dotnet/Mammoth/Couscous/java/nio/file/Path.cs | 9 ++ dotnet/Mammoth/Couscous/java/util/ArrayList.cs | 49 +++++++++ dotnet/Mammoth/Couscous/java/util/Collection.cs | 11 +++ dotnet/Mammoth/Couscous/java/util/HashMap.cs | 69 +++++++++++++ dotnet/Mammoth/Couscous/java/util/HashSet.cs | 34 +++++++ dotnet/Mammoth/Couscous/java/util/List.cs | 8 ++ dotnet/Mammoth/Couscous/java/util/Map.cs | 15 +++ .../Couscous/java/util/NoSuchElementException.cs | 6 ++ dotnet/Mammoth/Couscous/java/util/Optional.cs | 103 +++++++++++++++++++ dotnet/Mammoth/Couscous/java/util/Set.cs | 6 ++ .../Couscous/java/util/function/BiFunction.cs | 6 ++ .../Couscous/java/util/function/BiPredicate.cs | 6 ++ .../Couscous/java/util/function/Consumer.cs | 5 + .../Couscous/java/util/function/Function.cs | 6 ++ .../Couscous/java/util/function/Predicate.cs | 5 + .../Couscous/java/util/function/Supplier.cs | 5 + .../internal/docx/PathRelativeFileReader.cs | 17 ++++ .../internal/styles/parsing/StyleMapParser.cs | 14 +++ .../mammoth/internal/util/Base64Encoding.cs | 10 ++ .../Couscous/mammoth/internal/util/Casts.cs | 13 +++ .../Couscous/mammoth/internal/util/Iterables.cs | 60 +++++++++++ .../Couscous/mammoth/internal/util/Lists.cs | 97 ++++++++++++++++++ .../Mammoth/Couscous/mammoth/internal/util/Maps.cs | 110 +++++++++++++++++++++ .../mammoth/internal/util/PassThroughException.cs | 21 ++++ .../Couscous/mammoth/internal/util/Paths.cs | 8 ++ .../Mammoth/Couscous/mammoth/internal/util/Sets.cs | 19 ++++ .../Couscous/mammoth/internal/util/Strings.cs | 18 ++++ .../mammoth/internal/xml/parsing/SimpleSax.cs | 13 +++ dotnet/Mammoth/Mammoth.csproj | 87 ++++++++++++++++ dotnet/Mammoth/Properties/AssemblyInfo.cs | 27 +++++ .../internal/conversion/DocumentToHtml.java | 20 ++-- .../mammoth/internal/docx/BodyXmlReader.java | 4 +- .../zwobble/mammoth/internal/docx/DocxFile.java | 5 - .../zwobble/mammoth/internal/docx/DocxFiles.java | 11 +++ .../mammoth/internal/xml/parsing/XmlParser.java | 16 +-- 50 files changed, 1132 insertions(+), 35 deletions(-) create mode 100644 dotnet/Mammoth.sln create mode 100644 dotnet/Mammoth/Couscous/Adapters.cs create mode 100644 dotnet/Mammoth/Couscous/HorribleHacks.cs create mode 100644 dotnet/Mammoth/Couscous/IterableExtensions.cs create mode 100644 dotnet/Mammoth/Couscous/JavaStringExtensions.cs create mode 100644 dotnet/Mammoth/Couscous/java/io/Closeable.cs create mode 100644 dotnet/Mammoth/Couscous/java/io/IOException.cs create mode 100644 dotnet/Mammoth/Couscous/java/io/InputStream.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/String.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs create mode 100644 dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs create mode 100644 dotnet/Mammoth/Couscous/java/nio/file/Path.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/ArrayList.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Collection.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/HashMap.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/HashSet.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/List.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Map.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Optional.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/Set.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Consumer.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Function.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Predicate.cs create mode 100644 dotnet/Mammoth/Couscous/java/util/function/Supplier.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/docx/PathRelativeFileReader.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/styles/parsing/StyleMapParser.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Base64Encoding.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Casts.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Iterables.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Maps.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Paths.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Sets.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/util/Strings.cs create mode 100644 dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs create mode 100644 dotnet/Mammoth/Mammoth.csproj create mode 100644 dotnet/Mammoth/Properties/AssemblyInfo.cs create mode 100644 src/main/java/org/zwobble/mammoth/internal/docx/DocxFiles.java diff --git a/.gitignore b/.gitignore index 58c897a..a08e5b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /target /.idea /*.iml -/_dotnet +/dotnet/Mammoth/generated.cs +/dotnet/Mammoth/bin +/dotnet/Mammoth/obj diff --git a/couscous.json b/couscous.json index 5323305..7c78642 100644 --- a/couscous.json +++ b/couscous.json @@ -4,20 +4,19 @@ "src/main/java" ], "files": [ - "src/main/java/org/zwobble/mammoth/internal/documents", - "src/main/java/org/zwobble/mammoth/internal/docx", + "src/main/java/org/zwobble/mammoth", + "!src/main/java/org/zwobble/mammoth/DocumentConverter.java", "!src/main/java/org/zwobble/mammoth/internal/docx/ZippedDocxFile.java", "!src/main/java/org/zwobble/mammoth/internal/docx/InMemoryDocxFile.java", "!src/main/java/org/zwobble/mammoth/internal/docx/PathRelativeFileReader.java", - "src/main/java/org/zwobble/mammoth/internal/html", - "src/main/java/org/zwobble/mammoth/internal/results", - "src/main/java/org/zwobble/mammoth/internal/styles", "!src/main/java/org/zwobble/mammoth/internal/styles/parsing", + "!src/main/java/org/zwobble/mammoth/internal/util", "src/main/java/org/zwobble/mammoth/internal/util/InputStreamSupplier.java", - "src/main/java/org/zwobble/mammoth/internal/xml", - "!src/main/java/org/zwobble/mammoth/internal/xml/parsing", - "src/main/java/org/zwobble/mammoth/Result.java" + "src/main/java/org/zwobble/mammoth/internal/util/Optionals.java", + "src/main/java/org/zwobble/mammoth/internal/util/SupplierWithException.java", + "!src/main/java/org/zwobble/mammoth/internal/xml/parsing/SimpleSax.java" + ], - "output": "_dotnet", + "output": "dotnet/Mammoth/generated.cs", "namespace": "Mammoth.Couscous" } diff --git a/dotnet/Mammoth.sln b/dotnet/Mammoth.sln new file mode 100644 index 0000000..cd369cf --- /dev/null +++ b/dotnet/Mammoth.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mammoth", "Mammoth\Mammoth.csproj", "{51C5CBD6-8809-4D5E-BABE-1787A16F5ED8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {51C5CBD6-8809-4D5E-BABE-1787A16F5ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {51C5CBD6-8809-4D5E-BABE-1787A16F5ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {51C5CBD6-8809-4D5E-BABE-1787A16F5ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {51C5CBD6-8809-4D5E-BABE-1787A16F5ED8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/dotnet/Mammoth/Couscous/Adapters.cs b/dotnet/Mammoth/Couscous/Adapters.cs new file mode 100644 index 0000000..a613473 --- /dev/null +++ b/dotnet/Mammoth/Couscous/Adapters.cs @@ -0,0 +1,86 @@ +using System.Collections.Generic; +using System.Linq; +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; + +namespace Mammoth.Couscous { + internal static class FromJava { + internal static IEnumerable IterableToEnumerable(Iterable iterable) { + Iterator iterator = iterable.iterator(); + while (iterator.hasNext()) { + yield return iterator.next(); + } + } + + internal static IDictionary MapToDictionary(Map map) { + return map.AsDictionary(); + } + } + + internal static class ToJava { + internal static Iterable EnumerableToIterable(IEnumerable enumerator) { + return new IterableWrapper(enumerator); + } + + private class IterableWrapper : Iterable { + private readonly IEnumerable _enumerable; + + internal IterableWrapper(IEnumerable enumerable) { + _enumerable = enumerable; + } + + public Iterator iterator() { + return EnumeratorToIterator(_enumerable.GetEnumerator()); + } + } + + internal static Iterator EnumeratorToIterator(IEnumerator enumerator) { + return new EnumeratorToIteratorAdapter(enumerator); + } + + private class EnumeratorToIteratorAdapter : Iterator { + private readonly IEnumerator _enumerator; + private bool _ready; + private bool _hasNext; + + internal EnumeratorToIteratorAdapter(IEnumerator enumerator) { + _enumerator = enumerator; + _ready = false; + } + + public bool hasNext() { + MakeReady(); + return _hasNext; + } + + public T next() { + MakeReady(); + if (_hasNext) { + _ready = false; + return _enumerator.Current; + } else { + throw new NoSuchElementException(); + } + } + + private void MakeReady() { + if (!_ready) { + MoveNext(); + } + } + + private void MoveNext() { + _hasNext = _enumerator.MoveNext(); + _ready = true; + } + } + + internal static Map DictionaryToMap(IDictionary dictionary) { + return new HashMap(dictionary); + } + + internal static java.util.List ListToList(IList list) { + return new ArrayList(list); + } + } +} diff --git a/dotnet/Mammoth/Couscous/HorribleHacks.cs b/dotnet/Mammoth/Couscous/HorribleHacks.cs new file mode 100644 index 0000000..88c746b --- /dev/null +++ b/dotnet/Mammoth/Couscous/HorribleHacks.cs @@ -0,0 +1,21 @@ +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.org.zwobble.mammoth.@internal.documents; +using System.Linq; + +namespace Mammoth.Couscous { + internal static class HorribleHacks { + internal static bool equals(this Optional first, Optional second) { + return (!first.isPresent() && !second.isPresent()) || (first.isPresent() && second.isPresent() && first.get() == second.get()); + } + + internal static bool equals(this Map firstMap, Map secondMap) { + var first = FromJava.MapToDictionary(firstMap); + var second = FromJava.MapToDictionary(secondMap); + return first.Count == second.Count && first.All(item => second.ContainsKey(item.Key) && second[item.Key] == item.Value); + } + + internal static bool equals(this NoteType first, NoteType second) { + return first == second; + } + } +} diff --git a/dotnet/Mammoth/Couscous/IterableExtensions.cs b/dotnet/Mammoth/Couscous/IterableExtensions.cs new file mode 100644 index 0000000..bac0b43 --- /dev/null +++ b/dotnet/Mammoth/Couscous/IterableExtensions.cs @@ -0,0 +1,13 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util.function; + +namespace Mammoth.Couscous { + internal static class IterableExtensions { + public static void forEach(this Iterable iterable, Consumer consumer) { + var iterator = iterable.iterator(); + while (iterator.hasNext()) { + consumer.accept(iterator.next()); + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/JavaStringExtensions.cs b/dotnet/Mammoth/Couscous/JavaStringExtensions.cs new file mode 100644 index 0000000..429bc7d --- /dev/null +++ b/dotnet/Mammoth/Couscous/JavaStringExtensions.cs @@ -0,0 +1,17 @@ +using System; + +namespace Mammoth.Couscous { + internal static class JavaStringExtensions { + internal static bool equalsIgnoreCase(this string first, string second) { + return first.Equals(second, StringComparison.InvariantCultureIgnoreCase); + } + + internal static string replace(this string original, string search, string replacement) { + return original.Replace(search, replacement); + } + + internal static bool isEmpty(this string value) { + return value.Length == 0; + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/io/Closeable.cs b/dotnet/Mammoth/Couscous/java/io/Closeable.cs new file mode 100644 index 0000000..36b2a80 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/io/Closeable.cs @@ -0,0 +1,9 @@ +using System; + +namespace Mammoth.Couscous.java.io +{ + internal interface Closeable + { + } +} + diff --git a/dotnet/Mammoth/Couscous/java/io/IOException.cs b/dotnet/Mammoth/Couscous/java/io/IOException.cs new file mode 100644 index 0000000..f7b708e --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/io/IOException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Mammoth.Couscous.java.io +{ + internal class IOException : Exception { + internal IOException() : base() { + } + + internal IOException(string message) : base(message) { + } + + internal string getMessage() { + return Message; + } + } +} + diff --git a/dotnet/Mammoth/Couscous/java/io/InputStream.cs b/dotnet/Mammoth/Couscous/java/io/InputStream.cs new file mode 100644 index 0000000..9609a2b --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/io/InputStream.cs @@ -0,0 +1,5 @@ +namespace Mammoth.Couscous.java.io { + internal interface InputStream { + + } +} diff --git a/dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs b/dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs new file mode 100644 index 0000000..c56c7c1 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/IndexOutOfBoundsException.cs @@ -0,0 +1,7 @@ +using System; + +namespace Mammoth.Couscous.java.lang { + internal class IndexOutOfBoundsException : RuntimeException { + } +} + diff --git a/dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs b/dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs new file mode 100644 index 0000000..cf882aa --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/RuntimeException.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mammoth.Couscous.java.lang +{ + internal class RuntimeException : Exception { + internal RuntimeException() : base() { + } + + internal RuntimeException(string message) : base(message) { + } + } +} + diff --git a/dotnet/Mammoth/Couscous/java/lang/String.cs b/dotnet/Mammoth/Couscous/java/lang/String.cs new file mode 100644 index 0000000..bd0838d --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/String.cs @@ -0,0 +1,7 @@ +namespace Mammoth.Couscous.java.lang { + internal partial class String { + internal static string join(string separator, Iterable values) { + return string.Join(separator, FromJava.IterableToEnumerable(values)); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs b/dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs new file mode 100644 index 0000000..c894936 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/StringBuilder.cs @@ -0,0 +1,14 @@ +namespace Mammoth.Couscous.java.lang { + internal class StringBuilder { + private readonly System.Text.StringBuilder _builder = new System.Text.StringBuilder(); + + internal StringBuilder append(string value) { + _builder.Append(value); + return this; + } + + internal string toString() { + return _builder.ToString(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs b/dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs new file mode 100644 index 0000000..da86874 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/UnsupportedOperationException.cs @@ -0,0 +1,7 @@ +using System; + +namespace Mammoth.Couscous.java.lang { + internal class UnsupportedOperationException : RuntimeException { + } +} + diff --git a/dotnet/Mammoth/Couscous/java/nio/file/Path.cs b/dotnet/Mammoth/Couscous/java/nio/file/Path.cs new file mode 100644 index 0000000..6c85cc8 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/nio/file/Path.cs @@ -0,0 +1,9 @@ +using System; + +namespace Mammoth.Couscous.java.nio.file +{ + internal class Path + { + } +} + diff --git a/dotnet/Mammoth/Couscous/java/util/ArrayList.cs b/dotnet/Mammoth/Couscous/java/util/ArrayList.cs new file mode 100644 index 0000000..4414123 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/ArrayList.cs @@ -0,0 +1,49 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; + +namespace Mammoth.Couscous.java.util { + internal class ArrayList : List { + private readonly System.Collections.Generic.IList _list; + + internal ArrayList() : this(new System.Collections.Generic.List()) { + } + + internal ArrayList(System.Collections.Generic.IList list) { + _list = list; + } + + public Iterator iterator() { + return ToJava.EnumeratorToIterator(_list.GetEnumerator()); + } + + public bool isEmpty() { + return _list.Count == 0; + } + + public int size() { + return _list.Count; + } + + public bool contains(object value) { + return value is T && _list.Contains((T) value); + } + + public T get(int index) { + if (index < 0 || index >= _list.Count) { + throw new IndexOutOfBoundsException(); + } else { + return _list[index]; + } + } + + public void add(T value) { + _list.Add(value); + } + + public T remove(int index) { + T value = _list[index]; + _list.RemoveAt(index); + return value; + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/Collection.cs b/dotnet/Mammoth/Couscous/java/util/Collection.cs new file mode 100644 index 0000000..a0cae74 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/Collection.cs @@ -0,0 +1,11 @@ +using Mammoth.Couscous.java.lang; + +namespace Mammoth.Couscous.java.util { + interface Collection : Iterable { + bool isEmpty(); + int size(); + bool contains(object value); + + void add(T value); + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/HashMap.cs b/dotnet/Mammoth/Couscous/java/util/HashMap.cs new file mode 100644 index 0000000..38e516e --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/HashMap.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.Linq; +using Mammoth.Couscous.org.zwobble.mammoth.@internal.util; +using Mammoth.Couscous.java.lang; + +namespace Mammoth.Couscous.java.util { + internal class HashMap : Map { + private readonly IDictionary _dictionary; + + internal HashMap() : this(new Dictionary()) { + } + + internal HashMap(IDictionary dictionary) { + _dictionary = dictionary; + } + + public void put(TKey key, TValue value) { + _dictionary[key] = value; + } + + public bool containsKey(TKey key) { + return _dictionary.ContainsKey(key); + } + + public Set> entrySet() { + return new EntrySet(_dictionary); + } + + public Optional _lookup(TKey key) { + if (_dictionary.ContainsKey(key)) { + return new Some(_dictionary[key]); + } else { + return new None(); + } + } + + public IDictionary AsDictionary() { + return _dictionary; + } + + internal class EntrySet : Set> { + private readonly IDictionary _dictionary; + + internal EntrySet(IDictionary dictionary) { + _dictionary = dictionary; + } + + public Iterator> iterator() { + return ToJava.EnumeratorToIterator(_dictionary.Select(entry => Maps.entry(entry.Key, entry.Value)).GetEnumerator()); + } + + public bool isEmpty() { + return _dictionary.Count == 0; + } + + public int size() { + return _dictionary.Count; + } + + public bool contains(object value) { + return value is TKey && _dictionary.ContainsKey((TKey) value); + } + + public void add(Map__Entry value) { + throw new UnsupportedOperationException(); + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/HashSet.cs b/dotnet/Mammoth/Couscous/java/util/HashSet.cs new file mode 100644 index 0000000..ac10075 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/HashSet.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace Mammoth.Couscous.java.util { + internal class HashSet : Set { + private readonly ISet _set; + + internal HashSet() : this(new System.Collections.Generic.HashSet()) { + } + + internal HashSet(ISet set) { + _set = set; + } + + public Iterator iterator() { + return ToJava.EnumeratorToIterator(_set.GetEnumerator()); + } + + public bool isEmpty() { + return _set.Count == 0; + } + + public int size() { + return _set.Count; + } + + public bool contains(object value) { + return value is T && _set.Contains((T)value); + } + + public void add(T value) { + _set.Add(value); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/List.cs b/dotnet/Mammoth/Couscous/java/util/List.cs new file mode 100644 index 0000000..45a9299 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/List.cs @@ -0,0 +1,8 @@ +using Mammoth.Couscous.java.lang; + +namespace Mammoth.Couscous.java.util { + interface List : Collection { + T get(int index); + T remove(int index); + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/Map.cs b/dotnet/Mammoth/Couscous/java/util/Map.cs new file mode 100644 index 0000000..5405c77 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/Map.cs @@ -0,0 +1,15 @@ +namespace Mammoth.Couscous.java.util { + internal interface Map { + void put(K key, V value); + bool containsKey(K key); + Set> entrySet(); + + Optional _lookup(K key); + System.Collections.Generic.IDictionary AsDictionary(); + } + + internal interface Map__Entry { + K getKey(); + V getValue(); + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs b/dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs new file mode 100644 index 0000000..4a1ee9c --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/NoSuchElementException.cs @@ -0,0 +1,6 @@ +using Mammoth.Couscous.java.lang; + +namespace Mammoth.Couscous.java.util { + internal class NoSuchElementException : RuntimeException { + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/Optional.cs b/dotnet/Mammoth/Couscous/java/util/Optional.cs new file mode 100644 index 0000000..f295688 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/Optional.cs @@ -0,0 +1,103 @@ +using System; +using Mammoth.Couscous.java.util.function; + +namespace Mammoth.Couscous.java.util +{ + internal interface Optional + { + bool isPresent(); + Optional map(Function function); + Optional flatMap(Function> function); + T orElse(T value); + T orElseGet(Supplier supplier); + T orElseThrow(Supplier exceptionSupplier) where TException : Exception; + T get(); + void ifPresent(Consumer consumer); + } + + internal class None : Optional { + public bool isPresent() { + return false; + } + + public Optional map(Function function) { + return new None(); + } + + public Optional flatMap(Function> function) { + return new None(); + } + + public T orElse(T value) { + return value; + } + + public T orElseGet(Supplier supplier) { + return supplier.get(); + } + + public T orElseThrow(Supplier exceptionSupplier) where TException : Exception { + throw exceptionSupplier.get(); + } + + public T get() { + throw new NoSuchElementException(); + } + + public void ifPresent(Consumer consumer) { + } + } + + internal class Some : Optional { + private readonly T _value; + + internal Some(T value) { + _value = value; + } + + public bool isPresent() { + return true; + } + + public Optional map(Function function) { + return new Some(function.apply(_value)); + } + + public Optional flatMap(Function> function) { + return function.apply(_value); + } + + public T orElse(T value) { + return _value; + } + + public T orElseGet(Supplier supplier) { + return _value; + } + + public T orElseThrow(Supplier exceptionSupplier) where TException : Exception { + return _value; + } + + public T get() { + return _value; + } + + public void ifPresent(Consumer consumer) { + consumer.accept(_value); + } + } + + internal static class Optional + { + internal static Optional empty() + { + return new None(); + } + + internal static Optional of(T value) + { + return new Some (value); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/Set.cs b/dotnet/Mammoth/Couscous/java/util/Set.cs new file mode 100644 index 0000000..34a23ac --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/Set.cs @@ -0,0 +1,6 @@ +using Mammoth.Couscous.java.lang; + +namespace Mammoth.Couscous.java.util { + internal interface Set : Collection { + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs b/dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs new file mode 100644 index 0000000..050f85f --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/function/BiFunction.cs @@ -0,0 +1,6 @@ +namespace Mammoth.Couscous.java.util.function +{ + internal interface BiFunction { + U apply(T1 first, T2 second); + } +} \ No newline at end of file diff --git a/dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs b/dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs new file mode 100644 index 0000000..0419a6e --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/function/BiPredicate.cs @@ -0,0 +1,6 @@ +namespace Mammoth.Couscous.java.util.function +{ + internal interface BiPredicate { + bool test(T first, U second); + } +} \ No newline at end of file diff --git a/dotnet/Mammoth/Couscous/java/util/function/Consumer.cs b/dotnet/Mammoth/Couscous/java/util/function/Consumer.cs new file mode 100644 index 0000000..f80d426 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/function/Consumer.cs @@ -0,0 +1,5 @@ +namespace Mammoth.Couscous.java.util.function { + internal interface Consumer { + void accept(T value); + } +} \ No newline at end of file diff --git a/dotnet/Mammoth/Couscous/java/util/function/Function.cs b/dotnet/Mammoth/Couscous/java/util/function/Function.cs new file mode 100644 index 0000000..2b4d3ae --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/function/Function.cs @@ -0,0 +1,6 @@ +namespace Mammoth.Couscous.java.util.function +{ + internal interface Function { + U apply(T arg); + } +} \ No newline at end of file diff --git a/dotnet/Mammoth/Couscous/java/util/function/Predicate.cs b/dotnet/Mammoth/Couscous/java/util/function/Predicate.cs new file mode 100644 index 0000000..2023309 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/function/Predicate.cs @@ -0,0 +1,5 @@ +namespace Mammoth.Couscous.java.util.function { + internal interface Predicate { + bool test(T value); + } +} \ No newline at end of file diff --git a/dotnet/Mammoth/Couscous/java/util/function/Supplier.cs b/dotnet/Mammoth/Couscous/java/util/function/Supplier.cs new file mode 100644 index 0000000..eab3ffb --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/function/Supplier.cs @@ -0,0 +1,5 @@ +namespace Mammoth.Couscous.java.util.function { + internal interface Supplier { + T get(); + } +} \ No newline at end of file diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/docx/PathRelativeFileReader.cs b/dotnet/Mammoth/Couscous/mammoth/internal/docx/PathRelativeFileReader.cs new file mode 100644 index 0000000..b581e9d --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/docx/PathRelativeFileReader.cs @@ -0,0 +1,17 @@ +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.io; +using Mammoth.Couscous.java.nio.file; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.docx { + internal class PathRelativeFileReader : FileReader { + private readonly Optional _path; + + internal PathRelativeFileReader(Optional path) { + _path = path; + } + + public InputStream getInputStream(string uri) { + throw new System.NotImplementedException(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/styles/parsing/StyleMapParser.cs b/dotnet/Mammoth/Couscous/mammoth/internal/styles/parsing/StyleMapParser.cs new file mode 100644 index 0000000..44d1ddd --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/styles/parsing/StyleMapParser.cs @@ -0,0 +1,14 @@ +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.org.zwobble.mammoth.@internal.styles; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.styles.parsing { + internal static class StyleMapParser { + internal static StyleMap parseStyleMappings(List mappings) { + return StyleMap.builder().build(); + } + + internal static StyleMap parse(string styleMap) { + return StyleMap.builder().build(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Base64Encoding.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Base64Encoding.cs new file mode 100644 index 0000000..f8270b0 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Base64Encoding.cs @@ -0,0 +1,10 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.io; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Base64Encoding { + internal static string streamToBase64(SupplierWithException stream) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Casts.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Casts.cs new file mode 100644 index 0000000..c342e20 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Casts.cs @@ -0,0 +1,13 @@ +using Mammoth.Couscous.java.util; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Casts { + internal static Optional tryCast(System.Type type, object value) { + if (value is T) { + return new Some((T) value); + } else { + return new None(); + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Iterables.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Iterables.cs new file mode 100644 index 0000000..b1e1477 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Iterables.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Linq; +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.util.function; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util +{ + internal static class Iterables + { + internal static T getFirst(Iterable iterable, T defaultValue) { + var iterator = iterable.iterator(); + if (iterator.hasNext()) { + return iterator.next(); + } else { + return defaultValue; + } + } + + internal static Optional tryFind(Iterable iterable, Predicate predicate) { + var iterator = iterable.iterator(); + while (iterator.hasNext()) { + T value = iterator.next(); + if (predicate.test(value)) { + return new Some(value); + } + } + return new None(); + } + + internal static Iterable lazyFilter(Iterable iterable, Predicate predicate) { + var enumerable = FromJava.IterableToEnumerable(iterable).Where(predicate.test); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable lazyFilter(Iterable iterable, System.Type type) { + var enumerable = FromJava.IterableToEnumerable(iterable).OfType(); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable lazyMap(Iterable iterable, Function function) { + var enumerable = FromJava.IterableToEnumerable(iterable) + .Select(function.apply); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable lazyFlatMap(Iterable iterable, Function> function) { + var enumerable = FromJava.IterableToEnumerable(iterable) + .SelectMany(element => FromJava.IterableToEnumerable(function.apply(element))); + return ToJava.EnumerableToIterable(enumerable); + } + + internal static Iterable lazyConcat(Iterable first, Iterable second) { + var enumerable = FromJava.IterableToEnumerable(first) + .Concat(FromJava.IterableToEnumerable(second)); + return ToJava.EnumerableToIterable(enumerable); + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs new file mode 100644 index 0000000..b914a34 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs @@ -0,0 +1,97 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.util.function; +using System.Linq; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Lists { + internal static List list(params T[] values) { + return ToJava.ListToList(values); + } + + internal static List toList(Iterable iterable) { + return ToJava.ListToList(FromJava.IterableToEnumerable(iterable).ToList()); + } + + internal static List eagerMap(Iterable iterable, Function function) { + var result = FromJava.IterableToEnumerable(iterable) + .Select(function.apply) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List eagerFlatMap(Iterable iterable, Function> function) { + var result = FromJava.IterableToEnumerable(iterable) + .SelectMany(element => FromJava.IterableToEnumerable(function.apply(element))) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List cons(T head, Iterable tail) { + var result = new T[] { head } + .Concat(FromJava.IterableToEnumerable(tail)) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List eagerConcat(Iterable first, Iterable second) { + var result = FromJava.IterableToEnumerable(first) + .Concat(FromJava.IterableToEnumerable(second)) + .ToList(); + return ToJava.ListToList(result); + } + + internal static List orderedBy(Iterable iterable, Function getKey) { + var result = FromJava.IterableToEnumerable(iterable) + .OrderBy(getKey.apply) + .ToList(); + return ToJava.ListToList(result); + } + + internal static Optional tryGetLast(List list) { + if (list.isEmpty()) { + return new None(); + } else { + return new Some(list.get(list.size() - 1)); + } + } + + internal static Iterable reversed(List list) { + return new ReversedList(list); + } + + private class ReversedList : Iterable { + private readonly List _list; + + internal ReversedList(List list) { + _list = list; + } + + public Iterator iterator() { + return new ReverseIterator(_list); + } + } + + private class ReverseIterator : Iterator { + private readonly List _list; + private int _nextIndex; + + internal ReverseIterator(List list) { + _list = list; + _nextIndex = _list.size() - 1; + } + + public bool hasNext() { + return _nextIndex >= 0; + } + + public T next() { + if (hasNext()) { + return _list.get(_nextIndex--); + } else { + throw new NoSuchElementException(); + } + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Maps.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Maps.cs new file mode 100644 index 0000000..bee2dac --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Maps.cs @@ -0,0 +1,110 @@ +using System.Linq; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util.function; +using Mammoth.Couscous; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util +{ + internal static class Maps + { + internal static Map map() { + return ToJava.DictionaryToMap(new System.Collections.Generic.Dictionary()); + } + + internal static Map map(K key1, V value1) { + return ToJava.DictionaryToMap(new System.Collections.Generic.Dictionary { + {key1, value1} + }); + } + + internal static Map map(K key1, V value1, K key2, V value2) { + return ToJava.DictionaryToMap(new System.Collections.Generic.Dictionary { + {key1, value1}, + {key2, value2} + }); + } + + internal static Map toMap(Iterable iterable, Function> function) { + var dictionary = FromJava.IterableToEnumerable(iterable) + .Select(function.apply) + .ToDictionary(entry => entry.getKey(), entry => entry.getValue()); + return ToJava.DictionaryToMap(dictionary); + + } + + internal static Map toMapWithKey(Iterable iterable, Function function) { + var dictionary = FromJava.IterableToEnumerable(iterable) + .ToDictionary(function.apply); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Map> toMultiMapWithKey(Iterable iterable, Function function) { + var dictionary = FromJava.IterableToEnumerable(iterable) + .GroupBy(value => function.apply(value)) + .ToDictionary( + grouping => grouping.Key, + grouping => ToJava.ListToList(grouping.ToList())); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Optional lookup(Map map, K key) { + return map._lookup(key); + } + + internal static Map eagerMapKeys(Map map, Function function) { + var dictionary = FromJava.MapToDictionary(map) + .ToDictionary( + entry => function.apply(entry.Key), + entry => entry.Value); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Map eagerMapValues(Map map, Function function) { + var dictionary = FromJava.MapToDictionary(map) + .ToDictionary( + entry => entry.Key, + entry => function.apply(entry.Value)); + return ToJava.DictionaryToMap(dictionary); + } + + internal static Map__Entry entry(K key, V value) { + return new Entry(key, value); + } + + private class Entry : Map__Entry { + private readonly K _key; + private readonly V _value; + + internal Entry(K key, V value) { + this._key = key; + this._value = value; + } + + public K getKey() { + return _key; + } + + public V getValue() { + return _value; + } + } + + internal static Builder builder() { + return new Builder(); + } + + internal class Builder { + private readonly System.Collections.Generic.IDictionary _values = new System.Collections.Generic.Dictionary(); + + internal Builder put(K key, V value) { + _values[key] = value; + return this; + } + + internal Map build() { + return ToJava.DictionaryToMap(_values); + } + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs new file mode 100644 index 0000000..4bd2a2a --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs @@ -0,0 +1,21 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.io; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal class PassThroughException : RuntimeException { + internal static T wrap(SupplierWithException supplier) { + try { + return supplier.get(); + } catch (IOException exception) { + throw new PassThroughException(exception); + } + } + + private readonly IOException _exception; + + internal PassThroughException(IOException exception) { + _exception = exception; + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Paths.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Paths.cs new file mode 100644 index 0000000..ca876eb --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Paths.cs @@ -0,0 +1,8 @@ +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Paths { + internal static string getExtension(string path) { + int dotIndex = path.LastIndexOf('.'); + return dotIndex == -1 ? "" : path.Substring(dotIndex + 1); + } + } +} diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Sets.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Sets.cs new file mode 100644 index 0000000..7843537 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Sets.cs @@ -0,0 +1,19 @@ +using Mammoth.Couscous.java.lang; +using Mammoth.Couscous.java.util; +using Mammoth.Couscous.java.nio.file; +using System; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util +{ + internal static class Sets + { + internal static Set set(T[] values) { + return new HashSet(new System.Collections.Generic.HashSet(values)); + } + + internal static Set toSet(Iterable iterable) { + return new HashSet(new System.Collections.Generic.HashSet(FromJava.IterableToEnumerable(iterable))); + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Strings.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Strings.cs new file mode 100644 index 0000000..65f5e0b --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/util/Strings.cs @@ -0,0 +1,18 @@ +using System; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { + internal static class Strings { + internal static string trimLeft(string value, int character) { + int index = 0; + while (index < value.Length && value[index] == character) { + index++; + } + return value.Substring(index); + } + + internal static bool isNullOrEmpty(string value) { + return string.IsNullOrEmpty(value); + } + } +} + diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs b/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs new file mode 100644 index 0000000..8ebdf28 --- /dev/null +++ b/dotnet/Mammoth/Couscous/mammoth/internal/xml/parsing/SimpleSax.cs @@ -0,0 +1,13 @@ +using Mammoth.Couscous.java.io; + +namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.xml.parsing { + internal static class SimpleSax { + internal static void parseStream(InputStream input, SimpleSaxHandler handler) { + throw new System.NotImplementedException(); + } + + internal static void parseString(string value, SimpleSaxHandler handler) { + throw new System.NotImplementedException(); + } + } +} diff --git a/dotnet/Mammoth/Mammoth.csproj b/dotnet/Mammoth/Mammoth.csproj new file mode 100644 index 0000000..ac380f8 --- /dev/null +++ b/dotnet/Mammoth/Mammoth.csproj @@ -0,0 +1,87 @@ + + + + Debug + AnyCPU + {51C5CBD6-8809-4D5E-BABE-1787A16F5ED8} + Library + Mammoth + Mammoth + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet/Mammoth/Properties/AssemblyInfo.cs b/dotnet/Mammoth/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6ef611f --- /dev/null +++ b/dotnet/Mammoth/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("Mammoth")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("mick")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java b/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java index 19af0bc..b60e825 100644 --- a/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java +++ b/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java @@ -173,16 +173,6 @@ public class DocumentToHtml { return list(Html.collapsibleElement("a", attributes, convertChildrenToHtml(hyperlink))); } - private String generateHref(Hyperlink hyperlink) { - if (hyperlink.getHref().isPresent()) { - return hyperlink.getHref().get(); - } else if (hyperlink.getAnchor().isPresent()) { - return "#" + generateId(hyperlink.getAnchor().get()); - } else { - return ""; - } - } - @Override public List visit(Bookmark bookmark) { return list(Html.element("a", map("id", generateId(bookmark.getName())), list(Html.FORCE_WRITE))); @@ -224,6 +214,16 @@ public class DocumentToHtml { }); } + private String generateHref(Hyperlink hyperlink) { + if (hyperlink.getHref().isPresent()) { + return hyperlink.getHref().get(); + } else if (hyperlink.getAnchor().isPresent()) { + return "#" + generateId(hyperlink.getAnchor().get()); + } else { + return ""; + } + } + private String generateNoteHtmlId(NoteType noteType, String noteId) { return generateId(noteTypeToIdFragment(noteType) + "-" + noteId); } diff --git a/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java b/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java index be2cbb9..113578d 100644 --- a/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java +++ b/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java @@ -268,7 +268,7 @@ public class BodyXmlReader { Optional title = element.getAttributeOrNone("o:title"); String relationshipId = element.getAttribute("r:id"); String imagePath = relationshipIdToDocxPath(relationshipId); - return readImage(imagePath, title, () -> DocxFile.getInputStream(file, imagePath)); + return readImage(imagePath, title, () -> DocxFiles.getInputStream(file, imagePath)); } private ReadResult readInline(XmlElement element) { @@ -290,7 +290,7 @@ public class BodyXmlReader { Optional linkRelationshipId = blip.getAttributeOrNone("r:link"); if (embedRelationshipId.isPresent()) { String imagePath = relationshipIdToDocxPath(embedRelationshipId.get()); - return readImage(imagePath, altText, () -> DocxFile.getInputStream(file, imagePath)); + return readImage(imagePath, altText, () -> DocxFiles.getInputStream(file, imagePath)); } else if (linkRelationshipId.isPresent()) { String imagePath = relationships.findRelationshipById(linkRelationshipId.get()).getTarget(); return readImage(imagePath, altText, () -> fileReader.getInputStream(imagePath)); diff --git a/src/main/java/org/zwobble/mammoth/internal/docx/DocxFile.java b/src/main/java/org/zwobble/mammoth/internal/docx/DocxFile.java index 8e73a04..23bddb1 100644 --- a/src/main/java/org/zwobble/mammoth/internal/docx/DocxFile.java +++ b/src/main/java/org/zwobble/mammoth/internal/docx/DocxFile.java @@ -6,10 +6,5 @@ import java.io.InputStream; import java.util.Optional; public interface DocxFile extends Closeable { - static InputStream getInputStream(DocxFile file, String name) throws IOException { - return file.tryGetInputStream(name) - .orElseThrow(() -> new IOException("Missing entry in file: " + name)); - } - Optional tryGetInputStream(String name) throws IOException; } diff --git a/src/main/java/org/zwobble/mammoth/internal/docx/DocxFiles.java b/src/main/java/org/zwobble/mammoth/internal/docx/DocxFiles.java new file mode 100644 index 0000000..5d06b76 --- /dev/null +++ b/src/main/java/org/zwobble/mammoth/internal/docx/DocxFiles.java @@ -0,0 +1,11 @@ +package org.zwobble.mammoth.internal.docx; + +import java.io.IOException; +import java.io.InputStream; + +public class DocxFiles { + static InputStream getInputStream(DocxFile file, String name) throws IOException { + return file.tryGetInputStream(name) + .orElseThrow(() -> new IOException("Missing entry in file: " + name)); + } +} diff --git a/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java b/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java index c76e989..e0cc5b4 100644 --- a/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java +++ b/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java @@ -5,8 +5,8 @@ import org.zwobble.mammoth.internal.xml.XmlElement; import org.zwobble.mammoth.internal.xml.XmlTextNode; import java.io.InputStream; -import java.util.ArrayDeque; -import java.util.Deque; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import static org.zwobble.mammoth.internal.util.Maps.eagerMapKeys; @@ -32,14 +32,14 @@ public class XmlParser { } private class NodeGenerator implements SimpleSaxHandler { - private final Deque elementStack; + private final List elementStack; public NodeGenerator() { - elementStack = new ArrayDeque<>(); + elementStack = new ArrayList<>(); } public XmlElement getRoot() { - return elementStack.getFirst().build(); + return elementStack.get(0).build(); } @Override @@ -63,14 +63,14 @@ public class XmlParser { @Override public void endElement() { if (elementStack.size() > 1) { - XmlElementBuilder element = elementStack.removeLast(); - elementStack.getLast().addChild(element.build()); + XmlElementBuilder element = elementStack.remove(elementStack.size() - 1); + elementStack.get(elementStack.size() - 1).addChild(element.build()); } } @Override public void characters(String string) { - elementStack.getLast().addChild(new XmlTextNode(string)); + elementStack.get(elementStack.size() - 1).addChild(new XmlTextNode(string)); } } } -- cgit v1.2.3