[Mulgara-svn] r2006 - in trunk/src/jar/util/java: java/sql org/mulgara/util org/mulgara/util/conversion/html
pag at mulgara.org
pag at mulgara.org
Tue Jul 19 06:31:21 UTC 2011
Author: pag
Date: 2011-07-19 06:31:20 +0000 (Tue, 19 Jul 2011)
New Revision: 2006
Modified:
trunk/src/jar/util/java/java/sql/SQLXML.java
trunk/src/jar/util/java/org/mulgara/util/AbstractMulgaraResultSet.java
trunk/src/jar/util/java/org/mulgara/util/ExplicitIntFile.java
trunk/src/jar/util/java/org/mulgara/util/IntFileTest.java
trunk/src/jar/util/java/org/mulgara/util/LongToStringMap.java
trunk/src/jar/util/java/org/mulgara/util/LongToStringMapUnitTest.java
trunk/src/jar/util/java/org/mulgara/util/MapWrapper.java
trunk/src/jar/util/java/org/mulgara/util/Multimap.java
trunk/src/jar/util/java/org/mulgara/util/ResultSetMetaDataImpl.java
trunk/src/jar/util/java/org/mulgara/util/ResultSetRow.java
trunk/src/jar/util/java/org/mulgara/util/ServerInfoRef.java
trunk/src/jar/util/java/org/mulgara/util/ServerURIHandlerUnitTest.java
trunk/src/jar/util/java/org/mulgara/util/SoapClient.java
trunk/src/jar/util/java/org/mulgara/util/StringToLongMapUnitTest.java
trunk/src/jar/util/java/org/mulgara/util/conversion/html/Entities.java
trunk/src/jar/util/java/org/mulgara/util/conversion/html/HTMLParser.jj
trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverter.java
trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverterTester.java
trunk/src/jar/util/java/org/mulgara/util/conversion/html/ParserThread.java
Log:
Code cleanup, warning removal
Modified: trunk/src/jar/util/java/java/sql/SQLXML.java
===================================================================
--- trunk/src/jar/util/java/java/sql/SQLXML.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/java/sql/SQLXML.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -15,7 +15,7 @@
public Writer setCharacterStream() throws SQLException;
public String getString() throws SQLException;
public void setString(String str) throws SQLException;
- public Source getSource(Class clazz) throws SQLException;
- public Result setResult(Class clazz) throws SQLException;
+ public <T extends Source> T getSource(Class<T> clazz) throws SQLException;
+ public <T extends Result> T setResult(Class<T> clazz) throws SQLException;
}
Modified: trunk/src/jar/util/java/org/mulgara/util/AbstractMulgaraResultSet.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/AbstractMulgaraResultSet.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/AbstractMulgaraResultSet.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -706,9 +706,7 @@
* @return The Object value
* @throws SQLException on failure
*/
- @SuppressWarnings("unchecked")
- public Object getObject(int i, java.util.Map map) throws SQLException {
-
+ public Object getObject(int i, java.util.Map<String,Class<?>> map) throws SQLException {
throw new SQLException(NOT_IMPLEMENTED);
}
@@ -758,8 +756,7 @@
* @return The Object value
* @throws SQLException on failure
*/
- @SuppressWarnings("unchecked")
- public Object getObject(String colName, java.util.Map map)
+ public Object getObject(String colName, java.util.Map<String,Class<?>> map)
throws SQLException {
throw new SQLException(NOT_IMPLEMENTED);
Modified: trunk/src/jar/util/java/org/mulgara/util/ExplicitIntFile.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ExplicitIntFile.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/ExplicitIntFile.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -30,7 +30,6 @@
// Java 2 standard packages
import java.io.*;
import java.nio.*;
-import java.nio.channels.*;
// Third party packages
import org.apache.log4j.*;
@@ -57,6 +56,7 @@
*/
public final class ExplicitIntFile extends IntFile {
+ @SuppressWarnings("unused")
private static Logger logger =
Logger.getLogger(ExplicitIntFile.class.getName());
Modified: trunk/src/jar/util/java/org/mulgara/util/IntFileTest.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/IntFileTest.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/IntFileTest.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -31,11 +31,7 @@
import junit.framework.*;
import java.io.*;
-import java.nio.*;
-// Java 2 standard packages
-import java.util.*;
-
/**
* Test cases for IntFile.
*
Modified: trunk/src/jar/util/java/org/mulgara/util/LongToStringMap.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/LongToStringMap.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/LongToStringMap.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -58,6 +58,7 @@
public final class LongToStringMap {
/** Logger for this class */
+ @SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(LongToStringMap.class);
/** File used to store mappings */
Modified: trunk/src/jar/util/java/org/mulgara/util/LongToStringMapUnitTest.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/LongToStringMapUnitTest.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/LongToStringMapUnitTest.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -177,7 +177,7 @@
//open maps, load data, delete maps (repeat)
for (int i = 0; i < ITERATIONS; i++) {
- List openMaps = new ArrayList();
+ List<LongToStringMap> openMaps = new ArrayList<LongToStringMap>();
//create and populate tham all
for (int j = 0; j < OPEN_MAPS; j++) {
Modified: trunk/src/jar/util/java/org/mulgara/util/MapWrapper.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/MapWrapper.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/MapWrapper.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -39,26 +39,22 @@
* Software Pty Ltd</a>
* @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
*/
-public class MapWrapper implements Map {
+public class MapWrapper<K,V> implements Map<K,V> {
/**
* The wrapped instance.
- *
*/
- protected Map map;
+ protected Map<K,V> map;
/**
* Constructor.
*
* @param map the wrapped instance
*/
- public MapWrapper(Map map) {
-
+ public MapWrapper(Map<K,V> map) {
if (map == null) {
-
throw new IllegalArgumentException("Null \"map\" parameter");
}
-
this.map = map;
}
@@ -68,7 +64,6 @@
* @return The Empty value
*/
public boolean isEmpty() {
-
return map.isEmpty();
}
@@ -78,8 +73,7 @@
* @param key PARAMETER TO DO
* @return RETURNED VALUE TO DO
*/
- public Object get(Object key) {
-
+ public V get(Object key) {
return map.get(key);
}
@@ -93,7 +87,6 @@
* @return RETURNED VALUE TO DO
*/
public int size() {
-
return map.size();
}
@@ -104,7 +97,6 @@
* @return RETURNED VALUE TO DO
*/
public boolean containsKey(Object key) {
-
return map.containsKey(key);
}
@@ -115,7 +107,6 @@
* @return RETURNED VALUE TO DO
*/
public boolean containsValue(Object value) {
-
return map.containsValue(value);
}
@@ -126,8 +117,7 @@
* @param value PARAMETER TO DO
* @return RETURNED VALUE TO DO
*/
- public Object put(Object key, Object value) {
-
+ public V put(K key, V value) {
return map.put(key, value);
}
@@ -137,8 +127,7 @@
* @param key PARAMETER TO DO
* @return RETURNED VALUE TO DO
*/
- public Object remove(Object key) {
-
+ public V remove(Object key) {
return map.remove(key);
}
@@ -147,17 +136,14 @@
*
* @param t PARAMETER TO DO
*/
- public void putAll(Map t) {
-
+ public void putAll(Map<? extends K, ? extends V> t) {
map.putAll(t);
}
/**
* METHOD TO DO
- *
*/
public void clear() {
-
map.clear();
}
@@ -166,8 +152,7 @@
*
* @return RETURNED VALUE TO DO
*/
- public Set keySet() {
-
+ public Set<K> keySet() {
return map.keySet();
}
@@ -176,8 +161,7 @@
*
* @return RETURNED VALUE TO DO
*/
- public Collection values() {
-
+ public Collection<V> values() {
return map.values();
}
@@ -186,8 +170,7 @@
*
* @return RETURNED VALUE TO DO
*/
- public Set entrySet() {
-
+ public Set<Map.Entry<K,V>> entrySet() {
return map.entrySet();
}
@@ -198,7 +181,6 @@
* @return RETURNED VALUE TO DO
*/
public boolean equals(Object o) {
-
return map.equals(o);
}
@@ -208,7 +190,6 @@
* @return RETURNED VALUE TO DO
*/
public int hashCode() {
-
return map.hashCode();
}
}
Modified: trunk/src/jar/util/java/org/mulgara/util/Multimap.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Multimap.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/Multimap.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -31,6 +31,8 @@
// Java 2 standard packages
import java.util.*;
+import org.mulgara.util.functional.C;
+
/**
* A wrapper for {@link Map}s which makes it convenient to deal with keys that
* map to multiple values.
@@ -40,16 +42,18 @@
* Software Pty Ltd</a>
* @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
*/
-public class Multimap extends MapWrapper {
+public class Multimap<K,V> implements Map<K,V> {
+ protected Map<K,Set<V>> map;
+
/**
* Constructor.
*
* @param map the underlying {@link Map}, whose values will be {@link Set}s of
* values
*/
- public Multimap(Map map) {
- super(map);
+ public Multimap(Map<K,Set<V>> map) {
+ this.map = map;
}
//
@@ -64,15 +68,9 @@
* @return RETURNED VALUE TO DO
*/
public boolean containsValue(Object value) {
-
- for (Iterator i = map.values().iterator(); i.hasNext();) {
-
- if (((Collection) i.next()).contains(value)) {
-
- return true;
- }
+ for (Iterator<Set<V>> i = map.values().iterator(); i.hasNext();) {
+ if (i.next().contains(value)) return true;
}
-
return false;
}
@@ -83,20 +81,18 @@
* @param value PARAMETER TO DO
* @return RETURNED VALUE TO DO
*/
- public Object put(Object key, Object value) {
+ public V put(K key, V value) {
- Set values = (Set) map.get(key);
+ Set<V> values = map.get(key);
if (values == null) {
-
- values = new HashSet();
+ values = new HashSet<V>();
}
-
+ V old = values.contains(value) ? value : null;
values.add(value);
- return map.put(key, values);
-
- // FIXME: the result value is incorrect
+ map.put(key, values);
+ return old;
}
/**
@@ -106,23 +102,15 @@
* @param value the value to remove from the mapping
* @return whether the object existed and was unmapped
*/
- public boolean remove(Object key, Object value) {
+ public boolean remove(K key, V value) {
- Set values = (Set) map.get(key);
+ Set<V> values = map.get(key);
if (values != null) {
-
boolean removed = values.remove(value);
-
- if (values.isEmpty()) {
-
- map.remove(key);
- }
-
+ if (values.isEmpty()) map.remove(key);
return removed;
- }
- else {
-
+ } else {
return false;
}
}
@@ -132,15 +120,94 @@
*
* @return RETURNED VALUE TO DO
*/
- public Collection values() {
+ public Collection<V> values() {
- Set result = new HashSet();
+ Set<V> result = new HashSet<V>();
- for (Iterator i = map.values().iterator(); i.hasNext();) {
-
- result.addAll((Collection) i.next());
+ for (Iterator<Set<V>> i = map.values().iterator(); i.hasNext();) {
+ result.addAll(i.next());
}
return result;
}
+
+ @Override
+ public void clear() {
+ map.clear();
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ return map.containsKey(key);
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<K, V>> entrySet() {
+ Set<Map.Entry<K, V>> entries = new HashSet<Map.Entry<K, V>>();
+ for (Map.Entry<K,Set<V>> entry: map.entrySet()) {
+ for (V value: entry.getValue()) {
+ entries.add(new KV(entry.getKey(), value));
+ }
+ }
+ return entries;
+ }
+
+ /**
+ * This once broke the interface by returning a Set. Now it meets the interface
+ * but is useless.
+ * @see java.util.Map#get(java.lang.Object)
+ */
+ @Override
+ public V get(Object key) {
+ return C.first(map.get(key));
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return map.keySet();
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> m) {
+ for (Map.Entry<? extends K, ? extends V> e: m.entrySet()) {
+ put(e.getKey(), e.getValue());
+ }
+ }
+
+ @Override
+ public V remove(Object key) {
+ Set<V> v = map.remove(key);
+ return v == null ? null : C.first(v);
+ }
+
+ @Override
+ public int size() {
+ int total = 0;
+ for (Set<V> v: map.values()) total += v.size();
+ return total;
+ }
+
+ class KV implements Map.Entry<K,V> {
+ K key;
+ V value;
+ KV(K k, V v) {
+ key = k;
+ value = v;
+ }
+ @Override
+ public K getKey() { return key; }
+ @Override
+ public V getValue() { return value; }
+ @Override
+ public V setValue(V v) {
+ V tmp = value;
+ value = v;
+ return tmp;
+ }
+ }
}
Modified: trunk/src/jar/util/java/org/mulgara/util/ResultSetMetaDataImpl.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ResultSetMetaDataImpl.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/ResultSetMetaDataImpl.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -69,10 +69,8 @@
*/
static final long serialVersionUID = 4483688823263444933L;
- /**
- * Logger.
- *
- */
+ /** Logger. */
+ @SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(ResultSetMetaDataImpl.class);
/**
Modified: trunk/src/jar/util/java/org/mulgara/util/ResultSetRow.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ResultSetRow.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/ResultSetRow.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -55,7 +55,7 @@
*
* @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
*/
-public class ResultSetRow implements Comparable, Serializable {
+public class ResultSetRow implements Comparable<ResultSetRow>, Serializable {
/**
* Allow newer compiled version of the stub to operate when changes
@@ -262,25 +262,6 @@
}
/**
- * Returns a negative number if the object is less than the given object, a
- * positive number if larger and 0 if equal.
- *
- * @param object the object to compare it.
- * @return a negative number if the object is less than the given object, a
- * positive number if larger and 0 if equal.
- * @throws ClassCastException if the object is not of the correct type.
- */
- public int compareTo(Object object) throws ClassCastException {
-
- if (! (object instanceof ResultSetRow)) {
-
- throw new ClassCastException("Can't compare to " + object.getClass());
- }
-
- return compareTo( (ResultSetRow) object);
- }
-
- /**
* Returns true if the object is of the same type, the same length and its
* column values are equal.
*
@@ -371,23 +352,20 @@
* @return a negative number if the object is less than the given object, a
* positive number if larger and 0 if equal.
*/
- private int compareTo(ResultSetRow row) {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public int compareTo(ResultSetRow row) {
// Longer result sets are larger
if (row.columns.length != columns.length) {
-
return columns.length - row.columns.length;
}
for (int i = 0; i < columns.length; i++) {
if (columns[i] == null) {
-
// nulls come after other values
return (row.columns[i] == null) ? 0 : 1;
- }
- else if (! (columns[i] instanceof Comparable)) {
-
+ } else if (!(columns[i] instanceof Comparable)) {
throw new RuntimeException(
"Badly implemented code can't cope with non-Comparable " +
columns[i] + " of type " + columns[i].getClass());
@@ -397,9 +375,8 @@
try {
- result = ( (Comparable) columns[i]).compareTo(row.columns[i]);
- }
- catch (ClassCastException e) {
+ result = ((Comparable)columns[i]).compareTo(row.columns[i]);
+ } catch (ClassCastException e) {
logger.warn("Incomparable rows", e);
result =
Modified: trunk/src/jar/util/java/org/mulgara/util/ServerInfoRef.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ServerInfoRef.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/ServerInfoRef.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -161,7 +161,7 @@
private static final Method findGetter(String name) throws SecurityException, NoSuchMethodException, ClassNotFoundException {
String fullName = "get" + name;
Method getter = getters.get(fullName);
- if (fullName == null) {
+ if (getter == null) {
getter = getServerInfoClass().getMethod(fullName, new Class[] { });
getters.put(fullName, getter);
}
Modified: trunk/src/jar/util/java/org/mulgara/util/ServerURIHandlerUnitTest.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ServerURIHandlerUnitTest.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/ServerURIHandlerUnitTest.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -63,6 +63,7 @@
/**
* Logger. Named after the class.
*/
+ @SuppressWarnings("unused")
private Logger logger =
Logger.getLogger(ServerURIHandlerUnitTest.class.getName());
Modified: trunk/src/jar/util/java/org/mulgara/util/SoapClient.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/SoapClient.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/SoapClient.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -69,6 +69,7 @@
/**
* the category to log to
*/
+ @SuppressWarnings("unused")
private final static Logger log =
Logger.getLogger(SoapClient.class.getName());
Modified: trunk/src/jar/util/java/org/mulgara/util/StringToLongMapUnitTest.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/StringToLongMapUnitTest.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/StringToLongMapUnitTest.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -173,7 +173,7 @@
*/
public void testBulkPut() throws IOException {
// Get a list of random numbers.
- List numbersList = new ArrayList();
+ List<Long> numbersList = new ArrayList<Long>();
Random rand = new Random(12345);
for (int i = 0; i < 100000; ++i) {
long value = rand.nextLong();
@@ -186,7 +186,7 @@
);
}
- List moreNumbersList = new ArrayList();
+ List<Long> moreNumbersList = new ArrayList<Long>();
for (int i = 0; i < 100; ++i) {
long value = rand.nextLong();
moreNumbersList.add(new Long(value));
Modified: trunk/src/jar/util/java/org/mulgara/util/conversion/html/Entities.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/conversion/html/Entities.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/conversion/html/Entities.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -1,30 +1,3 @@
-/*
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is the Kowari Metadata Store.
- *
- * The Initial Developer of the Original Code is Plugged In Software Pty
- * Ltd (http://www.pisoftware.com, mailto:info at pisoftware.com). Portions
- * created by Plugged In Software Pty Ltd are Copyright (C) 2001,2002
- * Plugged In Software Pty Ltd. All Rights Reserved.
- *
- * Contributor(s): N/A.
- *
- * [NOTE: The text of this Exhibit A may differ slightly from the text
- * of the notices in the Source Code files of the Original Code. You
- * should use the text of this Exhibit A rather than the text found in the
- * Original Code Source Code for Your Modifications.]
- *
- */
-
package org.mulgara.util.conversion.html;
@@ -84,24 +57,22 @@
import java.util.*;
/**
- * CLASS TO DO
+ * A utility for encoding strings as XML entities, and decoding entities back into strings.
*/
public class Entities {
/**
- * Description of the Field
- *
+ * A map of XML entities to their UTF numbers.
*/
- final static Hashtable decoder = new Hashtable(300);
+ final static Map<String,String> decoder = new HashMap<String,String>(300);
/**
- * Description of the Field
- *
+ * A map of small character numbers to their entities.
*/
final static String[] encoder = new String[0x100];
+ // Initialize the maps
static {
-
add(""", 34);
add("&", 38);
add("<", 60);
@@ -357,38 +328,28 @@
}
/**
- * METHOD TO DO
+ * Identify characters in a string that can be entities and replace them.
*
- * @param s PARAMETER TO DO
- * @return RETURNED VALUE TO DO
+ * @param s The original unicode string.
+ * @return The string with some characters replaced with appropriate entities.
*/
public final static String encode(String s) {
-
int length = s.length();
StringBuffer buffer = new StringBuffer(length * 2);
for (int i = 0; i < length; i++) {
-
char c = s.charAt(i);
int j = (int) c;
if ((j < 0x100) && (encoder[j] != null)) {
-
buffer.append(encoder[j]);
-
// have a named encoding
buffer.append(';');
- }
- else if (j < 0x80) {
-
+ } else if (j < 0x80) {
buffer.append(c);
-
// use ASCII value
- }
- else {
-
+ } else {
buffer.append("&#");
-
// use numeric encoding
buffer.append((int) c);
buffer.append(';');
@@ -399,63 +360,44 @@
}
/**
- * METHOD TO DO
- *
- * @param entity PARAMETER TO DO
- * @return RETURNED VALUE TO DO
+ * Convert a string containing just an entity into its original unicode character.
+ * @param entity The string containing the entity of the form "&...;".
+ * @return A string with the unicode character for the entity.
*/
final static String decode(String entity) {
if (entity.charAt(entity.length() - 1) == ';') {
-
// remove trailing semicolon
entity = entity.substring(0, entity.length() - 1);
}
if (entity.charAt(1) == '#') {
-
int start = 2;
int radix = 10;
if ((entity.charAt(2) == 'X') || (entity.charAt(2) == 'x')) {
-
start++;
radix = 16;
}
- Character c =
- new Character((char) Integer.parseInt(entity.substring(start), radix));
-
+ Character c = new Character((char) Integer.parseInt(entity.substring(start), radix));
return c.toString();
- }
- else {
- String s = (String) decoder.get(entity);
+ } else {
- if (s != null) {
-
- return s;
- }
- else {
-
- return "";
- }
+ String s = (String) decoder.get(entity);
+ return (s != null) ? s : "";
}
}
/**
- * METHOD TO DO
+ * Internal initialization method. Maps an entity to a unicode character, and vice-versa.
*
- * @param entity PARAMETER TO DO
- * @param value PARAMETER TO DO
+ * @param entity The entity being mapped.
+ * @param value The unicode character value represented by the entity.
*/
final static void add(String entity, int value) {
-
decoder.put(entity, (new Character((char) value)).toString());
-
- if (value < 0x100) {
-
- encoder[value] = entity;
- }
+ if (value < 0x100) encoder[value] = entity;
}
}
Modified: trunk/src/jar/util/java/org/mulgara/util/conversion/html/HTMLParser.jj
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/conversion/html/HTMLParser.jj 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/conversion/html/HTMLParser.jj 2011-07-19 06:31:20 UTC (rev 2006)
@@ -87,7 +87,7 @@
public class HTMLParser {
public static int SUMMARY_LENGTH = 200;
- static Set endlineSet = new HashSet();
+ static Set<String> endlineSet = new HashSet<String>();
static boolean includeTitle = true;
static boolean includeImageAlts = true;
@@ -202,7 +202,7 @@
*
* @return The end of line tag set.
*/
- public static Set getEndlineSet() {
+ public static Set<String> getEndlineSet() {
return endlineSet;
}
@@ -213,7 +213,7 @@
*
* @param set The end of line tag set.
*/
- public static void setEndlineSet(Set set) {
+ public static void setEndlineSet(Set<String> set) {
endlineSet = set;
}
Modified: trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverter.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverter.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverter.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -29,7 +29,6 @@
// Java 2 standard packages
import java.io.*;
-import java.net.*;
import java.util.*;
/**
@@ -99,7 +98,7 @@
*
* @param set The end of line tag set.
*/
- public static void setEndlineSet(Set set) {
+ public static void setEndlineSet(Set<String> set) {
HTMLParser.setEndlineSet(set);
}
@@ -131,7 +130,7 @@
*
* @return The end of line tag set.
*/
- public static Set getEndlineSet() {
+ public static Set<String> getEndlineSet() {
return HTMLParser.getEndlineSet();
}
Modified: trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverterTester.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverterTester.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/conversion/html/HtmlToTextConverterTester.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -30,7 +30,6 @@
// Java 2 standard packages
import java.io.*;
-import java.net.*;
import java.util.*;
/**
Modified: trunk/src/jar/util/java/org/mulgara/util/conversion/html/ParserThread.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/conversion/html/ParserThread.java 2011-07-19 00:09:23 UTC (rev 2005)
+++ trunk/src/jar/util/java/org/mulgara/util/conversion/html/ParserThread.java 2011-07-19 06:31:20 UTC (rev 2006)
@@ -30,61 +30,44 @@
import java.io.*;
/**
- * CLASS TO DO
+ * The thread that performs HTML parsing.
*/
class ParserThread extends Thread {
- /**
- * Description of the Field
- */
+ /** The parser to use. */
HTMLParser parser;
/**
- * CONSTRUCTOR ParserThread TO DO
- *
- * @param p PARAMETER TO DO
+ * Creates the thread on the parser.
+ * @param p The parser to use.
*/
ParserThread(HTMLParser p) {
-
parser = p;
}
/**
* Main processing method for the ParserThread object
- *
*/
public void run() {
// convert pipeOut to pipeIn
try {
-
try {
-
// parse document to pipeOut
parser.HTMLDocument();
- }
- catch (ParseException e) {
-
+ } catch (ParseException e) {
System.out.println("Parse Aborted: " + e.getMessage());
- }
- catch (TokenMgrError e) {
-
+ } catch (TokenMgrError e) {
System.out.println("Parse Aborted: " + e.getMessage());
- }
- finally {
-
+ } finally {
parser.pipeOut.close();
-
synchronized (parser) {
-
- parser.summary.setLength(parser.SUMMARY_LENGTH);
+ parser.summary.setLength(HTMLParser.SUMMARY_LENGTH);
parser.titleComplete = true;
parser.notifyAll();
}
}
- }
- catch (IOException e) {
-
+ } catch (IOException e) {
e.printStackTrace();
}
}
More information about the Mulgara-svn
mailing list