cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r169180 - in /cocoon/blocks/unsupported/template/trunk: WEB-INF/xconf/ java/org/apache/cocoon/template/jxtg/ java/org/apache/cocoon/template/jxtg/script/ test/org/apache/cocoon/template/jxtg/
Date Sun, 08 May 2005 22:11:26 GMT
Author: lgawron
Date: Sun May  8 15:11:25 2005
New Revision: 169180

URL: http://svn.apache.org/viewcvs?rev=169180&view=rev
Log:
make ScriptManager a real component

Added:
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultScriptManager.java
  (with props)
Modified:
    cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/ScriptManager.java
    cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest

Modified: cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf?rev=169180&r1=169179&r2=169180&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf (original)
+++ cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf Sun May 
8 15:11:25 2005
@@ -21,4 +21,7 @@
     +-->
 <components>
   <include src="context://WEB-INF/xconf/cocoon-template-expression.xconf"/>
+  
+  <component role="org.apache.cocoon.template.jxtg.script.ScriptManager" 
+             class="org.apache.cocoon.template.jxtg.script.DefaultScriptManager"/>
 </components>

Modified: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java?rev=169180&r1=169179&r2=169180&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java
(original)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java
Sun May  8 15:11:25 2005
@@ -56,7 +56,8 @@
  * @cocoon.sitemap.component.pooling.max 16
  * 
  * 
