diff gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java @ 36:ad381cc47217

Format Code to max 80 Chars per Row gnv/trunk@172 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 02 Oct 2009 08:54:13 +0000
parents 4405f31bbc30
children fccf90761825
line wrap: on
line diff
--- a/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java	Fri Oct 02 08:49:18 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java	Fri Oct 02 08:54:13 2009 +0000
@@ -31,25 +31,23 @@
 import org.xml.sax.SAXException;
 
 /**
- *  @author Sascha L. Teichmann
+ * @author Sascha L. Teichmann
  */
-public class XMLUtils
-{
+public class XMLUtils {
     private static Logger logger = Logger.getLogger(XMLUtils.class);
 
     public XMLUtils() {
     }
 
-    public static class ElementCreator
-    {
+    public static class ElementCreator {
         protected Document document;
-        protected String   ns;
-        protected String   prefix;
+        protected String ns;
+        protected String prefix;
 
         public ElementCreator(Document document, String ns, String prefix) {
             this.document = document;
-            this.ns       = ns;
-            this.prefix   = prefix;
+            this.ns = ns;
+            this.prefix = prefix;
         }
 
         public Element create(String name) {
@@ -68,12 +66,9 @@
 
     public Document newDocument() {
         try {
-            return DocumentBuilderFactory
-                .newInstance()
-                .newDocumentBuilder()
-                .newDocument();
-        }
-        catch (ParserConfigurationException pce) {
+            return DocumentBuilderFactory.newInstance().newDocumentBuilder()
+                    .newDocument();
+        } catch (ParserConfigurationException pce) {
             logger.error(pce.getLocalizedMessage(), pce);
         }
         return null;
@@ -85,7 +80,7 @@
 
     public XPath newXPath(NamespaceContext namespaceContext) {
         XPathFactory factory = XPathFactory.newInstance();
-        XPath        xpath   = factory.newXPath();
+        XPath xpath = factory.newXPath();
         if (namespaceContext != null) {
             xpath.setNamespaceContext(namespaceContext);
         }
@@ -96,18 +91,14 @@
         return xpath(root, query, returnTyp, null);
     }
 
-    public final String xpathString(
-        Object root, String query, NamespaceContext namespaceContext
-    ) {
-        return (String)xpath(root, query, XPathConstants.STRING, namespaceContext);
+    public final String xpathString(Object root, String query,
+            NamespaceContext namespaceContext) {
+        return (String) xpath(root, query, XPathConstants.STRING,
+                namespaceContext);
     }
 
-    public static final Object xpath(
-        Object           root,
-        String           query,
-        QName            returnType,
-        NamespaceContext namespaceContext
-    ) {
+    public static final Object xpath(Object root, String query,
+            QName returnType, NamespaceContext namespaceContext) {
         if (root == null) {
             return null;
         }
@@ -117,17 +108,14 @@
             if (xpath != null) {
                 return xpath.evaluate(query, root, returnType);
             }
-        }
-        catch (XPathExpressionException xpee) {
+        } catch (XPathExpressionException xpee) {
             logger.error(xpee.getLocalizedMessage(), xpee);
         }
 
         return null;
     }
-    
-    public Object getXPath(
-        Object root, String query, QName returnType
-    ) {
+
+    public Object getXPath(Object root, String query, QName returnType) {
         return xpath(root, query, returnType);
     }
 
@@ -136,73 +124,70 @@
     }
 
     public NodeList getNodeSetXPath(Object root, String query) {
-        return (NodeList)getXPath(root, query, XPathConstants.NODESET);
+        return (NodeList) getXPath(root, query, XPathConstants.NODESET);
     }
 
     public Node getNodeXPath(Object root, String query) {
-        return (Node)getXPath(root, query, XPathConstants.NODE);
+        return (Node) getXPath(root, query, XPathConstants.NODE);
     }
 
     public String getStringXPath(Object root, String xpath) {
         return getStringXPath(root, xpath, null);
     }
 
-    public String getStringXPath(
-        Object root, String query, String def
-    ) {
-        String s = (String)getXPath(root, query, XPathConstants.STRING);
-        return s == null || s.length() == 0
-            ? def
-            : s;
+    public String getStringXPath(Object root, String query, String def) {
+        String s = (String) getXPath(root, query, XPathConstants.STRING);
+        return s == null || s.length() == 0 ? def : s;
     }
-    
-    public Document readDocument(InputStream inputStream){
+
+    public Document readDocument(InputStream inputStream) {
         Document returnValue = null;
         try {
-            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
+                    .newInstance();
             DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-            returnValue = docBuilder.parse (inputStream);
+            returnValue = docBuilder.parse(inputStream);
         } catch (ParserConfigurationException e) {
-            logger.error(e,e);
+            logger.error(e, e);
         } catch (SAXException e) {
-            logger.error(e,e);
+            logger.error(e, e);
         } catch (IOException e) {
-            logger.error(e,e);
+            logger.error(e, e);
         }
         return returnValue;
     }
-    
-    public String writeNode2String(Node node){
+
+    public String writeNode2String(Node node) {
         try {
             DOMSource source = new DOMSource(node);
             return writeDOMSource2String(source);
         } catch (TransformerConfigurationException e) {
-            logger.error(e,e);
+            logger.error(e, e);
         } catch (TransformerFactoryConfigurationError e) {
-            logger.error(e,e);
+            logger.error(e, e);
         } catch (TransformerException e) {
-            logger.error(e,e);
+            logger.error(e, e);
         }
         return null;
     }
-    
-    public Document reInitDocument(Document document){
-        
-        StringBufferInputStream inputStream = new StringBufferInputStream(this.writeDocument2String(document));
+
+    public Document reInitDocument(Document document) {
+
+        StringBufferInputStream inputStream = new StringBufferInputStream(this
+                .writeDocument2String(document));
         return this.readDocument(inputStream);
     }
-    
-    
-    public String writeDocument2String(Document document){
+
+    public String writeDocument2String(Document document) {
         try {
             DOMSource source = new DOMSource(document);
             return writeDOMSource2String(source);
         } catch (TransformerConfigurationException e) {
-            logger.error(e,e);
+            logger.error(e, e);
         } catch (TransformerFactoryConfigurationError e) {
-            logger.error(e,e);
+            logger.error(e, e);
         } catch (TransformerException e) {
-            logger.error(e,e);
+            logger.error(e, e);
         }
         return null;
     }
@@ -217,10 +202,11 @@
     private String writeDOMSource2String(DOMSource source)
             throws TransformerFactoryConfigurationError,
             TransformerConfigurationException, TransformerException {
-        TransformerFactory transformerFactory = TransformerFactory.newInstance();
+        TransformerFactory transformerFactory = TransformerFactory
+                .newInstance();
         Transformer transformer = transformerFactory.newTransformer();
         StringWriter sw = new StringWriter();
-        StreamResult result =  new StreamResult(sw);
+        StreamResult result = new StreamResult(sw);
         transformer.transform(source, result);
         return sw.getBuffer().toString();
     }

http://dive4elements.wald.intevation.org