[Yanel-commits] rev 44159 - public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase

guillaume at wyona.com guillaume at wyona.com
Thu Aug 13 09:01:18 CEST 2009


Author: guillaume
Date: 2009-08-13 09:01:18 +0200 (Thu, 13 Aug 2009)
New Revision: 44159

Modified:
   public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java
Log:
Now setting system and public IDs on the Jelly template InputSource
 so that Jelly does not loudly complain in logs about the missing source URL
 and (incidentally) so that finding the template used is easier when debugging.

Alos minor-cleaned up the class a bit.

Issue: 7243


Modified: public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java
===================================================================
--- public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java	2009-08-13 06:41:08 UTC (rev 44158)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java	2009-08-13 07:01:18 UTC (rev 44159)
@@ -41,12 +41,7 @@
 
     private static Logger log = Logger.getLogger(UsecaseResource.class);
 
-    /**
-     *
-     */
-    public UsecaseResource() {
-    }
-
+    @Override
     public View getView(String viewID) throws Exception {
         init();
         return processUsecase(viewID);
@@ -112,6 +107,7 @@
     protected InputStream getJellyXML(ConfigurableViewDescriptor viewDescriptor) throws UsecaseException {
         try {
             String viewTemplate = viewDescriptor.getTemplate();
+            if (log.isDebugEnabled()) log.debug("viewTemplate: "+viewTemplate);
             Repository repo = this.getRealm().getRepository();
             
             JellyContext jellyContext = new JellyContext();
@@ -129,22 +125,36 @@
             // problem: it breaks backwards compatibility
             //XMLOutput jellyOutput = XMLOutput.createXMLOutput(jellyResultStream, true);
             XMLOutput jellyOutput = XMLOutput.createXMLOutput(jellyResultStream);
-            
+            InputStream templateInputStream;
+            String templatePublicId;
+            String templateSystemId;
             if (viewTemplate.startsWith("/")) {
                 if (log.isDebugEnabled()) log.debug("Accessing view template directly from the repo (no protocol specified). View Template: " + viewTemplate);
                 // for backwards compatibility. when not using a protocol
-                jellyContext.runScript(new InputSource(repo.getNode(viewTemplate).getInputStream()), jellyOutput);
+                templateInputStream = repo.getNode(viewTemplate).getInputStream();
+                templatePublicId = "yanelrepo:"+viewTemplate;
+                /*XXX HACK the following does not work: Jelly wants URLs => protocol must be registered by the JVM!
+                templateSystemId = "yanelrepo:"+viewTemplate;
+                */
+                templateSystemId = "file:///yanelrepo"+viewTemplate;
+
             } else {
                 if (log.isDebugEnabled()) log.debug("Accessing view template through the source-resolver (protocol specified). View Template: " + viewTemplate);
                 SourceResolver resolver = new SourceResolver(this);
                 Source templateSource = resolver.resolve(viewTemplate, null);
-                InputStream templateInputStream = ((StreamSource)templateSource).getInputStream();
-                
-                jellyContext.runScript(new InputSource(templateInputStream), jellyOutput);
+                templateInputStream = ((StreamSource)templateSource).getInputStream();
+                templatePublicId = templateSource.getSystemId();
+                /*XXX HACK the following does not work: Jelly wants URLs => protocol must be registered by the JVM!
+                templateSystemId = templateSource.getSystemId();
+                */
+                templateSystemId = "file:///"+viewTemplate.replaceFirst(":", "/");
             }
+            InputSource inputSource = new InputSource(templateInputStream);
+            inputSource.setPublicId(templatePublicId);
+            inputSource.setSystemId(templateSystemId);
+            jellyContext.runScript(inputSource, jellyOutput);
+            //XXX should we close templateInputStream here?!?
             
-            
-            
             jellyOutput.flush();
             byte[] result = jellyResultStream.toByteArray();
             //System.out.println(new String(result, "utf-8"));
@@ -168,6 +178,7 @@
         return null;
     }
     
+    @Override
     public boolean exists() throws Exception {
         return true;
     }



More information about the Yanel-commits mailing list