[Yanel-commits] rev 30496 - in public/yanel/trunk/src/core/java/org/wyona/yanel/core: . serialization source

josias at wyona.com josias at wyona.com
Fri Jan 18 17:38:32 CET 2008


Author: josias
Date: 2008-01-18 17:38:32 +0100 (Fri, 18 Jan 2008)
New Revision: 30496

Added:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/Constants.java
Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/SerializerFactory.java
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/source/ResourceResolver.java
Log:
added Constants class which holds general yanel constants. added default text serializer to SerializerFactory. fixed a bug in ResourceResolver (correctly pass viewid). thanks to Evaldas Taroza for the patch.

Added: public/yanel/trunk/src/core/java/org/wyona/yanel/core/Constants.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/Constants.java	                        (rev 0)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/Constants.java	2008-01-18 16:38:32 UTC (rev 30496)
@@ -0,0 +1,25 @@
+package org.wyona.yanel.core;
+
+
+public abstract class Constants {
+    /**
+     * General parameters and values for passing requests to Yanel (e.g. http://.../yanel/resource.xml?param=value) 
+     * */
+    public static interface Request{
+        /**
+         * Controls which view a viewable resource should choose
+         * */
+        public static final String YANEL_RESOURCE_VIEWID = "yanel.resource.viewid";
+        /**
+         * The value for the default view
+         * */
+        public static final String DEFAULT_VIEW_ID = "default";
+        
+        /**
+         * The value for the source view
+         * */
+        public static final String SOURCE_VIEW_ID = "source";
+    }
+    
+    private Constants(){};
+}


Property changes on: public/yanel/trunk/src/core/java/org/wyona/yanel/core/Constants.java
___________________________________________________________________
Name: svn:eol-style
   + native

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	2008-01-18 16:23:54 UTC (rev 30495)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/SerializerFactory.java	2008-01-18 16:38:32 UTC (rev 30496)
@@ -2,66 +2,84 @@
 
 import java.util.Properties;
 import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
+import org.apache.xml.serializer.Method;
 import org.apache.xml.serializer.OutputPropertiesFactory;
 import org.apache.xml.serializer.Serializer;
+import org.apache.xml.serializer.ToTextStream;
 
 /**
  * Factory to create serializers. 
- * Currently only supports html serializers.
  */
 public class SerializerFactory {
 
-    private static Category log = Category.getInstance(SerializerFactory.class);
+    private static Logger log = Logger.getLogger(SerializerFactory.class);
     
     public static final int XHTML_STRICT = 1;
     public static final int HTML_TRANSITIONAL = 2;
     public static final int XML = 3;
+    public static final int TEXT = 4;
     
     public static final String XHTML_STRICT_KEY = "XHTML_STRICT";
     public static final String HTML_TRANSITIONAL_KEY = "HTML_TRANSITIONAL";
     public static final String XML_KEY = "XML";
+    public static final String TEXT_KEY = "TEXT";
 
+    /**
+     * @return HTML serializer with the format specified
+     * */
     public static Serializer getSerializer(Properties format) {
         Serializer serializer = new HTMLSerializer();
         serializer.setOutputFormat(format);
         return serializer;
     }
     
+    /**
+     * Get serializer by a given key. Will return TEXT serializer when the key is not recognized.
+     * */
     public static Serializer getSerializer(String key) {
         if (key.equals(XHTML_STRICT_KEY)) {
             return getSerializer(XHTML_STRICT);
         } else if (key.equals(HTML_TRANSITIONAL_KEY)) {
             return getSerializer(HTML_TRANSITIONAL);
-        } if (key.equals(XML_KEY)) {
+        } else if (key.equals(XML_KEY)) {
             return getSerializer(XML);
+        } else if (key.equals(TEXT_KEY)) {
+            return getSerializer(TEXT);
         }
-        return null;
+        return getSerializer(TEXT);
     }
     
+    /**
+     * Get serializer by a given key. Will return TEXT serializer when the key is not recognized.
+     * */
     public static Serializer getSerializer(int key) {
         Serializer serializer = null;
         if (key == XHTML_STRICT) {
             serializer = new HTMLSerializer();
-            Properties format = OutputPropertiesFactory.getDefaultMethodProperties("html");
+            Properties format = OutputPropertiesFactory.getDefaultMethodProperties(Method.XHTML);
             format.setProperty("indent", "yes");
             format.setProperty("doctype-public", "-//W3C//DTD XHTML 1.0 Strict//EN");
             format.setProperty("doctype-system", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
             serializer.setOutputFormat(format);
-        }
-        if (key == HTML_TRANSITIONAL) {
+        }else if (key == HTML_TRANSITIONAL) {
             serializer = new HTMLSerializer();
-            Properties format = OutputPropertiesFactory.getDefaultMethodProperties("html");
+            Properties format = OutputPropertiesFactory.getDefaultMethodProperties(Method.HTML);
             format.setProperty("indent", "yes");
             format.setProperty("omit-xml-declaration", "yes");
             format.setProperty("doctype-public", "-//W3C//DTD HTML 4.01 Transitional//EN");
             format.setProperty("doctype-system", "http://www.w3.org/TR/html4/loose.dtd");
             serializer.setOutputFormat(format);
-        }
-        if (key == XML) {
+        }else if (key == XML) {
             serializer = new XMLSerializer();
-            Properties format = OutputPropertiesFactory.getDefaultMethodProperties("xml");
+            Properties format = OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
             format.setProperty("indent", "yes");
             serializer.setOutputFormat(format);
+        } else {
+            // Internal Xalan serializer
+            Properties format = OutputPropertiesFactory.getDefaultMethodProperties(Method.TEXT);
+            serializer = new ToTextStream();
+            serializer.setOutputFormat(format);
         }
         return serializer;
     }

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/source/ResourceResolver.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/source/ResourceResolver.java	2008-01-18 16:23:54 UTC (rev 30495)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/source/ResourceResolver.java	2008-01-18 16:38:32 UTC (rev 30496)
@@ -3,6 +3,7 @@
 import java.util.HashMap;
 
 import org.apache.log4j.Category;
+import org.wyona.yanel.core.Constants;
 import org.wyona.yanel.core.Path;
 import org.wyona.yanel.core.Resource;
 import org.wyona.yanel.core.ResourceManager;
@@ -59,15 +60,19 @@
                     resource.getRealm(), uri);
             // TODO: don't overwrite existing parameters, but add the new ones
             targetResource.setParameters(parameters);
+            
+            // Check which if there is a view requested for the resource
+            String viewid = (String)parameters.get(Constants.Request.YANEL_RESOURCE_VIEWID);
+            
             if (ResourceAttributeHelper.hasAttributeImplemented(targetResource, "Viewable", "1")) {
                 String viewV1path = resource.getRealm().getMountPoint() + uri.substring(1);
                 if (log.isDebugEnabled()) {
                     log.debug("including document: " + viewV1path);
                 }
-                View view = ((ViewableV1) targetResource).getView(new Path(viewV1path), null);
+                View view = ((ViewableV1) targetResource).getView(new Path(viewV1path), viewid);
                 return new StreamSource(view.getInputStream());
             } else if (ResourceAttributeHelper.hasAttributeImplemented(targetResource, "Viewable", "2")) {
-                View view = ((ViewableV2) targetResource).getView(null);
+                View view = ((ViewableV2) targetResource).getView(viewid);
                 if (!view.isResponse()) {
                     throw new Exception("Reading from the response has not been implemented yet!");
                 } else {



More information about the Yanel-commits mailing list