[jsword-svn] r1167 - in trunk/common/src/main/java/org/crosswire/common: config util xml

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Thu Oct 19 14:47:27 MST 2006


Author: dmsmith
Date: 2006-10-19 14:47:05 -0700 (Thu, 19 Oct 2006)
New Revision: 1167

Modified:
   trunk/common/src/main/java/org/crosswire/common/config/ChoiceFactory.java
   trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/ReporterEvent.java
   trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java
   trunk/common/src/main/java/org/crosswire/common/util/WebResource.java
   trunk/common/src/main/java/org/crosswire/common/xml/FormatType.java
   trunk/common/src/main/java/org/crosswire/common/xml/HTMLSerializingContentHandler.java
   trunk/common/src/main/java/org/crosswire/common/xml/PrettySerializingContentHandler.java
   trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java
   trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java
   trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java
   trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java
   trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java
Log:
cleanup of issues identified by pmd

Modified: trunk/common/src/main/java/org/crosswire/common/config/ChoiceFactory.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/ChoiceFactory.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/config/ChoiceFactory.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -54,7 +54,7 @@
         Class clazz = null;
 
         String type = option.getAttributeValue("type"); //$NON-NLS-1$
-        if (type.equals("custom")) //$NON-NLS-1$
+        if ("custom".equals(type)) //$NON-NLS-1$
         {
             String clazzstr = option.getAttributeValue("class"); //$NON-NLS-1$
             clazz = Class.forName(clazzstr);

Modified: trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -65,13 +65,13 @@
             {
                 try
                 {
-                    String file_name = classname.replace(',', '/') + EXTENSION_CLASS;
+                    String fileName = classname.replace(',', '/') + EXTENSION_CLASS;
                     ZipFile zip = new ZipFile(paths[i]);
-                    ZipEntry entry = zip.getEntry(file_name);
+                    ZipEntry entry = zip.getEntry(fileName);
 
                     if (entry != null && !entry.isDirectory())
                     {
-                        if (full != null && !full.equals(file_name))
+                        if (full != null && !full.equals(fileName))
                         {
                             log.warn("Warning duplicate " + classname + " found: " + full + " and " + paths[i]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                         }
@@ -83,24 +83,30 @@
                 }
                 catch (IOException ex)
                 {
-                    // If that zip file failed, then ignore it and more on.
+                    // If that zip file failed, then ignore it and move on.
+                    log.warn("Missing zip file for " + classname + " and " + paths[i]); //$NON-NLS-1$ //$NON-NLS-2$
                 }
             }
             else
             {
+                StringBuffer path = new StringBuffer(256);
+
                 // Search for the file
                 String extra = classname.replace('.', File.separatorChar);
 
-                if (!paths[i].endsWith(File.separator))
+                path.append(paths[i]);
+                if (paths[i].charAt(paths[i].length() - 1) != File.separatorChar)
                 {
-                    paths[i] += File.separator;
+                    path.append(File.separatorChar);
                 }
 
-                String file_name = paths[i] + extra + EXTENSION_CLASS;
+                path.append(extra);
+                path.append(EXTENSION_CLASS);
+                String fileName = path.toString();
 
-                if (new File(file_name).isFile())
+                if (new File(fileName).isFile())
                 {
-                    if (full != null && !full.equals(file_name))
+                    if (full != null && !full.equals(fileName))
                     {
                         log.warn("Warning duplicate " + classname + " found: " + full + " and " + paths[i]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                     }
@@ -263,8 +269,7 @@
      */
     public static Object getImplementation(Class clazz) throws MalformedURLException, ClassCastException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
     {
-        Class impl = getImplementor(clazz);
-        return impl.newInstance();
+        return getImplementor(clazz).newInstance();
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -175,15 +175,13 @@
     {
         if (url.getProtocol().equals(PROTOCOL_FILE))
         {
-            File file = new File(url.getFile());
-            return file.isFile();
+            return new File(url.getFile()).isFile();
         }
 
         try
         {
             // This will throw if the resource does not exist
-            InputStream is = url.openStream();
-            is.close();
+            url.openStream().close();
             return true;
         }
         catch (IOException ex)
@@ -206,8 +204,7 @@
             return false;
         }
 
-        File file = new File(orig.getFile());
-        return file.isDirectory();
+        return new File(orig.getFile()).isDirectory();
     }
 
     /**
@@ -236,8 +233,7 @@
     {
         checkFileURL(orig);
 
-        File file = new File(orig.getFile());
-        return file.delete();
+        return new File(orig.getFile()).delete();
     }
 
     /**
@@ -534,7 +530,7 @@
      */
     public static int getSize(URL url)
     {
-        return getSize(url, null);
+        return getSize(url, null, null);
     }
     public static int getSize(URL url, String proxyHost)
     {
@@ -544,15 +540,12 @@
     {
         if (url.getProtocol().equals(PROTOCOL_HTTP))
         {
-            WebResource wr = new WebResource(url, proxyHost, proxyPort);
-            return wr.getSize();
+            return new WebResource(url, proxyHost, proxyPort).getSize();
         }
 
         try
         {
-            URLConnection urlConnection = url.openConnection();
-            int size = urlConnection.getContentLength();
-            return size;
+            return url.openConnection().getContentLength();
         }
         catch (IOException e)
         {
@@ -566,7 +559,7 @@
      */
     public static long getLastModified(URL url)
     {
-        return getLastModified(url, null);
+        return getLastModified(url, null, null);
     }
 
     public static long getLastModified(URL url, String proxyHost)
@@ -578,8 +571,7 @@
     {
         if (url.getProtocol().equals(PROTOCOL_HTTP))
         {
-            WebResource wr = new WebResource(url, proxyHost, proxyPort);
-            return wr.getLastModified();
+            return new WebResource(url, proxyHost, proxyPort).getLastModified();
         }
 
         try
@@ -614,7 +606,7 @@
      */
     public static boolean isNewer(URL left, URL right)
     {
-        return isNewer(left, right, null);
+        return isNewer(left, right, null, null);
     }
     public static boolean isNewer(URL left, URL right, String proxyHost)
     {

Modified: trunk/common/src/main/java/org/crosswire/common/util/ReporterEvent.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ReporterEvent.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/util/ReporterEvent.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -77,7 +77,7 @@
         }
 
         String full = clazz.getName();
-        int lastDot = full.lastIndexOf("."); //$NON-NLS-1$
+        int lastDot = full.lastIndexOf('.');
         if (lastDot == -1)
         {
             return full;

Modified: trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -95,8 +95,7 @@
      */
     public static InputStream getResourceAsStream(Class clazz, String search) throws IOException, MissingResourceException
     {
-        URL url = ResourceUtil.getResource(clazz, search);
-        return url.openStream();
+        return ResourceUtil.getResource(clazz, search).openStream();
     }
 
     /**

Modified: trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -212,12 +212,12 @@
 
         if (str == null)
         {
-            return EMPTY_STRING_ARRAY;
+            return (String[]) EMPTY_STRING_ARRAY.clone();
         }
         int len = str.length();
         if (len == 0)
         {
-            return EMPTY_STRING_ARRAY;
+            return (String[]) EMPTY_STRING_ARRAY.clone();
         }
         List list = new ArrayList();
         int i = 0;
@@ -276,12 +276,12 @@
 
         if (str == null)
         {
-            return EMPTY_STRING_ARRAY;
+            return (String[]) EMPTY_STRING_ARRAY.clone();
         }
         int len = str.length();
         if (len == 0)
         {
-            return EMPTY_STRING_ARRAY;
+            return (String[]) EMPTY_STRING_ARRAY.clone();
         }
         List list = new ArrayList();
         int i = 0;
@@ -369,12 +369,12 @@
 
         if (str == null)
         {
-            return EMPTY_STRING_ARRAY;
+            return (String[]) EMPTY_STRING_ARRAY.clone();
         }
         int len = str.length();
         if (len == 0)
         {
-            return EMPTY_STRING_ARRAY;
+            return (String[]) EMPTY_STRING_ARRAY.clone();
         }
         List list = new ArrayList();
         int sizePlus1 = 1;

Modified: trunk/common/src/main/java/org/crosswire/common/util/WebResource.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/WebResource.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/util/WebResource.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -86,8 +86,7 @@
             int status = client.executeMethod(method);
             if (status == HttpStatus.SC_OK)
             {
-                HttpURLConnection connection = new HttpURLConnection(method, url);
-                return connection.getContentLength();
+                return new HttpURLConnection(method, url).getContentLength();
             }
             String reason = HttpStatus.getStatusText(status);
             Reporter.informUser(this, Msg.MISSING_FILE, new Object[] { reason + ':' + url.getFile() });
@@ -119,8 +118,7 @@
             // Execute the method.
             if (client.executeMethod(method) == HttpStatus.SC_OK)
             {
-                HttpURLConnection connection = new HttpURLConnection(method, url);
-                return connection.getLastModified();
+                return new HttpURLConnection(method, url).getLastModified();
             }
         }
         catch (IOException e)

Modified: trunk/common/src/main/java/org/crosswire/common/xml/FormatType.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/FormatType.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/FormatType.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -134,24 +134,6 @@
         return VALUES[i];
     }
 
-    /**
-     * Prevent subclasses from overriding canonical identity based Object methods
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
-    public boolean equals(Object o)
-    {
-        return super.equals(o);
-    }
-
-    /**
-     * Prevent subclasses from overriding canonical identity based Object methods
-     * @see java.lang.Object#hashCode()
-     */
-    public int hashCode()
-    {
-        return super.hashCode();
-    }
-
     /* (non-Javadoc)
      * @see java.lang.Object#toString()
      */

Modified: trunk/common/src/main/java/org/crosswire/common/xml/HTMLSerializingContentHandler.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/HTMLSerializingContentHandler.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/HTMLSerializingContentHandler.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -70,7 +70,7 @@
     /* @Override */
     protected String decorateTagName(String tagName)
     {
-        StringBuffer buf = new StringBuffer();
+        StringBuffer buf = new StringBuffer(50);
         buf.append("<font class='tag'>"); //$NON-NLS-1$
         buf.append(super.decorateTagName(tagName));
         buf.append("</font>"); //$NON-NLS-1$
@@ -83,7 +83,7 @@
     /* @Override */
     protected String decorateAttributeName(String attrName)
     {
-        StringBuffer buf = new StringBuffer();
+        StringBuffer buf = new StringBuffer(50);
         buf.append("<font class='attr'>"); //$NON-NLS-1$
         buf.append(super.decorateAttributeName(attrName));
         buf.append("</font>"); //$NON-NLS-1$
@@ -96,7 +96,7 @@
     /* @Override */
     protected String decorateAttributeValue(String attrValue)
     {
-        StringBuffer buf = new StringBuffer();
+        StringBuffer buf = new StringBuffer(50);
         buf.append("<font class='value'>"); //$NON-NLS-1$
         buf.append(super.decorateAttributeValue(attrValue));
         buf.append("</font>"); //$NON-NLS-1$
@@ -109,7 +109,7 @@
     /* @Override */
     protected String decorateCharacters(String characters)
     {
-        StringBuffer buf = new StringBuffer();
+        StringBuffer buf = new StringBuffer(50);
         buf.append("<font class='text'>"); //$NON-NLS-1$
         buf.append(XMLUtil.escape(super.decorateCharacters(characters)).replaceAll("\n", "<br>")); //$NON-NLS-1$ //$NON-NLS-2$
         buf.append("</font>"); //$NON-NLS-1$
@@ -122,7 +122,7 @@
     /* @Override */
     protected String decorateIndent(int indentLevel)
     {
-        StringBuffer buf = new StringBuffer();
+        StringBuffer buf = new StringBuffer(100);
         buf.append("<font class='indent'>"); //$NON-NLS-1$
         buf.append(super.decorateIndent(indentLevel).replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;")); //$NON-NLS-1$ //$NON-NLS-2$
         buf.append("</font>"); //$NON-NLS-1$
@@ -135,19 +135,9 @@
     /* @Override */
     public void startDocument()
     {
-        StringBuffer buf = new StringBuffer();
-
         // Note: we should be using SPAN here but Sun's Java does not support styling it.
         // Also, it introduces whitespace between the span and the text.
-        buf.append("<html><head><style type='text/css'>\n"); //$NON-NLS-1$
-        buf.append("FONT.tag    { font-family:courier new, monospaced; color:#666699; font-weight:bold; }\n"); //$NON-NLS-1$
-        buf.append("FONT.attr   { font-family:courier new, monospaced; color:#669966; font-weight:bold; }\n"); //$NON-NLS-1$
-        buf.append("FONT.value  { font-family:courier new, monospaced; color:#669966; font-style:italic; }\n"); //$NON-NLS-1$
-        buf.append("FONT.indent { }\n"); //$NON-NLS-1$
-        buf.append("FONT.text   { font-family:courier new, monospaced; background:#FFFF99; }\n"); //$NON-NLS-1$
-        buf.append("</style></head><body>\n"); //$NON-NLS-1$
-
-        write(buf.toString());
+        write("<html><head><style type='text/css'>\nFONT.tag    { font-family:courier new, monospaced; color:#666699; font-weight:bold; }\nFONT.attr   { font-family:courier new, monospaced; color:#669966; font-weight:bold; }\nFONT.value  { font-family:courier new, monospaced; color:#669966; font-style:italic; }\nFONT.indent { }\nFONT.text   { font-family:courier new, monospaced; background:#FFFF99; }\n</style></head><body>\n"); //$NON-NLS-1$
     }
 
     /* (non-Javadoc)

Modified: trunk/common/src/main/java/org/crosswire/common/xml/PrettySerializingContentHandler.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/PrettySerializingContentHandler.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/PrettySerializingContentHandler.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -308,7 +308,7 @@
         }
         catch (IOException e)
         {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
         }
     }
 
@@ -320,7 +320,7 @@
         }
         catch (IOException e)
         {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
         }
     }
 

Modified: trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProvider.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -77,14 +77,11 @@
         TemplateInfo tinfo = (TemplateInfo) txers.get(xslurl);
 
         // But check it is up to date
-        if (tinfo != null)
+        if (tinfo != null && modtime > tinfo.getModtime())
         {
-            if (modtime > tinfo.getModtime())
-            {
-                txers.remove(xslurl);
-                tinfo = null;
-                log.debug("updated style, re-caching. xsl=" + xslurl.toExternalForm()); //$NON-NLS-1$
-            }
+            txers.remove(xslurl);
+            tinfo = null;
+            log.debug("updated style, re-caching. xsl=" + xslurl.toExternalForm()); //$NON-NLS-1$
         }
 
         if (tinfo == null)

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XMLFeatureSet.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -95,7 +95,7 @@
         for (int i = 0; i < argv.length; i++)
         {
             String arg = argv[i];
-            if (arg.startsWith("-")) //$NON-NLS-1$
+            if (arg.charAt(0) == '=')
             {
                 String option = arg.substring(1);
                 String key = option.toLowerCase(Locale.ENGLISH);

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XMLProcess.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -24,7 +24,6 @@
 import java.io.IOException;
 
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
@@ -74,10 +73,10 @@
         for (int i = 0; i < argv.length; i++)
         {
             arg = argv[i];
-            if (arg.startsWith("-")) //$NON-NLS-1$
+            if (arg.charAt(0) == '-')
             {
                 String option = arg.substring(1);
-                if (option.equals("h")) //$NON-NLS-1$
+                if ("h".equals(option)) //$NON-NLS-1$
                 {
                     checker.usage();
                     System.exit(0);
@@ -97,10 +96,10 @@
         for (i = 0; i < argv.length; i++)
         {
             String arg = argv[i];
-            if (arg.startsWith("-")) //$NON-NLS-1$
+            if (arg.charAt(0) == '-')
             {
                 String option = arg.substring(1);
-                if (option.equals("p")) //$NON-NLS-1$
+                if ("p".equals(option)) //$NON-NLS-1$
                 {
                     // get parser name
                     if (++i == argv.length)
@@ -112,7 +111,7 @@
                     createParser(parserName);
                     continue;
                 }
-                if (option.equals("a")) //$NON-NLS-1$
+                if ("a".equals(option)) //$NON-NLS-1$
                 {
                     // get parser name
                     if (++i == argv.length)
@@ -219,10 +218,6 @@
         {
             parser.parse(xmlFile);
         }
-        catch (SAXParseException e)
-        {
-            // ignore
-        }
         catch (SAXException e)
         {
             System.err.println("error: Parse error occurred - " + e.getMessage()); //$NON-NLS-1$

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XMLUtil.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -352,7 +352,7 @@
                         // attribute, so this must be the beginning of the next
                         // NOTE(joe): no - spaces can exist in attr values
                         String value = working.substring(startattr, i);
-                        if (value.indexOf("=") == -1) //$NON-NLS-1$
+                        if (value.indexOf('=') == -1)
                         {
                             // this 'attribute' does not contain an equals so
                             // we call it a word and end the parse

Modified: trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java	2006-10-18 01:05:14 UTC (rev 1166)
+++ trunk/common/src/main/java/org/crosswire/common/xml/XalanProcess.java	2006-10-19 21:47:05 UTC (rev 1167)
@@ -66,20 +66,20 @@
             }
             catch (ClassNotFoundException e1)
             {
-                e1.printStackTrace();
+                e1.printStackTrace(System.err);
             }
             catch (SecurityException e1)
             {
-                e1.printStackTrace();
+                e1.printStackTrace(System.err);
             }
             catch (NoSuchMethodException e1)
             {
-                e1.printStackTrace();
+                e1.printStackTrace(System.err);
             }
         }
         catch (NoSuchMethodException e)
         {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
             return;
         }
 
@@ -92,15 +92,15 @@
         }
         catch (IllegalArgumentException e)
         {
-             e.printStackTrace();
+             e.printStackTrace(System.err);
         }
         catch (IllegalAccessException e)
         {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
         }
         catch (InvocationTargetException e)
         {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
         }
     }
 }




More information about the jsword-svn mailing list