[Yanel-commits] rev 44980 - public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization

guillaume at wyona.com guillaume at wyona.com
Mon Oct 12 12:05:03 CEST 2009


Author: guillaume
Date: 2009-10-12 12:05:02 +0200 (Mon, 12 Oct 2009)
New Revision: 44980

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/SerializerFactory.java
Log:
Added debug log to check which serializer classes really get used!

Issue: 7285


Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/SerializerFactory.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/SerializerFactory.java	2009-10-12 09:40:59 UTC (rev 44979)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/SerializerFactory.java	2009-10-12 10:05:02 UTC (rev 44980)
@@ -1,6 +1,9 @@
 package org.wyona.yanel.core.serialization;
 
+import java.net.URL;
 import java.util.Properties;
+
+import org.apache.log4j.Logger;
 import org.apache.xml.serializer.Method;
 import org.apache.xml.serializer.OutputPropertiesFactory;
 import org.apache.xml.serializer.Serializer;
@@ -21,12 +24,15 @@
     public static final String XML_KEY = "XML";
     public static final String TEXT_KEY = "TEXT";
 
+    private static final Logger log = Logger.getLogger(SerializerFactory.class);
+
     /**
      * @return HTML serializer with the format specified
      * */
     public static Serializer getSerializer(Properties format) {
         Serializer serializer = new HTMLSerializer();
         serializer.setOutputFormat(format);
+        if (log.isDebugEnabled()) debug(serializer.getClass());
         return serializer;
     }
     
@@ -77,6 +83,20 @@
             serializer = new ToTextStream();
             serializer.setOutputFormat(format);
         }
+        if (log.isDebugEnabled()) debug(serializer.getClass());
         return serializer;
     }
+
+    /**
+     * @see http://stackoverflow.com/questions/779650/where-on-the-file-system-was-my-java-class-loaded-from/779687#779687
+     */
+    private static void debug(Class<?> clazz) {
+        //String jarRelativeURLtext = "/org/apache/xml/serializer/Encodings.properties"; //HACK: any other resource always present in the JAR would do
+        //String jarRelativeURLtext = "/META-INF/MANIFEST.MF"; // does not work: picks up a seemingly random JAR
+        String jarRelativeURLtext = "/" + clazz.getName().replace('.', '/') + ".class";
+        URL jarEntryURL = clazz.getResource(jarRelativeURLtext);
+        String jarEntryURLtext = jarEntryURL.toExternalForm();
+        String jarURLtext = jarEntryURLtext.substring(0, jarEntryURLtext.lastIndexOf(jarRelativeURLtext));
+        log.debug("This "+clazz.getName()+" comes from <"+jarURLtext+">!");
+    }
 }



More information about the Yanel-commits mailing list