- * @version SVN $Id$
+ * @version SVN $Id: JXTemplateGenerator.java 169169 2005-05-08 21:23:28Z
+ *          lgawron $
  */
 public class JXTemplateGenerator extends ServiceableGenerator implements
         CacheableProcessingComponent {
@@ -67,7 +68,7 @@
     public final static String VALIDITY = "cache-validity";
 
     private ExpressionContext expressionContext;
-    private ScriptManager scriptManager = new ScriptManager();
+    private ScriptManager scriptManager;
     private StartDocument startDocument;
     private Map definitions;
 
@@ -77,14 +78,14 @@
 
     public void service(ServiceManager manager) throws ServiceException {
         super.service(manager);
-        scriptManager.service(manager);
+        scriptManager = (ScriptManager) this.manager.lookup(ScriptManager.ROLE);
     }
 
     public void dispose() {
-        scriptManager.dispose();
+        this.manager.release(scriptManager);
         super.dispose();
     }
-    
+
     public void recycle() {
         this.startDocument = null;
         this.expressionContext = null;
@@ -125,7 +126,7 @@
     public Serializable getKey() {
         JXTExpression cacheKeyExpr = (JXTExpression) this.startDocument
                 .getTemplateProperty(JXTemplateGenerator.CACHE_KEY);
-        if ( cacheKeyExpr == null )
+        if (cacheKeyExpr == null)
             return null;
         try {
             final Serializable templateKey = (Serializable) cacheKeyExpr
@@ -142,7 +143,7 @@
     public SourceValidity getValidity() {
         JXTExpression validityExpr = (JXTExpression) this.startDocument
                 .getTemplateProperty(JXTemplateGenerator.VALIDITY);
-        if ( validityExpr == null )
+        if (validityExpr == null)
             return null;
         try {
             final SourceValidity sourceValidity = this.startDocument

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultScriptManager.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultScriptManager.java?rev=169180&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultScriptManager.java
(added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultScriptManager.java
Sun May  8 15:11:25 2005
@@ -0,0 +1,125 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.script;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.template.jxtg.script.event.StartDocument;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.store.Store;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class DefaultScriptManager extends AbstractLogEnabled implements
+        Serviceable, Disposable, ScriptManager {
+    private ServiceManager manager;
+    private final static String JX_STORE_PREFIX = "jxtg:";
+    private Store store = null;
+
+    public DefaultScriptManager() {
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+        this.store = (Store) this.manager.lookup(Store.ROLE);
+    }
+
+    public void dispose() {
+        this.manager.release(store);
+    }
+
+    private Store getStore() {
+        return store;
+    }
+
+    public StartDocument resolveTemplate(String uri) throws SAXParseException,
+            ProcessingException {
+        return resolveTemplate(uri, null);
+    }
+
+    public StartDocument resolveTemplate(String uri, Locator location)
+            throws SAXParseException, ProcessingException {
+        Source input = null;
+        StartDocument doc = null;
+        SourceResolver resolver = null;
+        try {
+            resolver = (SourceResolver) this.manager
+                    .lookup(SourceResolver.ROLE);
+            input = resolver.resolveURI(uri);
+            SourceValidity validity = null;
+
+            String storeUri = JX_STORE_PREFIX + input.getURI();
+            doc = (StartDocument) getStore().get(storeUri);
+
+            // TODO: why was this previously in synchronized( getCache() )?
+            if (doc != null) {
+                boolean recompile = false;
+                if (doc.getSourceValidity() == null) {
+                    recompile = true;
+                } else {
+                    int valid = doc.getSourceValidity().isValid();
+                    if (valid == SourceValidity.UNKNOWN) {
+                        validity = input.getValidity();
+                        valid = doc.getSourceValidity().isValid(validity);
+                    }
+                    if (valid != SourceValidity.VALID) {
+                        recompile = true;
+                    }
+                }
+                if (recompile) {
+                    doc = null; // recompile
+                }
+            }
+
+            if (doc == null) {
+                Parser parser = new Parser();
+                // call getValidity before using the stream is faster if
+                // the source is a SitemapSource
+                if (validity == null) {
+                    validity = input.getValidity();
+                }
+                SourceUtil.parse(manager, input, parser);
+                doc = parser.getStartEvent();
+                doc.setUri(input.getURI());
+                doc.setSourceValidity(validity);
+
+                getStore().store(storeUri, doc);
+            }
+        } catch (SourceException se) {
+            throw SourceUtil.handle("Error during resolving of '" + uri + "'.",
+                    se);
+        } catch (Exception exc) {
+            throw new SAXParseException(exc.getMessage(), location, exc);
+        } finally {
+            if (input != null)
+                resolver.release(input);
+            if (resolver != null)
+                manager.release(resolver);
+        }
+        return doc;
+    }
+}
\ No newline at end of file

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultScriptManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultScriptManager.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/ScriptManager.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/ScriptManager.java?rev=169180&r1=169179&r2=169180&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/ScriptManager.java
(original)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/ScriptManager.java
Sun May  8 15:11:25 2005
@@ -15,109 +15,20 @@
  */
 package org.apache.cocoon.template.jxtg.script;
 
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
 import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.template.jxtg.script.event.StartDocument;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceException;
-import org.apache.excalibur.source.SourceResolver;
-import org.apache.excalibur.source.SourceValidity;
-import org.apache.excalibur.store.Store;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXParseException;
 
 /**
  * @version SVN $Id$
  */
-public class ScriptManager implements Serviceable, Disposable {
-    private ServiceManager manager;
-    private final static String JX_STORE_PREFIX = "jxtg:";
-    private Store store = null;
+public interface ScriptManager {
+    public final static String ROLE = ScriptManager.class.getName();
 
-    public ScriptManager() {
-    }
+    public abstract StartDocument resolveTemplate(String uri)
+            throws SAXParseException, ProcessingException;
 
-    public void service(ServiceManager manager) throws ServiceException {
-        this.manager = manager;
-        this.store = (Store) this.manager.lookup(Store.ROLE);
-    }
-
-    public void dispose() {
-        this.manager.release(store);
-    }
-
-    private Store getStore() {
-        return store;
-    }
-
-    public StartDocument resolveTemplate(String uri) throws SAXParseException,
-            ProcessingException {
-        return resolveTemplate(uri, null);
-    }
-
-    public StartDocument resolveTemplate(String uri, Locator location)
-            throws SAXParseException, ProcessingException {
-        Source input = null;
-        StartDocument doc = null;
-        SourceResolver resolver = null;
-        try {
-            resolver = (SourceResolver) this.manager
-                    .lookup(SourceResolver.ROLE);
-            input = resolver.resolveURI(uri);
-            SourceValidity validity = null;
-
-            String storeUri = JX_STORE_PREFIX + input.getURI();
-            doc = (StartDocument) getStore().get(storeUri);
-
-            // TODO: why was this previously in synchronized( getCache() )?
-            if (doc != null) {
-                boolean recompile = false;
-                if (doc.getSourceValidity() == null) {
-                    recompile = true;
-                } else {
-                    int valid = doc.getSourceValidity().isValid();
-                    if (valid == SourceValidity.UNKNOWN) {
-                        validity = input.getValidity();
-                        valid = doc.getSourceValidity().isValid(validity);
-                    }
-                    if (valid != SourceValidity.VALID) {
-                        recompile = true;
-                    }
-                }
-                if (recompile) {
-                    doc = null; // recompile
-                }
-            }
-
-            if (doc == null) {
-                Parser parser = new Parser();
-                // call getValidity before using the stream is faster if
-                // the source is a SitemapSource
-                if (validity == null) {
-                    validity = input.getValidity();
-                }
-                SourceUtil.parse(manager, input, parser);
-                doc = parser.getStartEvent();
-                doc.setUri(input.getURI());
-                doc.setSourceValidity(validity);
-
-                getStore().store(storeUri, doc);
-            }
-        } catch (SourceException se) {
-            throw SourceUtil.handle("Error during resolving of '" + uri + "'.",
-                    se);
-        } catch (Exception exc) {
-            throw new SAXParseException(exc.getMessage(), location, exc);
-        } finally {
-            if (input != null)
-                resolver.release(input);
-            if (resolver != null)
-                manager.release(resolver);
-        }
-        return doc;
-    }
+    public abstract StartDocument resolveTemplate(String uri, Locator location)
+            throws SAXParseException, ProcessingException;
 }

Modified: cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest?rev=169180&r1=169179&r2=169180&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest
(original)
+++ cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest
Sun May  8 15:11:25 2005
@@ -43,6 +43,9 @@
     </generators>
 
     <store logger="test"/>
+
+    <component role="org.apache.cocoon.template.jxtg.script.ScriptManager" 
+               class="org.apache.cocoon.template.jxtg.script.DefaultScriptManager"/>
   </components>
  
 </testcase>



Mime
View raw message