diff flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 1367:ab8eb2f544f2

Replaced stdout and stderr logging with log4j loggers in server classes. flys-client/trunk@3069 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 25 Oct 2011 12:31:15 +0000
parents 9bf91bce6ca4
children f6fbfdc813f0
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Tue Oct 25 11:07:14 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java	Tue Oct 25 12:31:15 2011 +0000
@@ -14,6 +14,8 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import org.apache.log4j.Logger;
+
 import de.intevation.artifacts.common.ArtifactNamespaceContext;
 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
 import de.intevation.artifacts.common.utils.XMLUtils;
@@ -48,6 +50,10 @@
  */
 public class CollectionHelper {
 
+    private static final Logger logger =
+        Logger.getLogger(CollectionHelper.class);
+
+
     public static final String ERROR_ADD_ARTIFACT = "error_add_artifact";
 
     public static final String ERROR_REMOVE_ARTIFACT = "error_remove_artifact";
@@ -59,7 +65,7 @@
 
 
     public static Document createAttribute(Collection collection) {
-        System.out.println("CollectionHelper.createAttribute");
+        logger.debug("CollectionHelper.createAttribute");
 
         Document doc = XMLUtils.newDocument();
 
@@ -103,14 +109,14 @@
         Collection              c,
         Map<String, OutputMode> mmodes)
     {
-        System.out.println("CollectionHelper.createOutputElements");
+        logger.debug("CollectionHelper.createOutputElements");
 
         java.util.Collection<OutputMode> modes = mmodes != null
             ? mmodes.values()
             : null;
 
         if (modes == null || modes.size() == 0) {
-            System.err.println("Collection has no modes: " + c.identifier());
+            logger.debug("Collection has no modes: " + c.identifier());
             return null;
         }
 
@@ -142,7 +148,7 @@
         Collection     collection,
         OutputMode     mode)
     {
-        System.out.println("CollectionHelper.createOutputElement");
+        logger.debug("CollectionHelper.createOutputElement");
 
         Element out = cr.create("output");
         cr.addAttr(out, "name", mode.getName(), false);
@@ -151,7 +157,7 @@
         List<Theme> themes  = themeList != null ? themeList.getThemes() : null;
 
         if (themes == null || themes.size() == 0) {
-            System.err.println("No themes for output mode: " + mode.getName());
+            logger.debug("No themes for output mode: " + mode.getName());
             return null;
         }
 
@@ -221,12 +227,12 @@
         ElementCreator cr,
         Collection     c)
     {
-        System.out.println("CollectionHelper.createRecommendationsElements");
+        logger.debug("CollectionHelper.createRecommendationsElements");
 
         List<Recommendation> rs = c.getRecommendations();
 
         if (rs == null || rs.size() == 0) {
-            System.err.println("Collection did not load recommendations: " +
+            logger.debug("Collection did not load recommendations: " +
                 c.identifier());
             return null;
         }
@@ -259,7 +265,7 @@
         Collection     c,
         Recommendation r)
     {
-        System.out.println("CollectionHelper.createRecommendationElement");
+        logger.debug("CollectionHelper.createRecommendationElement");
 
         Element recommendation = cr.create("recommendation");
         cr.addAttr(recommendation, "factory", r.getFactory(), true);
@@ -280,10 +286,10 @@
      * @return a Collection with CollectionItems.
      */
     public static Collection parseCollection(Document description) {
-        System.out.println("AddArtifactServiceImpl.parseCollection");
+        logger.debug("AddArtifactServiceImpl.parseCollection");
 
         if (description == null) {
-            System.err.println("The DESCRIBE of the Collection is null!");
+            logger.warn("The DESCRIBE of the Collection is null!");
             return null;
         }
 
@@ -303,12 +309,12 @@
             ArtifactNamespaceContext.INSTANCE);
 
         if (uuid.length() == 0) {
-            System.err.println("Found an invalid (zero length uuid) Collection!");
+            logger.warn("Found an invalid (zero length uuid) Collection!");
             return null;
         }
 
         if (ttlStr.length() == 0) {
-            System.err.println("Found an invalid Collectioni (zero length ttl)!");
+            logger.warn("Found an invalid Collectioni (zero length ttl)!");
             return null;
         }
 
@@ -337,7 +343,7 @@
             ArtifactNamespaceContext.INSTANCE);
 
         if (items == null || items.getLength() == 0) {
-            System.out.println("No collection item found for this collection.");
+            logger.debug("No collection item found for this collection.");
 
             return c;
         }
@@ -354,7 +360,7 @@
             }
         }
 
