Skip to content

Commit

Permalink
Merge pull request #5 from wimsymons/fix-encoding-issue
Browse files Browse the repository at this point in the history
Changes for v1.5 - Fix encoding issues
  • Loading branch information
wimsymons authored Jul 31, 2016
2 parents dcbcad1 + cdef385 commit 52a8d8c
Show file tree
Hide file tree
Showing 30 changed files with 935 additions and 1,445 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.idea/
out/
src/testdata/
9 changes: 6 additions & 3 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2" url="https://github.com/wimsymons/intellij-ppimport">
<id>be.wimsymons.intellij.polopolyimport</id>
<name>Polopoly Importer</name>
<version>1.4</version>
<version>1.5</version>
<vendor email="[email protected]">Wim Symons</vendor>

<description><![CDATA[
Expand All @@ -15,8 +15,11 @@ This version keeps state on application-level, not on project level.

<change-notes><![CDATA[
<dl>
<dt>1.5</dt>
<dd>Fixed charset conversion issues</dd>
<dt>1.4</dt>
<dd>1.4 Fixed NullPointerException on IDEA 12</dd>
<dd>Fixed NullPointerException on IDEA 12</dd>
<dt>1.3</dt>
<dd>Fixed issue with Guava deprecating Closeables.closeQuietly in Guava 15</dd>
Expand Down Expand Up @@ -76,4 +79,4 @@ This version keeps state on application-level, not on project level.
</group>
</actions>

</idea-plugin>
</idea-plugin>
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/mavicon/intellij-ppimport> and inspiration
from Johan Rylander's Atex Polopoly plugin for IntelliJ <https://github.com/jrylander/PolopolyIntelliJPlugin>.

This plugin is written to simplify import of content XML files into the Polopoly CMS.

Expand All @@ -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.
Expand All @@ -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 <http://www.eli.sdsu.edu/java-SDSU/> 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.
Expand All @@ -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.
limitations under the License.
Binary file removed distributable/polopoly-import-1.4.jar
Binary file not shown.
Binary file added distributable/polopoly-import-1.5.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions intellij-ppimport.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testdata" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand All @@ -17,5 +18,4 @@
<option name="useAlternativeWorkingDir" value="false" />
<option name="workingDirSelection" value="&lt;MODULE&gt;" />
</component>
</module>

</module>
29 changes: 21 additions & 8 deletions src/main/be/wimsymons/intellij/polopolyimport/PPImporter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Replacement> 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;
}
}
}
44 changes: 0 additions & 44 deletions src/main/org/codehaus/swizzle/stream/FilteredInputStream.java

This file was deleted.

Loading

0 comments on commit 52a8d8c

Please sign in to comment.