]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-23: Improve javadoc formatting.
authorRay Lee <rhlee@berkeley.edu>
Tue, 2 Aug 2016 20:52:22 +0000 (13:52 -0700)
committerRay Lee <rhlee@berkeley.edu>
Wed, 3 Aug 2016 18:09:45 +0000 (11:09 -0700)
services/common/src/main/java/org/collectionspace/services/common/xmljson/JsonField.java
services/common/src/main/java/org/collectionspace/services/common/xmljson/JsonToXmlFilter.java
services/common/src/main/java/org/collectionspace/services/common/xmljson/JsonToXmlStreamConverter.java
services/common/src/main/java/org/collectionspace/services/common/xmljson/XmlNode.java
services/common/src/main/java/org/collectionspace/services/common/xmljson/XmlToJsonFilter.java
services/common/src/main/java/org/collectionspace/services/common/xmljson/XmlToJsonStreamConverter.java

index 5f3ebf42173a761ccecd5c5efdec8cb0aca8d8c6..9d71f2f109890fea5a1070899b945097879a20f3 100644 (file)
@@ -1,12 +1,12 @@
 package org.collectionspace.services.common.xmljson;
 
 /**
- * A lightweight representation of a JSON field. Instances are created
+ * <p>A lightweight representation of a JSON field. Instances are created
  * by JsonToXmlStreamConverter in the course of parsing JSON, in order
- * to track the current state.
+ * to track the current state.</p>
  * 
- * Each JSON field has a name and a type, which is either scalar, array,
- * or object.
+ * <p>Each JSON field has a name and a type, which is either scalar, array,
+ * or object.</p>
  */
 public class JsonField {
     private String name;
index e4c8efca2edb08d02d2fd0e7ee1c243c7019ae40..8007f3ad0db1e70956d9be4e07738613d27360b8 100644 (file)
@@ -18,7 +18,15 @@ import javax.xml.stream.XMLStreamException;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
 /**
- * A filter that translates JSON to XML.
+ * <p>A filter that translates JSON requests to XML.</p>
+ * 
+ * <p>This filter only has an effect if the content of the request (determined from
+ * the Content-type header) is JSON. If the content is JSON, the request is
+ * wrapped.</p>
+ * 
+ * <p>The request wrapper changes the Content-type header to XML, and provides an
+ * input stream containing an XML translation of the original JSON request
+ * content.</p>
  */
 public class JsonToXmlFilter implements Filter {
 
@@ -51,7 +59,8 @@ public class JsonToXmlFilter implements Filter {
     }
     
     /**
-     * A request wrapper that .
+     * A request wrapper that has a content type of XML, and replaces the
+     * wrapped input stream with an XML translation.
      */
     public class RequestWrapper extends HttpServletRequestWrapper {
         public RequestWrapper(HttpServletRequest request) {
@@ -74,14 +83,32 @@ public class JsonToXmlFilter implements Filter {
                 throw new IOException("error converting JSON stream to XML", e);
             }
             
-            final InputStream xmlInput = out.toInputStream();
+            return new InputStreamWrapper(out.toInputStream());
+        }
+    }
+    
+    /**
+     * A ServletInputStream that wraps another input stream.
+     */
+    public class InputStreamWrapper extends ServletInputStream {
 
-            return new ServletInputStream() {
-                @Override
-                public int read() throws IOException {
-                    return xmlInput.read();
-                }
-            };
+        /**
+         * The wrapped input stream.
+         */
+        private InputStream in;
+        
+        /**
+         * Creates an InputStreamWrapper that wraps a given input stream.
+         * 
+         * @param in the input stream to wrap
+         */
+        public InputStreamWrapper(InputStream in) {
+            this.in = in;
+        }
+        
+        @Override
+        public int read() throws IOException {
+            return in.read();
         }
     }
 }
index bda3a6f1db68df467af13258234ff1aafc95dbc7..0a4c924383e20eb05dcff4843a9d2405dd1b4ab3 100644 (file)
@@ -17,13 +17,14 @@ import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonToken;
 
 /**
- * Converts a CSpace JSON payload to an XML payload.
+ * <p>Converts a CSpace JSON payload to an XML payload.</p>
  *
- * This class is not intended to serve as a general purpose JSON to XML
+ * <p>This class is not intended to serve as a general purpose JSON to XML
  * translator. It is instead a lightweight processor tuned for the kinds
  * of JSON generated by CSpace, and the particular transformations needed
- * to generate XML for CSpace.
+ * to generate XML for CSpace.</p>
  * 
+ * <p>
  * The conversion is performed as follows:
  * <ul>
  * <li>JSON fields starting with "@xmlns:" are converted XML namespace declarations.</li>
@@ -33,12 +34,14 @@ import com.fasterxml.jackson.core.JsonToken;
  * <li>The contents of JSON arrays are expanded into multiple XML elements, each
  *     named with the field name of the JSON array.</li>
  * </ul>
+ * </p>
  *
- * This implementation is schema-unaware. It operates by examining only the input
- * document, without utilizing any XML schema information.
+ * <p>This implementation is schema-unaware. It operates by examining only the input
+ * document, without utilizing any XML schema information.</p>
  * 
- * Example:
+ * <p>Example:</p>
  *
+ * <p>
  * JSON
  * <pre>
  * {
@@ -80,43 +83,46 @@ import com.fasterxml.jackson.core.JsonToken;
  *   }
  * }
  * </pre>
- *
+ * </p>
+ * 
+ * <p>
  * XML
  * <pre>
- * <document name="collectionobjects">
- *   <ns2:collectionobjects_common xmlns:ns2="http://collectionspace.org/services/collectionobject" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- *     <objectNumber>2016.1.1</objectNumber>
- *     <objectNameList>
- *       <objectNameGroup>
- *         <objectNameCurrency/>
- *         <objectNameLanguage/>
- *         <objectName>Object name</objectName>
- *         <objectNameSystem/>
- *         <objectNameType/>
- *         <objectNameNote/>
- *         <objectNameLevel/>
- *       </objectNameGroup>
- *       <objectNameGroup>
- *         <objectNameCurrency/>
- *         <objectNameLanguage/>
- *         <objectName>Another name</objectName>
- *         <objectNameSystem/>
- *         <objectNameType/>
- *         <objectNameNote/>
- *         <objectNameLevel/>
- *       </objectNameGroup>
- *     </objectNameList>
- *     <comments>
- *       <comment>Some comment text</comment>
- *       <comment>Another comment</comment>
- *     </comments>
- *   </ns2:collectionobjects_common>
- * </document>
+ * &lt;document name="collectionobjects"&gt;
+ *   &lt;ns2:collectionobjects_common xmlns:ns2="http://collectionspace.org/services/collectionobject" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
+ *     &lt;objectNumber&gt;2016.1.1&lt;/objectNumber&gt;
+ *     &lt;objectNameList&gt;
+ *       &lt;objectNameGroup&gt;
+ *         &lt;objectNameCurrency/&gt;
+ *         &lt;objectNameLanguage/&gt;
+ *         &lt;objectName&gt;Object name&lt;/objectName&gt;
+ *         &lt;objectNameSystem/&gt;
+ *         &lt;objectNameType/&gt;
+ *         &lt;objectNameNote/&gt;
+ *         &lt;objectNameLevel/&gt;
+ *       &lt;/objectNameGroup&gt;
+ *       &lt;objectNameGroup&gt;
+ *         &lt;objectNameCurrency/&gt;
+ *         &lt;objectNameLanguage/&gt;
+ *         &lt;objectName&gt;Another name&lt;/objectName&gt;
+ *         &lt;objectNameSystem/&gt;
+ *         &lt;objectNameType/&gt;
+ *         &lt;objectNameNote/&gt;
+ *         &lt;objectNameLevel/&gt;
+ *       &lt;/objectNameGroup&gt;
+ *     &lt;/objectNameList&gt;
+ *     &lt;comments&gt;
+ *       &lt;comment&gt;Some comment text&lt;/comment&gt;
+ *       &lt;comment&gt;Another comment&lt;/comment&gt;
+ *     &lt;/comments&gt;
+ *   &lt;/ns2:collectionobjects_common&gt;
+ * &lt;/document&gt;
  * </pre>
+ * </p>
  * 
- * This implementation uses a streaming JSON parser and a streaming
+ * <p>This implementation uses a streaming JSON parser and a streaming
  * XML writer to do a direct stream-to-stream conversion, without
- * building a complete in-memory representation of the document.
+ * building a complete in-memory representation of the document.</p>
  */
 public class JsonToXmlStreamConverter {
     
index 99145aabd200481c5e397e56f9dedca23625a9a4..37b3d39379d1e33826e0a7ff69eb6fefee296749 100644 (file)
@@ -12,15 +12,15 @@ import org.apache.commons.lang3.StringUtils;
 import com.fasterxml.jackson.annotation.JsonValue;
 
 /**
- * A lightweight representation of an XML node. Instances are created
+ * <p>A lightweight representation of an XML node. Instances are created
  * by XmlToJsonStreamConverter in the course of parsing XML. This class
  * differs from a DOM node in that it is intended to contain just the
  * information needed to generate JSON for CSpace, in a structure that
- * is optimized for doing that generation.
+ * is optimized for doing that generation.</p>
  * 
- * Each XML node has a name, and optionally namespaces and attributes.
+ * <p>Each XML node has a name, and optionally namespaces and attributes.
  * The node may contain either text or child nodes (not both, as CSpace
- * XML is assumed not to contain mixed-content elements).
+ * XML is assumed not to contain mixed-content elements).</p>
  */
 public class XmlNode {
     /**
@@ -78,14 +78,14 @@ public class XmlNode {
     }
     
     /**
-     * Gets the value of the node. If this is a text node, the
+     * <p>Gets the value of the node. If this is a text node, the
      * value is a String. Otherwise it's a map of the node's
      * namespaces, attributes, and children, via
-     * getCombinedMap().
+     * getCombinedMap().</p>
      * 
-     * Note that namespaces and attributes are not returned
+     * <p>Note that namespaces and attributes are not returned
      * as part of a text node's value. It is assumed that text
-     * nodes do not have namespace declarations or attributes.
+     * nodes do not have namespace declarations or attributes.</p>
      * 
      * @return the node's value
      */
@@ -299,14 +299,14 @@ public class XmlNode {
     }
 
     /**
-     * Adds a child node to this node.
+     * <p>Adds a child node to this node.</p>
      * 
-     * If the node contains any text content, the text content
+     * <p>If the node contains any text content, the text content
      * is removed, and text content is disallowed from being added
-     * in the future.
+     * in the future.</p>
      * 
-     * If the node to be added contains no content, and
-     * isDiscardEmptyChildren() is true, the node is not added.
+     * <p>If the node to be added contains no content, and
+     * isDiscardEmptyChildren() is true, the node is not added.</p>
      * 
      * @param node the node to add as a child
      */
index 87a221b9d6d8db4125e46aee0b2daec749dd2cbb..843e297228325259b93e68c35e589c4aad57bc63 100644 (file)
@@ -28,25 +28,25 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
 /**
- * A filter that translates XML responses to JSON.
+ * <p>A filter that translates XML responses to JSON.</p>
  * 
- * This filter only has an effect if the preferred content type of the response
+ * <p>This filter only has an effect if the preferred content type of the response
  * (determined from the Accept header) is JSON. If JSON is preferred, both the
- * request and response are wrapped.
+ * request and response are wrapped.</p>
  * 
- * The request wrapper modifies the Accept header, ensuring that XML is accepted
+ * <p>The request wrapper modifies the Accept header, ensuring that XML is accepted
  * in addition to (but at a lower quality factor than) JSON. This handles the
  * case where the original request only accepts JSON. In that case, XML should
  * also be accepted, so that the XML response may be translated to JSON on the
- * way back.
+ * way back.</p>
  * 
- * The response wrapper provides a buffered output stream, so that XML output
+ * <p>The response wrapper provides a buffered output stream, so that XML output
  * is captured before being sent over the network. If the content type of the
  * response is XML, the content type is changed to JSON, the content of the
  * buffer is translated to JSON, and the JSON is written to the original output
  * stream. If the content type of the response is not XML, the content type is
  * not changed, and the content of the buffer is written to the original
- * output stream unchanged.
+ * output stream unchanged.</p>
  */
 public class XmlToJsonFilter implements Filter {
 
index f7add54f4997ab58405f45055087a1156445eed0..99ddc50ad6447c17f32eac83364d64a251df0301 100644 (file)
@@ -21,14 +21,15 @@ import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 /**
- * Converts a CSpace XML payload to a JSON payload.
+ * <p>Converts a CSpace XML payload to a JSON payload.</p>
  *
- * This class is not intended to serve as a general purpose XML to JSON
+ * <p>This class is not intended to serve as a general purpose XML to JSON
  * translator. It is instead a lightweight processor tuned for the kinds
  * of XML generated by CSpace, and the particular transformations needed
  * to generate JSON for CSpace. The XML input is expected to conform to
- * conventions (described below) of CSpace XML payloads.
+ * conventions (described below) of CSpace XML payloads.</p>
  * 
+ * <p>
  * The conversion is performed as follows:
  * <ul>
  * <li>XML elements are converted to identically-named JSON fields.</li>
@@ -36,7 +37,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
  * <li>XML namespace declarations are converted to JSON fields prepended with "@xmlns:".</li>
  * <li>Sibling XML elements that have the same name are converted to JSON arrays.</li>
  * </ul>
+ * </p>
  *
+ * <p>
  * This implementation is schema-unaware. It operates by examining only the input
  * document, without utilizing any XML schema information. This allows for speed
  * and simplicity, but has some consequences:
@@ -54,46 +57,50 @@ import com.fasterxml.jackson.databind.ObjectMapper;
  *     necessary to read the entire XML document into memory first, instead of
  *     doing a direct stream-to-stream conversion.</li>
  * </ul>
- *
- * Example:
+ * </p>
+ * 
+ * <p>Example:</p>
  * 
+ * <p>
  * XML
  * <pre>
- * <document name="collectionobjects">
- *   <ns2:collectionspace_core xmlns:ns2="http://collectionspace.org/collectionspace_core/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- *     <createdBy>admin@core.collectionspace.org</createdBy>
- *     <createdAt>2016-07-27T04:31:38.290Z</createdAt>
- *   </ns2:collectionspace_core>
- *   <ns2:collectionobjects_common xmlns:ns2="http://collectionspace.org/services/collectionobject" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- *     <objectNumber>2016.1.1</objectNumber>
- *     <objectNameList>
- *       <objectNameGroup>
- *         <objectNameCurrency/>
- *         <objectNameLanguage/>
- *         <objectName>Object name</objectName>
- *         <objectNameSystem/>
- *         <objectNameType/>
- *         <objectNameNote/>
- *         <objectNameLevel/>
- *       </objectNameGroup>
- *       <objectNameGroup>
- *         <objectNameCurrency/>
- *         <objectNameLanguage/>
- *         <objectName>Another name</objectName>
- *         <objectNameSystem/>
- *         <objectNameType/>
- *         <objectNameNote/>
- *         <objectNameLevel/>
- *       </objectNameGroup>
- *     </objectNameList>
- *     <comments>
- *       <comment>Some comment text</comment>
- *       <comment>Another comment</comment>
- *     </comments>
- *   </ns2:collectionobjects_common>
- * </document>
+ * &lt;document name="collectionobjects"&gt;
+ *   &lt;ns2:collectionspace_core xmlns:ns2="http://collectionspace.org/collectionspace_core/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
+ *     &lt;createdBy&gt;admin@core.collectionspace.org&lt;/createdBy&gt;
+ *     &lt;createdAt&gt;2016-07-27T04:31:38.290Z&lt;/createdAt&gt;
+ *   &lt;/ns2:collectionspace_core&gt;
+ *   &lt;ns2:collectionobjects_common xmlns:ns2="http://collectionspace.org/services/collectionobject" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
+ *     &lt;objectNumber&gt;2016.1.1&lt;/objectNumber&gt;
+ *     &lt;objectNameList&gt;
+ *       &lt;objectNameGroup&gt;
+ *         &lt;objectNameCurrency/&gt;
+ *         &lt;objectNameLanguage/&gt;
+ *         &lt;objectName&gt;Object name&lt;/objectName&gt;
+ *         &lt;objectNameSystem/&gt;
+ *         &lt;objectNameType/&gt;
+ *         &lt;objectNameNote/&gt;
+ *         &lt;objectNameLevel/&gt;
+ *       &lt;/objectNameGroup&gt;
+ *       &lt;objectNameGroup&gt;
+ *         &lt;objectNameCurrency/&gt;
+ *         &lt;objectNameLanguage/&gt;
+ *         &lt;objectName&gt;Another name&lt;/objectName&gt;
+ *         &lt;objectNameSystem/&gt;
+ *         &lt;objectNameType/&gt;
+ *         &lt;objectNameNote/&gt;
+ *         &lt;objectNameLevel/&gt;
+ *       &lt;/objectNameGroup&gt;
+ *     &lt;/objectNameList&gt;
+ *     &lt;comments&gt;
+ *       &lt;comment&gt;Some comment text&lt;/comment&gt;
+ *       &lt;comment&gt;Another comment&lt;/comment&gt;
+ *     &lt;/comments&gt;
+ *   &lt;/ns2:collectionobjects_common&gt;
+ * &lt;/document&gt;
  * </pre>
+ * </p>
  * 
+ * <p>
  * JSON
  * <pre>
  * {
@@ -141,7 +148,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
  *   }
  * }
  * </pre>
+ * </p>
  * 
+ * <p>
  * The conversion algorithm assumes that the input XML adheres to the following 
  * conventions:
  * 
@@ -154,18 +163,18 @@ import com.fasterxml.jackson.databind.ObjectMapper;
  *     only text, they are discarded.</li>
  * <li>The XML does not contain sequences of identically-named elements that are
  *     interrupted by other elements; or if it does, those interruptions are not
- *     important. For example, the parent node below contains a list of item
- *     elements, interrupted by an other element:
+ *     important. For example, the <code>parent</code> node below contains a list of <code>item</code>
+ *     elements, interrupted by an <code>other</code> element:
  *     
  *     <pre>
- *       <parent>
- *         <item>a</item>
- *         <item>b</item>
- *         <item>c</item>
- *         <other>uh oh</other>
- *         <item>d</item>
- *         <item>e</item>
- *       </parent>
+ *       &lt;parent&gt;
+ *         &lt;item&gt;a&lt;/item&gt;
+ *         &lt;item&gt;b&lt;/item&gt;
+ *         &lt;item&gt;c&lt;/item&gt;
+ *         &lt;other&gt;uh oh&lt;/other&gt;
+ *         &lt;item&gt;d&lt;/item&gt;
+ *         &lt;item&gt;e&lt;/item&gt;
+ *       &lt;/parent&gt;
  *     </pre>
  *     
  *     This is translated to:
@@ -183,20 +192,21 @@ import com.fasterxml.jackson.databind.ObjectMapper;
  *       }
  *     </pre>
  *     
- *     All of the item children of parent are converted into a single
- *     list, so the placement of the other element is not retained in
+ *     All of the <code>item</code> children of parent are converted into a single
+ *     list, so the placement of the <code>other</code> element is not retained in
  *     JSON.
  * </li>
  * </ul>
+ * </p>
  * 
- * This implementation uses a StAX parser to generate a lightweight 
+ * <p>This implementation uses a StAX parser to generate a lightweight 
  * representation of the input XML document in memory, performs the
  * necessary transformations, and outputs a JSON rendering of the
  * transformed document. A direct stream-to-stream conversion is
  * not possible because of the need to collect identically-named
  * XML elements for output as a JSON array; for any element, all children
  * must be known before JSON for that element may be written to the
- * output stream.
+ * output stream.</p>
  */
 public class XmlToJsonStreamConverter {
     /**