jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1166638 [2/3] - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/cnd/ jackrabbit-jcr-commons/src/main/java/org/apac...
Date Thu, 08 Sep 2011 11:50:45 GMT
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/QueryObjectModelBuilderRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/QueryObjectModelBuilderRegistry.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/QueryObjectModelBuilderRegistry.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/QueryObjectModelBuilderRegistry.java Thu Sep  8 11:50:44 2011
@@ -16,16 +16,15 @@
  */
 package org.apache.jackrabbit.commons.query;
 
-import java.util.List;
+import javax.imageio.spi.ServiceRegistry;
+import javax.jcr.query.InvalidQueryException;
 import java.util.ArrayList;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Arrays;
 import java.util.Collections;
-
-import javax.imageio.spi.ServiceRegistry;
-import javax.jcr.query.InvalidQueryException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
 
 /**
  * Implements a central access to QueryObjectModelBuilder instances.
@@ -33,7 +32,7 @@ import javax.jcr.query.InvalidQueryExcep
 public class QueryObjectModelBuilderRegistry {
 
     /**
-     * List of <code>QueryObjectModelBuilder</code> instances known to the classloader.
+     * List of {@code QueryObjectModelBuilder} instances known to the classloader.
      */
     private static final List<QueryObjectModelBuilder> BUILDERS = new ArrayList<QueryObjectModelBuilder>();
 
@@ -42,10 +41,14 @@ public class QueryObjectModelBuilderRegi
      */
     private static final Set<String> LANGUAGES;
 
