diff --git a/.gitignore b/.gitignore
index 775882d..1395c2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,2 @@
.idea/
out/
-src/testdata/
diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml
index 3a7876b..6e3dc77 100644
--- a/META-INF/plugin.xml
+++ b/META-INF/plugin.xml
@@ -1,7 +1,7 @@
be.wimsymons.intellij.polopolyimport
Polopoly Importer
- 1.4
+ 1.5
Wim Symons
+ 1.5
+ Fixed charset conversion issues
+
1.4
- 1.4 Fixed NullPointerException on IDEA 12
+ Fixed NullPointerException on IDEA 12
1.3
Fixed issue with Guava deprecating Closeables.closeQuietly in Guava 15
@@ -76,4 +79,4 @@ This version keeps state on application-level, not on project level.
-
\ No newline at end of file
+
diff --git a/README.md b/README.md
index cf228d4..6fa9410 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Polopoly Importer Plugin for IntelliJ
-Based on Marc Viane's work (https://github.com/mavicon/intellij-ppimport) and inspiration
-from Johan Rylander's Atex Polopoly plugin for IntelliJ (https://github.com/jrylander/PolopolyIntelliJPlugin).
+Based on Marc Viane's work and inspiration
+from Johan Rylander's Atex Polopoly plugin for IntelliJ .
This plugin is written to simplify import of content XML files into the Polopoly CMS.
@@ -20,6 +20,7 @@ This is different from Johan or Marc's plugin, which store this information sepa
## Change log
+ 1.5 Fixed charset conversion issues
1.4 Fixed NullPointerException on IDEA 12
1.3 Fixed issue with Guava deprecating Closeables.closeQuietly in Guava 15
1.2 Fixed ArrayIndexOutOfBoundsException: 0 when there are no replacements.
@@ -45,22 +46,22 @@ This is different from Johan or Marc's plugin, which store this information sepa
Requires IntelliJ IDEA 11 or later.
-Download the **polopoly-import-1.4.jar** from the **distributable** folder.
+Download the **polopoly-import-1.5.jar** from the **distributable** folder.
1. Start IntelliJ IDEA.
2. Open the plugin manager dialog (**Menu: File > Settings > Plugins**)
3. Click **Install plugin from disk** button to open the **Choose Plugin file** dialog.
-4. Select the **polopoly-import-1.4.jar** file and click **OK** to close the dialog.
+4. Select the **polopoly-import-1.5.jar** file and click **OK** to close the dialog.
5. Click **OK** to close the **Settings** dialog.
6. Restart IntelliJ IDEA.
## Libraries
-This software uses the [Swizzle Stream](http://swizzle.codehaus.org/Swizzle+Stream) library from The Codehaus.
+This software uses parts of distributed under Apache License 2.0.
## Copyright and license
-Copyright 2013 Wim Symons
+Copyright 2016 Wim Symons
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this work except in compliance with the License.
@@ -72,4 +73,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
-limitations under the License.
\ No newline at end of file
+limitations under the License.
diff --git a/distributable/polopoly-import-1.4.jar b/distributable/polopoly-import-1.4.jar
deleted file mode 100644
index da858c1..0000000
Binary files a/distributable/polopoly-import-1.4.jar and /dev/null differ
diff --git a/distributable/polopoly-import-1.5.jar b/distributable/polopoly-import-1.5.jar
new file mode 100644
index 0000000..6eb9200
Binary files /dev/null and b/distributable/polopoly-import-1.5.jar differ
diff --git a/intellij-ppimport.iml b/intellij-ppimport.iml
index 68eb9d2..4dcf428 100644
--- a/intellij-ppimport.iml
+++ b/intellij-ppimport.iml
@@ -6,6 +6,7 @@
+
@@ -17,5 +18,4 @@
-
-
+
\ No newline at end of file
diff --git a/src/main/be/wimsymons/intellij/polopolyimport/PPImporter.java b/src/main/be/wimsymons/intellij/polopolyimport/PPImporter.java
index 97358e0..02c11d7 100644
--- a/src/main/be/wimsymons/intellij/polopolyimport/PPImporter.java
+++ b/src/main/be/wimsymons/intellij/polopolyimport/PPImporter.java
@@ -1,6 +1,6 @@
package be.wimsymons.intellij.polopolyimport;
-import be.wimsymons.intellij.polopolyimport.io.ReplacementsInputStreamBuilder;
+import be.wimsymons.intellij.polopolyimport.io.ReplacementsReaderBuilder;
import com.google.common.base.Strings;
import com.google.common.io.CharStreams;
import com.google.common.io.Closeables;
@@ -11,11 +11,24 @@
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.*;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.TreeSet;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@@ -98,7 +111,7 @@ private void doImportSingleFile(VirtualFile virtualFile) {
try {
dataIS = virtualFile.getInputStream();
String contentType = "text/xml;charset=" + virtualFile.getCharset();
- postData(virtualFile.getName(), wrapWithReplacements(dataIS), contentType, "");
+ postData(virtualFile.getName(), wrapWithReplacements(dataIS, virtualFile.getCharset()), contentType, "");
} catch (IOException e) {
PPImportPlugin.doNotify("Import of " + virtualFile.getName() + " failed: " + e.getMessage(), NotificationType.ERROR);
}
@@ -184,7 +197,7 @@ private void addToJar(JarOutputStream jarOS, VirtualFile file) throws IOExceptio
JarEntry entry = new JarEntry(file.getCanonicalPath());
entry.setTime(file.getTimeStamp());
jarOS.putNextEntry(entry);
- Reader reader = wrapWithReplacements(file.getInputStream());
+ Reader reader = wrapWithReplacements(file.getInputStream(), file.getCharset());
Writer writer = new OutputStreamWriter(jarOS);
try {
CharStreams.copy(reader, writer);
@@ -271,11 +284,11 @@ public boolean processFile(VirtualFile virtualFile) {
return result;
}
- private Reader wrapWithReplacements(InputStream in) {
+ private Reader wrapWithReplacements(InputStream in, Charset charset) {
if (replacements.isEmpty()) {
- return new InputStreamReader(in);
+ return new InputStreamReader(in, charset);
} else {
- return new InputStreamReader(ReplacementsInputStreamBuilder.with(in, replacements));
+ return ReplacementsReaderBuilder.with(new InputStreamReader(in, charset), replacements);
}
}
}
diff --git a/src/main/be/wimsymons/intellij/polopolyimport/io/ReplacementsInputStreamBuilder.java b/src/main/be/wimsymons/intellij/polopolyimport/io/ReplacementsInputStreamBuilder.java
deleted file mode 100644
index 049ac20..0000000
--- a/src/main/be/wimsymons/intellij/polopolyimport/io/ReplacementsInputStreamBuilder.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package be.wimsymons.intellij.polopolyimport.io;
-
-import be.wimsymons.intellij.polopolyimport.Replacement;
-import com.google.common.base.Strings;
-import com.google.common.collect.Maps;
-import org.codehaus.swizzle.stream.ReplaceStringsInputStream;
-
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Builder to wrap a normal inputstream with replacements.
- */
-public class ReplacementsInputStreamBuilder {
-
- public static InputStream with(final InputStream in, final List replacements) {
- Map tokenMap = Maps.newTreeMap();
- for (Replacement replacement : replacements) {
- if (!Strings.isNullOrEmpty(replacement.getSearch())) {
- tokenMap.put(replacement.getSearch(), replacement.getReplacement());
- }
- }
- return new ReplaceStringsInputStream(in, tokenMap);
- }
-
-}
diff --git a/src/main/be/wimsymons/intellij/polopolyimport/io/ReplacementsReaderBuilder.java b/src/main/be/wimsymons/intellij/polopolyimport/io/ReplacementsReaderBuilder.java
new file mode 100644
index 0000000..be5dcc6
--- /dev/null
+++ b/src/main/be/wimsymons/intellij/polopolyimport/io/ReplacementsReaderBuilder.java
@@ -0,0 +1,29 @@
+package be.wimsymons.intellij.polopolyimport.io;
+
+import be.wimsymons.intellij.polopolyimport.Replacement;
+import com.google.common.base.Strings;
+import sdsu.io.StringReplaceReader;
+
+import java.io.Reader;
+import java.util.List;
+
+public class ReplacementsReaderBuilder {
+
+ public static Reader with(final Reader in, final List replacements) {
+ if (replacements.isEmpty()) {
+ return in;
+ } else {
+ StringReplaceReader replaceReader = null;
+ for (Replacement replacement : replacements) {
+ if (!Strings.isNullOrEmpty(replacement.getSearch())) {
+ if (replaceReader == null) {
+ replaceReader = new StringReplaceReader(in, replacement.getSearch(), replacement.getReplacement());
+ } else {
+ replaceReader.replace(replacement.getSearch(), replacement.getReplacement());
+ }
+ }
+ }
+ return replaceReader;
+ }
+ }
+}
diff --git a/src/main/org/codehaus/swizzle/stream/FilteredInputStream.java b/src/main/org/codehaus/swizzle/stream/FilteredInputStream.java
deleted file mode 100644
index a40cc94..0000000
--- a/src/main/org/codehaus/swizzle/stream/FilteredInputStream.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.codehaus.swizzle.stream;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-abstract class FilteredInputStream extends FilterInputStream {
-
- private boolean done = false;
-
- public FilteredInputStream(InputStream in) {
- super(in);
- }
-
- @Override
- public int read(byte[] bytes, int off, int len) throws IOException {
-
- int count = 0;
-
- if (done) {
- return (-1);
- }
-
- for (int i = off, max = off + len; i < max; i++) {
-
- final int read = read();
-
- if (read == -1) {
- done = true;
- return count == 0 ? -1 : count;
- }
-
- bytes[i] = (byte) read;
- count++;
- }
-
- return count;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-}
diff --git a/src/main/org/codehaus/swizzle/stream/FixedTokenListReplacementInputStream.java b/src/main/org/codehaus/swizzle/stream/FixedTokenListReplacementInputStream.java
deleted file mode 100644
index b78dd86..0000000
--- a/src/main/org/codehaus/swizzle/stream/FixedTokenListReplacementInputStream.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- *
- * Copyright 2003 David Blevins
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.codehaus.swizzle.stream;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-
-class FixedTokenListReplacementInputStream extends FilteredInputStream {
-
- private final StreamTokenHandler handler;
- private InputStream value;
- private final ScanBuffer[] tokenBuffers;
- private final ScanBuffer mainBuffer;
-
- public FixedTokenListReplacementInputStream(InputStream in, List tokens, StreamTokenHandler handler) {
- this(in, tokens, handler, true);
- }
-
- public FixedTokenListReplacementInputStream(InputStream in, List tokens, StreamTokenHandler handler, boolean caseSensitive) {
- super(in);
- int largestBuffer = 0;
- tokenBuffers = new ScanBuffer[tokens.size()];
- for (int i = 0; i < tokens.size(); i++) {
- String token = (String) tokens.get(i);
- ScanBuffer buffer = new ScanBuffer(token, caseSensitive);
- tokenBuffers[i] = buffer;
- largestBuffer = (buffer.size() > largestBuffer) ? buffer.size() : largestBuffer;
- }
- this.mainBuffer = new ScanBuffer(largestBuffer);
- this.handler = handler;
- strategy = lookingForToken;
- }
-
- private StreamReadingStrategy strategy;
-
- public int read() throws IOException {
- return strategy._read();
- }
-
- // reading url (looking for end)
- // flushing url
- // regular read (looking for begin)
- interface StreamReadingStrategy {
- int _read() throws IOException;
- }
-
- private final StreamReadingStrategy flushingValue = new StreamReadingStrategy() {
- public int _read() throws IOException {
- int i = value.read();
- if (i == -1) {
- strategy = lookingForToken;
- i = read();
- }
- return i;
- }
- };
-
- private final StreamReadingStrategy flushingMainBuffer = new StreamReadingStrategy() {
- public int _read() throws IOException {
- int buffer = mainBuffer.append(-1);
-
- if (buffer != -1) {
- return buffer;
- } else if (mainBuffer.hasData()) {
- return _read();
- } else {
- strategy = flushingValue;
- return read();
- }
- }
- };
-
- private final StreamReadingStrategy lookingForToken = new StreamReadingStrategy() {
- public int _read() throws IOException {
- int stream = superRead();
- int buffer = mainBuffer.append(stream);
-
- for (ScanBuffer tokenBuffer : tokenBuffers) {
- tokenBuffer.append(stream);
-
- if (tokenBuffer.match()) {
- clearAllBuffers();
-
- String token = tokenBuffer.getScanString();
- mainBuffer.clear(token.length());
-
- value = handler.processToken(token);
-
- if (mainBuffer.hasData()) {
- strategy = flushingMainBuffer;
- } else {
- strategy = flushingValue;
- }
-
- return (buffer != -1) ? buffer : read();
- }
- }
-
- // Have we just started?
-
- // The buffer starts out in -1 state. If the
- // data coming from the stream is valid, we
- // need to just keep reading till the buffer
- // gives us good data.
- return (buffer == -1 && mainBuffer.hasData()) ? _read() : buffer;
- }
- };
-
- private void clearAllBuffers() {
- for (ScanBuffer tokenBuffer : tokenBuffers) {
- tokenBuffer.flush();
- }
- }
-
- private int superRead() throws IOException {
- return super.read();
- }
-}
diff --git a/src/main/org/codehaus/swizzle/stream/MappedTokenHandler.java b/src/main/org/codehaus/swizzle/stream/MappedTokenHandler.java
deleted file mode 100644
index 29a09ac..0000000
--- a/src/main/org/codehaus/swizzle/stream/MappedTokenHandler.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- *
- * Copyright 2003 David Blevins
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.codehaus.swizzle.stream;
-
-import java.util.Map;
-
-public class MappedTokenHandler extends StringTokenHandler {
-
- private final Map entries;
-
- public MappedTokenHandler(Map entries) {
- this.entries = entries;
- }
-
- public String handleToken(String token) {
- return entries.get(token);
- }
-}
diff --git a/src/main/org/codehaus/swizzle/stream/ReplaceStringsInputStream.java b/src/main/org/codehaus/swizzle/stream/ReplaceStringsInputStream.java
deleted file mode 100644
index 669630e..0000000
--- a/src/main/org/codehaus/swizzle/stream/ReplaceStringsInputStream.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- *
- * Copyright 2003 David Blevins
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.codehaus.swizzle.stream;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Map;
-
-public class ReplaceStringsInputStream extends FixedTokenListReplacementInputStream {
-
- public ReplaceStringsInputStream(InputStream in, Map tokenMap) {
- super(in, new ArrayList(tokenMap.keySet()), new MappedTokenHandler(tokenMap));
- }
-
-}
diff --git a/src/main/org/codehaus/swizzle/stream/ScanBuffer.java b/src/main/org/codehaus/swizzle/stream/ScanBuffer.java
deleted file mode 100755
index a41659e..0000000
--- a/src/main/org/codehaus/swizzle/stream/ScanBuffer.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/**
- *
- * Copyright 2001 David Blevins
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.codehaus.swizzle.stream;
-
-class ScanBuffer {
-
- private char[] buffer = new char[0];
- private int[] buffer2 = new int[0];
- private char[] token = new char[0];
- private int pos;
-
- boolean cs;
-
- public ScanBuffer(String scanString) {
- this(scanString, false);
- }
-
- public ScanBuffer(int size) {
- buffer = new char[size];
- buffer2 = new int[size];
- token = new char[size];
- flush();
- cs = true;
- }
-
- public ScanBuffer(String scanString, boolean caseSensitive) {
- this(scanString.length());
- setScanString(scanString, caseSensitive);
- }
-
- public int size() {
- return buffer.length;
- }
-
- public String toString() {
- return getClass().getSimpleName() + "#" + getScanString() + " # buffer[" + new String(getBuffer()) + "]";
- }
-
- public void resetPosition() {
- pos = 0;
- }
-
- public String getScanString() {
- return new String(token);
- }
-
- public void setScanString(String stringToken) {
- setScanString(stringToken, true);
- }
-
- public void setScanString(String stringToken, boolean caseSensitive) {
- cs = caseSensitive;
- // Optimize - no need to recreate char array everytime
- token = new char[stringToken.length()];
- stringToken.getChars(0, token.length, token, 0);
-
- if (token.length > buffer.length) {
- buffer = new char[token.length * 4];
- buffer2 = new int[token.length * 4];
- }
-
- pos = 0;
- if (!cs) for (int i = 0; i < token.length; i++)
- token[i] = Character.toLowerCase(token[i]);
-
- flush();
- }
-
- public int append(int newByte) {
- int old = buffer2[pos];
-
- buffer2[pos] = newByte;
- buffer[pos] = (cs) ? (char) newByte : Character.toLowerCase((char) newByte);
-
- pos = (++pos < buffer.length) ? pos : 0;
- return old;
- }
-
- public void flush() {
- char NULL = (char) -1;
- for (int i = 0; i < buffer.length; i++) {
- buffer[i] = NULL;
- buffer2[i] = -1;
- }
- resetPosition();
- }
-
- public boolean match() {
-
- // Absolute position (apos) is the number of characters actually
- // searched.
- // This number should never exceed the length of the token.
- int apos = token.length - 1;
-
- // The relative position indicates where we are on the buffer.
- // It is possible to reach the end of the buffer before we are
- // finished searching enough characters. In this contition we
- // wrap to the beginning of the buffer and continue matching
- // the remaining chars of the token array against the buffer.
- int rpos = pos - 1;
-
- // We start the search, possibly from the middle of the buffer,
- // and go as far as we can. We will either come to the end of the
- // token or the end of the buffer. If we come to the end of the
- // buffer the next for loop wil naturally pick up at the beginning
- // of the buffer and continue matching where we left off in the
- // token array.
- for (; rpos > -1 && apos > -1; rpos--, apos--) {
- if (buffer[rpos] != token[apos]) return false;
- }
- for (rpos = buffer.length - 1; apos > -1; rpos--, apos--) {
- if (buffer[rpos] != token[apos]) return false;
- }
- // for (; rpos < buffer.length && apos < token.length; rpos++, apos++) {
- // if (buffer[rpos] != token[apos]) return false;
- // }
- // for (rpos = 0; apos < token.length; rpos++, apos++ ) {
- // if (buffer[rpos] != token[apos]) return false;
- // }
-
- return true;
- }
-
- public boolean hasData() {
- int apos = token.length - 1;
- int rpos = pos - 1;
- for (; rpos > -1 && apos > -1; rpos--, apos--) {
- if (buffer2[rpos] != -1) return true;
- }
- for (rpos = buffer2.length - 1; apos > -1; rpos--, apos--) {
- if (buffer2[rpos] != -1) return true;
- }
- return false;
- }
-
- private void log(String str) {
- System.out.println("[Scan] " + str);
- }
-
- public void clear(int i) {
- char NULL = (char) -1;
-
- // Absolute position (apos) is the number of characters actually
- // searched.
- // This number should never exceed the length of the token.
- int apos = i - 1;
-
- // The relative position indicates where we are on the buffer.
- // It is possible to reach the end of the buffer before we are
- // finished searching enough characters. In this contition we
- // wrap to the beginning of the buffer and continue matching
- // the remaining chars of the token array against the buffer.
- int rpos = pos - 1;
-
- // We start the search, possibly from the middle of the buffer,
- // and go as far as we can. We will either come to the end of the
- // token or the end of the buffer. If we come to the end of the
- // buffer the next for loop wil naturally pick up at the beginning
- // of the buffer and continue matching where we left off in the
- // token array.
- for (; rpos > -1 && apos > -1; rpos--, apos--) {
- buffer[rpos] = NULL;
- buffer2[rpos] = -1;
- }
- for (rpos = buffer.length - 1; apos > -1; rpos--, apos--) {
- buffer[rpos] = NULL;
- buffer2[rpos] = -1;
- }
- }
-
- public byte[] getBuffer() {
- byte[] out = new byte[getSize()];
- for (int i = 0; i < out.length; i++) {
- out[i] = (byte) getByte(buffer.length - out.length + i);
- }
- return out;
- }
-
- /**
- * The current size of the buffer. The number of non -1 items in the buffer.
- */
- private int getSize() {
- int size = 0;
- for (int i = buffer.length - 1; i >= 0; i--) {
- int b = getByte(i);
- if (b != -1) {
- size++;
- } else {
- break;
- }
- }
- return size;
- }
-
- /**
- * Gets the byte at the specified absolute positon
- */
- private int getByte(int absolutePosition) {
- if (absolutePosition >= buffer.length) {
- throw new IndexOutOfBoundsException();
- }
- int realPosition = (pos + absolutePosition) % buffer.length;
- return buffer2[realPosition];
- }
-}
diff --git a/src/main/org/codehaus/swizzle/stream/StreamTokenHandler.java b/src/main/org/codehaus/swizzle/stream/StreamTokenHandler.java
deleted file mode 100644
index d61e8ec..0000000
--- a/src/main/org/codehaus/swizzle/stream/StreamTokenHandler.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- *
- * Copyright 2003 David Blevins
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.codehaus.swizzle.stream;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public interface StreamTokenHandler {
- public InputStream processToken(String token) throws IOException;
-}
diff --git a/src/main/org/codehaus/swizzle/stream/StringTokenHandler.java b/src/main/org/codehaus/swizzle/stream/StringTokenHandler.java
deleted file mode 100644
index 4985bec..0000000
--- a/src/main/org/codehaus/swizzle/stream/StringTokenHandler.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- *
- * Copyright 2003 David Blevins
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.codehaus.swizzle.stream;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-public abstract class StringTokenHandler implements StreamTokenHandler {
-
- public abstract String handleToken(String token) throws IOException;
-
- public final InputStream processToken(String token) throws IOException {
- String result = handleToken(token);
- result = (result != null) ? result : "null";
- return new ByteArrayInputStream(result.getBytes());
- }
-
-}
diff --git a/src/main/sdsu/io/StringReplaceReader.java b/src/main/sdsu/io/StringReplaceReader.java
new file mode 100644
index 0000000..31f0ae6
--- /dev/null
+++ b/src/main/sdsu/io/StringReplaceReader.java
@@ -0,0 +1,415 @@
+/*
+ * Copyright (C) 1997 Roger Whitney
+ *
+ * This file is part of the San Diego State University Java Library.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package sdsu.io;
+
+import sdsu.util.CharQueue;
+
+import java.io.BufferedReader;
+import java.io.FilterReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+
+/**
+ * Given a string pattern, a string replacementPattern and
+ * an input stream, this
+ * class will replace all occurances of pattern with
+ * replacementPattern in the inputstream. You can give multiple
+ * pattern-replacementPattern pairs. Multiple pairs are done in order
+ * they are given.
+ * If first pair is "cat"-"dog" and second pair is "dog"-"house", then
+ * the result will
+ * be all occurences of "cat" or "dog" will be replaced with "house".
+ *
+ * @version 0.6 21 August 1997
+ * @since version 0.5, Fixed error that occured when input was shorter
+ * than the pattern
+ * @author Roger Whitney
+ * (whitney@cs.sdsu.edu)
+ */
+
+public class StringReplaceReader extends FilterReader implements Cloneable
+{
+ protected CharQueue outputBuffer; // holds filtered data
+ protected char[] inputBuffer;
+ protected int[] shiftTable; // quick search shift table
+ protected int inputBufferCharCount; // number of chars in inputBuffer
+
+ protected char[] patternToFind = null;
+ protected char[] replacementPattern = null;
+
+ protected boolean reachedEOF = false;
+ protected static int EOFIndicator = -1;
+ protected static int DEFAULT_BUFFER_SIZE = 1024;
+
+ /**
+ * Create an StringReplaceReader object that will replace all
+ * occurrences ofpattern with replacementPattern in the Reader in.
+ */
+ public StringReplaceReader( Reader in,
+ String pattern,
+ String replacementPattern )
+ {
+ super( in );
+ patternToFind = pattern.toCharArray();
+ this.replacementPattern = replacementPattern.toCharArray();
+
+ allocateBuffers();
+ }
+
+ /**
+ * Create an StringReplaceReader object that will replace all
+ * occurrences of pattern with replacementPattern in the inputstream in.
+ */
+ public StringReplaceReader( InputStream in,
+ String pattern,
+ String replacementPattern )
+ {
+ this( new BufferedReader(new InputStreamReader(in)),
+ pattern,
+ replacementPattern );
+ }
+
+ /**
+ * Create an StringReplaceReader object that will replace all
+ * occurrences of pattern with replacementPattern in the string input.
+ */
+ public StringReplaceReader( String input,
+ String pattern,
+ String replacementPattern )
+ {
+ this( new StringReader( input) , pattern, replacementPattern );
+ }
+
+
+ /**
+ * Returns the entire contents of the input stream.
+ */
+ public String contents() throws IOException
+ {
+ StringBuffer contents = new StringBuffer( 1024 );
+ int readSize = 512;
+
+ char[] filteredChars = new char[readSize];
+ int charsRead = read( filteredChars, 0, readSize);
+
+ while ( charsRead != EOFIndicator)
+ {
+ contents.append( filteredChars, 0, charsRead );
+ charsRead = read( filteredChars, 0, readSize);
+ }
+
+ return contents.toString();
+ }
+
+ /**
+ * Adds another pattern-replacementPattern pair.
+ * All occurrences of pattern will be replaced with replacementPattern.
+ * @exception OutOfMemoryError if there is not enough memory to add new
+ * pattern-replacementPattern pair
+ */
+ public void replace( String pattern, String replacementPattern )
+ throws OutOfMemoryError
+ {
+ // Chain StringReplaceReader objects. Clone current object
+ // add clone to input stream to insure it filters before this
+ // object, which gets the new pattern-replacement pair
+ if ( patternToFind != null )
+ {
+ // Replace this with clone
+ try
+ {
+ StringReplaceReader currentReplace =
+ (StringReplaceReader) this.clone();
+ in = currentReplace;
+ }
+ catch (CloneNotSupportedException x)
+ {
+ }
+ }
+ patternToFind = pattern.toCharArray();
+ this.replacementPattern = replacementPattern.toCharArray();
+ allocateBuffers();
+
+ reachedEOF = false;
+ }
+
+ /**
+ * Read characters into a portion of an array.
+ * This method will block until some input is available, an I/O error
+ * occurs, or the end of the stream is reached.
+ * @parm buffer Destination buffer
+ * @parm offset location in buffer to start storing characters
+ * @parm charsToRead maximum characters to read
+ * @return number of characters actually read, -1 if reah EOF on reading
+ * first character
+ * @exception IOException if an I/O error occurs
+ */
+ public int read( char[] buffer, int offset, int charsToRead )
+ throws IOException
+ {
+ int charsRead = 0;
+
+ while (( charsRead < charsToRead) && ( !eof() ))
+ {
+ if (outputBuffer.isEmpty() )
+ {
+ fillInputWindow();
+ filterInput();
+ }
+ charsRead += outputBuffer.dequeue(buffer,
+ offset + charsRead,
+ charsToRead - charsRead);
+ }
+ if ( charsRead > 0 )
+ return charsRead;
+ else if ( outputBuffer.size() > 0 )
+ {
+ charsRead = outputBuffer.dequeue(buffer, offset , charsToRead );
+ return charsRead;
+ }
+ else if ( ( eof() ) &&
+ ( inputBufferCharCount > 0 ) &&
+ ( inputBufferCharCount < patternToFind.length)
+ )
+ {
+ // remaining input is less than length of pattern
+ transferRemainingInputToOutputBuffer();
+ System.out.println( ">> End << " + outputBuffer );
+ charsRead = outputBuffer.dequeue(buffer, offset, charsToRead);
+ return charsRead;
+ }
+ else if ( eof() )
+ return EOFIndicator;
+ else
+ // this should never happen
+ throw new IOException("Read attempted. Did not reach EOF and " +
+ " no chars were read");
+ }
+
+ /**
+ * Call when remaining input is less than the pattern size, so pattern
+ * can not exist in remaining input. Just shift all input to output.
+ * Assumes that have reached EOF and inputBufferCharCount < patternToFind.length
+ */
+ private void transferRemainingInputToOutputBuffer()
+ {
+ outputBuffer.enqueue( inputBuffer, 0, inputBufferCharCount );
+ inputBufferCharCount = 0;
+ }
+
+ /**
+ * Returns the next character in the inputstream with
+ * string replacement done.
+ * @exception IOException if error occurs reading io stream
+ */
+ public int read() throws IOException
+ {
+ char[] output = new char[1];
+ int charsRead = read( output, 0, 1);
+ if ( charsRead == EOFIndicator )
+ return EOFIndicator;
+ else if ( charsRead == 1 )
+ return output[0];
+ else
+ throw new IOException("Single Read attempted. Did not reach EOF and " +
+ " no chars were read");
+
+ }
+
+ /**
+ * Determines if a previous ASCII I/O operation caught End Of File.
+ * @return true if end of file was reached.
+ */
+ public boolean eof()
+ {
+ return reachedEOF;
+ }
+
+ /**
+ * Read inpout to see if we have found the pattern.
+ * Requires: When this is called we have already have
+ * read first character in pattern.
+ * Side Effects: After attempt to find pattern, output
+ * buffer contains either the replacement pattern or all characters
+ * we konw are not part of pattern.
+ */
+ protected void filterInput() throws IOException
+ {
+ // Use quick-search to find pattern. Fill inputBuffer with text.
+ // Process all text in inputBuffer. Place processed text in
+ // outputBuffer.
+
+ int searchStart = 0;
+ int windowStart = 0;
+ int patternLength = patternToFind.length;
+
+ // Search until pattern extends past end of inputBuffer
+ while ( searchStart < inputBufferCharCount - patternLength + 1 )
+ {
+ boolean foundPattern = true;
+
+ // The search
+ for ( int index = 0; index < patternLength; index++ )
+ if ( patternToFind[index] != inputBuffer[index + searchStart] )
+ {
+ foundPattern = false;
+ break; // for loop
+ }
+
+ if ( foundPattern )
+ {
+ // move text before pattern
+ outputBuffer.enqueue( inputBuffer,
+ windowStart,
+ searchStart - windowStart);
+
+ replacementPatternToBuffer();
+ windowStart = searchStart + patternLength;
+ searchStart = windowStart;
+ }
+ else
+ {
+ // look farther along in inputBuffer
+ int charLocationAfterPattern = searchStart+ patternLength;
+
+ if ( charLocationAfterPattern >= inputBufferCharCount )
+ searchStart += 1;
+ else
+ searchStart +=
+ getShift( inputBuffer[ charLocationAfterPattern] );
+ }
+ }
+
+ if (searchStart > inputBufferCharCount)
+ searchStart = inputBufferCharCount;
+
+ //move chars already searched
+ if ( reachedEOF )
+ {
+ outputBuffer.enqueue( inputBuffer,
+ windowStart,
+ inputBufferCharCount - windowStart);
+ inputBufferCharCount = 0;
+ }
+ else
+ {
+ outputBuffer.enqueue( inputBuffer,
+ windowStart,
+ searchStart - windowStart);
+ System.arraycopy( inputBuffer,
+ searchStart,
+ inputBuffer,
+ 0,
+ inputBufferCharCount - searchStart);
+
+ inputBufferCharCount = inputBufferCharCount - searchStart;
+ }
+ }
+
+
+ /**
+ * Fill sliding input window with chars from input
+ * Read until window is full or reach EOF
+ */
+ final protected void fillInputWindow() throws IOException
+ {
+ int charsToRead = inputBuffer.length - inputBufferCharCount;
+
+ int firstEmptySlotInWindow = inputBufferCharCount;
+
+ int charsRead = in.read( inputBuffer,
+ firstEmptySlotInWindow,
+ charsToRead );
+
+ if (charsRead == charsToRead) //full read
+ {
+ inputBufferCharCount = inputBufferCharCount + charsRead;
+ charsToRead = 0;
+ }
+ else if (charsRead > 0 ) //parial read
+ {
+ inputBufferCharCount = inputBufferCharCount + charsRead;
+ charsToRead = charsToRead - charsRead;
+
+ }
+ else if (charsRead == EOFIndicator)
+ {
+ reachedEOF = true;
+ }
+ else
+ throw new IOException("Read attempted. Did not reach EOF and " +
+ " no chars were read");
+
+ }
+
+
+ /**
+ * Return the number of positions we can shift pattern when
+ * findMyShift is character in inputBuffer after the pattern
+ */
+ protected int getShift( char findMyShift )
+ {
+ if ( findMyShift >= shiftTable.length )
+ return 1;
+ else
+ return shiftTable[ findMyShift];
+ }
+
+ /**
+ * Put replacement pattern in output buffer.
+ * Subclass overrides for more complex replacement
+ */
+ protected void replacementPatternToBuffer()
+ {
+ outputBuffer.enqueue( replacementPattern );
+ }
+
+ private void allocateBuffers()
+ {
+ outputBuffer = new CharQueue( DEFAULT_BUFFER_SIZE );
+
+ inputBuffer = new char[ Math.max( patternToFind.length + 1,
+ DEFAULT_BUFFER_SIZE
+ )
+ ];
+ inputBufferCharCount = 0;
+ // allocate for most ascii characters
+ shiftTable = new int[126];
+
+ // build shiftTable for quick search
+ // Entry for character X contains how far to shift
+ // pattern when pattern does not match text and
+ // character X is the character in text after end of
+ // pattern
+
+ // Default for characters not in pattern
+ for (int k = 0; k < shiftTable.length; k++)
+ shiftTable[k] = patternToFind.length + 1;
+
+ for (int k = 0; k < patternToFind.length; k++ )
+ if (patternToFind[k] < shiftTable.length )
+ shiftTable[ patternToFind[k]] = patternToFind.length - k;
+ }
+
+} // end class
diff --git a/src/main/sdsu/util/CharQueue.java b/src/main/sdsu/util/CharQueue.java
new file mode 100644
index 0000000..d57405f
--- /dev/null
+++ b/src/main/sdsu/util/CharQueue.java
@@ -0,0 +1,302 @@
+/*
+ * Copyright (C) 1997 Roger Whitney
+ *
+ * This file is part of the San Diego State University Java Library.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package sdsu.util;
+
+/**
+ * This class implements a characater queue. Yes the JKD does contain
+ * a general queue. However that queue operates on objects. This queue
+ * just handles char elements. Use in IO operations where converting
+ * chars to objects will be too expensive.
+ * @version 1.0 21 August 1997
+ * @author Roger Whitney (whitney@cs.sdsu.edu)
+ */
+
+final public class CharQueue
+ {
+ /* Class invariant,
+ * queueRear is the location the next queue item should be placed
+ * If the queue is not empty, queueFront is the location of the first item
+ * in the queue
+ */
+
+ private char[] queueElements;
+ private int queueFront;
+ private int queueRear;
+ private int elementCount; // number of elements in the queue
+
+ public static final int DEFAULT_QUEUE_SIZE = 256;
+
+ public CharQueue( int Size )
+ {
+ queueElements = new char[ Size ];
+ queueFront = 0;
+ queueRear = 0;
+ elementCount = 0;
+ }
+
+ public CharQueue( )
+ {
+ this( DEFAULT_QUEUE_SIZE );
+ }
+
+ /**
+ * Returns the current number of locations for chars in queue
+ */
+ public int capacity()
+ {
+ return queueElements.length;
+ }
+
+ /**
+ * Returns true if the queue is empty
+ */
+ public boolean isEmpty()
+ {
+ if ( elementCount == 0 )
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Returns true if the queue is full
+ */
+ public boolean isFull()
+ {
+ if ( elementCount >= capacity() )
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Returns the number of chars in the queue
+ */
+ public int size()
+ {
+ return elementCount;
+ }
+
+ /**
+ * Returns string representation of the queue
+ */
+ public String toString()
+ {
+ StringBuffer queueString = new StringBuffer( elementCount );
+ if ( queueFront < queueRear )
+ {
+ queueString.append( queueElements, queueFront, elementCount);
+ }
+ else
+ {
+ int elementsFromFrontToEnd = capacity() - queueFront;
+ queueString.append( queueElements, queueFront, elementsFromFrontToEnd);
+ queueString.append( queueElements, 0, queueRear);
+ }
+
+ return queueString.toString();
+ }
+
+ /**
+ * Returns the current number of unused locations in the queue
+ */
+ public int unusedCapacity()
+ {
+ return capacity() - size();
+ }
+
+ /**
+ * Removes front char from the queue and returns the char
+ */
+ public char dequeue( )
+ {
+ char itemRemoved = queueElements[ queueFront ];
+ queueFront = ( queueFront + 1 ) % capacity();
+ elementCount--;
+ return itemRemoved;
+ }
+
+ /**
+ * Fills charsRemoved with chars removed from the queue. If charsRemoved is
+ * larger than queue then charsRemoved is not completely filled
+ * @return actual number of chars put in charsRemoved
+ */
+ public int dequeue( char[] charsRemoved )
+ {
+ return dequeue( charsRemoved, 0, charsRemoved.length );
+ }
+
+ /**
+ * Places chars from queue in charsRemoved starting at charsRemoved[offset].
+ * Will place numCharsRequested into charsRemoved if queue has enougth chars.
+ * @return actual number of chars put in charsRemoved
+ */
+ public int dequeue( char[] charsRemoved, int offset, int numCharsRequested )
+ {
+ // Don't return more chars than are in the queue
+ int numCharsToReturn = Math.min( numCharsRequested, elementCount);
+
+ int numCharsAtEnd = capacity() - queueFront;
+
+ // Are there enough characters after front pointer?
+ if ( numCharsAtEnd >= numCharsToReturn )
+ {
+ // arraycopy is about 20 times faster than coping element by element
+ System.arraycopy( queueElements, queueFront, charsRemoved, offset, numCharsToReturn );
+ }
+ else
+ {
+ // Handle wrap around
+ System.arraycopy( queueElements, queueFront, charsRemoved, offset, numCharsAtEnd );
+ System.arraycopy( queueElements, 0, charsRemoved, offset + numCharsAtEnd,
+ numCharsToReturn - numCharsAtEnd );
+ }
+
+ queueFront = ( queueFront + numCharsToReturn ) % capacity();
+ elementCount = elementCount - numCharsToReturn;
+ return numCharsToReturn;
+ }
+
+ /**
+ * Returns an array containing all chars in the queue. Afterwards queue is empty.
+ */
+ public char[] dequeueAll( )
+ {
+ char[] contents = new char[ elementCount ];
+ dequeue( contents );
+ return contents;
+ }
+
+ /**
+ * Returns the front char from the queue without removing it
+ */
+ public char peek()
+ {
+ return queueElements[ queueFront ];
+ }
+
+ /**
+ * Adds charToAdd to the end of the queue
+ */
+ public void enqueue( char charToAdd )
+ {
+ if ( isFull() )
+ grow();
+
+ queueElements[ queueRear] = charToAdd;
+ queueRear = ( queueRear + 1 ) % capacity();
+ elementCount++;
+ }
+
+ /**
+ * Adds charsToAdd to the end of the queue
+ */
+ public void enqueue( String charsToAdd )
+ {
+ enqueue( charsToAdd.toCharArray() );
+ }
+
+ /**
+ * Adds all elements of charsToAdd to the end of the queue
+ */
+ public void enqueue( char[] charsToAdd )
+ {
+ enqueue( charsToAdd, 0, charsToAdd.length );
+ }
+
+ /**
+ * Adds numCharsToAdd elements of charsToAdd, starting with charsToAdd[offset]
+ * to the end of the queue
+ */
+ public void enqueue( char[] charsToAdd, int offset, int numCharsToAdd )
+ {
+ if ( numCharsToAdd > unusedCapacity() )
+ grow( Math.max( numCharsToAdd + 32, capacity() * 2 ) );
+ // 32 to insure some spare capacity after growing
+
+ int numSpacesAtEnd = capacity() - queueRear;
+
+ // Are there enough spaces after rear pointer?
+ if ( numSpacesAtEnd >= numCharsToAdd )
+ {
+ System.arraycopy( charsToAdd, offset, queueElements, queueRear, numCharsToAdd );
+ }
+ else // Handle wrap around
+ {
+ System.arraycopy( charsToAdd, offset, queueElements, queueRear, numSpacesAtEnd );
+ System.arraycopy( charsToAdd, offset + numSpacesAtEnd, queueElements, 0,
+ numCharsToAdd - numSpacesAtEnd);
+ }
+
+ queueRear = ( queueRear + numCharsToAdd ) % capacity();
+ elementCount = elementCount + numCharsToAdd;
+ }
+
+
+ /**
+ * Clears the queue so it has no more elements in it
+ */
+ public void clear()
+ {
+ queueFront = 0;
+ queueRear = 0;
+ elementCount = 0;
+ }
+
+
+ /**
+ * Grows the queue. Growth policy insures amortized cost per insert is O(1)
+ */
+ private void grow()
+ {
+ // Doubling queue insures that amortized cost per insert is O(1)
+ if ( capacity() <= 16 )
+ grow( 32 );
+ else if ( capacity() <= 1024 )
+ grow( capacity() * 2 );
+ else
+ grow( (int) (capacity() * 1.5) );
+ }
+
+ /**
+ * Grows the queue to the given new size
+ */
+ private void grow( int newSize )
+ {
+ char[] newQueue = new char[ newSize ];
+
+ if ( queueFront < queueRear )
+ {
+ System.arraycopy( queueElements, queueFront, newQueue, 0, elementCount);
+ }
+ else
+ {
+ int elementsFromFrontToEnd = capacity() - queueFront;
+ System.arraycopy( queueElements, queueFront, newQueue, 0, elementsFromFrontToEnd);
+ System.arraycopy( queueElements, 0, newQueue, elementsFromFrontToEnd, queueRear);
+ }
+
+ queueElements = newQueue;
+ queueFront = 0;
+ queueRear = elementCount;
+ }
+
+ }
diff --git a/src/test/be/wimsymons/intellij/polopolyimport/io/ReplacementsInputStreamBuilderTest.java b/src/test/be/wimsymons/intellij/polopolyimport/io/ReplacementsInputStreamBuilderTest.java
deleted file mode 100644
index e60b3c3..0000000
--- a/src/test/be/wimsymons/intellij/polopolyimport/io/ReplacementsInputStreamBuilderTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package be.wimsymons.intellij.polopolyimport.io;
-
-import be.wimsymons.intellij.polopolyimport.Replacement;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-import com.google.common.io.CharStreams;
-import com.google.common.io.Closeables;
-import org.junit.Test;
-
-import java.io.*;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Test for {@link ReplacementsInputStreamBuilder}.
- *
- * @author Wim Symons
- */
-public class ReplacementsInputStreamBuilderTest {
-
- @Test
- public void testNoReplace() throws IOException {
- List replacements = Collections.emptyList();
- String originalString = "R.I.P. James Gandolfini.";
-
- String actual = doReplace(originalString, replacements);
-
- assertEquals("R.I.P. James Gandolfini.", actual);
- }
-
- @Test
- public void testSimpleReplace() throws IOException {
- List replacements = ImmutableList.of(new Replacement("James Gandolfini", "Tony Soprano"));
- String originalString = "R.I.P. James Gandolfini.";
-
- String actual = doReplace(originalString, replacements);
-
- assertEquals("R.I.P. Tony Soprano.", actual);
- }
-
- @Test
- public void testReplaceMultipleInstances() throws IOException {
- List replacements = ImmutableList.of(new Replacement("abc", "xyz"));
- String originalString = "abcdefabcdefabcdef";
-
- String actual = doReplace(originalString, replacements);
-
- assertEquals("xyzdefxyzdefxyzdef", actual);
- }
-
- @Test
- public void testReplaceLargeBuffer() throws IOException {
- List replacements = ImmutableList.of(new Replacement("0123456789", ""));
- String originalString = Strings.repeat("0123456789ABCDEF", 256);
-
- String actual = doReplace(originalString, replacements);
-
- assertEquals(Strings.repeat("ABCDEF", 256), actual);
- }
-
- @Test
- public void testMultipleReplace() throws IOException {
- List replacements = ImmutableList.of(
- new Replacement("{author}", "Wim Symons"),
- new Replacement("{date}", "21-07-2013")
- );
- String originalString = "This example was coded by {author} on {date}.";
-
- String actual = doReplace(originalString, replacements);
-
- assertEquals("This example was coded by Wim Symons on 21-07-2013.", actual);
- }
-
- private String doReplace(String originalString, List replacements) throws IOException {
- Reader reader = null;
- StringWriter writer = null;
- ByteArrayInputStream in = null;
- String actual;
- try {
- in = new ByteArrayInputStream(originalString.getBytes());
- if (replacements.isEmpty()) {
- reader = new InputStreamReader(in);
- } else {
- reader = new InputStreamReader(ReplacementsInputStreamBuilder.with(in, replacements));
- }
- writer = new StringWriter();
- CharStreams.copy(reader, writer);
- actual = writer.toString();
- } finally {
- Closeables.close(reader, true);
- Closeables.close(in, true);
- Closeables.close(writer, true);
- }
- return actual;
- }
-
-}
diff --git a/src/test/be/wimsymons/intellij/polopolyimport/io/ReplacementsReaderBuilderTest.java b/src/test/be/wimsymons/intellij/polopolyimport/io/ReplacementsReaderBuilderTest.java
new file mode 100644
index 0000000..5305d7c
--- /dev/null
+++ b/src/test/be/wimsymons/intellij/polopolyimport/io/ReplacementsReaderBuilderTest.java
@@ -0,0 +1,127 @@
+package be.wimsymons.intellij.polopolyimport.io;
+
+import be.wimsymons.intellij.polopolyimport.Replacement;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+import com.google.common.io.CharStreams;
+import com.google.common.io.Closeables;
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for {@link ReplacementsReaderBuilder}.
+ *
+ * @author Wim Symons
+ */
+public class ReplacementsReaderBuilderTest {
+
+ @Test
+ public void testNoReplace() throws IOException {
+ List replacements = Collections.emptyList();
+ String originalString = "R.I.P. James Gandolfini.";
+
+ String actual = doReplace(originalString, replacements);
+
+ assertEquals("R.I.P. James Gandolfini.", actual);
+ }
+
+ @Test
+ public void testSimpleReplace() throws IOException {
+ List replacements = ImmutableList.of(new Replacement("James Gandolfini", "Tony Soprano"));
+ String originalString = "R.I.P. James Gandolfini.";
+
+ String actual = doReplace(originalString, replacements);
+
+ assertEquals("R.I.P. Tony Soprano.", actual);
+ }
+
+ @Test
+ public void testReplaceMultipleInstances() throws IOException {
+ List replacements = ImmutableList.of(new Replacement("abc", "xyz"));
+ String originalString = "abcdefabcdefabcdef";
+
+ String actual = doReplace(originalString, replacements);
+
+ assertEquals("xyzdefxyzdefxyzdef", actual);
+ }
+
+ @Test
+ public void testReplaceLargeBuffer() throws IOException {
+ List replacements = ImmutableList.of(new Replacement("0123456789", ""));
+ String originalString = Strings.repeat("0123456789ABCDEF", 256);
+
+ String actual = doReplace(originalString, replacements);
+
+ assertEquals(Strings.repeat("ABCDEF", 256), actual);
+ }
+
+ @Test
+ public void testMultipleReplace() throws IOException {
+ List replacements = ImmutableList.of(
+ new Replacement("{author}", "Wim Symons"),
+ new Replacement("{date}", "21-07-2013")
+ );
+ String originalString = "This example was coded by {author} on {date}.";
+
+ String actual = doReplace(originalString, replacements);
+
+ assertEquals("This example was coded by Wim Symons on 21-07-2013.", actual);
+ }
+
+ @Test
+ public void doFileReplacements() throws IOException {
+ Reader in = null;
+ Reader replacementsReader = null;
+ StringWriter writer = null;
+ try {
+ final InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("testdata.xml");
+ in = new InputStreamReader(resourceAsStream,
+ Charset.forName("UTF-8"));
+ List replacements = ImmutableList.of(
+ new Replacement("dummy_content", "other_content")
+ );
+ replacementsReader = ReplacementsReaderBuilder.with(in, replacements);
+ writer = new StringWriter();
+ CharStreams.copy(replacementsReader, writer);
+ String actual = writer.toString();
+ assertThat(actual, CoreMatchers.containsString("other_content"));
+ } finally {
+ Closeables.close(replacementsReader, true);
+ Closeables.close(in, true);
+ Closeables.close(writer, true);
+ }
+ }
+
+ private String doReplace(String originalString, List replacements) throws IOException {
+ Reader reader = null;
+ StringWriter writer = null;
+ Reader in = null;
+ String actual;
+ try {
+ in = new StringReader(originalString);
+ reader = ReplacementsReaderBuilder.with(in, replacements);
+ writer = new StringWriter();
+ CharStreams.copy(reader, writer);
+ actual = writer.toString();
+ } finally {
+ Closeables.close(reader, true);
+ Closeables.close(in, true);
+ Closeables.close(writer, true);
+ }
+ return actual;
+ }
+
+}
diff --git a/src/test/testdata.xml b/src/test/testdata.xml
new file mode 100644
index 0000000..bc90688
--- /dev/null
+++ b/src/test/testdata.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+ Article
+ 12345
+ test.externalid
+
+
+ InputTemplate
+ test.inputtemplate
+
+
+ Department
+ test.department
+
+
+ dummy_content
+ اسرائیل: حماس هر ماه ده کیلومتر تونل حفر می کند
+ S-ryhmä vastaa kritiikkiin: "Kyse ei ole niin isosta tiedon hyödyntämisen muutoksesta"
+ Мутко: в спорте РФ после ОИ-2016 могут произойти кадровые изменения
+
+
diff --git a/src/test/testdata/01_livestreams.xml b/src/test/testdata/01_livestreams.xml
deleted file mode 100644
index e2c1282..0000000
--- a/src/test/testdata/01_livestreams.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
- Article
- 1346261
- vrtnieuws.videozone.livestream.nieuws_vr
-
-
- InputTemplate
- be.vrt.cm.common.resource.VideoStream.it
-
-
- Department
- vrtnieuws.videozone
-
-
- V_LIVESTREAM_1_nieuws
- false
- VRT
- rtmp://live.stream.vrt.be/vrt_nieuws_live/web_800.sdp
- rtsp://live.stream.vrt.be/vrt_nieuws_live/android_800.sdp
- http://live.stream.vrt.be/vrt_nieuws_live/smil:vrt_nieuws_live_ios.smil/playlist.m3u8
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
-
-
-
-
- Article
- 1346259
- vrtnieuws.videozone.livestream.nieuws_mv
-
-
- InputTemplate
- be.vrt.wco.cm.it.v3MediaVideoArticle
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- true
- true
- false
-
- false
-
- MV_LIVESTREAM_1_nieuws
- Livestream Nieuws
- 0
- 00:00
- 0
- 0
- 2012-09-23 15:13
- 1348405980219
- 23/09/2012 15:13
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- Article
- vrtnieuws.videozone.livestream.nieuws_vr
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/02_livestreams.xml b/src/test/testdata/02_livestreams.xml
deleted file mode 100644
index b8269cc..0000000
--- a/src/test/testdata/02_livestreams.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
- Article
- 744505
- vrtnieuws.videozone.livestream.journaal_vr
-
-
- InputTemplate
- be.vrt.cm.common.resource.VideoStream.it
-
-
- Department
- vrtnieuws.videozone
-
-
- V_LIVESTREAM_2_journaal
- false
- VRT
- rtmp://live.stream.vrt.be/vrt_journaal_live/web_800.sdp
- rtsp://live.stream.vrt.be/vrt_journaal_live/android_800.sdp
- http://live.stream.vrt.be/vrt_journaal_live/smil:vrt_journaal_live_ios.smil/playlist.m3u8
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
-
-
-
-
- Article
- 449312
- vrtnieuws.videozone.livestream.journaal_mv
-
-
- InputTemplate
- be.vrt.wco.cm.it.v3MediaVideoArticle
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- true
- true
- false
-
- false
-
- MV_LIVESTREAM_2_journaal
- Livestream Journaal
- 0
- 00:00
- 0
- 0
- 2012-09-23 15:13
- 1348405980219
- 23/09/2012 15:13
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- Article
- vrtnieuws.videozone.livestream.journaal_vr
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/03_livestreams.xml b/src/test/testdata/03_livestreams.xml
deleted file mode 100644
index f288fc1..0000000
--- a/src/test/testdata/03_livestreams.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
- Article
- 1346265
- be.sporza.videozone.livestream.sporza_vr
-
-
- InputTemplate
- be.vrt.cm.common.resource.VideoStream.it
-
-
- Department
- be.sporza.videozone
-
-
- V_LIVESTREAM_3_sporza
- false
- VRT
- rtmp://live.stream.vrt.be/vrt_sporza_live/web_800.sdp
- rtsp://live.stream.vrt.be/vrt_sporza_live/android_800.sdp
- http://live.stream.vrt.be/vrt_sporza_live/smil:vrt_sporza_live_ios.smil/playlist.m3u8
-
-
- Department
- be.sporza.videozone
-
-
-
-
-
-
-
-
- Article
- 1346264
- be.sporza.videozone.livestream.sporza_mv
-
-
- InputTemplate
- be.vrt.wco.cm.it.v3MediaVideoArticle
-
-
- Department
- be.sporza.videozone
-
-
-
-
- true
- true
- false
-
- false
-
- MV_LIVESTREAM_3_sporza
- Livestream Sporza
- 0
- 00:00
- 0
- 0
- 2012-09-23 15:13
- 1348405980219
- 23/09/2012 15:13
-
-
- Department
- be.sporza.videozone
-
-
-
-
- Article
- be.sporza.videozone.livestream.sporza_vr
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/04_livestreams.xml b/src/test/testdata/04_livestreams.xml
deleted file mode 100644
index 04ca829..0000000
--- a/src/test/testdata/04_livestreams.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
- Article
- 1346267
- vrtnieuws.videozone.livestream.events1_vr
-
-
- InputTemplate
- be.vrt.cm.common.resource.VideoStream.it
-
-
- Department
- vrtnieuws.videozone
-
-
- V_LIVESTREAM_4_events1
- false
- VRT
- rtmp://live.stream.vrt.be/vrt_events1_live/web_800.sdp
- rtsp://live.stream.vrt.be/vrt_events1_live/android_800.sdp
- http://live.stream.vrt.be/vrt_events1_live/smil:vrt_events1_live_ios.smil/playlist.m3u8
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
-
-
-
-
- Article
- 1346266
- vrtnieuws.videozone.livestream.events1_mv
-
-
- InputTemplate
- be.vrt.wco.cm.it.v3MediaVideoArticle
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- true
- true
- false
-
- false
-
- MV_LIVESTREAM_4_events1
- Livestream Events 1
- 0
- 00:00
- 0
- 0
- 2012-09-23 15:13
- 1348405980219
- 23/09/2012 15:13
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- Article
- vrtnieuws.videozone.livestream.events1_vr
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/05_livestreams.xml b/src/test/testdata/05_livestreams.xml
deleted file mode 100644
index 7622f09..0000000
--- a/src/test/testdata/05_livestreams.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
- Article
- 1346269
- vrtnieuws.videozone.livestream.events2_vr
-
-
- InputTemplate
- be.vrt.cm.common.resource.VideoStream.it
-
-
- Department
- vrtnieuws.videozone
-
-
- V_LIVESTREAM_5_events2
- false
- VRT
- rtmp://live.stream.vrt.be/vrt_events2_live/web_800.sdp
- rtsp://live.stream.vrt.be/vrt_events2_live/android_800.sdp
- http://live.stream.vrt.be/vrt_events2_live/smil:vrt_events2_live_ios.smil/playlist.m3u8
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
-
-
-
-
- Article
- 1346268
- vrtnieuws.videozone.livestream.events2_mv
-
-
- InputTemplate
- be.vrt.wco.cm.it.v3MediaVideoArticle
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- true
- true
- false
-
- false
-
- MV_LIVESTREAM_5_events2
- Livestream Events 2
- 0
- 00:00
- 0
- 0
- 2012-09-23 15:13
- 1348405980219
- 23/09/2012 15:13
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- Article
- vrtnieuws.videozone.livestream.events2_vr
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/10_livestreams.xml b/src/test/testdata/10_livestreams.xml
deleted file mode 100644
index a6337c3..0000000
--- a/src/test/testdata/10_livestreams.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
- Article
- 1346271
- vrtnieuws.videozone.livestream.mnm_vr
-
-
- InputTemplate
- be.vrt.cm.common.resource.VideoStream.it
-
-
- Department
- vrtnieuws.videozone
-
-
- V_LIVESTREAM_10_mnm
- false
- VRT
- rtmp://live.stream.vrt.be/vrt_mnm_live/web_800.sdp
- rtsp://live.stream.vrt.be/vrt_mnm_live/android_800.sdp
- http://live.stream.vrt.be/vrt_mnm_live/smil:vrt_mnm_live_ios.smil/playlist.m3u8
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
-
-
-
-
- Article
- 1346270
- vrtnieuws.videozone.livestream.mnm_mv
-
-
- InputTemplate
- be.vrt.wco.cm.it.v3MediaVideoArticle
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- true
- true
- false
-
- false
-
- MV_LIVESTREAM_10_mnm
- Livestream MNM
- 0
- 00:00
- 0
- 0
- 2012-09-23 15:13
- 1348405980219
- 23/09/2012 15:13
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- Article
- vrtnieuws.videozone.livestream.mnm_vr
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/11_livestreams.xml b/src/test/testdata/11_livestreams.xml
deleted file mode 100644
index 153473a..0000000
--- a/src/test/testdata/11_livestreams.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
- Article
- 1346275
- vrtnieuws.videozone.livestream.stubru_vr
-
-
- InputTemplate
- be.vrt.cm.common.resource.VideoStream.it
-
-
- Department
- vrtnieuws.videozone
-
-
- V_LIVESTREAM_11_stubru
- false
- VRT
- rtmp://live.stream.vrt.be/vrt_stubru_live/web_800.sdp
- rtsp://live.stream.vrt.be/vrt_stubru_live/android_800.sdp
- http://live.stream.vrt.be/vrt_stubru_live/smil:vrt_stubru_live_ios.smil/playlist.m3u8
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
-
-
-
-
- Article
- 1346272
- vrtnieuws.videozone.livestream.stubru_mv
-
-
- InputTemplate
- be.vrt.wco.cm.it.v3MediaVideoArticle
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- true
- true
- false
-
- false
-
- MV_LIVESTREAM_11_stubru
- Livestream Studio Brussel
- 0
- 00:00
- 0
- 0
- 2012-09-23 15:13
- 1348405980219
- 23/09/2012 15:13
-
-
- Department
- vrtnieuws.videozone
-
-
-
-
- Article
- vrtnieuws.videozone.livestream.stubru_vr
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/99_livestreams.xml b/src/test/testdata/99_livestreams.xml
deleted file mode 100644
index 08bcc09..0000000
--- a/src/test/testdata/99_livestreams.xml
+++ /dev/null
@@ -1,175 +0,0 @@
-
-
-
-
-
-
-
- Department
- 22750
- vrtnieuws.videozone.streaming
-
-
- be.vrt.wco.cm.it.RepositoryDepartment
-
-
- streaming
-
-
-
- 0
-
-
- Article
- vrtnieuws.videozone.livestream.nieuws_mv
-
-
-
-
-
-
- 1
-
-
- Article
- vrtnieuws.videozone.livestream.journaal_mv
-
-
-
-
-
-
- 2
-
-
- Article
- be.sporza.videozone.livestream.sporza_mv
-
-
-
-
-
-
- 3
-
-
- Article
- vrtnieuws.videozone.livestream.events1_mv
-
-
-
-
-
-
- 4
-
-
- Article
- vrtnieuws.videozone.livestream.events2_mv
-
-
-
-
-
-
- 5
-
-
- Article
- vrtnieuws.videozone.livestream.mnm_mv
-
-
-
-
-
-
- 6
-
-
- Article
- vrtnieuws.videozone.livestream.stubru_mv
-
-
-
-
-
-
- 7
-
-
- Article
- vrtnieuws.videozone.livestream.nieuws_vr
-
-
-
-
-
-
- 8
-
-
- Article
- vrtnieuws.videozone.livestream.journaal_vr
-
-
-
-
-
-
- 9
-
-
- Article
- be.sporza.videozone.livestream.sporza_vr
-
-
-
-
-
-
- 10
-
-
- Article
- vrtnieuws.videozone.livestream.events1_vr
-
-
-
-
-
-
- 11
-
-
- Article
- vrtnieuws.videozone.livestream.events2_vr
-
-
-
-
-
-
- 12
-
-
- Article
- vrtnieuws.videozone.livestream.mnm_vr
-
-
-
-
-
-
- 13
-
-
- Article
- vrtnieuws.videozone.livestream.stubru_vr
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/testdata/cobra_jsresources.xml b/src/test/testdata/cobra_jsresources.xml
deleted file mode 100644
index cf01064..0000000
--- a/src/test/testdata/cobra_jsresources.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
- cultuur
-
-
- 13
- http://build.uitdatabank.be/widgets/js/json.js
- http://build.uitdatabank.be/widgets/p/209/widgets.js
- /html/js/site.concat.js?v=${js.version}
- /html/js/general.concat.js?v=${js.version}
- /html/js/elems.concat.js?v=${js.version}
- /html/js/common/start.js?v=${js.version}
- /html/js/cultuur2011.js?v=${js.version}
- /html/js/common/new-videozone.js?v=${js.version}
- http://c.pebblemedia.be/js/c.js
- http://pool.pebblemedia.adhese.com/tag/tag.js
- /html/js/common/eventtracking.js?v=${js.version}
- http://mp.vrt.be/player/vrtMediaPlayer.js
- /html/js/common/videoplayer-mp.js?v=${js.version}
-
-
\ No newline at end of file