cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r169635 - in /cocoon/blocks/unsupported/template/trunk: WEB-INF/xconf/cocoon-template.xconf java/org/apache/cocoon/template/script/DefaultInstructionFactory.java java/org/apache/cocoon/template/template-instructions.xml test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest
Date Wed, 11 May 2005 13:42:36 GMT
Author: lgawron
Date: Wed May 11 06:42:31 2005
New Revision: 169635

URL: http://svn.apache.org/viewcvs?rev=169635&view=rev
Log:
moved template instructions' configuration to a separate file kept in jar

Added:
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/template-instructions.xml
  (with props)
Modified:
    cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/DefaultInstructionFactory.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=169635&r1=169634&r2=169635&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 Wed May 11
06:42:31 2005
@@ -22,27 +22,5 @@
 <components>
     <include src="context://WEB-INF/xconf/cocoon-template-expression.xconf"/>
     <component role="org.apache.cocoon.template.script.ScriptManager" class="org.apache.cocoon.template.script.DefaultScriptManager"/>
-    <component role="org.apache.cocoon.template.script.InstructionFactory" class="org.apache.cocoon.template.script.DefaultInstructionFactory">
-        <instructions targetNamespace="http://apache.org/cocoon/templates/jx/1.0">
-            <instruction name="template" class="org.apache.cocoon.template.instruction.Template"/>
-            <instruction name="forEach" class="org.apache.cocoon.template.instruction.ForEach"/>
-            <instruction name="if" class="org.apache.cocoon.template.instruction.If"/>
-            <instruction name="choose" class="org.apache.cocoon.template.instruction.Choose"/>
-            <instruction name="when" class="org.apache.cocoon.template.instruction.When"/>
-            <instruction name="otherwise" class="org.apache.cocoon.template.instruction.Otherwise"/>
-            <instruction name="out" class="org.apache.cocoon.template.instruction.Out"/>
-            <instruction name="import" class="org.apache.cocoon.template.instruction.Import"/>
-            <instruction name="set" class="org.apache.cocoon.template.instruction.Set"/>
-            <instruction name="macro" class="org.apache.cocoon.template.instruction.Define"/>
-            <instruction name="evalBody" class="org.apache.cocoon.template.instruction.EvalBody"/>
-            <instruction name="eval" class="org.apache.cocoon.template.instruction.Eval"/>
-            <instruction name="parameter" class="org.apache.cocoon.template.instruction.Parameter"/>
-            <instruction name="formatNumber" class="org.apache.cocoon.template.instruction.FormatNumber"/>
-            <instruction name="formatDate" class="org.apache.cocoon.template.instruction.FormatDate"/>
-            <instruction name="comment" class="org.apache.cocoon.template.instruction.Comment"/>
-            <instruction name="call" class="org.apache.cocoon.template.instruction.Call"/>
-            <instruction name="withParam" class="org.apache.cocoon.template.instruction.ParameterInstance"/>
-            <instruction name="attribute" class="org.apache.cocoon.template.instruction.Attribute"/>
-        </instructions>
-    </component>
+    <component role="org.apache.cocoon.template.script.InstructionFactory" class="org.apache.cocoon.template.script.DefaultInstructionFactory"/>
 </components>

Modified: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/DefaultInstructionFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/DefaultInstructionFactory.java?rev=169635&r1=169634&r2=169635&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/DefaultInstructionFactory.java
(original)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/DefaultInstructionFactory.java
Wed May 11 06:42:31 2005
@@ -23,11 +23,17 @@
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
 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.avalon.framework.thread.ThreadSafe;
 import org.apache.cocoon.template.instruction.Instruction;
 import org.apache.cocoon.template.script.event.StartElement;
 import org.apache.commons.lang.ClassUtils;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
@@ -36,34 +42,13 @@
  * @version SVN $Id: DefaultInstructionFactory.java 169615 2005-05-11 09:57:41Z
  *          lgawron $
  */