+    private QueryObjectModelBuilderRegistry() {
+    }
+
     static {
         Set<String> languages = new HashSet<String>();
         Iterator<QueryObjectModelBuilder> it = ServiceRegistry.lookupProviders(QueryObjectModelBuilder.class,
                 QueryObjectModelBuilder.class.getClassLoader());
+
         while (it.hasNext()) {
             QueryObjectModelBuilder builder = it.next();
             BUILDERS.add(builder);
@@ -55,17 +58,15 @@ public class QueryObjectModelBuilderRegi
     }
 
     /**
-     * Returns the <code>QueryObjectModelBuilder</code> for
-     * <code>language</code>.
+     * Returns the {@code QueryObjectModelBuilder} for
+     * {@code language}.
      *
      * @param language the language of the query statement.
-     * @return the <code>QueryObjectModelBuilder</code> for
-     *         <code>language</code>.
+     * @return the {@code QueryObjectModelBuilder} for {@code language}.
      * @throws InvalidQueryException if there is no query object model builder
-     *                               for <code>language</code>.
+     *                               for {@code language}.
      */
-    public static QueryObjectModelBuilder getQueryObjectModelBuilder(String language)
-            throws InvalidQueryException {
+    public static QueryObjectModelBuilder getQueryObjectModelBuilder(String language) throws InvalidQueryException {
         for (QueryObjectModelBuilder builder : BUILDERS) {
             if (builder.canHandle(language)) {
                 return builder;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/JoinType.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/JoinType.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/JoinType.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/JoinType.java Thu Sep  8 11:50:44 2011
@@ -43,7 +43,7 @@ public enum JoinType {
 
     private final String sql;
 
-    private JoinType(String name, String sql) {
+    JoinType(String name, String sql) {
         this.name = name;
         this.sql = sql;
     }
@@ -58,10 +58,9 @@ public enum JoinType {
      * @return join
      * @throws RepositoryException if the join can not be created
      */
-    public Join join(
-            QueryObjectModelFactory factory,
-            Source left, Source right, JoinCondition condition)
+    public Join join(QueryObjectModelFactory factory, Source left, Source right, JoinCondition condition)
             throws RepositoryException {
+        
         return factory.join(left, right, name, condition);
     }
 
@@ -73,10 +72,10 @@ public enum JoinType {
      * @param left left source
      * @param right right source
      * @param condition join condition
-     * @return SQL join, <code>left join right</code>
+     * @return SQL join, {@code left join right}
      */
     public String formatSql(Object left, Object right, Object condition) {
-        return left + " " + sql + " " + right + " ON " + condition;
+        return left + " " + sql + ' ' + right + " ON " + condition;
     }
 
     /**
@@ -96,8 +95,7 @@ public enum JoinType {
      * @return join type with the given name
      * @throws RepositoryException if the given name is unknown
      */
-    public static JoinType getJoinTypeByName(String name)
-            throws RepositoryException {
+    public static JoinType getJoinTypeByName(String name) throws RepositoryException {
         for (JoinType type : JoinType.values()) {
             if (type.name.equals(name)) {
                 return type;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Operator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Operator.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Operator.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Operator.java Thu Sep  8 11:50:44 2011
@@ -59,11 +59,11 @@ public enum Operator {
      */
     private final String sql;
 
-    private Operator(String name, String op) {
+    Operator(String name, String op) {
         this(name, op, op);
     }
 
-    private Operator(String name, String xpath, String sql) {
+    Operator(String name, String xpath, String sql) {
         this.name = name;
         this.xpath = xpath;
         this.sql = sql;
@@ -78,10 +78,9 @@ public enum Operator {
      * @return comparison
      * @throws RepositoryException if the comparison can not be created
      */
-    public Comparison comparison(
-            QueryObjectModelFactory factory,
-            DynamicOperand left, StaticOperand right)
+    public Comparison comparison(QueryObjectModelFactory factory, DynamicOperand left, StaticOperand right)
             throws RepositoryException {
+
         return factory.comparison(left, name, right);
     }
 
@@ -91,14 +90,13 @@ public enum Operator {
      *
      * @param a first operand
      * @param b second operand
-     * @return XPath constraint, <code>a op b</code> or
-     *         <code>jcr:like(a, b)</code> for {@link #LIKE}
+     * @return XPath constraint, {@code a op b} or {@code jcr:like(a, b)} for {@link #LIKE}
      */
     public String formatXpath(String a, String b) {
         if (this == LIKE) {
-            return "jcr:like(" + a + ", " + b + ")";
+            return "jcr:like(" + a + ", " + b + ')';
         } else {
-            return a + " " + xpath + " " + b;
+            return a + ' ' + xpath + ' ' + b;
         }
     }
 
@@ -108,10 +106,10 @@ public enum Operator {
      *
      * @param a first operand
      * @param b second operand
-     * @return SQL constraint, <code>a op b</code>
+     * @return SQL constraint, {@code a op b}
      */
     public String formatSql(String a, String b) {
-        return a + " " + sql + " " + b;
+        return a + ' ' + sql + ' ' + b;
     }
 
     /**
@@ -130,15 +128,8 @@ public enum Operator {
      * @return names of all query operators
      */
     public static String[] getAllQueryOperators() {
-        return new String[] {
-                EQ.toString(),
-                NE.toString(),
-                GT.toString(),
-                GE.toString(),
-                LT.toString(),
-                LE.toString(),
-                LIKE.toString()
-        };
+        return new String[] {EQ.toString(), NE.toString(), GT.toString(), GE.toString(), LT.toString(),
+                LE.toString(), LIKE.toString()};
     }
 
     /**
@@ -148,8 +139,7 @@ public enum Operator {
      * @return operator with the given name
      * @throws RepositoryException if the given name is unknown
      */
-    public static Operator getOperatorByName(String name)
-            throws RepositoryException {
+    public static Operator getOperatorByName(String name) throws RepositoryException {
         for (Operator operator : Operator.values()) {
             if (operator.name.equals(name)) {
                 return operator;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Order.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Order.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Order.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/query/qom/Order.java Thu Sep  8 11:50:44 2011
@@ -34,7 +34,7 @@ public enum Order {
      */
     private final String name;
 
-    private Order(String name) {
+    Order(String name) {
         this.name = name;
     }
 
@@ -50,7 +50,7 @@ public enum Order {
      *
      * @param name the JCR name of an order.
      * @return the order with the given name.
-     * @throws IllegalArgumentException if <code>name</code> is not a known JCR
+     * @throws IllegalArgumentException if {@code name} is not a known JCR
      *                                  order name.
      */
     public static Order getOrderByName(String name) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java Thu Sep  8 11:50:44 2011
@@ -16,14 +16,11 @@
  */
 package org.apache.jackrabbit.commons.xml;
 
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.DefaultHandler;
 
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Result;
@@ -33,12 +30,13 @@ import javax.xml.transform.TransformerFa
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-import org.xml.sax.helpers.DefaultHandler;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * A {@link ContentHandler} that serializes SAX events to a given
@@ -63,7 +61,7 @@ public class SerializingContentHandler e
      * The character encoding used for serialization (UTF-8).
      * The encoding is fixed to make the text/xml content type safer to use.
      *
-     * @see https://issues.apache.org/jira/browse/JCR-1621
+     * see https://issues.apache.org/jira/browse/JCR-1621
      */
     public static final String ENCODING = "UTF-8";
 
@@ -107,7 +105,7 @@ public class SerializingContentHandler e
             probe.endElement("uri", "e", "p:e");
             probe.endPrefixMapping("p");
             probe.endDocument();
-            return writer.toString().indexOf("xmlns") == -1;
+            return !writer.toString().contains("xmlns");
         } catch (Exception e) {
             throw new UnsupportedOperationException("XML serialization fails");
         }
@@ -116,12 +114,11 @@ public class SerializingContentHandler e
     /**
      * Creates a serializing content handler that writes to the given stream.
      *
-     * @param stream serialization target
+     * @param output serialization target
      * @return serializing content handler
      * @throws SAXException if the content handler could not be initialized
      */
-    public static DefaultHandler getSerializer(OutputStream output)
-            throws SAXException {
+    public static DefaultHandler getSerializer(OutputStream output) throws SAXException {
         return getSerializer(new StreamResult(output));
     }
 
@@ -132,8 +129,7 @@ public class SerializingContentHandler e
      * @return serializing content handler
      * @throws SAXException if the content handler could not be initialized
      */
-    public static DefaultHandler getSerializer(Writer writer)
-            throws SAXException {
+    public static DefaultHandler getSerializer(Writer writer) throws SAXException {
         return getSerializer(new StreamResult(writer));
     }
 
@@ -144,15 +140,13 @@ public class SerializingContentHandler e
      * @return serializing content handler
      * @throws SAXException if the content handler could not be initialized
      */
-    public static DefaultHandler getSerializer(Result result)
-            throws SAXException {
+    public static DefaultHandler getSerializer(Result result) throws SAXException {
         try {
             TransformerHandler handler = FACTORY.newTransformerHandler();
             handler.setResult(result);
 
-            // Specify the output properties to avoid surprises especially in
-            // character encoding or the output method (might be html for some
-            // documents!)
+            // Specify the output properties to avoid surprises especially in character
+            // encoding or the output method (might be html for some documents!)
             Transformer transformer = handler.getTransformer();
             transformer.setOutputProperty(OutputKeys.METHOD, "xml");
             transformer.setOutputProperty(OutputKeys.ENCODING, ENCODING);
@@ -173,75 +167,77 @@ public class SerializingContentHandler e
     /**
      * The prefixes of startPrefixMapping() declarations for the coming element.
      */
-    private List prefixList = new ArrayList();
+    private final List<String> prefixList = new ArrayList<String>();
 
     /**
      * The URIs of startPrefixMapping() declarations for the coming element.
      */
-    private List uriList = new ArrayList();
+    private final List<String> uriList = new ArrayList<String>();
 
     /**
      * Maps of URI<->prefix mappings. Used to work around a bug in the Xalan
      * serializer.
      */
-    private Map uriToPrefixMap = new HashMap();
-    private Map prefixToUriMap = new HashMap();
+    private final Map<String, String> uriToPrefixMap = new HashMap<String, String>();
+    private final Map<String, String> prefixToUriMap = new HashMap<String, String>();
 
     /**
      * True if there has been some startPrefixMapping() for the coming element.
      */
-    private boolean hasMappings = false;
+    private boolean hasMappings;
 
     /**
      * Stack of the prefixes of explicitly generated prefix mapping calls
      * per each element level. An entry is appended at the beginning of each
      * {@link #startElement(String, String, String, Attributes)} call and
      * removed at the end of each {@link #endElement(String, String, String)}
-     * call. By default the entry for each element is <code>null</code> to
+     * call. By default the entry for each element is {@code null} to
      * avoid losing performance, but whenever the code detects a new prefix
-     * mapping that needs to be registered, the <code>null</code> entry is
+     * mapping that needs to be registered, the {@code null} entry is
      * replaced with a list of explicitly registered prefixes for that node.
      * When that element is closed, the listed prefixes get unmapped.
      *
      * @see #checkPrefixMapping(String, String)
      * @see <a href="https://issues.apache.org/jira/browse/JCR-1767">JCR-1767</a>
      */
-    private final List addedPrefixMappings = new ArrayList();
+    private final List<List<String>> addedPrefixMappings = new ArrayList<List<String>>();
 
     private SerializingContentHandler(ContentHandler handler) {
         super(handler);
     }
 
+    @Override
     public void startDocument() throws SAXException {
         // Cleanup
-        this.uriToPrefixMap.clear();
-        this.prefixToUriMap.clear();
+        uriToPrefixMap.clear();
+        prefixToUriMap.clear();
         clearMappings();
         super.startDocument();
     }
 
     /**
-     * Track mappings to be able to add <code>xmlns:</code> attributes
-     * in <code>startElement()</code>.
+     * Track mappings to be able to add {@code xmlns:} attributes
+     * in {@code startElement()}.
      */
+    @Override
     public void startPrefixMapping(String prefix, String uri) throws SAXException {
         // Store the mappings to reconstitute xmlns:attributes
         // except prefixes starting with "xml": these are reserved
         // VG: (uri != null) fixes NPE in startElement
         if (uri != null && !prefix.startsWith("xml")) {
-            this.hasMappings = true;
-            this.prefixList.add(prefix);
-            this.uriList.add(uri);
+            hasMappings = true;
+            prefixList.add(prefix);
+            uriList.add(uri);
 
             // append the prefix colon now, in order to save concatenations later, but
             // only for non-empty prefixes.
             if (prefix.length() > 0) {
-                this.uriToPrefixMap.put(uri, prefix + ":");
+                uriToPrefixMap.put(uri, prefix + ':');
             } else {
-                this.uriToPrefixMap.put(uri, prefix);
+                uriToPrefixMap.put(uri, prefix);
             }
 
-            this.prefixToUriMap.put(prefix, uri);
+            prefixToUriMap.put(prefix, uri);
         }
         super.startPrefixMapping(prefix, uri);
     }
@@ -255,20 +251,19 @@ public class SerializingContentHandler e
      *
      * @see <a href="https://issues.apache.org/jira/browse/JCR-1767">JCR-1767</a>
      * @param uri namespace URI
-     * @param qname element name with the prefix, or <code>null</code>
+     * @param qName element name with the prefix, or {@code null}
      * @throws SAXException if the prefix mapping can not be added
      */
-    private void checkPrefixMapping(String uri, String qname)
-            throws SAXException {
+    private void checkPrefixMapping(String uri, String qName) throws SAXException {
         // Only add the prefix mapping if the URI is not already known
         if (uri != null && uri.length() > 0 && !uri.startsWith("xml")
                 && !uriToPrefixMap.containsKey(uri)) {
             // Get the prefix
             String prefix = "ns";
-            if (qname != null && qname.length() > 0) {
-                int colon = qname.indexOf(':');
+            if (qName != null && qName.length() > 0) {
+                int colon = qName.indexOf(':');
                 if (colon != -1) {
-                    prefix = qname.substring(0, colon);
+                    prefix = qName.substring(0, colon);
                 }
             }
 
@@ -279,9 +274,9 @@ public class SerializingContentHandler e
             }
 
             int last = addedPrefixMappings.size() - 1;
-            List prefixes = (List) addedPrefixMappings.get(last);
+            List<String> prefixes = addedPrefixMappings.get(last);
             if (prefixes == null) {
-                prefixes = new ArrayList();
+                prefixes = new ArrayList<String>();
                 addedPrefixMappings.set(last, prefixes);
             }
             prefixes.add(prefix);
@@ -291,47 +286,48 @@ public class SerializingContentHandler e
     }
 
     /**
-     * Ensure all namespace declarations are present as <code>xmlns:</code> attributes
+     * Ensure all namespace declarations are present as {@code xmlns:} attributes
      * and add those needed before calling superclass. This is a workaround for a Xalan bug
-     * (at least in version 2.0.1) : <code>org.apache.xalan.serialize.SerializerToXML</code>
-     * ignores <code>start/endPrefixMapping()</code>.
+     * (at least in version 2.0.1) : {@code org.apache.xalan.serialize.SerializerToXML}
+     * ignores {@code start/endPrefixMapping()}.
      */
-    public void startElement(
-            String eltUri, String eltLocalName, String eltQName, Attributes attrs)
+    @Override
+    public void startElement(String eltUri, String eltLocalName, String eltQName, Attributes attributes)
             throws SAXException {
+        
         // JCR-1767: Generate extra prefix mapping calls where needed
         addedPrefixMappings.add(null);
         checkPrefixMapping(eltUri, eltQName);
-        for (int i = 0; i < attrs.getLength(); i++) {
-            checkPrefixMapping(attrs.getURI(i), attrs.getQName(i));
+        for (int i = 0; i < attributes.getLength(); i++) {
+            checkPrefixMapping(attributes.getURI(i), attributes.getQName(i));
         }
 
         // try to restore the qName. The map already contains the colon
-        if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) {
-            eltQName = this.uriToPrefixMap.get(eltUri) + eltLocalName;
+        if (null != eltUri && eltUri.length() != 0 && uriToPrefixMap.containsKey(eltUri)) {
+            eltQName = uriToPrefixMap.get(eltUri) + eltLocalName;
         }
-        if (this.hasMappings) {
+        if (hasMappings) {
             // Add xmlns* attributes where needed
 
             // New Attributes if we have to add some.
-            AttributesImpl newAttrs = null;
+            AttributesImpl newAttributes = null;
 
-            int mappingCount = this.prefixList.size();
-            int attrCount = attrs.getLength();
+            int mappingCount = prefixList.size();
+            int attrCount = attributes.getLength();
 
             for (int mapping = 0; mapping < mappingCount; mapping++) {
 
                 // Build infos for this namespace
-                String uri = (String) this.uriList.get(mapping);
-                String prefix = (String) this.prefixList.get(mapping);
-                String qName = prefix.equals("") ? "xmlns" : ("xmlns:" + prefix);
+                String uri = uriList.get(mapping);
+                String prefix = prefixList.get(mapping);
+                String qName = prefix.isEmpty() ? "xmlns" : "xmlns:" + prefix;
 
                 // Search for the corresponding xmlns* attribute
                 boolean found = false;
                 for (int attr = 0; attr < attrCount; attr++) {
-                    if (qName.equals(attrs.getQName(attr))) {
+                    if (qName.equals(attributes.getQName(attr))) {
                         // Check if mapping and attribute URI match
-                        if (!uri.equals(attrs.getValue(attr))) {
+                        if (!uri.equals(attributes.getValue(attr))) {
                             throw new SAXException("URI in prefix mapping and attribute do not match");
                         }
                         found = true;
@@ -341,20 +337,20 @@ public class SerializingContentHandler e
 
                 if (!found) {
                     // Need to add this namespace
-                    if (newAttrs == null) {
-                        // Need to test if attrs is empty or we go into an infinite loop...
+                    if (newAttributes == null) {
+                        // Need to test if attributes is empty or we go into an infinite loop...
                         // Well know SAX bug which I spent 3 hours to remind of :-(
                         if (attrCount == 0) {
-                            newAttrs = new AttributesImpl();
+                            newAttributes = new AttributesImpl();
                         } else {
-                            newAttrs = new AttributesImpl(attrs);
+                            newAttributes = new AttributesImpl(attributes);
                         }
                     }
 
-                    if (prefix.equals("")) {
-                        newAttrs.addAttribute(XML, qName, qName, "CDATA", uri);
+                    if (prefix.isEmpty()) {
+                        newAttributes.addAttribute(XML, qName, qName, "CDATA", uri);
                     } else {
-                        newAttrs.addAttribute(XML, prefix, qName, "CDATA", uri);
+                        newAttributes.addAttribute(XML, prefix, qName, "CDATA", uri);
                     }
                 }
             } // end for mapping
@@ -363,10 +359,10 @@ public class SerializingContentHandler e
             clearMappings();
 
             // Start element with new attributes, if any
-            super.startElement(eltUri, eltLocalName, eltQName, newAttrs == null ? attrs : newAttrs);
+            super.startElement(eltUri, eltLocalName, eltQName, newAttributes == null ? attributes : newAttributes);
         } else {
             // Normal job
-            super.startElement(eltUri, eltLocalName, eltQName, attrs);
+            super.startElement(eltUri, eltLocalName, eltQName, attributes);
         }
     }
 
@@ -375,21 +371,21 @@ public class SerializingContentHandler e
      * Receive notification of the end of an element.
      * Try to restore the element qName.
      */
+    @Override
     public void endElement(String eltUri, String eltLocalName, String eltQName) throws SAXException {
         // try to restore the qName. The map already contains the colon
-        if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) {
-            eltQName = this.uriToPrefixMap.get(eltUri) + eltLocalName;
+        if (null != eltUri && eltUri.length() != 0 && uriToPrefixMap.containsKey(eltUri)) {
+            eltQName = uriToPrefixMap.get(eltUri) + eltLocalName;
         }
 
         super.endElement(eltUri, eltLocalName, eltQName);
 
         // JCR-1767: Generate extra prefix un-mapping calls where needed
         int last = addedPrefixMappings.size() - 1;
-        List prefixes = (List) addedPrefixMappings.remove(last);
+        List<String> prefixes = addedPrefixMappings.remove(last);
         if (prefixes != null) {
-            Iterator iterator = prefixes.iterator();
-            while (iterator.hasNext()) {
-                endPrefixMapping((String) iterator.next());
+            for (String prefix : prefixes) {
+                endPrefixMapping(prefix);
             }
         }
     }
@@ -398,13 +394,14 @@ public class SerializingContentHandler e
      * End the scope of a prefix-URI mapping:
      * remove entry from mapping tables.
      */
+    @Override
     public void endPrefixMapping(String prefix) throws SAXException {
         // remove mappings for xalan-bug-workaround.
         // Unfortunately, we're not passed the uri, but the prefix here,
         // so we need to maintain maps in both directions.
-        if (this.prefixToUriMap.containsKey(prefix)) {
-            this.uriToPrefixMap.remove(this.prefixToUriMap.get(prefix));
-            this.prefixToUriMap.remove(prefix);
+        if (prefixToUriMap.containsKey(prefix)) {
+            uriToPrefixMap.remove(prefixToUriMap.get(prefix));
+            prefixToUriMap.remove(prefix);
         }
 
         if (hasMappings) {
@@ -424,18 +421,19 @@ public class SerializingContentHandler e
         super.endPrefixMapping(prefix);
     }
 
+    @Override
     public void endDocument() throws SAXException {
         // Cleanup
-        this.uriToPrefixMap.clear();
-        this.prefixToUriMap.clear();
+        uriToPrefixMap.clear();
+        prefixToUriMap.clear();
         clearMappings();
         super.endDocument();
     }
 
     private void clearMappings() {
-        this.hasMappings = false;
-        this.prefixList.clear();
-        this.uriList.clear();
+        hasMappings = false;
+        prefixList.clear();
+        uriList.clear();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Base64.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Base64.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Base64.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Base64.java Thu Sep  8 11:50:44 2011
@@ -28,7 +28,7 @@ import java.io.Writer;
 import java.io.BufferedWriter;
 
 /**
- * <code>Base64</code> provides Base64 encoding/decoding of strings and streams.
+ * {@code Base64} provides Base64 encoding/decoding of strings and streams.
  */
 public class Base64 {
 
@@ -41,16 +41,16 @@ public class Base64 {
 
     // decoding table (used to lookup original 6-bit with base64 character
     // as table index)
-    private static final byte[] DECODETABLE = new byte[128];
+    private static final byte[] DECODE_TABLE = new byte[128];
 
     static {
         // initialize decoding table
-        for (int i = 0; i < DECODETABLE.length; i++) {
-            DECODETABLE[i] = 0x7f;
+        for (int i = 0; i < DECODE_TABLE.length; i++) {
+            DECODE_TABLE[i] = 0x7f;
         }
         // build decoding table
         for (int i = 0; i < BASE64CHARS.length; i++) {
-            DECODETABLE[BASE64CHARS[i]] = (byte) i;
+            DECODE_TABLE[BASE64CHARS[i]] = (byte) i;
         }
     }
 
@@ -64,20 +64,6 @@ public class Base64 {
     }
 
     /**
-     * Base64-decodes or -encodes (see {@link #decodeOrEncode(String)}
-     * all the given arguments and prints the results on separate lines
-     * in standard output.
-     *
-     * @since Apache Jackrabbit 2.3
-     * @param args command line arguments to be decoded or encoded
-     */
-    public static void main(String[] args) {
-        for (String arg : args) {
-            System.out.println(decodeOrEncode(arg));
-        }
-    }
-
-    /**
      * Base64-decodes or -encodes the given string, depending on whether
      * or not it contains a "{base64}" prefix. If the string gets encoded,
      * the "{base64}" prefix is added to it.
@@ -97,11 +83,11 @@ public class Base64 {
     /**
      * Decodes a base64-encoded string marked by a "{base64}" prefix.
      * If the prefix is not found, then the string is returned as-is.
-     * If the given string is <code>null</code>, then <code>null</code>
+     * If the given string is {@code null}, then {@code null}
      * is returned.
      *
      * @since Apache Jackrabbit 2.3
-     * @param data string to be decoded, can be <code>null</code>
+     * @param data string to be decoded, can be {@code null}
      * @return the given string, possibly decoded
      */
     public static String decodeIfEncoded(String data) {
@@ -140,16 +126,15 @@ public class Base64 {
 
     /**
      * Outputs base64 representation of the specified stream data to a
-     * <code>Writer</code>.
+     * {@code Writer}.
      *
      * @param in     stream data to be encoded
      * @param writer writer to output the encoded data
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void encode(InputStream in, Writer writer)
-            throws IOException {
+    public static void encode(InputStream in, Writer writer) throws IOException {
         // encode stream data in chunks;
-        // chunksize must be a multiple of 3 in order
+        // chunk size must be a multiple of 3 in order
         // to avoid padding within output
         byte[] buffer = new byte[9 * 1024];
         int read;
@@ -160,14 +145,13 @@ public class Base64 {
 
     /**
      * Outputs base64 representation of the specified stream data to an
-     * <code>OutputStream</code>.
+     * {@code OutputStream}.
      *
      * @param in  stream data to be encoded
      * @param out stream where the encoded data should be written to
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void encode(InputStream in, OutputStream out)
-            throws IOException {
+    public static void encode(InputStream in, OutputStream out) throws IOException {
         Writer writer = new BufferedWriter(new OutputStreamWriter(out, CHARSET));
         try {
             encode(in, writer);
@@ -181,7 +165,7 @@ public class Base64 {
 
     /**
      * Outputs base64 representation of the specified data to a
-     * <code>Writer</code>.
+     * {@code Writer}.
      *
      * @param data   data to be encoded
      * @param off    offset within data at which to start encoding
@@ -189,8 +173,7 @@ public class Base64 {
      * @param writer writer to output the encoded data
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void encode(byte[] data, int off, int len, Writer writer)
-            throws IOException {
+    public static void encode(byte[] data, int off, int len, Writer writer) throws IOException {
         if (len == 0) {
             return;
         }
@@ -204,8 +187,8 @@ public class Base64 {
                     + ((data[off + 1] & 0xff) << 8)
                     + (data[off + 2] & 0xff);
             enc[0] = BASE64CHARS[i >> 18];
-            enc[1] = BASE64CHARS[(i >> 12) & 0x3f];
-            enc[2] = BASE64CHARS[(i >> 6) & 0x3f];
+            enc[1] = BASE64CHARS[i >> 12 & 0x3f];
+            enc[2] = BASE64CHARS[i >> 6 & 0x3f];
             enc[3] = BASE64CHARS[i & 0x3f];
             writer.write(enc, 0, 4);
             off += 3;
@@ -215,15 +198,15 @@ public class Base64 {
         if (len == 1) {
             int i = data[off] & 0xff;
             enc[0] = BASE64CHARS[i >> 2];
-            enc[1] = BASE64CHARS[(i << 4) & 0x3f];
+            enc[1] = BASE64CHARS[i << 4 & 0x3f];
             enc[2] = BASE64PAD;
             enc[3] = BASE64PAD;
             writer.write(enc, 0, 4);
         } else if (len == 2) {
             int i = ((data[off] & 0xff) << 8) + (data[off + 1] & 0xff);
             enc[0] = BASE64CHARS[i >> 10];
-            enc[1] = BASE64CHARS[(i >> 4) & 0x3f];
-            enc[2] = BASE64CHARS[(i << 2) & 0x3f];
+            enc[1] = BASE64CHARS[i >> 4 & 0x3f];
+            enc[2] = BASE64CHARS[i << 2 & 0x3f];
             enc[3] = BASE64PAD;
             writer.write(enc, 0, 4);
         }
@@ -234,7 +217,6 @@ public class Base64 {
      *
      * @since Apache Jackrabbit 2.3
      * @param data the string to be encoded
-     * @param base64-encoding of the string
      */
     public static String encode(String data) {
         try {
@@ -277,8 +259,7 @@ public class Base64 {
      * @param out    stream where the decoded data should be written to
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void decode(Reader reader, OutputStream out)
-            throws IOException {
+    public static void decode(Reader reader, OutputStream out) throws IOException {
         char[] chunk = new char[8192];
         int read;
         while ((read = reader.read(chunk)) > -1) {
@@ -287,15 +268,14 @@ public class Base64 {
     }
 
     /**
-     * Decode base64 encoded data. The data read from the inputstream is
+     * Decode base64 encoded data. The data read from the input stream is
      * assumed to be of charset "US-ASCII".
      *
-     * @param in  inputstream of the base64 encoded data to be decoded
+     * @param in  input stream of the base64 encoded data to be decoded
      * @param out stream where the decoded data should be written to
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void decode(InputStream in, OutputStream out)
-            throws IOException {
+    public static void decode(InputStream in, OutputStream out) throws IOException {
         decode(new InputStreamReader(in, CHARSET), out);
     }
 
@@ -306,8 +286,7 @@ public class Base64 {
      * @param out  stream where the decoded data should be written to
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void decode(String data, OutputStream out)
-            throws IOException {
+    public static void decode(String data, OutputStream out) throws IOException {
         char[] chars = data.toCharArray();
         decode(chars, 0, chars.length, out);
     }
@@ -319,8 +298,7 @@ public class Base64 {
      * @param out   stream where the decoded data should be written to
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void decode(char[] chars, OutputStream out)
-            throws IOException {
+    public static void decode(char[] chars, OutputStream out) throws IOException {
         decode(chars, 0, chars.length, out);
     }
 
@@ -333,8 +311,7 @@ public class Base64 {
      * @param out   stream where the decoded data should be written to
      * @throws java.io.IOException if an i/o error occurs
      */
-    public static void decode(char[] chars, int off, int len, OutputStream out)
-            throws IOException {
+    public static void decode(char[] chars, int off, int len, OutputStream out) throws IOException {
         if (len == 0) {
             return;
         }
@@ -346,16 +323,16 @@ public class Base64 {
         byte[] dec = new byte[3];
         int posChunk = 0;
         // decode in chunks of 4 characters
-        for (int i = off; i < (off + len); i++) {
+        for (int i = off; i < off + len; i++) {
             char c = chars[i];
-            if (c < DECODETABLE.length && DECODETABLE[c] != 0x7f
+            if (c < DECODE_TABLE.length && DECODE_TABLE[c] != 0x7f
                     || c == BASE64PAD) {
                 chunk[posChunk++] = c;
                 if (posChunk == chunk.length) {
-                    int b0 = DECODETABLE[chunk[0]];
-                    int b1 = DECODETABLE[chunk[1]];
-                    int b2 = DECODETABLE[chunk[2]];
-                    int b3 = DECODETABLE[chunk[3]];
+                    int b0 = DECODE_TABLE[chunk[0]];
+                    int b1 = DECODE_TABLE[chunk[1]];
+                    int b2 = DECODE_TABLE[chunk[2]];
+                    int b3 = DECODE_TABLE[chunk[3]];
                     if (chunk[3] == BASE64PAD && chunk[2] == BASE64PAD) {
                         dec[0] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
                         out.write(dec, 0, 1);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ChildrenCollectorFilter.java Thu Sep  8 11:50:44 2011
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.util;
 
+import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
+import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
+
 import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -23,19 +26,13 @@ import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.util.TraversingItemVisitor;
-
-import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
-import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.StringTokenizer;
 
 /**
- * <code>ChildrenCollectorFilter</code> is a utility class
- * which can be used to 'collect' child items of a
- * node whose names match a certain pattern. It implements the
- * <code>ItemVisitor</code> interface.
+ * {@code ChildrenCollectorFilter} is a utility class which can be used to 'collect' child items
+ * of a node whose names match a certain pattern. It implements the {@code ItemVisitor} interface.
  */
 public class ChildrenCollectorFilter extends TraversingItemVisitor.Default {
     static final char WILDCARD_CHAR = '*';
@@ -44,12 +41,13 @@ public class ChildrenCollectorFilter ext
     private final Collection<Item> children;
     private final boolean collectNodes;
     private final boolean collectProperties;
+
     // namePattern and nameGlobs fields are used mutually exclusive
     private final String namePattern;
     private final String[] nameGlobs;
 
     /**
-     * Constructs a <code>ChildrenCollectorFilter</code>
+     * Constructs a {@code ChildrenCollectorFilter}
      *
      * @param namePattern       the pattern which should be applied to the names
      *                          of the children
@@ -59,9 +57,9 @@ public class ChildrenCollectorFilter ext
      * @param maxLevel          number of hierarchy levels to traverse
      *                          (e.g. 1 for direct children only, 2 for children and their children, and so on)
      */
-    public ChildrenCollectorFilter(
-            String namePattern, Collection<Item> children,
-            boolean collectNodes, boolean collectProperties, int maxLevel) {
+    public ChildrenCollectorFilter(String namePattern, Collection<Item> children, boolean collectNodes,
+            boolean collectProperties, int maxLevel) {
+
         super(false, maxLevel);
         this.namePattern = namePattern;
         nameGlobs = null;
@@ -71,7 +69,7 @@ public class ChildrenCollectorFilter ext
     }
 
     /**
-     * Constructs a <code>ChildrenCollectorFilter</code>
+     * Constructs a {@code ChildrenCollectorFilter}
      *
      * @param nameGlobs         an array of globbing strings which should be
      *                          applied to the names of the children
@@ -81,9 +79,9 @@ public class ChildrenCollectorFilter ext
      * @param maxLevel          number of hierarchy levels to traverse
      *                          (e.g. 1 for direct children only, 2 for children and their children, and so on)
      */
-    public ChildrenCollectorFilter(
-            String[] nameGlobs, Collection<Item> children,
-            boolean collectNodes, boolean collectProperties, int maxLevel) {
+    public ChildrenCollectorFilter(String[] nameGlobs, Collection<Item> children, boolean collectNodes,
+            boolean collectProperties, int maxLevel) {
+
         super(false, maxLevel);
         this.nameGlobs = nameGlobs;
         namePattern = null;
@@ -92,43 +90,32 @@ public class ChildrenCollectorFilter ext
         this.collectProperties = collectProperties;
     }
 
-    public static NodeIterator collectChildNodes(
-            Node node, String namePattern) throws RepositoryException {
+    public static NodeIterator collectChildNodes(Node node, String namePattern) throws RepositoryException {
         Collection<Item> nodes = new ArrayList<Item>();
-        node.accept(new ChildrenCollectorFilter(
-                namePattern, nodes, true, false, 1));
+        node.accept(new ChildrenCollectorFilter(namePattern, nodes, true, false, 1));
         return new NodeIteratorAdapter(nodes);
     }
 
-    public static NodeIterator collectChildNodes(
-            Node node, String[] nameGlobs) throws RepositoryException {
+    public static NodeIterator collectChildNodes(Node node, String[] nameGlobs) throws RepositoryException {
         Collection<Item> nodes = new ArrayList<Item>();
-        node.accept(new ChildrenCollectorFilter(
-                nameGlobs, nodes, true, false, 1));
+        node.accept(new ChildrenCollectorFilter(nameGlobs, nodes, true, false, 1));
         return new NodeIteratorAdapter(nodes);
     }
 
-    public static PropertyIterator collectProperties(
-            Node node, String namePattern) throws RepositoryException {
+    public static PropertyIterator collectProperties(Node node, String namePattern) throws RepositoryException {
         Collection<Item> properties = new ArrayList<Item>();
-        node.accept(new ChildrenCollectorFilter(
-                namePattern, properties, false, true, 1));
+        node.accept(new ChildrenCollectorFilter(namePattern, properties, false, true, 1));
         return new PropertyIteratorAdapter(properties);
     }
 
-    public static PropertyIterator collectProperties(
-            Node node, String[] nameGlobs) throws RepositoryException {
+    public static PropertyIterator collectProperties(Node node, String[] nameGlobs) throws RepositoryException {
         Collection<Item> properties = new ArrayList<Item>();
-        node.accept(new ChildrenCollectorFilter(
-                nameGlobs, properties, false, true, 1));
+        node.accept(new ChildrenCollectorFilter(nameGlobs, properties, false, true, 1));
         return new PropertyIteratorAdapter(properties);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    protected void entering(Node node, int level)
-            throws RepositoryException {
+    @Override
+    protected void entering(Node node, int level) throws RepositoryException {
         if (level > 0 && collectNodes) {
             if (namePattern != null) {
                 if (matches(node.getName(), namePattern)) {
@@ -142,11 +129,8 @@ public class ChildrenCollectorFilter ext
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    protected void entering(Property property, int level)
-            throws RepositoryException {
+    @Override
+    protected void entering(Property property, int level) throws RepositoryException {
         if (level > 0 && collectProperties) {
             if (namePattern != null) {
                 if (matches(property.getName(), namePattern)) {
@@ -167,11 +151,11 @@ public class ChildrenCollectorFilter ext
      * wildcard characters ("*"), or a disjunction (using the "|" character
      * to represent logical <i>OR</i>) of these. For example,
      * <p/>
-     * <code>"jcr:*|foo:bar"</code>
+     * {@code "jcr:*|foo:bar"}
      * <p/>
      * would match
      * <p/>
-     * <code>"foo:bar"</code>, but also <code>"jcr:whatever"</code>.
+     * {@code "foo:bar"}, but also {@code "jcr:whatever"}.
      * <p/>
      * <pre>
      * The EBNF for pattern is:
@@ -208,11 +192,11 @@ public class ChildrenCollectorFilter ext
     }
 
     /**
-     * Matches the <code>nameGlob</code> strings in the passed array against
+     * Matches the {@code nameGlob} strings in the passed array against
      * the specified name.
      * <p>
      * A glob may be a full name or a partial name with one or more
-     * wildcard characters ("<code>*</code>").
+     * wildcard characters ("{@code *}").
      * <p>
      * Note that unlike in the case of the {@link #matches(String, String)}
      * leading and trailing whitespace around a glob is <i>not</i> ignored.
@@ -223,10 +207,9 @@ public class ChildrenCollectorFilter ext
      * @see javax.jcr.Node#getNodes(String[])
      */
     public static boolean matches(String name, String[] nameGlobs) {
-        for (int i = 0; i < nameGlobs.length; i++) {
-            // use globbing string as-is, i.e. don't trim any leading/trailing
-            // whitespace
-            if (internalMatches(name, nameGlobs[i], 0, 0)) {
+        for (String nameGlob : nameGlobs) {
+            // use globbing string as-is, i.e. don't trim any leading/trailing whitespace
+            if (internalMatches(name, nameGlob, 0, 0)) {
                 return true;
             }
         }
@@ -238,28 +221,17 @@ public class ChildrenCollectorFilter ext
      *
      * @param s       The string to be tested
      * @param pattern The pattern
-     * @param sOff    offset within <code>s</code>
-     * @param pOff    offset within <code>pattern</code>.
-     * @return true if <code>s</code> matched pattern, else false.
+     * @param sOff    offset within {@code s}
+     * @param pOff    offset within {@code pattern}.
+     * @return true if {@code s} matched pattern, else false.
      */
-    private static boolean internalMatches(String s, String pattern,
-                                           int sOff, int pOff) {
+    private static boolean internalMatches(String s, String pattern, int sOff, int pOff) {
         int pLen = pattern.length();
         int sLen = s.length();
 
         while (true) {
             if (pOff >= pLen) {
-                if (sOff >= sLen) {
-                    return true;
-                } else if (s.charAt(sOff) == '[') {
-                    // check for subscript notation (e.g. "whatever[1]")
-
-                    // the entire pattern matched up to the subscript:
-                    // -> ignore the subscript
-                    return true;
-                } else {
-                    return false;
-                }
+                return sOff >= sLen || s.charAt(sOff) == '[';
             }
             if (sOff >= sLen && pattern.charAt(pOff) != WILDCARD_CHAR) {
                 return false;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java Thu Sep  8 11:50:44 2011
@@ -21,7 +21,7 @@ import java.util.GregorianCalendar;
 import java.util.TimeZone;
 
 /**
- * The <code>ISO8601</code> utility class provides helper methods
+ * The {@code ISO8601} utility class provides helper methods
  * to deal with date/time formatting using a specific ISO8601-compliant
  * format (see <a href="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a>).
  * <p/>
@@ -46,13 +46,17 @@ import java.util.TimeZone;
  * </pre>
  */
 public final class ISO8601 {
+
+    private ISO8601() {
+    }
+
     /**
      * Parses an ISO8601-compliant date/time string.
      *
      * @param text the date/time string to be parsed
-     * @return a <code>Calendar</code>, or <code>null</code> if the input could
+     * @return a {@code Calendar}, or {@code null} if the input could
      *         not be parsed
-     * @throws IllegalArgumentException if a <code>null</code> argument is passed
+     * @throws IllegalArgumentException if a {@code null} argument is passed
      */
     public static Calendar parse(String text) {
         if (text == null) {
@@ -184,14 +188,10 @@ public final class ISO8601 {
         cal.set(Calendar.MILLISECOND, ms);
 
         try {
-            /**
-             * the following call will trigger an IllegalArgumentException
-             * if any of the set values are illegal or out of range
-             */
+            // the following call will trigger an IllegalArgumentException
+            // if any of the set values are illegal or out of range
             cal.getTime();
-            /**
-             * in addition check the validity of the year
-             */
+            // in addition check the validity of the year
             getYear(cal);
         } catch (IllegalArgumentException e) {
             return null;
@@ -201,12 +201,12 @@ public final class ISO8601 {
     }
 
     /**
-     * Formats a <code>Calendar</code> value into an ISO8601-compliant
+     * Formats a {@code Calendar} value into an ISO8601-compliant
      * date/time string.
      *
      * @param cal the time value to be formatted into a date/time string.
      * @return the formatted date/time string.
-     * @throws IllegalArgumentException if a <code>null</code> argument is passed
+     * @throws IllegalArgumentException if a {@code null} argument is passed
      * or the calendar cannot be represented as defined by ISO 8601 (i.e. year
      * with more than four digits).
      */
@@ -215,13 +215,10 @@ public final class ISO8601 {
             throw new IllegalArgumentException("argument can not be null");
         }
 
-        /**
-         * the format of the date/time string is:
-         * YYYY-MM-DDThh:mm:ss.SSSTZD
-         *
-         * note that we cannot use java.text.SimpleDateFormat for
-         * formatting because it can't handle years <= 0 and TZD's
-         */
+        // the format of the date/time string is:
+        // YYYY-MM-DDThh:mm:ss.SSSTZD
+        // note that we cannot use java.text.SimpleDateFormat for
+        // formatting because it can't handle years <= 0 and TZD's
         StringBuilder buf = new StringBuilder();
         // year ([-]YYYY)
         appendZeroPaddedInt(buf, getYear(cal), 4);
@@ -248,8 +245,8 @@ public final class ISO8601 {
         // determine offset of timezone from UTC (incl. daylight saving)
         int offset = tz.getOffset(cal.getTimeInMillis());
         if (offset != 0) {
-            int hours = Math.abs((offset / (60 * 1000)) / 60);
-            int minutes = Math.abs((offset / (60 * 1000)) % 60);
+            int hours = Math.abs(offset / (60 * 1000) / 60);
+            int minutes = Math.abs(offset / (60 * 1000) % 60);
             buf.append(offset < 0 ? '-' : '+');
             appendZeroPaddedInt(buf, hours, 2);
             buf.append(':');
@@ -272,12 +269,9 @@ public final class ISO8601 {
     public static int getYear(Calendar cal) throws IllegalArgumentException {
         // determine era and adjust year if necessary
         int year = cal.get(Calendar.YEAR);
-        if (cal.isSet(Calendar.ERA)
-                && cal.get(Calendar.ERA) == GregorianCalendar.BC) {
-            /**
-             * calculate year using astronomical system:
-             * year n BCE => astronomical year -n + 1
-             */
+        if (cal.isSet(Calendar.ERA) && cal.get(Calendar.ERA) == GregorianCalendar.BC) {
+            // calculate year using astronomical system:
+            // year n BCE => astronomical year -n + 1
             year = 0 - year + 1;
         }
 

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java Thu Sep  8 11:50:44 2011
@@ -22,7 +22,7 @@ import java.util.regex.Pattern;
 /**
  * Implements the encode and decode routines as specified for XML name to SQL
  * identifier conversion in ISO 9075-14:2003.<br/>
- * If a character <code>c</code> is not valid at a certain position in an XML 1.0
+ * If a character {@code c} is not valid at a certain position in an XML 1.0
  * NCName it is encoded in the form: '_x' + hexValueOf(c) + '_'.
  */
 public class ISO9075 {
@@ -40,17 +40,16 @@ public class ISO9075 {
     private static final String HEX_DIGITS = "0123456789abcdefABCDEF";
 
     /**
-     * Encodes <code>name</code> as specified in ISO 9075.
-     * @param name the <code>String</code> to encode.
-     * @return the encoded <code>String</code> or <code>name</code> if it does
-     *   not need encoding.
+     * Encodes {@code name} as specified in ISO 9075.
+     * @param name the {@code String} to encode.
+     * @return the encoded {@code String} or {@code name} if it does not need encoding.
      */
     public static String encode(String name) {
         // quick check for root node name
         if (name.length() == 0) {
             return name;
         }
-        if (XMLChar.isValidName(name) && name.indexOf("_x") < 0) {
+        if (XMLChar.isValidName(name) && !name.contains("_x")) {
             // already valid
             return name;
         } else {
@@ -86,16 +85,16 @@ public class ISO9075 {
     }
 
     /**
-     * Encodes <code>path</code> as specified in ISO 9075. Please note that
-     * the character '<code>[</code>' is not encoded but rather interpreted as
+     * Encodes {@code path} as specified in ISO 9075. Please note that
+     * the character '{@code [}' is not encoded but rather interpreted as
      * the start of an index in a path segment.
      *
-     * @param path the <code>String</code> to encode.
-     * @return the encoded <code>String</code>.
+     * @param path the {@code String} to encode.
+     * @return the encoded {@code String}.
      */
     public static String encodePath(String path) {
         String[] names = Text.explode(path, '/', true);
-        StringBuffer encoded = new StringBuffer(path.length());
+        StringBuilder encoded = new StringBuilder(path.length());
         for (int i = 0; i < names.length; i++) {
             // detect index
             String index = null;
@@ -116,13 +115,13 @@ public class ISO9075 {
     }
 
     /**
-     * Decodes the <code>name</code>.
-     * @param name the <code>String</code> to decode.
-     * @return the decoded <code>String</code>.
+     * Decodes the {@code name}.
+     * @param name the {@code String} to decode.
+     * @return the decoded {@code String}.
      */
     public static String decode(String name) {
         // quick check
-        if (name.indexOf("_x") < 0) {
+        if (!name.contains("_x")) {
             // not encoded
             return name;
         }
@@ -143,25 +142,25 @@ public class ISO9075 {
     //-------------------------< internal >-------------------------------------
 
     /**
-     * Encodes the character <code>c</code> as a String in the following form:
-     * <code>"_x" + hex value of c + "_"</code>. Where the hex value has
+     * Encodes the character {@code c} as a String in the following form:
+     * {@code "_x" + hex value of c + "_"}. Where the hex value has
      * four digits if the character with possibly leading zeros.
      * <p/>
      * Example: ' ' (the space character) is encoded to: _x0020_
      * @param c the character to encode
-     * @param b the encoded character is appended to <code>StringBuffer</code>
-     *  <code>b</code>.
+     * @param b the encoded character is appended to {@code StringBuffer}
+     *  {@code b}.
      */
     private static void encode(char c, StringBuffer b) {
         b.append("_x");
         String hex = Integer.toHexString(c);
         b.append(PADDING, 0, 4 - hex.length());
         b.append(hex);
-        b.append("_");
+        b.append('_');
     }
 
     /**
-     * Returns true if <code>name.charAt(location)</code> is the underscore
+     * Returns true if {@code name.charAt(location)} is the underscore
      * character and the following character sequence is 'xHHHH_' where H
      * is a hex digit.
      * @param name the name to check.

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java?rev=1166638&r1=1166637&r2=1166638&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java Thu Sep  8 11:50:44 2011
@@ -47,8 +47,7 @@ public class Text {
      * @param enc  the character encoding to use
      * @return a hex encoded string of the md5 digested input
      */
-    public static String md5(String data, String enc)
-            throws UnsupportedEncodingException {
+    public static String md5(String data, String enc) throws UnsupportedEncodingException {
         try {
             return digest("MD5", data.getBytes(enc));
         } catch (NoSuchAlgorithmException e) {
@@ -73,7 +72,7 @@ public class Text {
     /**
      * Digest the plain string using the given algorithm.
      *
-     * @param algorithm The alogrithm for the digest. This algorithm must be
+     * @param algorithm The algorithm for the digest. This algorithm must be
      *                  supported by the MessageDigest class.
      * @param data      The plain text String to be digested.
      * @param enc       The character encoding to use
@@ -98,14 +97,12 @@ public class Text {
      * @throws java.security.NoSuchAlgorithmException if the desired algorithm is not supported by
      *                                  the MessageDigest class.
      */
-    public static String digest(String algorithm, byte[] data)
-            throws NoSuchAlgorithmException {
-
+    public static String digest(String algorithm, byte[] data) throws NoSuchAlgorithmException {
         MessageDigest md = MessageDigest.getInstance(algorithm);
         byte[] digest = md.digest(data);
         StringBuilder res = new StringBuilder(digest.length * 2);
         for (byte b : digest) {
-            res.append(hexTable[(b >> 4) & 15]);
+            res.append(hexTable[b >> 4 & 15]);
             res.append(hexTable[b & 15]);
         }
         return res.toString();
@@ -130,7 +127,7 @@ public class Text {
      *
      * @param str          the string to decompose
      * @param ch           the character to use a split pattern
-     * @param respectEmpty if <code>true</code>, empty elements are generated
+     * @param respectEmpty if {@code true}, empty elements are generated
      * @return an array of strings
      */
     public static String[] explode(String str, int ch, boolean respectEmpty) {
@@ -140,19 +137,19 @@ public class Text {
 
         ArrayList<String> strings = new ArrayList<String>();
         int pos;
-        int lastpos = 0;
+        int lastPos = 0;
 
-        // add snipples
-        while ((pos = str.indexOf(ch, lastpos)) >= 0) {
-            if (pos - lastpos > 0 || respectEmpty) {
-                strings.add(str.substring(lastpos, pos));
+        // add snippets
+        while ((pos = str.indexOf(ch, lastPos)) >= 0) {
+            if (pos - lastPos > 0 || respectEmpty) {
+                strings.add(str.substring(lastPos, pos));
             }
-            lastpos = pos + 1;
+            lastPos = pos + 1;
         }
         // add rest
-        if (lastpos < str.length()) {
-            strings.add(str.substring(lastpos));
-        } else if (respectEmpty && lastpos == str.length()) {
+        if (lastPos < str.length()) {
+            strings.add(str.substring(lastPos));
+        } else if (respectEmpty && lastPos == str.length()) {
             strings.add("");
         }
 
@@ -163,14 +160,14 @@ public class Text {
     /**
      * Concatenates all strings in the string array using the specified delimiter.
      * @param arr
-     * @param delim
+     * @param deliminator
      * @return the concatenated string
      */
-    public static String implode(String[] arr, String delim) {
+    public static String implode(String[] arr, String deliminator) {
         StringBuilder buf = new StringBuilder();
         for (int i = 0; i < arr.length; i++) {
             if (i > 0) {
-                buf.append(delim);
+                buf.append(deliminator);
             }
             buf.append(arr[i]);
         }
@@ -178,12 +175,12 @@ public class Text {
     }
 
     /**
-     * Replaces all occurrences of <code>oldString</code> in <code>text</code>
-     * with <code>newString</code>.
+     * Replaces all occurrences of {@code oldString} in {@code text}
+     * with {@code newString}.
      *
      * @param text
-     * @param oldString old substring to be replaced with <code>newString</code>
-     * @param newString new substring to replace occurrences of <code>oldString</code>
+     * @param oldString old substring to be replaced with {@code newString}
+     * @param newString new substring to replace occurrences of {@code oldString}
      * @return a string
      */
     public static String replace(String text, String oldString, String newString) {
@@ -264,8 +261,8 @@ public class Text {
     }
 
     /**
-     * The list of characters that are not encoded by the <code>escape()</code>
-     * and <code>unescape()</code> METHODS. They contains the characters as
+     * The list of characters that are not encoded by the {@code escape()}
+     * and {@code unescape()} METHODS. They contains the characters as
      * defined 'unreserved' in section 2.3 of the RFC 2396 'URI generic syntax':
      * <p/>
      * <pre>
@@ -273,12 +270,12 @@ public class Text {
      * mark        = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
      * </pre>
      */
-    public static BitSet URISave;
+    public static final BitSet URISave;
 
     /**
      * Same as {@link #URISave} but also contains the '/'
      */
-    public static BitSet URISaveEx;
+    public static final BitSet URISaveEx;
 
     static {
         URISave = new BitSet(256);
@@ -307,32 +304,32 @@ public class Text {
     }
 
     /**
-     * Does an URL encoding of the <code>string</code> using the
-     * <code>escape</code> character. The characters that don't need encoding
+     * Does an URL encoding of the {@code string} using the
+     * {@code escape} character. The characters that don't need encoding
      * are those defined 'unreserved' in section 2.3 of the 'URI generic syntax'
      * RFC 2396, but without the escape character.
      *
      * @param string the string to encode.
      * @param escape the escape character.
      * @return the escaped string
-     * @throws NullPointerException if <code>string</code> is <code>null</code>.
+     * @throws NullPointerException if {@code string} is {@code null}.
      */
     public static String escape(String string, char escape) {
         return escape(string, escape, false);
     }
 
     /**
-     * Does an URL encoding of the <code>string</code> using the
-     * <code>escape</code> character. The characters that don't need encoding
+     * Does an URL encoding of the {@code string} using the
+     * {@code escape} character. The characters that don't need encoding
      * are those defined 'unreserved' in section 2.3 of the 'URI generic syntax'
-     * RFC 2396, but without the escape character. If <code>isPath</code> is
-     * <code>true</code>, additionally the slash '/' is ignored, too.
+     * RFC 2396, but without the escape character. If {@code isPath} is
+     * {@code true}, additionally the slash '/' is ignored, too.
      *
      * @param string the string to encode.
      * @param escape the escape character.
-     * @param isPath if <code>true</code>, the string is treated as path
+     * @param isPath if {@code true}, the string is treated as path
      * @return the escaped string
-     * @throws NullPointerException if <code>string</code> is <code>null</code>.
+     * @throws NullPointerException if {@code string} is {@code null}.
      */
     public static String escape(String string, char escape, boolean isPath) {
         try {
@@ -345,8 +342,8 @@ public class Text {
                     out.append((char) c);
                 } else {
                     out.append(escape);
-                    out.append(hexTable[(c >> 4) & 0x0f]);
-                    out.append(hexTable[(c) & 0x0f]);
+                    out.append(hexTable[c >> 4 & 0x0f]);
+                    out.append(hexTable[c & 0x0f]);
                 }
             }
             return out.toString();
@@ -356,20 +353,20 @@ public class Text {
     }
 
     /**
-     * Does a URL encoding of the <code>string</code>. The characters that
+     * Does a URL encoding of the {@code string}. The characters that
      * don't need encoding are those defined 'unreserved' in section 2.3 of
      * the 'URI generic syntax' RFC 2396.
      *
      * @param string the string to encode
      * @return the escaped string
-     * @throws NullPointerException if <code>string</code> is <code>null</code>.
+     * @throws NullPointerException if {@code string} is {@code null}.
      */
     public static String escape(String string) {
         return escape(string, '%');
     }
 
     /**
-     * Does a URL encoding of the <code>path</code>. The characters that
+     * Does a URL encoding of the {@code path}. The characters that
      * don't need encoding are those defined 'unreserved' in section 2.3 of
      * the 'URI generic syntax' RFC 2396. In contrast to the
      * {@link #escape(String)} method, not the entire path string is escaped,
@@ -377,21 +374,21 @@ public class Text {
      *
      * @param path the path to encode
      * @return the escaped path
-     * @throws NullPointerException if <code>path</code> is <code>null</code>.
+     * @throws NullPointerException if {@code path} is {@code null}.
      */
     public static String escapePath(String path) {
         return escape(path, '%', true);
     }
 
     /**
-     * Does a URL decoding of the <code>string</code> using the
-     * <code>escape</code> character. Please note that in opposite to the
+     * Does a URL decoding of the {@code string} using the
+     * {@code escape} character. Please note that in opposite to the
      * {@link java.net.URLDecoder} it does not transform the + into spaces.
      *
      * @param string the string to decode
      * @param escape the escape character
      * @return the decoded string
-     * @throws NullPointerException           if <code>string</code> is <code>null</code>.
+     * @throws NullPointerException           if {@code string} is {@code null}.
      * @throws IllegalArgumentException       if the 2 characters following the escape
      *                                        character do not represent a hex-number
      *                                        or if not enough characters follow an
@@ -402,8 +399,8 @@ public class Text {
             byte[] utf8 = string.getBytes("utf-8");
 
             // Check whether escape occurs at invalid position
-            if ((utf8.length >= 1 && utf8[utf8.length - 1] == escape) ||
-                (utf8.length >= 2 && utf8[utf8.length - 2] == escape)) {
+            if (utf8.length >= 1 && utf8[utf8.length - 1] == escape ||
+                    utf8.length >= 2 && utf8[utf8.length - 2] == escape) {
                 throw new IllegalArgumentException("Premature end of escape sequence at end of input");
             }
 
@@ -426,13 +423,13 @@ public class Text {
     }
 
     /**
-     * Does a URL decoding of the <code>string</code>. Please note that in
+     * Does a URL decoding of the {@code string}. Please note that in
      * opposite to the {@link java.net.URLDecoder} it does not transform the +
      * into spaces.
      *
      * @param string the string to decode
      * @return the decoded string
-     * @throws NullPointerException           if <code>string</code> is <code>null</code>.
+     * @throws NullPointerException           if {@code string} is {@code null}.
      * @throws ArrayIndexOutOfBoundsException if not enough character follow an
      *                                        escape character
      * @throws IllegalArgumentException       if the 2 characters following the escape
@@ -469,8 +466,8 @@ public class Text {
             char ch = name.charAt(i);
             if (ch == '%' || ch == '/' || ch == ':' || ch == '[' || ch == ']'
                 || ch == '*' || ch == '|'
-                || (ch == '.' && name.length() < 3)
-                || (ch == ' ' && (i == 0 || i == name.length() - 1))
+                || ch == '.' && name.length() < 3
+                || ch == ' ' && (i == 0 || i == name.length() - 1)
                 || ch == '\t' || ch == '\r' || ch == '\n') {
                 buffer.append('%');
                 buffer.append(Character.toUpperCase(Character.forDigit(ch / 16, 16)));
@@ -493,7 +490,7 @@ public class Text {
      */
     public static String escapeIllegalXpathSearchChars(String s) {
         StringBuilder sb = new StringBuilder();
-        sb.append(s.substring(0, (s.length() - 1)));
+        sb.append(s.substring(0, s.length() - 1));
         char c = s.charAt(s.length() - 1);
         // NOTE: keep this in sync with _ESCAPED_CHAR below!
         if (c == '!' || c == '(' || c == ':' || c == '^'
@@ -539,25 +536,25 @@ public class Text {
      * (i.e. contains no slashes) it is returned.
      *
      * @param path the path
-     * @return the name part or <code>null</code> if <code>path</code> is <code>null</code>.
+     * @return the name part or {@code null} if {@code path} is {@code null}.
      */
     public static String getName(String path) {
         return getName(path, '/');
     }
 
     /**
-     * Returns the name part of the path, delimited by the given <code>delim</code>.
-     * If the given path is already a name (i.e. contains no <code>delim</code>
+     * Returns the name part of the path, delimited by the given {@code deliminator}.
+     * If the given path is already a name (i.e. contains no {@code deliminator}
      * characters) it is returned.
      *
      * @param path the path
-     * @param delim the delimiter
-     * @return the name part or <code>null</code> if <code>path</code> is <code>null</code>.
+     * @param deliminator the delimiter
+     * @return the name part or {@code null} if {@code path} is {@code null}.
      */
-    public static String getName(String path, char delim) {
+    public static String getName(String path, char deliminator) {
         return path == null
                 ? null
-                : path.substring(path.lastIndexOf(delim) + 1);
+                : path.substring(path.lastIndexOf(deliminator) + 1);
     }
 
     /**
@@ -574,44 +571,44 @@ public class Text {
     }
 
     /**
-     * Returns the namespace prefix of the given <code>qname</code>. If the
+     * Returns the namespace prefix of the given {@code qName}. If the
      * prefix is missing, an empty string is returned. Please note, that this
      * method does not validate the name or prefix.
      * </p>
-     * the qname has the format: qname := [prefix ':'] local;
+     * the qName has the format: qName := [prefix ':'] local;
      *
-     * @param qname a qualified name
+     * @param qName a qualified name
      * @return the prefix of the name or "".
      *
      * @see #getLocalName(String)
      *
-     * @throws NullPointerException if <code>qname</code> is <code>null</code>
+     * @throws NullPointerException if {@code qName} is {@code null}
      */
-    public static String getNamespacePrefix(String qname) {
-        int pos = qname.indexOf(':');
-        return pos >=0 ? qname.substring(0, pos) : "";
+    public static String getNamespacePrefix(String qName) {
+        int pos = qName.indexOf(':');
+        return pos >=0 ? qName.substring(0, pos) : "";
     }
 
     /**
-     * Returns the local name of the given <code>qname</code>. Please note, that
+     * Returns the local name of the given {@code qName}. Please note, that
      * this method does not validate the name.
      * </p>
-     * the qname has the format: qname := [prefix ':'] local;
+     * the qName has the format: qName := [prefix ':'] local;
      *
-     * @param qname a qualified name
+     * @param qName a qualified name
      * @return the localname
      *
      * @see #getNamespacePrefix(String)
      *
-     * @throws NullPointerException if <code>qname</code> is <code>null</code>
+     * @throws NullPointerException if {@code qName} is {@code null}
      */
-    public static String getLocalName(String qname) {
-        int pos = qname.indexOf(':');
-        return pos >=0 ? qname.substring(pos+1) : qname;
+    public static String getLocalName(String qName) {
+        int pos = qName.indexOf(':');
+        return pos >=0 ? qName.substring(pos+1) : qName;
     }
 
     /**
-     * Determines, if two paths denote hierarchical siblins.
+     * Determines, if two paths denote hierarchical siblings.
      *
      * @param p1 first path
      * @param p2 second path
@@ -620,38 +617,38 @@ public class Text {
     public static boolean isSibling(String p1, String p2) {
         int pos1 = p1.lastIndexOf('/');
         int pos2 = p2.lastIndexOf('/');
-        return (pos1 == pos2 && pos1 >= 0 && p1.regionMatches(0, p2, 0, pos1));
+        return pos1 == pos2 && pos1 >= 0 && p1.regionMatches(0, p2, 0, pos1);
     }
 
     /**
-     * Determines if the <code>descendant</code> path is hierarchical a
-     * descendant of <code>path</code>.
+     * Determines if the {@code descendant} path is hierarchical a
+     * descendant of {@code path}.
      *
      * @param path     the current path
      * @param descendant the potential descendant
-     * @return <code>true</code> if the <code>descendant</code> is a descendant;
-     *         <code>false</code> otherwise.
+     * @return {@code true} if the {@code descendant} is a descendant;
+     *         {@code false} otherwise.
      */
     public static boolean isDescendant(String path, String descendant) {
-        String pattern = path.endsWith("/") ? path : path + "/";
+        String pattern = path.endsWith("/") ? path : path + '/';
         return !pattern.equals(descendant) &&
                 descendant.startsWith(pattern);
     }
 
     /**
-     * Determines if the <code>descendant</code> path is hierarchical a
-     * descendant of <code>path</code> or equal to it.
+     * Determines if the {@code descendant} path is hierarchical a
+     * descendant of {@code path} or equal to it.
      *
      * @param path       the path to check
      * @param descendant the potential descendant
-     * @return <code>true</code> if the <code>descendant</code> is a descendant
-     *         or equal; <code>false</code> otherwise.
+     * @return {@code true} if the {@code descendant} is a descendant
+     *         or equal; {@code false} otherwise.
      */
     public static boolean isDescendantOrEqual(String path, String descendant) {
         if (path.equals(descendant)) {
             return true;
         } else {
-            String pattern = path.endsWith("/") ? path : path + "/";
+            String pattern = path.endsWith("/") ? path : path + '/';
             return descendant.startsWith(pattern);
         }
     }
@@ -659,7 +656,7 @@ public class Text {
     /**
      * Returns the n<sup>th</sup> relative parent of the path, where n=level.
      * <p>Example:<br>
-     * <code>
+     * {@code }
      * Text.getRelativeParent("/foo/bar/test", 1) == "/foo/bar"
      * </code>
      *
@@ -675,7 +672,7 @@ public class Text {
             }
             level--;
         }
-        return (idx == 0) ? "/" : path.substring(0, idx);
+        return idx == 0 ? "/" : path.substring(0, idx);
     }
 
     /**
@@ -694,7 +691,7 @@ public class Text {
     /**
      * Returns the n<sup>th</sup> absolute parent of the path, where n=level.
      * <p>Example:<br>
-     * <code>
+     * {@code }
      * Text.getAbsoluteParent("/foo/bar/test", 1) == "/foo/bar"
      * </code>
      *
@@ -716,22 +713,22 @@ public class Text {
 
     /**
      * Performs variable replacement on the given string value.
-     * Each <code>${...}</code> sequence within the given value is replaced
+     * Each {@code $}{...}</code> sequence within the given value is replaced
      * with the value of the named parser variable. If a variable is not found
      * in the properties an IllegalArgumentException is thrown unless
-     * <code>ignoreMissing</code> is <code>true</code>. In the later case, the
+     * {@code ignoreMissing} is {@code true}. In the later case, the
      * missing variable is replaced by the empty string.
      *
      * @param value         the original value
-     * @param ignoreMissing if <code>true</code>, missing variables are replaced
+     * @param ignoreMissing if {@code true}, missing variables are replaced
      *                      by the empty string.
      * @return value after variable replacements
      * @throws IllegalArgumentException if the replacement of a referenced
      *                                  variable is not found
      */
-    public static String replaceVariables(Properties variables, String value,
-                                          boolean ignoreMissing)
+    public static String replaceVariables(Properties variables, String value, boolean ignoreMissing)
             throws IllegalArgumentException {
+
         StringBuilder result = new StringBuilder();
 
         // Value:
@@ -742,7 +739,7 @@ public class Text {
         while (q != -1) {
             result.append(value.substring(p, q));          // Text before ${
             p = q;
-            q = value.indexOf("}", q + 2);                 // Find }
+            q = value.indexOf('}', q + 2);                 // Find }
             if (q != -1) {
                 String variable = value.substring(p + 2, q);
                 String replacement = variables.getProperty(variable);



Mime
View raw message