You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/07/31 19:29:02 UTC
svn commit: r681422 [4/4] - in
/myfaces/extensions/validator/branches/trunk_layout_myfaces/core: ./
src/main/java/org/apache/myfaces/extensions/validator/core/
src/main/java/org/apache/myfaces/extensions/validator/core/adapter/
src/main/java/org/apache...
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FaceletsTaglibExpressionUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FaceletsTaglibExpressionUtils.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FaceletsTaglibExpressionUtils.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FaceletsTaglibExpressionUtils.java Thu Jul 31 10:28:59 2008
@@ -1,29 +1,23 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.myfaces.extensions.validator.util;
-import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
-
-import javax.el.ELContext;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
import java.io.Externalizable;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
@@ -34,23 +28,36 @@
import java.util.List;
import java.util.Map;
+import javax.faces.component.UIComponent;
+import javax.faces.el.ValueBinding;
+
/**
* @author Gerhard Petracek
*/
-public class FaceletsTaglibExpressionUtils {
- public static String tryToCreateValueBindingForFaceletsBinding(UIComponent uiComponent) {
- String faceletsValueBindingExpression = ELUtils.getValueBindingExpression(uiComponent);
+public class FaceletsTaglibExpressionUtils
+{
+ public static String tryToCreateValueBindingForFaceletsBinding(
+ UIComponent uiComponent)
+ {
+ String faceletsValueBindingExpression = ELUtils
+ .getValueBindingExpression(uiComponent);
+
+ try
+ {
+ List<String> foundBindings = extractELTerms(uiComponent
+ .getValueExpression("value"));
- try {
- List<String> foundBindings = extractELTerms(uiComponent.getValueExpression("value"));
-
- return faceletsValueBindingExpression.substring(0, 1) + "{" + createBinding(foundBindings) + "}";
- } catch (Throwable t) {
+ return faceletsValueBindingExpression.substring(0, 1) + "{"
+ + createBinding(foundBindings) + "}";
+ }
+ catch (Throwable t)
+ {
return faceletsValueBindingExpression;
}
}
- private static String createBinding(List<String> expressions) {
+ private static String createBinding(List<String> expressions)
+ {
String result = "";
String prevFaceletsAttributeName = null;
@@ -61,30 +68,43 @@
String[] foundBindingDetails;
String[] bindingDetails;
- for (String entry : expressions) {
- if (entry.startsWith("ValueExpression[")) {
+ for (String entry : expressions)
+ {
+ if (entry.startsWith("ValueExpression["))
+ {
continue;
}
//TODO log entry
foundBindingDetails = entry.split(" ");
indexOfBindingDetails = findIndexOfBindingDetails(foundBindingDetails);
- if (indexOfBindingDetails == -1) {
+ if (indexOfBindingDetails == -1)
+ {
return null;
}
- bindingDetails = foundBindingDetails[indexOfBindingDetails].split("=");
+ bindingDetails = foundBindingDetails[indexOfBindingDetails]
+ .split("=");
- if (bindingDetails.length < 2) {
+ if (bindingDetails.length < 2)
+ {
return null;
}
currentBinding = bindingDetails[1];
- if (prevFaceletsAttributeName != null) {
- partOfBinding = currentBinding.substring(currentBinding.indexOf(prevFaceletsAttributeName) + prevFaceletsAttributeName.length(), currentBinding.indexOf("}"));
+ if (prevFaceletsAttributeName != null)
+ {
+ partOfBinding = currentBinding.substring(currentBinding
+ .indexOf(prevFaceletsAttributeName)
+ + prevFaceletsAttributeName.length(), currentBinding
+ .indexOf("}"));
result = result + partOfBinding;
- } else {
- result = currentBinding.substring(currentBinding.indexOf("{") + 1, currentBinding.indexOf("}"));
+ }
+ else
+ {
+ result = currentBinding.substring(
+ currentBinding.indexOf("{") + 1, currentBinding
+ .indexOf("}"));
}
prevFaceletsAttributeName = bindingDetails[0];
@@ -92,10 +112,13 @@
return result;
}
- private static int findIndexOfBindingDetails(String[] bindingDetails) {
+ private static int findIndexOfBindingDetails(String[] bindingDetails)
+ {
int count = 0;
- for (String entry : bindingDetails) {
- if (entry.contains("=")) {
+ for (String entry : bindingDetails)
+ {
+ if (entry.contains("="))
+ {
return count;
}
count++;
@@ -103,21 +126,29 @@
return -1;
}
- private static List<String> extractELTerms(Object o) {
+ private static List<String> extractELTerms(Object o)
+ {
List<String> foundELTerms = new ArrayList<String>();
- try {
- if (resolveELTerms(o, new HashMap<Object, Object>(), foundELTerms, 0) > 0) {
+ try
+ {
+ if (resolveELTerms(o, new HashMap<Object, Object>(), foundELTerms,
+ 0) > 0)
+ {
return foundELTerms;
}
}
- catch (Exception ex) {
+ catch (Exception ex)
+ {
return null;
}
return null;
}
- private static int resolveELTerms(Object o, Map<Object, Object> visited, List<String> foundELTerms, int count) throws Exception {
- if (o == null || visited.containsKey(o) || count > 50) {
+ private static int resolveELTerms(Object o, Map<Object, Object> visited,
+ List<String> foundELTerms, int count) throws Exception
+ {
+ if (o == null || visited.containsKey(o) || count > 50)
+ {
return 0;
}
@@ -127,36 +158,50 @@
Class c = o.getClass();
//inspect maps
- if (o instanceof java.util.Map) {
+ if (o instanceof java.util.Map)
+ {
- for (Object entry : ((Map) o).values()) {
- elCount += resolveELTerms(entry, visited, foundELTerms, count + 1);
+ for (Object entry : ((Map) o).values())
+ {
+ elCount += resolveELTerms(entry, visited, foundELTerms,
+ count + 1);
}
return elCount;
}
- if (isELTerm(o)) {
- if (foundELTerms != null) {
+ if (isELTerm(o))
+ {
+ if (foundELTerms != null)
+ {
foundELTerms.add(o.toString());
}
return ++elCount;
}
//analyze arrays
- if (c.isArray()) {
+ if (c.isArray())
+ {
int length = Array.getLength(o);
//check array [L -> no array of primitive types
- if (o.toString().startsWith("[L")) {
- for (int i = 0; i < length; i++) {
- if (o.toString().startsWith("[Ljava.lang.String")) {
- if (isELTerm(Array.get(o, i))) {
- if (foundELTerms != null) {
+ if (o.toString().startsWith("[L"))
+ {
+ for (int i = 0; i < length; i++)
+ {
+ if (o.toString().startsWith("[Ljava.lang.String"))
+ {
+ if (isELTerm(Array.get(o, i)))
+ {
+ if (foundELTerms != null)
+ {
foundELTerms.add(o.toString());
}
elCount++;
}
- } else {
- elCount += resolveELTerms(Array.get(o, i), visited, foundELTerms, count + 1);
+ }
+ else
+ {
+ elCount += resolveELTerms(Array.get(o, i), visited,
+ foundELTerms, count + 1);
}
}
}
@@ -164,46 +209,63 @@
}
List<Field> attributes = findAllAttributes(c, new ArrayList<Field>());
- Field[] fields = (Field[]) attributes.toArray(new Field[attributes.size()]);
+ Field[] fields = (Field[]) attributes.toArray(new Field[attributes
+ .size()]);
AccessibleObject.setAccessible(fields, true);
- for (Field currentField : fields) {
- if (currentField.get(o) == null) {
+ for (Field currentField : fields)
+ {
+ if (currentField.get(o) == null)
+ {
continue;
}
- if (currentField.getType().equals(String.class)) {
- if (currentField.get(o) != null && isELTerm(currentField.get(o))) {
- if (foundELTerms != null) {
+ if (currentField.getType().equals(String.class))
+ {
+ if (currentField.get(o) != null
+ && isELTerm(currentField.get(o)))
+ {
+ if (foundELTerms != null)
+ {
foundELTerms.add(o.toString());
}
elCount++;
}
- } else if (!currentField.getType().isPrimitive()) {
- elCount += resolveELTerms(currentField.get(o), visited, foundELTerms, count + 1);
+ }
+ else if (!currentField.getType().isPrimitive())
+ {
+ elCount += resolveELTerms(currentField.get(o), visited,
+ foundELTerms, count + 1);
}
}
return elCount;
}
- private static boolean isELTerm(Object o) {
- if (o instanceof ValueBinding || o instanceof Externalizable) {
+ private static boolean isELTerm(Object o)
+ {
+ if (o instanceof ValueBinding || o instanceof Externalizable)
+ {
return false;
}
String s = o.toString();
- return ((s.contains("#") || s.contains("$")) && s.contains("{") && s.contains("}"));
+ return ((s.contains("#") || s.contains("$")) && s.contains("{") && s
+ .contains("}"));
}
- private static List<Field> findAllAttributes(Class c, List<Field> attributes) {
- if (c == null) {
+ private static List<Field> findAllAttributes(Class c, List<Field> attributes)
+ {
+ if (c == null)
+ {
return attributes;
}
findAllAttributes(c.getSuperclass(), attributes);
Field[] fields = c.getDeclaredFields();
- for (Field currentField : fields) {
- if (!Modifier.isStatic(currentField.getModifiers())) {
+ for (Field currentField : fields)
+ {
+ if (!Modifier.isStatic(currentField.getModifiers()))
+ {
attributes.add(currentField);
}
}
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FactoryUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FactoryUtils.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FactoryUtils.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/FactoryUtils.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.myfaces.extensions.validator.util;
@@ -37,21 +37,31 @@
* @author Gerhard Petracek
*/
//TODO
-public class FactoryUtils {
+public class FactoryUtils
+{
private static AnnotationExtractorFactory annotationExtractorFactory;
- public static AnnotationExtractorFactory getAnnotationExtractorFactory() {
- if (annotationExtractorFactory == null) {
+ public static AnnotationExtractorFactory getAnnotationExtractorFactory()
+ {
+ if (annotationExtractorFactory == null)
+ {
List<String> annotationExtractorFactoryClassNames = new ArrayList<String>();
- annotationExtractorFactoryClassNames.add(WebXmlParameter.CUSTOM_ANNOTATION_EXTRACTOR_FACTORY);
- annotationExtractorFactoryClassNames.add(ExtValUtils.getInformationProviderBean().getCustomAnnotationExtractorFactory());
- annotationExtractorFactoryClassNames.add(DefaultAnnotationExtractorFactory.class.getName());
+ annotationExtractorFactoryClassNames
+ .add(WebXmlParameter.CUSTOM_ANNOTATION_EXTRACTOR_FACTORY);
+ annotationExtractorFactoryClassNames.add(ExtValUtils
+ .getInformationProviderBean()
+ .getCustomAnnotationExtractorFactory());
+ annotationExtractorFactoryClassNames
+ .add(DefaultAnnotationExtractorFactory.class.getName());
+
+ for (String className : annotationExtractorFactoryClassNames)
+ {
+ annotationExtractorFactory = (AnnotationExtractorFactory) ClassUtils
+ .tryToInstantiateClassForName(className);
- for (String className : annotationExtractorFactoryClassNames) {
- annotationExtractorFactory = (AnnotationExtractorFactory) ClassUtils.tryToInstantiateClassForName(className);
-
- if (annotationExtractorFactory != null) {
+ if (annotationExtractorFactory != null)
+ {
//TODO logging
break;
}
@@ -63,18 +73,27 @@
private static ClassMappingFactory<Annotation, ValidationStrategy> validationStrategyFactory;
- public static ClassMappingFactory<Annotation, ValidationStrategy> getValidationStrategyFactory() {
- if (validationStrategyFactory == null) {
+ public static ClassMappingFactory<Annotation, ValidationStrategy> getValidationStrategyFactory()
+ {
+ if (validationStrategyFactory == null)
+ {
List<String> validationStrategyFactoryClassNames = new ArrayList<String>();
- validationStrategyFactoryClassNames.add(WebXmlParameter.CUSTOM_VALIDATION_STRATEGY_FACTORY);
- validationStrategyFactoryClassNames.add(ExtValUtils.getInformationProviderBean().getCustomValidationStrategyFactory());
- validationStrategyFactoryClassNames.add(DefaultValidationStrategyFactory.class.getName());
-
- for (String className : validationStrategyFactoryClassNames) {
- validationStrategyFactory = (ClassMappingFactory<Annotation, ValidationStrategy>) ClassUtils.tryToInstantiateClassForName(className);
+ validationStrategyFactoryClassNames
+ .add(WebXmlParameter.CUSTOM_VALIDATION_STRATEGY_FACTORY);
+ validationStrategyFactoryClassNames.add(ExtValUtils
+ .getInformationProviderBean()
+ .getCustomValidationStrategyFactory());
+ validationStrategyFactoryClassNames
+ .add(DefaultValidationStrategyFactory.class.getName());
+
+ for (String className : validationStrategyFactoryClassNames)
+ {
+ validationStrategyFactory = (ClassMappingFactory<Annotation, ValidationStrategy>) ClassUtils
+ .tryToInstantiateClassForName(className);
- if (validationStrategyFactory != null) {
+ if (validationStrategyFactory != null)
+ {
//TODO logging
break;
}
@@ -86,18 +105,27 @@
private static ClassMappingFactory<ValidationStrategy, MessageResolver> messageResolverFactory;
- public static ClassMappingFactory<ValidationStrategy, MessageResolver> getMessageResolverFactory() {
- if (messageResolverFactory == null) {
+ public static ClassMappingFactory<ValidationStrategy, MessageResolver> getMessageResolverFactory()
+ {
+ if (messageResolverFactory == null)
+ {
List<String> messageResolverFactoryClassNames = new ArrayList<String>();
- messageResolverFactoryClassNames.add(WebXmlParameter.CUSTOM_MESSAGE_RESOLVER_FACTORY);
- messageResolverFactoryClassNames.add(ExtValUtils.getInformationProviderBean().getCustomMessageResolverFactory());
- messageResolverFactoryClassNames.add(DefaultMessageResolverFactory.class.getName());
+ messageResolverFactoryClassNames
+ .add(WebXmlParameter.CUSTOM_MESSAGE_RESOLVER_FACTORY);
+ messageResolverFactoryClassNames.add(ExtValUtils
+ .getInformationProviderBean()
+ .getCustomMessageResolverFactory());
+ messageResolverFactoryClassNames
+ .add(DefaultMessageResolverFactory.class.getName());
+
+ for (String className : messageResolverFactoryClassNames)
+ {
+ messageResolverFactory = (ClassMappingFactory<ValidationStrategy, MessageResolver>) ClassUtils
+ .tryToInstantiateClassForName(className);
- for (String className : messageResolverFactoryClassNames) {
- messageResolverFactory = (ClassMappingFactory<ValidationStrategy, MessageResolver>) ClassUtils.tryToInstantiateClassForName(className);
-
- if (messageResolverFactory != null) {
+ if (messageResolverFactory != null)
+ {
//TODO logging
break;
}
@@ -110,18 +138,27 @@
private static ClassMappingFactory<Converter, Converter> converterAdapterFactory;
@Deprecated
- public static ClassMappingFactory<Converter, Converter> getConverterAdapterFactory() {
- if (converterAdapterFactory == null) {
+ public static ClassMappingFactory<Converter, Converter> getConverterAdapterFactory()
+ {
+ if (converterAdapterFactory == null)
+ {
List<String> converterAdapterFactoryClassNames = new ArrayList<String>();
- converterAdapterFactoryClassNames.add(WebXmlParameter.CUSTOM_CONVERTER_ADAPTER_FACTORY);
- converterAdapterFactoryClassNames.add(ExtValUtils.getInformationProviderBean().getCustomConverterAdapterFactory());
- converterAdapterFactoryClassNames.add(DefaultConverterAdapterFactory.class.getName());
-
- for (String className : converterAdapterFactoryClassNames) {
- converterAdapterFactory = (ClassMappingFactory<Converter, Converter>) ClassUtils.tryToInstantiateClassForName(className);
+ converterAdapterFactoryClassNames
+ .add(WebXmlParameter.CUSTOM_CONVERTER_ADAPTER_FACTORY);
+ converterAdapterFactoryClassNames.add(ExtValUtils
+ .getInformationProviderBean()
+ .getCustomConverterAdapterFactory());
+ converterAdapterFactoryClassNames
+ .add(DefaultConverterAdapterFactory.class.getName());
+
+ for (String className : converterAdapterFactoryClassNames)
+ {
+ converterAdapterFactory = (ClassMappingFactory<Converter, Converter>) ClassUtils
+ .tryToInstantiateClassForName(className);
- if (converterAdapterFactory != null) {
+ if (converterAdapterFactory != null)
+ {
//TODO logging
break;
}
Modified: myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java?rev=681422&r1=681421&r2=681422&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java (original)
+++ myfaces/extensions/validator/branches/trunk_layout_myfaces/core/src/main/java/org/apache/myfaces/extensions/validator/util/WebXmlUtils.java Thu Jul 31 10:28:59 2008
@@ -1,20 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.myfaces.extensions.validator.util;
@@ -25,10 +25,14 @@
/**
* @author Gerhard Petracek
*/
-public class WebXmlUtils {
+public class WebXmlUtils
+{
- public static String getInitParameter(String key) {
- String value = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(ExtValInformation.WEBXML_PARAM_PREFIX + "." + key);
+ public static String getInitParameter(String key)
+ {
+ String value = FacesContext.getCurrentInstance().getExternalContext()
+ .getInitParameter(
+ ExtValInformation.WEBXML_PARAM_PREFIX + "." + key);
//TODO
return (value != null) ? value.replace(" ", "").trim() : null;
}