← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1857: Cosmetic fix

 

------------------------------------------------------------
revno: 1857
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Fri 2010-07-16 22:12:45 +0200
message:
  Cosmetic fix
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/DefaultImportService.java
  dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XMLPipe.java
  dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XPathFilter.java
  dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLEventReader.java
  dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java
  dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/transformer/TransformerTask.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/DefaultImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/DefaultImportService.java	2010-07-15 12:10:45 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/DefaultImportService.java	2010-07-16 20:12:45 +0000
@@ -66,6 +66,7 @@
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
+    
     @Autowired
     private XMLPreConverter preConverter;
 
@@ -75,6 +76,7 @@
     // -------------------------------------------------------------------------
     // ImportService implementation
     // -------------------------------------------------------------------------
+    
     @Override
     public void importData( ImportParams params, InputStream inputStream )
         throws ImportException

=== modified file 'dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XMLPipe.java'
--- dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XMLPipe.java	2010-07-02 12:37:38 +0000
+++ dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XMLPipe.java	2010-07-16 20:12:45 +0000
@@ -27,15 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.NoSuchElementException;
 import java.util.concurrent.LinkedBlockingQueue;
+
 import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.XMLEvent;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
 import org.codehaus.stax2.XMLEventReader2;
 
 /**
@@ -47,7 +46,7 @@
  * 
  * The input of the pipe looks like an XMLEventWriter and can be used as a
  * Result of a transformation.
- *
+ * 
  * Only minimal required methods of XMLReader and XMLWriter are implemented.
  * 
  * @author bobj
@@ -55,8 +54,6 @@
  */
 public class XMLPipe
 {
-    private final Log log = LogFactory.getLog( XMLPipe.class );
-
     protected XMLEventReader2 output;
 
     protected XMLEventWriter input;
@@ -71,7 +68,6 @@
         return output;
     }
 