-public class DefaultInstructionFactory extends AbstractLogEnabled implements ThreadSafe,
Configurable,
+public class DefaultInstructionFactory extends AbstractLogEnabled implements ThreadSafe,
Serviceable, Configurable,
         InstructionFactory {
-    private Map instructions;
-    final static Class[] INSTRUCTION_CONSTRUCTOR_PARAMS = new Class[] { StartElement.class,
Attributes.class,
+    private Map instructions = new HashMap();
+    private ServiceManager manager;
+    private final static Class[] INSTRUCTION_CONSTRUCTOR_PARAMS = new Class[] { StartElement.class,
Attributes.class,
             Stack.class };
-
-    public void configure(Configuration conf) throws ConfigurationException {
-        this.instructions = new HashMap();
-        Configuration[] instructionSets = conf.getChildren("instructions");
-        for (int i = 0; i < instructionSets.length; i++) {
-            Configuration instructionSet = instructionSets[i];
-            String namespace = instructionSet.getAttribute("targetNamespace", "");
-            
-            Configuration[] instr = instructionSet.getChildren("instruction");
-            for (int j = 0; j < instr.length; j++) {
-                Configuration currentInstruction = instr[j];
-                String name = currentInstruction.getAttribute("name");
-                if (name == null)
-                    throw new ConfigurationException("@name for instruction required");
-                
-                String className = currentInstruction.getAttribute("class");
-                if (className == null)
-                    throw new ConfigurationException("@class for instruction required");
-                
-                registerInstruction(name, namespace, className);
-            }
-        }
-    }
+    private final static String CONFIG_LOCATION = "resource://org/apache/cocoon/template/template-instructions.xml";
 
     private void registerInstruction(String instructionName, String targetNamespace, String
className)
             throws ConfigurationException {
@@ -77,12 +62,11 @@
 
             String instructionKey = instructionKey(instructionName, targetNamespace);
             this.instructions.put(instructionKey, constructor);
-        } catch (ClassNotFoundException e) {
-            throw new ConfigurationException("unable to register instruction", e);
-        } catch (SecurityException e) {
-            throw new ConfigurationException("unable to register instruction", e);
-        } catch (NoSuchMethodException e) {
-            throw new ConfigurationException("unable to register instruction", e);
+        } catch (Exception e) {
+            if (e instanceof ConfigurationException)
+                throw (ConfigurationException) e;
+            else
+                throw new ConfigurationException("unable to register instruction", e);
         }
     }
 
@@ -99,8 +83,7 @@
         return this.instructions.containsKey(instructionKey);
     }
 
