cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r447012 - in /cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms: binding/ datatype/ datatype/validationruleimpl/ formmodel/ util/
Date Sun, 17 Sep 2006 04:22:36 GMT
Author: vgritsenko
Date: Sat Sep 16 21:22:34 2006
New Revision: 447012

URL: http://svn.apache.org/viewvc?view=rev&rev=447012
Log:
use locatable exception in DomHelper

Modified:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/CustomJXPathBindingBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/DefaultDatatypeManager.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/EnumSelectionListBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/RegExpValidationRuleBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/DomHelper.java

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/CustomJXPathBindingBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/CustomJXPathBindingBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/CustomJXPathBindingBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/CustomJXPathBindingBuilder.java
Sat Sep 16 21:22:34 2006
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -27,7 +27,7 @@
  * implemented in {@link JXPathBindingManager} that helps construct the
  * actual {@link CustomJXPathBinding} out of the configuration in the
  * provided configElement which looks like one of the following:
- * 
+ *
  * <p> 1. No additional configuration requirements:
  * <pre><code>
  * &lt;fb:custom id="<i>widget-id</i>" path="<i>xpath expression</i>"
@@ -37,11 +37,11 @@
  * <p> 2. With custom configuration requirements:
  * <pre><code>
  * &lt;fb:custom id="<i>widget-id</i>" path="<i>xpath expression</i>"
- *     builderclass="your.package.CustomBindingXBuilder" 
+ *     builderclass="your.package.CustomBindingXBuilder"
  *     factorymethod="makeBinding"
  * &gt;
  *   &lt;fb:config custom-atts="someValue"&gt;
- *     &lt;!-- in here come the nested custom elements (recommended in own namespace)

+ *     &lt;!-- in here come the nested custom elements (recommended in own namespace)
  *             that make up the custom config --&gt;
  *   &lt;/fb:config&gt;
  * &lt;/fb:context&gt;