-
     public int getEventCount()
     {
         return eventQ.size();
@@ -92,8 +88,10 @@
     private class PipeReader
         implements XMLEventReader2
     {
+        // ---------------------------------------------------------------------
+        // XMLEventReader methods
+        // ---------------------------------------------------------------------
 
-        // ------------------- XMLEventReader methods ------------------
         @Override
         public XMLEvent nextEvent()
             throws XMLStreamException
@@ -103,7 +101,6 @@
             {
                 // non-blocking poll()
                 // return eventQ.poll();
-
                 // do beware - this will block if q is empty
                 result = eventQ.take();
                 return result;
@@ -132,28 +129,26 @@
         public String getElementText()
             throws XMLStreamException
         {
-                // get the text
-                String result = nextEvent().asCharacters().getData();
-                // pop (and test caste) the end element
-                nextEvent().asEndElement();
-
-                return result;
-
+            // get the text
+            String result = nextEvent().asCharacters().getData();
+            // pop (and test caste) the end element
+            nextEvent().asEndElement();
+
+            return result;
         }
 
         @Override
         public XMLEvent nextTag()
             throws XMLStreamException
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
-
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public Object getProperty( String name )
             throws IllegalArgumentException
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
@@ -161,49 +156,48 @@
             throws XMLStreamException
         {
             // not a real stream ... no handle to close
-    	    return;
+            return;
         }
 
         @Override
         public Object next()
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public void remove()
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public boolean hasNextEvent()
             throws XMLStreamException
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public boolean isPropertySupported( String string )
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public boolean setProperty( String string, Object o )
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
     };
 
     private class PipeWriter
         implements XMLEventWriter
     {
-
         // ---------------------------------------------------------------------
         // XMLEventWriter methods
         // ---------------------------------------------------------------------
-        
+
         @Override
         public void flush()
             throws XMLStreamException
@@ -233,34 +227,34 @@
         public String getPrefix( String uri )
             throws XMLStreamException
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public void setPrefix( String prefix, String uri )
             throws XMLStreamException
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public void setDefaultNamespace( String uri )
             throws XMLStreamException
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public void setNamespaceContext( NamespaceContext context )
             throws XMLStreamException
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
         public NamespaceContext getNamespaceContext()
         {
-            throw new UnsupportedOperationException("Unused functionality.  Not implemented" );
+            throw new UnsupportedOperationException( "Unused functionality.  Not implemented" );
         }
 
         @Override
@@ -268,7 +262,7 @@
             throws XMLStreamException
         {
             // not a real stream ... no handle to close
-	    return;
+            return;
         }
     };
 }

=== modified file 'dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XPathFilter.java'
--- dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XPathFilter.java	2010-05-13 21:14:53 +0000
+++ dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/framework/XPathFilter.java	2010-07-16 20:12:45 +0000
@@ -1,22 +1,5 @@
 package org.amplecode.staxwax.framework;
 
-
-import java.io.InputStream;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
 /*
  * Copyright (c) 2004-2005, University of Oslo
  * All rights reserved.
@@ -43,20 +26,36 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 /**
  * A simple utility class for evaluating xpath expressions on xml streams
- *
+ * 
  * @author bobj
  * @version created 16-Feb-2010
  */
 public class XPathFilter
 {
-
     private static final Log log = LogFactory.getLog( XPathFilter.class );
 
     /**
      * Find at most one Node from stream
-     *
+     * 
      * @param in
      * @param xpathExpr
      * @return
@@ -67,13 +66,14 @@
 
         try
         {
-            XPathExpression expr = compileXPath(xpathExpr);
-
-            Document doc = parseDocument(in);
-            
+            XPathExpression expr = compileXPath( xpathExpr );
+
+            Document doc = parseDocument( in );
+
             result = (Node) expr.evaluate( doc, XPathConstants.NODE );
 
-        } catch ( Exception ex )
+        }
+        catch ( Exception ex )
         {
             log.info( ex );
         }
@@ -82,59 +82,59 @@
 
     /**
      * Find set of nodes in stream
-     *
+     * 
      * @param in
      * @param xpathExpr
      * @return
      */
     public static NodeList findNodes( InputStream in, String xpathExpr )
     {
-
         NodeList result = null;
 
         try
         {
-            XPathExpression expr = compileXPath(xpathExpr);
+            XPathExpression expr = compileXPath( xpathExpr );
 
-            Document doc = parseDocument(in);
+            Document doc = parseDocument( in );
 
             result = (NodeList) expr.evaluate( doc, XPathConstants.NODESET );
 
-        } catch ( Exception ex )
+        }
+        catch ( Exception ex )
         {
             log.info( ex );
         }
+
         return result;
     }
 
     /**
      * Find text data in stream
-     *
+     * 
      * @param in
      * @param xpathExpr
      * @return
      */
     public static String findText( InputStream in, String xpathExpr )
     {
-
         String result = null;
 
         try
         {
-            XPathExpression expr = compileXPath(xpathExpr);
+            XPathExpression expr = compileXPath( xpathExpr );
 
-            Document doc = parseDocument(in);
+            Document doc = parseDocument( in );
 
             result = (String) expr.evaluate( doc, XPathConstants.STRING );
-
-        } catch ( Exception ex )
+        }
+        catch ( Exception ex )
         {
             log.info( ex );
         }
         return result;
     }
 
-    private static synchronized XPathExpression compileXPath(String xpathString)
+    private static synchronized XPathExpression compileXPath( String xpathString )
     {
         XPathFactory factory = XPathFactory.newInstance();
         XPath xpath = factory.newXPath();
@@ -143,34 +143,34 @@
         try
         {
             expr = xpath.compile( xpathString );
-        } catch ( XPathExpressionException ex )
+        }
+        catch ( XPathExpressionException ex )
         {
-            log.info( "Failed to compile xpath: " + xpathString + " : " + ex.getCause());
+            log.info( "Failed to compile xpath: " + xpathString + " : " + ex.getCause() );
         }
 
         return expr;
-
     }
 
-    private static synchronized Document parseDocument(InputStream in)
+    private static synchronized Document parseDocument( InputStream in )
     {
         Document doc = null;
 
         DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
 
         // keep life simple using xpath 1.0
-        docBuilderFactory.setNamespaceAware( false);
+        docBuilderFactory.setNamespaceAware( false );
 
-        try {
+        try
+        {
             DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
-            doc = docBuilder.parse(in);
+            doc = docBuilder.parse( in );
         }
-        catch (Exception ex)
+        catch ( Exception ex )
         {
-            log.info( "XPath: Failed to parse input stream" + ex.getCause());
+            log.info( "XPath: Failed to parse input stream" + ex.getCause() );
         }
 
         return doc;
-
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLEventReader.java'
--- dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLEventReader.java	2010-07-16 13:04:51 +0000
+++ dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLEventReader.java	2010-07-16 20:12:45 +0000
@@ -193,8 +193,7 @@
         }
         catch ( ClassCastException ex )
         {
-            // asStartElement() will throw ClassCastException if not a
-            // StartElement
+            // asStartElement() will throw ClassCastException if not a StartElement
             return false;
         }
     }
