Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java @ 806:2cea76f1112e
Added Javadoc in utils package.
gnv-artifacts/trunk@888 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 08 Apr 2010 13:10:39 +0000 |
parents | c4156275c1e1 |
children | a645bd23c1c8 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Thu Apr 08 11:31:44 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Thu Apr 08 13:10:39 2010 +0000 @@ -32,6 +32,8 @@ import org.xml.sax.SAXException; /** + * This class provides some methods for creating and working with xml documents. + * * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> * */ @@ -51,14 +53,19 @@ public static final String XFORM_PREFIX = "xform"; /** - * Constructor + * Constructor.<br> + * <b>Note:</b> It should not be necessary to create an object of this + * class - which is a helper class. Call static methods instead. */ public ArtifactXMLUtilities() { } /** - * @param document - * @return + * Creates an <code>Element</code> and returns it. + * + * @param document A document + * @param name Name of a node. + * @return an Element. */ public static Element createArtifactElement(Document document, String name) { Element node = document.createElementNS( @@ -67,6 +74,13 @@ return node; } + + /** + * Turns an xml document into a string. + * + * @param document An xml document. + * @return String representation of <i>document</i>. + */ public static String writeDocument2String(Document document) { try { TransformerFactory transformerFactory = TransformerFactory @@ -87,6 +101,12 @@ return null; } + /** + * Read a document from input stream. + * + * @param inputStream The input stream. + * @return the document read from stream. + */ public static Document readDocument(InputStream inputStream) { Document returnValue = null; try { @@ -104,24 +124,43 @@ return returnValue; } + + @SuppressWarnings("static-access") public Document reInitDocument(Document document) { try { - byte[] barray = this.writeDocument2String(document).getBytes( + @SuppressWarnings("static-access") + byte[] barray = ArtifactXMLUtilities.writeDocument2String(document).getBytes( "UTF-8"); InputStream inputStream = new ByteArrayInputStream(barray); - return this.readDocument(inputStream); + return ArtifactXMLUtilities.readDocument(inputStream); } catch (UnsupportedEncodingException e) { log.error(e, e); } return document; } + + /** + * Creates an <code>Element</code> with {@link #XFORM_PREFIX} and <i>name + * </i>. + * + * @param document A document. + * @param name The node name. + * @return the created element. + */ public static Element createXFormElement(Document document, String name) { Element node = document.createElementNS(XFORM_URL, name); node.setPrefix(XFORM_PREFIX); return node; } + /** + * Creates an exception node. + * + * @param message The message in the node. + * @param document A document. + * @return the document containing the exception node. + */ public static Document createExceptionReport(String message, Document document) { log.debug("ArtifactXMLUtilities.createExceptionReport"); Element exceptionReportNode = createArtifactElement(document, @@ -134,6 +173,13 @@ return document; } + /** + * Creates an input exception node. + * + * @param msg The message in the node. + * @param doc A document. + * @return the document containing the exception node. + */ public static Document createInputExceptionReport(String msg, Document doc) { Element exceptionReportNode = createArtifactElement( doc,"exceptionreport"); @@ -148,6 +194,13 @@ return doc; } + /** + * Creates a success node. + * + * @param message The message. + * @param document A document. + * @return the document containing the success node. + */ public static Document createSuccessReport(String message, Document document) { log.debug("ArtifactXMLUtilities.creatSuccessReport"); Element reportNode = createArtifactElement(document, "result"); @@ -158,6 +211,12 @@ return document; } + /** + * Read <i>fileName</i> and return the first child node. + * + * @param fileName An xml document. + * @return the first child node in this document. + */ public Node readConfiguration(String fileName){ try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -174,5 +233,5 @@ return null; } } - } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : \ No newline at end of file