-        System.out.println(
+        logger.debug(
             "Found " + c.getItemLength() + " collection items " +
             "for the Collection '" + c.identifier() + "'.");
 
@@ -363,7 +369,7 @@
 
 
     protected static Map<String, ThemeList> parseThemeLists(Document desc) {
-        System.out.println("DescribeCollectionServiceImpl.parseThemeLists");
+        logger.debug("DescribeCollectionServiceImpl.parseThemeLists");
 
         NodeList lists = (NodeList) XMLUtils.xpath(
             desc,
@@ -395,7 +401,7 @@
 
 
     protected static ThemeList parseThemeList(Element node) {
-        System.out.println("DescribeCollectionServiceImpl.parseThemeList");
+        logger.debug("DescribeCollectionServiceImpl.parseThemeList");
 
         NodeList themes = node.getElementsByTagNameNS(
             ArtifactNamespaceContext.NAMESPACE_URI,
@@ -418,7 +424,7 @@
 
 
     protected static Theme parseTheme(Element ele) {
-        System.out.println("DescribeCollectionServiceImpl.parseTheme");
+        logger.debug("DescribeCollectionServiceImpl.parseTheme");
 
         String uri = ArtifactNamespaceContext.NAMESPACE_URI;
 
@@ -453,10 +459,10 @@
         Element node,
         boolean outs
     ) {
-        System.out.println("AddArtifactServiceImpl.parseCollectionItem");
+        logger.debug("AddArtifactServiceImpl.parseCollectionItem");
 
         if (node == null) {
-            System.err.println("The node for parsing CollectionItem is null!");
+            logger.debug("The node for parsing CollectionItem is null!");
             return null;
         }
 
@@ -466,7 +472,7 @@
         String hash = node.getAttributeNS(uri, "hash");
 
         if (uuid == null || uuid.length() == 0) {
-            System.err.println("Found an invalid CollectionItem!");
+            logger.warn("Found an invalid CollectionItem!");
             return null;
         }
 
@@ -498,10 +504,10 @@
      * @return a list of OutputModes.
      */
     protected static List<OutputMode> parseOutputModes(Element node) {
-        System.out.println("AddArtifactServiceImpl.parseOutputModes");
+        logger.debug("AddArtifactServiceImpl.parseOutputModes");
 
         if (node == null) {
-            System.err.println("The node for parsing OutputModes is null!");
+            logger.debug("The node for parsing OutputModes is null!");
             return null;
         }
 
@@ -512,7 +518,7 @@
         int size = list.getLength();
 
         if (size == 0) {
-            System.err.println("No outputmode nodes found!");
+            logger.debug("No outputmode nodes found!");
             return null;
         }
 
@@ -527,7 +533,7 @@
             String type = tmp.getAttributeNS(uri, "type");
 
             if (name.length() == 0) {
-                System.err.println("Found an invalid output mode.");
+                logger.warn("Found an invalid output mode.");
                 continue;
             }
 
@@ -547,7 +553,7 @@
                 outmode = new MapMode(name, desc, mime, fs);
             }
             else {
-                System.err.println("Broken Output mode without type found.");
+                logger.warn("Broken Output mode without type found.");
                 continue;
             }
 
@@ -559,7 +565,7 @@
 
 
     protected static List<Facet> extractFacets(Element outmode) {
-        System.out.println("DescribeCollectionServiceImpl - extractFacets()");
+        logger.debug("DescribeCollectionServiceImpl - extractFacets()");
 
         NodeList facetList = (NodeList) XMLUtils.xpath(
             outmode,
@@ -590,7 +596,7 @@
 
 
     public static List<Recommendation> parseRecommendations(Document doc) {
-        System.out.println("DescribeCollectionServiceImpl.parseRecommendations");
+        logger.debug("DescribeCollectionServiceImpl.parseRecommendations");
 
         NodeList list = (NodeList) XMLUtils.xpath(
             doc,
@@ -631,10 +637,10 @@
         String     locale)
     throws ServerException
     {
-        System.out.println("Collection.addArtifact");
+        logger.debug("Collection.addArtifact");
 
         if (collection == null) {
-            System.err.println("The given Collection is null!");
+            logger.warn("The given Collection is null!");
             return null;
         }
 
@@ -644,12 +650,12 @@
         HttpClient client = new HttpClientImpl(url, locale);
 
         try {
-            System.out.println("Do HTTP request now.");
+            logger.debug("Do HTTP request now.");
 
             Document response = (Document) client.doCollectionAction(
                 add, collection.identifier(), new DocumentResponseHandler());
 
-            System.out.println(
+            logger.debug(
                 "Finished HTTP request successfully. Parse Collection now.");
 
             Collection c = CollectionHelper.parseCollection(response);
@@ -661,10 +667,10 @@
             return c;
         }
         catch (ConnectionException ce) {
-            System.err.println(ce.getLocalizedMessage());
+            logger.error(ce, ce);
         }
         catch (Exception e) {
-            e.printStackTrace();
+            logger.error(e, e);
         }
 
         throw new ServerException(ERROR_ADD_ARTIFACT);
@@ -683,10 +689,10 @@
         String     locale)
     throws ServerException
     {
-        System.out.println("Collection.removeArtifact");
+        logger.debug("Collection.removeArtifact");
 
         if (collection == null) {
-            System.err.println("The given Collection is null!");
+            logger.warn("The given Collection is null!");
             return null;
         }
 
@@ -696,14 +702,14 @@
         HttpClient client = new HttpClientImpl(url, locale);
 
         try {
-            System.out.println("Do HTTP request now.");
+            logger.debug("Do HTTP request now.");
 
             Document response = (Document) client.doCollectionAction(
                 remove, collection.identifier(), new DocumentResponseHandler());
 
-            System.out.println(
+            logger.debug(
                 "Finished HTTP request successfully. Parse Collection now.");
-            System.out.println(XMLUtils.toString(response));
+            logger.debug(XMLUtils.toString(response));
 
             Collection c = CollectionHelper.parseCollection(response);
 
@@ -714,10 +720,10 @@
             return c;
         }
         catch (ConnectionException ce) {
-            System.err.println(ce.getLocalizedMessage());
+            logger.error(ce, ce);
         }
         catch (Exception e) {
-            e.printStackTrace();
+            logger.error(e, e);
         }
         throw new ServerException(ERROR_REMOVE_ARTIFACT);
     }

http://dive4elements.wald.intevation.org