@@ -353,20 +352,15 @@
             throw new RuntimeException( "Failed to close reader", ex );
         }
     }
-    
-    protected String getText() throws XMLStreamException
+
+    protected String getText()
+        throws XMLStreamException
     {
         StringBuffer sb = new StringBuffer();
-        while (reader.peek().isCharacters()) {
-            sb.append( reader.nextEvent().asCharacters().getData());
-        }
-        if (sb.length() == 0)
-        {
-            return null;
-        }
-        else
-        {
-            return sb.toString();
-        }
+        while ( reader.peek().isCharacters() )
+        {
+            sb.append( reader.nextEvent().asCharacters().getData() );
+        }
+        return sb.length() == 0 ? null : sb.toString();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java'
--- dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java	2010-07-16 13:04:51 +0000
+++ dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java	2010-07-16 20:12:45 +0000
@@ -54,7 +54,6 @@
 public class DefaultXMLStreamReader
     implements XMLReader
 {
-
     private static final Log log = LogFactory.getLog( DefaultXMLStreamReader.class );
 
     private static final String[] EVENTS =
@@ -69,6 +68,7 @@
     // -------------------------------------------------------------------------
     // Constructor
     // -------------------------------------------------------------------------
+    
     public DefaultXMLStreamReader( XMLStreamReader2 reader )
     {
         this.reader = reader;
@@ -77,6 +77,7 @@
     // -------------------------------------------------------------------------
     // XMLReader implementation
     // -------------------------------------------------------------------------
+    
     @Override
     public String getElementName()
     {
@@ -343,20 +344,15 @@
         }
     }
 
-    protected String getText() throws XMLStreamException
+    protected String getText()
+        throws XMLStreamException
     {
         StringBuffer sb = new StringBuffer();
-        while (reader.isCharacters()) {
-            sb.append( reader.getText());
+        while ( reader.isCharacters() )
+        {
+            sb.append( reader.getText() );
             reader.next();
         }
-        if (sb.length() == 0)
-        {
-            return null;
-        }
-        else
-        {
-            return sb.toString();
-        }
+        return sb.length() == 0 ? null : sb.toString();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/transformer/TransformerTask.java'
--- dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/transformer/TransformerTask.java	2010-05-13 21:18:56 +0000
+++ dhis-2/dhis-services/dhis-service-xml/src/main/java/org/amplecode/staxwax/transformer/TransformerTask.java	2010-07-16 20:12:45 +0000
@@ -28,7 +28,6 @@
  */
 
 import java.io.BufferedInputStream;
-import java.io.InputStream;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -146,7 +145,6 @@
         t.transform( this.sourcePort.getSource(), this.resultPort.getResult() );
     }
 
-
     /**
      * Transforms xml datastream to Pipe 
      *
@@ -158,26 +156,23 @@
      * @throws Exception
      *
      * TODO: implement XMLPipe as a Result type
-     *
      */
     public XMLReader transformToPipe(BufferedInputStream dataStream)
         throws Exception
     {
-
-            Source dataSource = new StreamSource( dataStream );
-
-            // make a pipe to capture output of transform
-            XMLPipe pipe = new XMLPipe();
-            XMLEventWriter pipeinput = pipe.getInput();
-            XMLEventReader2 pipeoutput = pipe.getOutput();
-
-            // set result of transform to input of pipe
-            StAXResult result = new StAXResult( pipeinput );
-            transform( dataSource, result, null );
-            log.info( "transform successful - importing dxf" );
-
-            // set reader to output of pipe
-            return new DefaultXMLEventReader( (XMLEventReader2) pipeoutput );
-        }
-
+        Source dataSource = new StreamSource( dataStream );
+
+        // make a pipe to capture output of transform
+        XMLPipe pipe = new XMLPipe();
+        XMLEventWriter pipeinput = pipe.getInput();
+        XMLEventReader2 pipeoutput = pipe.getOutput();
+
+        // set result of transform to input of pipe
+        StAXResult result = new StAXResult( pipeinput );
+        transform( dataSource, result, null );
+        log.info( "transform successful - importing dxf" );
+
+        // set reader to output of pipe
+        return new DefaultXMLEventReader( (XMLEventReader2) pipeoutput );
+    }
 }