-    public Instruction createInstruction(StartElement startElement, Attributes attrs, Stack
stack)
-            throws SAXException {
+    public Instruction createInstruction(StartElement startElement, Attributes attrs, Stack
stack) throws SAXException {
         String instructionKey = instructionKey(startElement);
         Constructor constructor = (Constructor) this.instructions.get(instructionKey);
         if (constructor == null)
@@ -110,6 +93,56 @@
             return (Instruction) constructor.newInstance(arguments);
         } catch (Exception e) {
             throw new SAXParseException("error creating instruction: " + instructionKey,
startElement.getLocation(), e);
+        }
+    }
+
+    public void setupInstructions(Configuration conf) throws ConfigurationException {
+        Configuration[] instructionSets = conf.getChildren("instructions");
+        for (int i = 0; i < instructionSets.length; i++) {
+            Configuration instructionSet = instructionSets[i];
+            String namespace = instructionSet.getAttribute("targetNamespace", "");
+
+            Configuration[] instr = instructionSet.getChildren("instruction");
+            for (int j = 0; j < instr.length; j++) {
+                Configuration currentInstruction = instr[j];
+                String name = currentInstruction.getAttribute("name");
+                if (name == null)
+                    throw new ConfigurationException("@name for instruction required");
+
+                String className = currentInstruction.getAttribute("class");
+                if (className == null)
+                    throw new ConfigurationException("@class for instruction required");
+
+                registerInstruction(name, namespace, className);
+            }
+        }
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
+    public void configure(Configuration omitted) throws ConfigurationException {
+        // do NOT use configuration from cocoon.xconf!
+        // TODO: can we do it in more elegant way?
+        SourceResolver resolver = null;
+        Source source = null;
+        try {
+            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+            source = resolver.resolveURI(CONFIG_LOCATION);
+            DefaultConfigurationBuilder configurationBuilder = new DefaultConfigurationBuilder();
+            Configuration conf = configurationBuilder.build(source.getInputStream());
+            setupInstructions(conf);
+        } catch (Exception e) {
+            if (e instanceof ConfigurationException)
+                throw (ConfigurationException) e;
+            else
+                throw new ConfigurationException("unable to parse template instructions configuration",
e);
+        } finally {
+            if (source != null)
+                resolver.release(source);
+            if (resolver != null)
+                this.manager.release(resolver);
         }
     }
 }

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/template-instructions.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/template-instructions.xml?rev=169635&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/template-instructions.xml
(added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/template-instructions.xml
Wed May 11 06:42:31 2005
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<root>
+    <instructions targetNamespace="http://apache.org/cocoon/templates/jx/1.0">
+        <instruction name="template" class="org.apache.cocoon.template.instruction.Template"/>
+        <instruction name="forEach" class="org.apache.cocoon.template.instruction.ForEach"/>
+        <instruction name="if" class="org.apache.cocoon.template.instruction.If"/>
+        <instruction name="choose" class="org.apache.cocoon.template.instruction.Choose"/>
+        <instruction name="when" class="org.apache.cocoon.template.instruction.When"/>
+        <instruction name="otherwise" class="org.apache.cocoon.template.instruction.Otherwise"/>
+        <instruction name="out" class="org.apache.cocoon.template.instruction.Out"/>
+        <instruction name="import" class="org.apache.cocoon.template.instruction.Import"/>
+        <instruction name="set" class="org.apache.cocoon.template.instruction.Set"/>
+        <instruction name="macro" class="org.apache.cocoon.template.instruction.Define"/>
+        <instruction name="evalBody" class="org.apache.cocoon.template.instruction.EvalBody"/>
+        <instruction name="eval" class="org.apache.cocoon.template.instruction.Eval"/>
+        <instruction name="parameter" class="org.apache.cocoon.template.instruction.Parameter"/>
+        <instruction name="formatNumber" class="org.apache.cocoon.template.instruction.FormatNumber"/>
+        <instruction name="formatDate" class="org.apache.cocoon.template.instruction.FormatDate"/>
+        <instruction name="comment" class="org.apache.cocoon.template.instruction.Comment"/>
+        <instruction name="call" class="org.apache.cocoon.template.instruction.Call"/>
+        <instruction name="withParam" class="org.apache.cocoon.template.instruction.ParameterInstance"/>
+        <instruction name="attribute" class="org.apache.cocoon.template.instruction.Attribute"/>
+    </instructions>
+</root>

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/template-instructions.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/template-instructions.xml
------------------------------------------------------------------------------
    svn:keywords = Id

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=169635&r1=169634&r2=169635&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
Wed May 11 06:42:31 2005
@@ -19,6 +19,8 @@
         <role name="org.apache.excalibur.xml.sax.SAXParser" shorthand="xml-parser" default-class="org.apache.excalibur.xml.impl.JaxpParser"/>
         <role name="org.apache.cocoon.generation.GeneratorSelector" shorthand="generators"
default-class="org.apache.cocoon.core.container.StandaloneServiceSelector"/>
         <role name="org.apache.excalibur.store.Store/TransientStore" shorthand="store"
default-class="org.apache.excalibur.store.impl.MemoryStore"/>
+        <role name="org.apache.excalibur.source.SourceFactorySelector" shorthand="source-factories"
default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
+        <role name="org.apache.excalibur.source.SourceResolver" shorthand="source-resolver"
default-class="org.apache.excalibur.source.impl.SourceResolverImpl"/>
     </roles>
     <components>
         <xml-parser class="org.apache.excalibur.xml.impl.JaxpParser">
@@ -33,28 +35,6 @@
         </generators>
         <store logger="test"/>
         <component role="org.apache.cocoon.template.script.ScriptManager" class="org.apache.cocoon.template.script.DefaultScriptManager"/>
-        <component role="org.apache.cocoon.template.script.InstructionFactory" class="org.apache.cocoon.template.script.DefaultInstructionFactory">
-            <instructions targetNamespace="http://apache.org/cocoon/templates/jx/1.0">
-                <instruction name="template" class="org.apache.cocoon.template.instruction.Template"/>
-                <instruction name="forEach" class="org.apache.cocoon.template.instruction.ForEach"/>
-                <instruction name="if" class="org.apache.cocoon.template.instruction.If"/>
-                <instruction name="choose" class="org.apache.cocoon.template.instruction.Choose"/>
-                <instruction name="when" class="org.apache.cocoon.template.instruction.When"/>
-                <instruction name="otherwise" class="org.apache.cocoon.template.instruction.Otherwise"/>
-                <instruction name="out" class="org.apache.cocoon.template.instruction.Out"/>
-                <instruction name="import" class="org.apache.cocoon.template.instruction.Import"/>
-                <instruction name="set" class="org.apache.cocoon.template.instruction.Set"/>
-                <instruction name="macro" class="org.apache.cocoon.template.instruction.Define"/>
-                <instruction name="evalBody" class="org.apache.cocoon.template.instruction.EvalBody"/>
-                <instruction name="eval" class="org.apache.cocoon.template.instruction.Eval"/>
-                <instruction name="parameter" class="org.apache.cocoon.template.instruction.Parameter"/>
-                <instruction name="formatNumber" class="org.apache.cocoon.template.instruction.FormatNumber"/>
-                <instruction name="formatDate" class="org.apache.cocoon.template.instruction.FormatDate"/>
-                <instruction name="comment" class="org.apache.cocoon.template.instruction.Comment"/>
-                <instruction name="call" class="org.apache.cocoon.template.instruction.Call"/>
-                <instruction name="withParam" class="org.apache.cocoon.template.instruction.ParameterInstance"/>
-                <instruction name="attribute" class="org.apache.cocoon.template.instruction.Attribute"/>
-            </instructions>
-        </component>
+        <component role="org.apache.cocoon.template.script.InstructionFactory" class="org.apache.cocoon.template.script.DefaultInstructionFactory"/>
     </components>
 </testcase>



Mime
View raw message