cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r169626 - in /cocoon/blocks/unsupported/template/trunk: WEB-INF/xconf/cocoon-template.xconf java/org/apache/cocoon/template/jxtg/script/DefaultInstructionFactory.java test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest
Date Wed, 11 May 2005 11:37:44 GMT
Author: lgawron
Date: Wed May 11 04:37:42 2005
New Revision: 169626

URL: http://svn.apache.org/viewcvs?rev=169626&view=rev
Log:
increase instructions configuration readability by introducing an instruction set with common
namespace

Modified:
    cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/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=169626&r1=169625&r2=169626&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
04:37:42 2005
@@ -20,69 +20,29 @@
     | SVN $Id$
     +-->
 <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"/>
-
-  <component role="org.apache.cocoon.template.jxtg.script.InstructionFactory"
-             class="org.apache.cocoon.template.jxtg.script.DefaultInstructionFactory">
-    <instruction name="template" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartTemplate"/>
-    <instruction name="forEach" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartForEach"/>
-    <instruction name="if" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartIf"/>
-    <instruction name="choose" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartChoose"/>
-    <instruction name="when" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartWhen"/>
-    <instruction name="otherwise" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartOtherwise"/>
-    <instruction name="out" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartOut"/>
-    <instruction name="import" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartImport"/>
-    <instruction name="set" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartSet"/>
-    <instruction name="macro" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartDefine"/>
-    <instruction name="evalBody" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartEvalBody"/>
-    <instruction name="eval" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartEval"/>
-    <instruction name="parameter" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartParameter"/>
-    <instruction name="formatNumber" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartFormatNumber"/>
-    <instruction name="formatDate" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartFormatDate"/>
-    <instruction name="comment" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartComment"/>
-    <instruction name="call" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartCall"/>
-    <instruction name="withParam" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartParameterInstance"/>
-    <instruction name="attribute" 
-                 targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                 class="org.apache.cocoon.template.jxtg.instruction.StartAttribute"/>
-  </component>
+    <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"/>
+    <component role="org.apache.cocoon.template.jxtg.script.InstructionFactory" class="org.apache.cocoon.template.jxtg.script.DefaultInstructionFactory">
+        <instructions targetNamespace="http://apache.org/cocoon/templates/jx/1.0">
+            <instruction name="template" class="org.apache.cocoon.template.jxtg.instruction.StartTemplate"/>
+            <instruction name="forEach" class="org.apache.cocoon.template.jxtg.instruction.StartForEach"/>
+            <instruction name="if" class="org.apache.cocoon.template.jxtg.instruction.StartIf"/>
+            <instruction name="choose" class="org.apache.cocoon.template.jxtg.instruction.StartChoose"/>
+            <instruction name="when" class="org.apache.cocoon.template.jxtg.instruction.StartWhen"/>
+            <instruction name="otherwise" class="org.apache.cocoon.template.jxtg.instruction.StartOtherwise"/>
+            <instruction name="out" class="org.apache.cocoon.template.jxtg.instruction.StartOut"/>
+            <instruction name="import" class="org.apache.cocoon.template.jxtg.instruction.StartImport"/>
+            <instruction name="set" class="org.apache.cocoon.template.jxtg.instruction.StartSet"/>
+            <instruction name="macro" class="org.apache.cocoon.template.jxtg.instruction.StartDefine"/>
+            <instruction name="evalBody" class="org.apache.cocoon.template.jxtg.instruction.StartEvalBody"/>
+            <instruction name="eval" class="org.apache.cocoon.template.jxtg.instruction.StartEval"/>
+            <instruction name="parameter" class="org.apache.cocoon.template.jxtg.instruction.StartParameter"/>
+            <instruction name="formatNumber" class="org.apache.cocoon.template.jxtg.instruction.StartFormatNumber"/>
+            <instruction name="formatDate" class="org.apache.cocoon.template.jxtg.instruction.StartFormatDate"/>
+            <instruction name="comment" class="org.apache.cocoon.template.jxtg.instruction.StartComment"/>
+            <instruction name="call" class="org.apache.cocoon.template.jxtg.instruction.StartCall"/>
+            <instruction name="withParam" class="org.apache.cocoon.template.jxtg.instruction.StartParameterInstance"/>
+            <instruction name="attribute" class="org.apache.cocoon.template.jxtg.instruction.StartAttribute"/>
+        </instructions>
+    </component>
 </components>

Modified: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultInstructionFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultInstructionFactory.java?rev=169626&r1=169625&r2=169626&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultInstructionFactory.java
(original)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/DefaultInstructionFactory.java
Wed May 11 04:37:42 2005
@@ -33,58 +33,56 @@
 import org.xml.sax.SAXParseException;
 
 /**
- * @version SVN $Id$
+ * @version SVN $Id: DefaultInstructionFactory.java 169615 2005-05-11 09:57:41Z
+ *          lgawron $
  */
