Permalink
Browse files

use mvn shade plugin instead of copying code.

  • Loading branch information...
1 parent 866229f commit 34b52b594e4e09584dbd12eaf87a59761cdcccee @grobmeier committed Mar 17, 2012
View
@@ -7,5 +7,4 @@ Christian Grobmeier(http://www.grobmeier.de/).
Contributors are listed in the pom.xml file.
This product uses some code developed by Apache Commons:
-http://commons.apache.org
-You can find that code in the translators package. It has been taken from [lang].
+[lang]: http://commons.apache.org/lang
View
@@ -143,8 +143,28 @@
</dependency>
</dependencies>
</plugin>
-
-
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.commons.lang</pattern>
+ <shadedPattern>de.grobmeier.jjson.shaded.org.apache.commons.lang</shadedPattern>
+ </relocation>
+ </relocations>
+ <minimizeJar>true</minimizeJar>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
<dependencies>
@@ -154,6 +174,13 @@
<version>4.4</version>
<scope>test</scope>
</dependency>
+ <!-- is shaded in the release -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.1</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<reporting>
<plugins>
@@ -30,7 +30,7 @@
import java.util.Set;
import de.grobmeier.jjson.JSONException;
-import de.grobmeier.jjson.translator.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
/**
*
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 de.grobmeier.jjson.translator;
-
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * Executes a sequence of translators one after the other. Execution ends whenever
- * the first translator consumes codepoints from the input.
- *
- * @since 3.0
- * @version $Id: AggregateTranslator.java 1088899 2011-04-05 05:31:27Z bayard $
- */
-public class AggregateTranslator extends CharSequenceTranslator {
-
- private final CharSequenceTranslator[] translators;
-
- /**
- * Specify the translators to be used at creation time.
- *
- * @param translators CharSequenceTranslator array to aggregate
- */
- public AggregateTranslator(CharSequenceTranslator... translators) {
- this.translators = translators.clone();
- }
-
- /**
- * The first translator to consume codepoints from the input is the 'winner'.
- * Execution stops with the number of consumed codepoints being returned.
- * {@inheritDoc}
- */
- @Override
- public int translate(CharSequence input, int index, Writer out) throws IOException {
- for (CharSequenceTranslator translator : translators) {
- int consumed = translator.translate(input, index, out);
- if(consumed != 0) {
- return consumed;
- }
- }
- return 0;
- }
-
-}
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 de.grobmeier.jjson.translator;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.Locale;
-
-/**
- * An API for translating text.
- * Its core use is to escape and unescape text. Because escaping and unescaping
- * is completely contextual, the API does not present two separate signatures.
- */
-public abstract class CharSequenceTranslator {
-
- /**
- * Translate a set of codepoints, represented by an int index into a CharSequence,
- * into another set of codepoints. The number of codepoints consumed must be returned,
- * and the only IOExceptions thrown must be from interacting with the Writer so that
- * the top level API may reliable ignore StringWriter IOExceptions.
- *
- * @param input CharSequence that is being translated
- * @param index int representing the current point of translation
- * @param out Writer to translate the text to
- * @return int count of codepoints consumed
- * @throws IOException if and only if the Writer produces an IOException
- */
- public abstract int translate(CharSequence input, int index, Writer out) throws IOException;
-
- /**
- * Helper for non-Writer usage.
- * @param input CharSequence to be translated
- * @return String output of translation
- */
- public final String translate(CharSequence input) {
- if (input == null) {
- return null;
- }
- try {
- StringWriter writer = new StringWriter(input.length() * 2);
- translate(input, writer);
- return writer.toString();
- } catch (IOException ioe) {
- // this should never ever happen while writing to a StringWriter
- throw new RuntimeException(ioe);
- }
- }
-
- /**
- * Translate an input onto a Writer. This is intentionally final as its algorithm is
- * tightly coupled with the abstract method of this class.
- *
- * @param input CharSequence that is being translated
- * @param out Writer to translate the text to
- * @throws IOException if and only if the Writer produces an IOException
- */
- public final void translate(CharSequence input, Writer out) throws IOException {
- if (out == null) {
- throw new IllegalArgumentException("The Writer must not be null");
- }
- if (input == null) {
- return;
- }
- int pos = 0;
- int len = input.length();
- while (pos < len) {
- int consumed = translate(input, pos, out);
- if (consumed == 0) {
- char[] c = Character.toChars(Character.codePointAt(input, pos));
- out.write(c);
- pos+= c.length;
- continue;
- }
-// // contract with translators is that they have to understand codepoints
-// // and they just took care of a surrogate pair
- for (int pt = 0; pt < consumed; pt++) {
- pos += Character.charCount(Character.codePointAt(input, pos));
- }
- }
- }
-
- /**
- * Helper method to create a merger of this translator with another set of
- * translators. Useful in customizing the standard functionality.
- *
- * @param translators CharSequenceTranslator array of translators to merge with this one
- * @return CharSequenceTranslator merging this translator with the others
- */
- public final CharSequenceTranslator with(CharSequenceTranslator... translators) {
- CharSequenceTranslator[] newArray = new CharSequenceTranslator[translators.length + 1];
- newArray[0] = this;
- System.arraycopy(translators, 0, newArray, 1, translators.length);
- return new AggregateTranslator(newArray);
- }
-
- /**
- * <p>Returns an upper case hexadecimal <code>String</code> for the given
- * character.</p>
- *
- * @param codepoint The codepoint to convert.
- * @return An upper case hexadecimal <code>String</code>
- */
- public static String hex(int codepoint) {
- return Integer.toHexString(codepoint).toUpperCase(Locale.ENGLISH);
- }
-
-}
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 de.grobmeier.jjson.translator;
-
-/**
- * Class holding various entity data for HTML and XML - generally for use with
- * the LookupTranslator.
- * All arrays are of length [*][2].
- *
- * @since 3.0
- * @version $Id: EntityArrays.java 1088899 2011-04-05 05:31:27Z bayard $
- */
-public class EntityArrays {
- /**
- * Mapping to escape the Java control characters.
- *
- * Namely: {@code \b \n \t \f \r}
- * @return the mapping table
- */
- public static String[][] JAVA_CTRL_CHARS_ESCAPE() { return JAVA_CTRL_CHARS_ESCAPE.clone(); }
- private static final String[][] JAVA_CTRL_CHARS_ESCAPE = {
- {"\b", "\\b"},
- {"\n", "\\n"},
- {"\t", "\\t"},
- {"\f", "\\f"},
- {"\r", "\\r"}
- };
-}
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 de.grobmeier.jjson.translator;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.HashMap;
-
-/**
- * Translates a value using a lookup table.
- *
- * @since 3.0
- * @version $Id: LookupTranslator.java 1091096 2011-04-11 15:07:29Z mbenson $
- */
-public class LookupTranslator extends CharSequenceTranslator {
-
- private final HashMap<CharSequence, CharSequence> lookupMap;
- private final int shortest;
- private final int longest;
-
- /**
- * Define the lookup table to be used in translation
- *
- * @param lookup CharSequence[][] table of size [*][2]
- */
- public LookupTranslator(CharSequence[]... lookup) {
- lookupMap = new HashMap<CharSequence, CharSequence>();
- int _shortest = Integer.MAX_VALUE;
- int _longest = 0;
- if (lookup != null) {
- for (CharSequence[] seq : lookup) {
- this.lookupMap.put(seq[0], seq[1]);
- int sz = seq[0].length();
- if (sz < _shortest) {
- _shortest = sz;
- }
- if (sz > _longest) {
- _longest = sz;
- }
- }
- }
- shortest = _shortest;
- longest = _longest;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int translate(CharSequence input, int index, Writer out) throws IOException {
- int max = longest;
- if (index + longest > input.length()) {
- max = input.length() - index;
- }
- // descend so as to get a greedy algorithm
- for (int i = max; i >= shortest; i--) {
- CharSequence subSeq = input.subSequence(index, index + i);
- CharSequence result = lookupMap.get(subSeq);
- if (result != null) {
- out.write(result.toString());
- return i;
- }
- }
- return 0;
- }
-}
Oops, something went wrong.

0 comments on commit 34b52b5

Please sign in to comment.