@@ -52,7 +52,7 @@
 public class CustomJXPathBindingBuilder extends JXPathBindingBuilderBase {
     private static final Class[] DOMELEMENT_METHODARGS;
     private static final Class[] EMPTY_METHODARGS;
-    
+
     static {
         DOMELEMENT_METHODARGS = new Class[1];
         DOMELEMENT_METHODARGS[0] = Element.class;
@@ -61,64 +61,64 @@
 
     /**
      * Builds the custom Binding class and wraps it into a CustomJXPathBinding
-     * 
-     * @param bindingElm configuration element describing the binding to build  
-     * @param assistant helper-class for building possible nested bindings 
+     *
+     * @param bindingElm configuration element describing the binding to build
+     * @param assistant helper-class for building possible nested bindings
      * @return the freshly built binding based on the configuration element
      * @throws BindingException
      */
-    public JXPathBindingBase buildBinding(Element bindingElm, 
+    public JXPathBindingBase buildBinding(Element bindingElm,
         Assistant assistant) throws BindingException {
 
         try {
-            CommonAttributes commonAtts = 
+            CommonAttributes commonAtts =
                 JXPathBindingBuilderBase.getCommonAttributes(bindingElm);
             String xpath = DomHelper.getAttribute(bindingElm, "path", ".");
             String widgetId = DomHelper.getAttribute(bindingElm, "id", null);
 
             Object bindingInstance = null;
-            
+
             String className = DomHelper.getAttribute(bindingElm, "class", null);
             if(className != null) {
                 Class clazz = Class.forName(className);
                 bindingInstance = clazz.newInstance();
-                
+
             } else {
-                String builderClassName = 
-                    DomHelper.getAttribute(bindingElm, "builderclass");
-                String factoryMethodName = 
-                    DomHelper.getAttribute(bindingElm, "factorymethod");                
-                Element configNode = 
+                String builderClassName =
+                    DomHelper.getAttribute(bindingElm, "builderclass", null);
+                String factoryMethodName =
+                    DomHelper.getAttribute(bindingElm, "factorymethod", null);
+                Element configNode =
                     DomHelper.getChildElement(bindingElm, BindingManager.NAMESPACE, "config");
-                
+
                 // only do it if attributes exist
-                if(! (builderClassName == null || factoryMethodName == null) ) {
+                if (builderClassName != null && factoryMethodName != null) {
 	                Class builderClass = Class.forName(builderClassName);
-	                Method factoryMethod = null; 
+	                Method factoryMethod;
 	                Object[] args = null;
 	                try {
 	                    factoryMethod = builderClass.getMethod(factoryMethodName, DOMELEMENT_METHODARGS);
 	                    args = new Object[1];
-	                    args[0] = configNode; 
+	                    args[0] = configNode;
 	                } catch (NoSuchMethodException e) {
 	                    factoryMethod = null;
 	                }
-	                
+
 	                if (factoryMethod == null) {
 	                    factoryMethod = builderClass.getMethod(factoryMethodName, EMPTY_METHODARGS);
 	                    args = null;
 	                }
-	                  
+
 	                // we pass null to indicate that the method should be static
 	                bindingInstance = factoryMethod.invoke(null, args);
                 }
             }
-            
-//          do inheritance
+
+            // do inheritance
             CustomJXPathBinding otherBinding = (CustomJXPathBinding)assistant.getContext().getSuperBinding();
             if(otherBinding!=null) {
             	commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
-            	
+
             	if(xpath==null)
             		xpath = otherBinding.getXPath();
             	if(widgetId==null)
@@ -127,7 +127,7 @@
             		bindingInstance = otherBinding.getWrappedBinding();
             }
 
-            CustomJXPathBinding customBinding = 
+            CustomJXPathBinding customBinding =
                 new CustomJXPathBinding(commonAtts, widgetId, xpath, (AbstractCustomBinding)bindingInstance);
 
             // Fire Avalon-setup for the custom binding

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/StructJXPathBindingBuilder.java
Sat Sep 16 21:22:34 2006
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -33,11 +33,10 @@
  *
  * @version $Id$
  */
-public class StructJXPathBindingBuilder
-    extends JXPathBindingBuilderBase {
+public class StructJXPathBindingBuilder extends JXPathBindingBuilderBase {
 
     public JXPathBindingBase buildBinding(Element bindingElm, JXPathBindingManager.Assistant
assistant)
-            throws BindingException {
+    throws BindingException {
         Deprecation.logger.info("'fb:struct' is deprecated and replaced by 'fb:group' at
" + DomHelper.getLocation(bindingElm));
         try {
             String widgetId = DomHelper.getAttribute(bindingElm, "id");
@@ -46,20 +45,22 @@
 
             JXPathBindingBase[] childBindings = new JXPathBindingBase[0];
 
-//          do inheritance
-            StructJXPathBinding otherBinding = (StructJXPathBinding)assistant.getContext().getSuperBinding();
-            if(otherBinding!=null) {
-            	childBindings = otherBinding.getChildBindings();
-            	commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),commonAtts);
-            	
-            	if(xpath==null)
-            		xpath = otherBinding.getXPath();
-            	if(widgetId==null)
-            		widgetId = otherBinding.getId();
+            // do inheritance
+            StructJXPathBinding otherBinding = (StructJXPathBinding) assistant.getContext().getSuperBinding();
+            if (otherBinding != null) {
+                childBindings = otherBinding.getChildBindings();
+                commonAtts = JXPathBindingBuilderBase.mergeCommonAttributes(otherBinding.getCommonAtts(),
commonAtts);
+
+                // FIXME Never happens
+                if (xpath == null)
+                    xpath = otherBinding.getXPath();
+                // FIXME Never happens
+                if (widgetId == null)
+                    widgetId = otherBinding.getId();
             }
-            
+
             childBindings = assistant.makeChildBindings(bindingElm,childBindings);
-            
+
             StructJXPathBinding structBinding =
                 new StructJXPathBinding(commonAtts, widgetId, xpath, childBindings);
             return structBinding;

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/DefaultDatatypeManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/DefaultDatatypeManager.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/DefaultDatatypeManager.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/DefaultDatatypeManager.java
Sat Sep 16 21:22:34 2006
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -41,7 +41,7 @@
  * by delegating the creation of them to {@link DatatypeBuilder}s and {@link ValidationRuleBuilder}s.
  * Currently the list of datatype and validationrule builders is hardcoded, but this will
  * become externally configurable in the future.
- * 
+ *
  * @version $Id$
  *
  */
@@ -83,9 +83,9 @@
 
     public Datatype createDatatype(Element datatypeElement, boolean arrayType) throws Exception
{
         String typeName = DomHelper.getAttribute(datatypeElement, "base");
-        DatatypeBuilder builder = null;
+        DatatypeBuilder builder;
         try {
-            builder = (DatatypeBuilder)typeBuilderSelector.select(typeName);
+            builder = (DatatypeBuilder) typeBuilderSelector.select(typeName);
         } catch (ServiceException e) {
             throw new CascadingException("Unknown datatype '" + typeName + "' specified at
" + DomHelper.getLocation(datatypeElement), e);
         }
@@ -94,9 +94,9 @@
 
     public ValidationRule createValidationRule(Element validationRuleElement) throws Exception
{
         String name  = validationRuleElement.getLocalName();
-        ValidationRuleBuilder builder = null;
+        ValidationRuleBuilder builder;
         try {
-            builder = (ValidationRuleBuilder)validationRuleBuilderSelector.select(name);
+            builder = (ValidationRuleBuilder) validationRuleBuilderSelector.select(name);
         } catch (ServiceException e) {
             throw new CascadingException("Unknown validation rule \"" + name + "\" specified
at " + DomHelper.getLocation(validationRuleElement), e);
         }

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/EnumSelectionListBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/EnumSelectionListBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/EnumSelectionListBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/EnumSelectionListBuilder.java
Sat Sep 16 21:22:34 2006
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -28,7 +28,7 @@
      * @see org.apache.cocoon.forms.datatype.SelectionListBuilder#build(org.w3c.dom.Element,
org.apache.cocoon.forms.datatype.Datatype)
      */
     public SelectionList build(Element selectionListElement, Datatype datatype)
-        throws Exception {
+    throws Exception {
         String className = DomHelper.getAttribute(selectionListElement, "class");
         boolean nullable = DomHelper.getAttributeAsBoolean(selectionListElement, "nullable",
true);
         String nulltext = DomHelper.getAttribute(selectionListElement, "null-text", null);

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/FlowJXPathSelectionListBuilder.java
Sat Sep 16 21:22:34 2006
@@ -59,6 +59,7 @@
 
         String listPath = DomHelper.getAttribute(selectionListElement, "list-path");
         String valuePath = DomHelper.getAttribute(selectionListElement, "value-path");
+
         Map nspfx = DomHelper.getInheritedNSDeclarations(selectionListElement);
         String i18nPfx = FormsConstants.I18N_PREFIX;
         if (nspfx != null) {
@@ -67,33 +68,33 @@
                 i18nPfx = FormsConstants.I18N_PREFIX;
             }
         }
+
         String labelPath = DomHelper.getAttribute(selectionListElement, "label-path", null);
         boolean labelIsI18nKey = false;
-        if( labelPath == null )
-        {
+        if (labelPath == null) {
             labelPath = DomHelper.getAttribute(selectionListElement, i18nPfx + ":label-path");
             labelIsI18nKey = true;
         }
+
         String nullText = DomHelper.getAttribute(selectionListElement, "null-text", null);
         boolean nullTextIsI18nKey = false;
-        if( nullText == null ) {
+        if (nullText == null) {
             nullText = DomHelper.getAttribute(selectionListElement, i18nPfx + ":null-text",
null);
-            if( nullText != null ) {
+            if (nullText != null) {
                 nullTextIsI18nKey = true;
             }
         }
-        
-        String i18nCatalog = DomHelper.getAttribute(selectionListElement, "catalogue", null);
 
+        String i18nCatalog = DomHelper.getAttribute(selectionListElement, "catalogue", null);
 
-        return new FlowJXPathSelectionList(context, 
-                                           listPath, 
-                                           valuePath, 
-                                           labelPath, 
-                                           datatype, 
-                                           nullText, 
-                                           nullTextIsI18nKey, 
-                                           i18nCatalog, 
+        return new FlowJXPathSelectionList(context,
+                                           listPath,
+                                           valuePath,
+                                           labelPath,
+                                           datatype,
+                                           nullText,
+                                           nullTextIsI18nKey,
+                                           i18nCatalog,
                                            labelIsI18nKey);
     }
 

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/RegExpValidationRuleBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/RegExpValidationRuleBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/RegExpValidationRuleBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/datatype/validationruleimpl/RegExpValidationRuleBuilder.java
Sat Sep 16 21:22:34 2006
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -24,7 +24,7 @@
 
 /**
  * Builds {@link RegExpValidationRule}s.
- * 
+ *
  * @version $Id$
  */
 public class RegExpValidationRuleBuilder extends AbstractValidationRuleBuilder {
@@ -36,7 +36,7 @@
         buildFailMessage(validationRuleElement, rule);
 
         Perl5Compiler compiler = new Perl5Compiler();
-        Pattern pattern = null;
+        Pattern pattern;
         try {
             pattern = compiler.compile(regexp, Perl5Compiler.READ_ONLY_MASK);
         } catch (MalformedPatternException e) {

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractDatatypeWidgetDefinitionBuilder.java
Sat Sep 16 21:22:34 2006
@@ -19,7 +19,9 @@
 import java.util.Locale;
 
 import org.apache.avalon.framework.service.ServiceSelector;
+
 import org.apache.cocoon.forms.FormsConstants;
+import org.apache.cocoon.forms.FormsException;
 import org.apache.cocoon.forms.datatype.Datatype;
 import org.apache.cocoon.forms.datatype.SelectionList;
 import org.apache.cocoon.forms.datatype.SelectionListBuilder;
@@ -27,6 +29,7 @@
 import org.apache.cocoon.forms.event.ValueChangedListener;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.apache.cocoon.i18n.I18nUtils;
+
 import org.w3c.dom.Element;
 
 /**
@@ -43,7 +46,8 @@
     }
 
     protected void setupDefinition(Element widgetElement,
-                                   AbstractDatatypeWidgetDefinition definition, boolean isArrayType)
+                                   AbstractDatatypeWidgetDefinition definition,
+                                   boolean isArrayType)
     throws Exception {
         super.setupDefinition(widgetElement, definition);
         // parse "label", "hint", etc.
@@ -69,8 +73,8 @@
                 String value = DomHelper.getElementText(initialValueElement);
                 ConversionResult result = datatype.convertFromString(value, locale);
                 if (!result.isSuccessful()) {
-                    throw new Exception("Cannot parse initial value '" + value + "' at "
+
-                                        DomHelper.getLocation(initialValueElement));
+                    throw new FormsException("Cannot parse initial value '" + value + "'.",
+                                             DomHelper.getLocationObject(initialValueElement));
                 }
                 initialValue = result.getResult();
             }

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
Sat Sep 16 21:22:34 2006
@@ -121,10 +121,6 @@
             widgetDefinition.setId(DomHelper.getAttribute(widgetElement, "id", ""));
         } else {
             String id = DomHelper.getAttribute(widgetElement, "id");
-            if (id.length() < 1) {
-                throw new Exception("Missing id attribute on element '" + widgetElement.getTagName()
+ "' at " +
-                                    DomHelper.getLocation(widgetElement));
-            }
             if (id.indexOf('/') != -1 || id.indexOf('.') != -1) {
                 throw new Exception("A widget name cannot contain '.' or '/' as this conflicts
with widget paths, at " +
                                     DomHelper.getLocation(widgetElement));

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinitionBuilder.java
Sat Sep 16 21:22:34 2006
@@ -56,7 +56,7 @@
         if (splitElement != null) {
             String patternString = DomHelper.getAttribute(splitElement, "pattern");
             Perl5Compiler compiler = new Perl5Compiler();
-            Pattern pattern = null;
+            Pattern pattern;
             try {
                 pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK);
             } catch (MalformedPatternException e) {
@@ -95,7 +95,7 @@
         Element combineElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS,
"combine", true);
         if(combineElement!=null) {
             String combineExprString = DomHelper.getAttribute(combineElement, "expression");
-            Expression combineExpr = null;
+            Expression combineExpr;
             try {
                 combineExpr = expressionManager.parse(combineExprString);
             } catch (Exception e) {

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/DomHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/DomHelper.java?view=diff&rev=447012&r1=447011&r2=447012
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/DomHelper.java
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/util/DomHelper.java
Sat Sep 16 21:22:34 2006
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2005 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.
@@ -22,19 +22,21 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
-
 import javax.xml.XMLConstants;
 
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.xml.sax.SAXParser;
+import org.apache.excalibur.xml.sax.XMLizable;
+
+import org.apache.cocoon.forms.FormsException;
 import org.apache.cocoon.util.location.Location;
 import org.apache.cocoon.util.location.LocationAttributes;
 import org.apache.cocoon.xml.SaxBuffer;
 import org.apache.cocoon.xml.dom.DOMBuilder;
 import org.apache.cocoon.xml.dom.DOMStreamer;
+
 import org.apache.commons.lang.BooleanUtils;
-import org.apache.excalibur.xml.sax.SAXParser;
-import org.apache.excalibur.xml.sax.XMLizable;
 import org.w3c.dom.Attr;
 import org.w3c.dom.CDATASection;
 import org.w3c.dom.Document;
@@ -58,7 +60,7 @@
  * <p>This class depends specifically on the Xerces DOM implementation to be
  * able to provide information about the location of elements in their source
  * XML file. See the {@link #getLocation(Element)} method.
- * 
+ *
  * @version $Id$
  */
 public class DomHelper {
@@ -77,11 +79,11 @@
     public static String getLocation(Element element) {
         return LocationAttributes.getLocationString(element);
     }
-    
+
     public static String getSystemIdLocation(Element element) {
         return LocationAttributes.getURI(element);
     }
-    
+
     public static int getLineLocation(Element element) {
         return LocationAttributes.getLine(element);
     }
@@ -103,7 +105,7 @@
                     && namespace.equals(node.getNamespaceURI()))
                 elements.add(node);
         }
-        return (Element[])elements.toArray(new Element[elements.size()]);
+        return (Element[]) elements.toArray(new Element[elements.size()]);
     }
 
     /**
@@ -111,27 +113,29 @@
      * namespace and have the given local name.
      */
     public static Element[] getChildElements(Element element,
-            String namespace, String localName) {
+                                             String namespace,
+                                             String localName) {
         ArrayList elements = new ArrayList();
         NodeList nodeList = element.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++) {
             Node node = nodeList.item(i);
             if (node instanceof Element
-                    && namespace.equals(node.getNamespaceURI()) 
+                    && namespace.equals(node.getNamespaceURI())
                     && localName.equals(node.getLocalName())) {
                 elements.add(node);
             }
         }
-        return (Element[])elements.toArray(new Element[elements.size()]);
+        return (Element[]) elements.toArray(new Element[elements.size()]);
     }
 
     /**
      * Returns the first child element with the given namespace and localName,
      * or null if there is no such element.
      */
-    public static Element getChildElement(Element element, String namespace, 
-            String localName) {
-        Element node = null;
+    public static Element getChildElement(Element element,
+                                          String namespace,
+                                          String localName) {
+        Element node;
         try {
             node = getChildElement(element, namespace, localName, false);
         } catch (Exception e) {
@@ -145,24 +149,26 @@
      * or null if there is no such element and required flag is unset or
      * throws an Exception if the "required" flag is set.
      */
-    public static Element getChildElement(Element element, String namespace, 
-            String localName, boolean required) throws Exception {
+    public static Element getChildElement(Element element,
+                                          String namespace,
+                                          String localName,
+                                          boolean required) throws Exception {
         NodeList nodeList = element.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++) {
             Node node = nodeList.item(i);
             if (node instanceof Element
-                    && namespace.equals(node.getNamespaceURI()) 
+                    && namespace.equals(node.getNamespaceURI())
                     && localName.equals(node.getLocalName())) {
-                return (Element)node;
+                return (Element) node;
             }
         }
+
         if (required) {
-            throw new Exception("Missing element \"" + localName +
-                    "\" as child of element \"" + element.getTagName() + 
-                    "\" at " + DomHelper.getLocation(element));
-        } else {
-            return null;
+            throw new FormsException("Required element '" + localName + "' is missing.",
+                                     DomHelper.getLocationObject(element));
         }
+
+        return null;
     }
 
     /**
@@ -170,22 +176,23 @@
      * if the element has no such attribute.
      */
     public static String getAttribute(Element element, String attributeName)
-            throws Exception {
+    throws Exception {
         String attrValue = element.getAttribute(attributeName);
         if (attrValue.length() == 0) {
-            throw new Exception("Missing attribute \"" + attributeName + 
-                    "\" on element \"" + element.getTagName() + 
-                    "\" at " + getLocation(element));
+            throw new FormsException("Required attribute '" + attributeName + "' is missing.",
+                                     DomHelper.getLocationObject(element));
         }
+
         return attrValue;
     }
 
     /**
-     * Returns the value of an element's attribute, or a default value if the 
+     * Returns the value of an element's attribute, or a default value if the
      * element has no such attribute.
      */
-    public static String getAttribute(Element element, String attributeName, 
-            String defaultValue) {
+    public static String getAttribute(Element element,
+                                      String attributeName,
+                                      String defaultValue) {
         String attrValue = element.getAttribute(attributeName);
         if (attrValue.length() == 0) {
             return defaultValue;
@@ -193,58 +200,58 @@
         return attrValue;
     }
 
-    public static int getAttributeAsInteger(Element element, 
-            String attributeName) throws Exception {
+    public static int getAttributeAsInteger(Element element,
+                                            String attributeName) throws Exception {
         String attrValue = getAttribute(element, attributeName);
         try {
             return Integer.parseInt(attrValue);
         } catch (NumberFormatException e) {
-            throw new Exception("Cannot parse the value \"" + attrValue + 
-                    "\" as an integer in the attribute \"" + attributeName + 
-                    "\" on the element \"" + element.getTagName() + 
-                    "\" at " + getLocation(element));
+            throw new FormsException("Cannot parse the value '" + attrValue + "' " +
+                                     "as an integer in the attribute '" + attributeName +
"'," +
+                                     DomHelper.getLocationObject(element));
         }
     }
 
-    public static int getAttributeAsInteger(Element element, 
-            String attributeName, int defaultValue) throws Exception {
+    public static int getAttributeAsInteger(Element element,
+                                            String attributeName,
+                                            int defaultValue) throws Exception {
         String attrValue = element.getAttribute(attributeName);
         if (attrValue.length() == 0) {
             return defaultValue;
-        } else {
-            try {
-                return Integer.parseInt(attrValue);
-            } catch (NumberFormatException e) {
-                throw new Exception("Cannot parse the value \"" + attrValue + 
-                        "\" as an integer in the attribute \"" + 
-                        attributeName + "\" on the element \"" +
-                        element.getTagName() + "\" at " +
-                        getLocation(element));
-            }
+        }
+
+        try {
+            return Integer.parseInt(attrValue);
+        } catch (NumberFormatException e) {
+            throw new FormsException("Cannot parse the value '" + attrValue + "' " +
+                                     "as an integer in the attribute '" + attributeName +
"'," +
+                                     DomHelper.getLocationObject(element));
         }
     }
 
-    public static boolean getAttributeAsBoolean(Element element, 
-                String attributeName, boolean defaultValue) {
+    public static boolean getAttributeAsBoolean(Element element,
+                                                String attributeName,
+                                                boolean defaultValue) {
         String attrValue = element.getAttribute(attributeName);
+        if (attrValue.length() == 0) {
+            return defaultValue;
+        }
+
         Boolean result;
         try {
             result = BooleanUtils.toBooleanObject(attrValue, "true", "false", null);
-        } catch (IllegalArgumentException iae) {
-            result = null;
-        }
-        if (result != null) {
-            return result.booleanValue();
-        }
-        try {
-            result = BooleanUtils.toBooleanObject(attrValue, "yes", "no", null);
-        } catch (IllegalArgumentException iae) {
-            result = null;
+        } catch (IllegalArgumentException e1) {
+            try {
+                result = BooleanUtils.toBooleanObject(attrValue, "yes", "no", null);
+            } catch (IllegalArgumentException e2) {
+                result = null;
+            }
         }
-        if (result != null) {
-            return result.booleanValue();
+        if (result == null) {
+            return defaultValue;
         }
-        return defaultValue;    
+
+        return result.booleanValue();
     }
 
     public static String getElementText(Element element) {
@@ -281,9 +288,8 @@
             } catch (SAXException e) {
                 // It's unlikely that an exception will occur here,
                 // so use a runtime exception
-                throw new RuntimeException(
-                        "Error in DomHelper.compileElementContent: " + 
-                        e.toString());
+                throw new RuntimeException("Error in DomHelper.compileElementContent: " +
+                                           e.toString());
             }
         }
         return saxBuffer;
@@ -298,69 +304,63 @@
      * @param manager the service manager where to lookup the entity resolver
      */
     public static Document parse(InputSource inputSource, ServiceManager manager)
-            throws SAXException, SAXNotSupportedException, IOException, ServiceException
{
-        
+    throws SAXException, SAXNotSupportedException, IOException, ServiceException {
+
         SAXParser parser = (SAXParser)manager.lookup(SAXParser.ROLE);
         DOMBuilder builder = new DOMBuilder();
-        
+
         // Enhance the sax stream with location information
         ContentHandler locationHandler = new LocationAttributes.Pipe(builder);
-        
+
         try {
             parser.parse(inputSource, locationHandler);
         } finally {
             manager.release(parser);
         }
-        
+
         return builder.getDocument();
     }
 
-    public static Map getLocalNSDeclarations(Element elm)
-    {
+    public static Map getLocalNSDeclarations(Element elm) {
         return addLocalNSDeclarations(elm, null);
     }
-    
-    private static Map addLocalNSDeclarations(Element elm, Map nsDeclarations)
-    {
+
+    private static Map addLocalNSDeclarations(Element elm, Map nsDeclarations) {
         NamedNodeMap atts = elm.getAttributes();
         int attsSize = atts.getLength();
 
-        for (int i = 0; i < attsSize; i++)
-        {
-            Attr attr = (Attr)atts.item(i);
-            if (XMLNS_URI.equals(attr.getNamespaceURI()))
-            {
+        for (int i = 0; i < attsSize; i++) {
+            Attr attr = (Attr) atts.item(i);
+            if (XMLNS_URI.equals(attr.getNamespaceURI())) {
                 String nsUri = attr.getValue();
                 String pfx = attr.getLocalName();
                 if (nsDeclarations == null)
                     nsDeclarations = new HashMap();
                 nsDeclarations.put(nsUri, pfx);
             }
-        }        
-        return nsDeclarations;    }
-    
-    public static Map getInheritedNSDeclarations(Element elm)
-    {
+        }
+        return nsDeclarations;
+    }
+
+    public static Map getInheritedNSDeclarations(Element elm) {
         List ancestorsAndSelf = new LinkedList();
         Element current = elm;
-        while (current != null) 
-        {
+        while (current != null) {
             ancestorsAndSelf.add(current);
             Node parent = current.getParentNode();
             if (parent.getNodeType() == Node.ELEMENT_NODE)
-                current = (Element)parent;
-            else 
+                current = (Element) parent;
+            else
                 current = null;
         }
-        
+
         Map nsDeclarations = null;
-        ListIterator iter = ancestorsAndSelf.listIterator(ancestorsAndSelf.size());
-        while (iter.hasPrevious())
-        {
-            Element element = (Element) iter.previous();
+        ListIterator i = ancestorsAndSelf.listIterator(ancestorsAndSelf.size());
+        while (i.hasPrevious()) {
+            Element element = (Element) i.previous();
             nsDeclarations = addLocalNSDeclarations(element, nsDeclarations);
         }
-        
+
         return nsDeclarations;
     }
 }



Mime
View raw message