-public class DefaultInstructionFactory extends AbstractLogEnabled implements
-        ThreadSafe, Configurable, InstructionFactory {
+public class DefaultInstructionFactory extends AbstractLogEnabled implements ThreadSafe,
Configurable,
+        InstructionFactory {
     private Map instructions;
-    final static Class[] INSTRUCTION_CONSTRUCTOR_PARAMS = new Class[] {
-            StartElement.class, Attributes.class, Stack.class };
+    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[] instr = conf.getChildren("instruction");
-        for (int i = 0; i < instr.length; i++) {
-            Configuration currentInstruction = instr[i];
-            String name = currentInstruction.getAttribute("name");
-            if (name == null)
-                throw new ConfigurationException(
-                        "@name for instruction required");
-            String namespace = currentInstruction.getAttribute(
-                    "targetNamespace", "");
-            String className = currentInstruction.getAttribute("class");
-            if (className == null)
-                throw new ConfigurationException(
-                        "@class for instruction required");
-            registerInstruction(name, namespace, className);
+        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 void registerInstruction(String instructionName,
-            String targetNamespace, String className)
+    private void registerInstruction(String instructionName, String targetNamespace, String
className)
             throws ConfigurationException {
         Class clazz;
         try {
             clazz = Class.forName(className);
             if (!ClassUtils.isAssignable(clazz, StartInstruction.class))
-                throw new ConfigurationException("Class '" + className
-                        + "' is not assignable to "
+                throw new ConfigurationException("Class '" + className + "' is not assignable
to "
                         + "o.a.c.template.jxtg.script.event.StartInstruction ");
-            Constructor constructor = clazz
-                    .getConstructor(INSTRUCTION_CONSTRUCTOR_PARAMS);
+            Constructor constructor = clazz.getConstructor(INSTRUCTION_CONSTRUCTOR_PARAMS);
 
-            String instructionKey = instructionKey(instructionName,
-                    targetNamespace);
+            String instructionKey = instructionKey(instructionName, targetNamespace);
             this.instructions.put(instructionKey, constructor);
         } catch (ClassNotFoundException e) {
-            throw new ConfigurationException("unable to register instruction",
-                    e);
+            throw new ConfigurationException("unable to register instruction", e);
         } catch (SecurityException e) {
-            throw new ConfigurationException("unable to register instruction",
-                    e);
+            throw new ConfigurationException("unable to register instruction", e);
         } catch (NoSuchMethodException e) {
-            throw new ConfigurationException("unable to register instruction",
-                    e);
+            throw new ConfigurationException("unable to register instruction", e);
         }
     }
 
@@ -101,20 +99,17 @@
         return this.instructions.containsKey(instructionKey);
     }
 
-    public StartInstruction createInstruction(StartElement startElement,
-            Attributes attrs, Stack stack) throws SAXException {
+    public StartInstruction createInstruction(StartElement startElement, Attributes attrs,
Stack stack)
+            throws SAXException {
         String instructionKey = instructionKey(startElement);
-        Constructor constructor = (Constructor) this.instructions
-                .get(instructionKey);
+        Constructor constructor = (Constructor) this.instructions.get(instructionKey);
         if (constructor == null)
-            throw new SAXParseException("unrecognized instruction: "
-                    + instructionKey, startElement.getLocation(), null);
+            throw new SAXParseException("unrecognized instruction: " + instructionKey, startElement.getLocation(),
null);
         Object[] arguments = new Object[] { startElement, attrs, stack };
         try {
             return (StartInstruction) constructor.newInstance(arguments);
         } catch (Exception e) {
-            throw new SAXParseException("error creating instruction: "
-                    + instructionKey, startElement.getLocation(), e);
+            throw new SAXParseException("error creating instruction: " + instructionKey,
startElement.getLocation(), e);
         }
     }
 }

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=169626&r1=169625&r2=169626&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 04:37:42 2005
@@ -14,100 +14,47 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-
 <testcase>
-  <roles>
-    <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"/>
-  </roles>
- 
-  <components>
-    <xml-parser class="org.apache.excalibur.xml.impl.JaxpParser">
-      <parameter name="validate" value="false"/>
-      <parameter name="namespace-prefixes" value="false"/>
-      <parameter name="stop-on-warning" value="true"/>
-      <parameter name="stop-on-recoverable-error" value="true"/>
-      <parameter name="reuse-parsers" value="false"/>
-    </xml-parser>
-
-    <generators logger="test">
-      <component-instance class="org.apache.cocoon.template.jxtg.JXTemplateGenerator"

-        name="jx"/>
-    </generators>
-
-    <store logger="test"/>
-
-    <component role="org.apache.cocoon.template.jxtg.script.ScriptManager" 
-               class="org.apache.cocoon.template.jxtg.script.DefaultScriptManager"/>
-               
-    <component role="org.apache.cocoon.template.jxtg.script.InstructionFactory"
-               class="org.apache.cocoon.template.jxtg.script.DefaultInstructionFactory">
-      <instruction name="template" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartTemplate"/>
-      <instruction name="forEach" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartForEach"/>
-      <instruction name="if" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartIf"/>
-      <instruction name="choose" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartChoose"/>
-      <instruction name="when" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartWhen"/>
-      <instruction name="otherwise" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartOtherwise"/>
-      <instruction name="out" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartOut"/>
-      <instruction name="import" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartImport"/>
-      <instruction name="set" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartSet"/>
-      <instruction name="macro" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartDefine"/>
-      <instruction name="evalBody" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartEvalBody"/>
-      <instruction name="eval" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartEval"/>
-      <instruction name="parameter" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartParameter"/>
-      <instruction name="formatNumber" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartFormatNumber"/>
-      <instruction name="formatDate" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartFormatDate"/>
-      <instruction name="comment" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartComment"/>
-      <instruction name="call" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartCall"/>
-      <instruction name="withParam" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartParameterInstance"/>
-      <instruction name="attribute" 
-                   targetNamespace="http://apache.org/cocoon/templates/jx/1.0" 
-                   class="org.apache.cocoon.template.jxtg.instruction.StartAttribute"/>
-    </component>
-  </components>
- 
+    <roles>
+        <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"/>
+    </roles>
+    <components>
+        <xml-parser class="org.apache.excalibur.xml.impl.JaxpParser">
+            <parameter name="validate" value="false"/>
+            <parameter name="namespace-prefixes" value="false"/>
+            <parameter name="stop-on-warning" value="true"/>
+            <parameter name="stop-on-recoverable-error" value="true"/>
+            <parameter name="reuse-parsers" value="false"/>
+        </xml-parser>
+        <generators logger="test">
+            <component-instance class="org.apache.cocoon.template.jxtg.JXTemplateGenerator"
name="jx"/>
+        </generators>
+        <store logger="test"/>
+        <component role="org.apache.cocoon.template.jxtg.script.ScriptManager" class="org.apache.cocoon.template.jxtg.script.DefaultScriptManager"/>
+        <component role="org.apache.cocoon.template.jxtg.script.InstructionFactory" class="org.apache.cocoon.template.jxtg.script.DefaultInstructionFactory">
+            <instructions targetNamespace="http://apache.org/cocoon/templates/jx/1.0">
+                <instruction name="template" class="org.apache.cocoon.template.jxtg.instruction.StartTemplate"/>
+                <instruction name="forEach" class="org.apache.cocoon.template.jxtg.instruction.StartForEach"/>
+                <instruction name="if" class="org.apache.cocoon.template.jxtg.instruction.StartIf"/>
+                <instruction name="choose" class="org.apache.cocoon.template.jxtg.instruction.StartChoose"/>
+                <instruction name="when" class="org.apache.cocoon.template.jxtg.instruction.StartWhen"/>
+                <instruction name="otherwise" class="org.apache.cocoon.template.jxtg.instruction.StartOtherwise"/>
+                <instruction name="out" class="org.apache.cocoon.template.jxtg.instruction.StartOut"/>
+                <instruction name="import" class="org.apache.cocoon.template.jxtg.instruction.StartImport"/>
+                <instruction name="set" class="org.apache.cocoon.template.jxtg.instruction.StartSet"/>
+                <instruction name="macro" class="org.apache.cocoon.template.jxtg.instruction.StartDefine"/>
+                <instruction name="evalBody" class="org.apache.cocoon.template.jxtg.instruction.StartEvalBody"/>
+                <instruction name="eval" class="org.apache.cocoon.template.jxtg.instruction.StartEval"/>
+                <instruction name="parameter" class="org.apache.cocoon.template.jxtg.instruction.StartParameter"/>
+                <instruction name="formatNumber" class="org.apache.cocoon.template.jxtg.instruction.StartFormatNumber"/>
+                <instruction name="formatDate" class="org.apache.cocoon.template.jxtg.instruction.StartFormatDate"/>
+                <instruction name="comment" class="org.apache.cocoon.template.jxtg.instruction.StartComment"/>
+                <instruction name="call" class="org.apache.cocoon.template.jxtg.instruction.StartCall"/>
+                <instruction name="withParam" class="org.apache.cocoon.template.jxtg.instruction.StartParameterInstance"/>
+                <instruction name="attribute" class="org.apache.cocoon.template.jxtg.instruction.StartAttribute"/>
+            </instructions>
+        </component>
+    </components>
 </testcase>
- 



Mime
View raw message