You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2008/07/14 19:58:22 UTC
svn commit: r676664 [7/12] - in /myfaces/extensions/validator: branches/
branches/jsf_1.1/ branches/jsf_1.1/core/ branches/jsf_1.1/core/src/
branches/jsf_1.1/core/src/main/ branches/jsf_1.1/core/src/main/config/
branches/jsf_1.1/core/src/main/java/ bra...
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,155 @@
+/*
+ * 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.crossval.strategy;
+
+import org.apache.myfaces.extensions.validator.crossval.CrossValidationStorageEntry;
+import org.apache.myfaces.extensions.validator.crossval.annotation.DateIs;
+import org.apache.myfaces.extensions.validator.crossval.annotation.DateIsType;
+
+import javax.faces.context.FacesContext;
+import java.lang.annotation.Annotation;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.MissingResourceException;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class DateIsStrategy extends AbstractCompareStrategy {
+ //TODO
+ protected static final String TOO_EARLY = "early";
+ protected static final String TOO_LATE = "late";
+ protected static final String NOT_EQUAL_DATE_TIME = "not equal";
+ protected static final String RESULT_KEY = "result";
+ protected static final String COMPARED_VALUE_KEY = "target value";
+
+ public boolean useTargetComponentToDisplayErrorMsg(CrossValidationStorageEntry crossValidationStorageEntry) {
+ return true;
+ }
+
+ //TODO
+ public boolean isViolation(Object object1, Object object2, Annotation annotation) {
+ boolean violationFound;
+
+ if (((DateIs) annotation).type().equals(DateIsType.same)) {
+ violationFound = object1 != null && !object1.equals(object2);
+
+ if (violationFound) {
+ this.violationResultStorage.put(RESULT_KEY, NOT_EQUAL_DATE_TIME);
+ }
+ } else if (((DateIs) annotation).type().equals(DateIsType.before)) {
+ violationFound = object1 != null && object2 != null && (!new Date(((Date) object1).getTime()).before((Date) object2) || object1.equals(object2));
+
+ if (violationFound) {
+ this.violationResultStorage.put(RESULT_KEY, TOO_LATE);
+ }
+ } else {
+ violationFound = object1 != null && object2 != null && (!new Date(((Date) object1).getTime()).after((Date) object2) || object1.equals(object2));
+
+ if (violationFound) {
+ this.violationResultStorage.put(RESULT_KEY, TOO_EARLY);
+ }
+ }
+
+ if (violationFound) {
+ this.violationResultStorage.put(COMPARED_VALUE_KEY, object1);
+ }
+
+ return violationFound;
+ }
+
+ public String[] getValidationTargets(Annotation annotation) {
+ return ((DateIs) annotation).valueOf();
+ }
+
+ /*
+ * protected
+ */
+ protected String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent) {
+ if (!isTargetComponent) {
+ return null;
+ }
+
+ String result = (String) this.violationResultStorage.get(RESULT_KEY);
+ if (TOO_EARLY.equals(result)) {
+ return getNotAfterErrorMsgKey((DateIs) annotation);
+ } else if (TOO_LATE.equals(result)) {
+ return getNotBeforeErrorMsgKey((DateIs) annotation);
+ } else {
+ return getNotEqualErrorMsgKey((DateIs) annotation);
+ }
+ }
+
+ @Override
+ protected String getErrorMessageSummary(Annotation annotation, boolean isTargetComponent) {
+ if (!isTargetComponent) {
+ return super.getErrorMessageSummary(annotation, isTargetComponent);
+ }
+
+ return getErrorMessage(getValidationErrorMsgKey(annotation, isTargetComponent), annotation, isTargetComponent);
+ }
+
+ @Override
+ protected String getErrorMessageDetails(Annotation annotation, boolean isTargetComponent) {
+ if (!isTargetComponent) {
+ return super.getErrorMessageDetails(annotation, isTargetComponent);
+ }
+
+ try {
+ return getErrorMessage(getValidationErrorMsgKey(annotation, isTargetComponent) + DETAIL_MESSAGE_KEY_POSTFIX, annotation, isTargetComponent);
+ } catch (MissingResourceException e) {
+ logger.warn("couldn't find key " + getValidationErrorMsgKey(annotation, isTargetComponent) + DETAIL_MESSAGE_KEY_POSTFIX, e);
+ }
+ return null;
+ }
+
+ //TODO
+ protected String getErrorMessage(String key, Annotation annotation, boolean isTargetComponent) {
+ String message = resolveMessage(key);
+
+ DateFormat dateFormat = DateFormat.getDateInstance(((DateIs) annotation).errorMessageDateStyle(), FacesContext.getCurrentInstance().getViewRoot().getLocale());
+
+ //replace placeholder with the value of the other component
+ return message.replace("{0}", dateFormat.format((Date) this.violationResultStorage.get(COMPARED_VALUE_KEY)));
+ }
+
+ /*
+ * private
+ */
+ private String getNotAfterErrorMsgKey(DateIs annotation) {
+ if (annotation.validationErrorMsgKey().equals("")) {
+ return annotation.notAfterErrorMsgKey();
+ }
+ return annotation.validationErrorMsgKey();
+ }
+
+ private String getNotBeforeErrorMsgKey(DateIs annotation) {
+ if (annotation.validationErrorMsgKey().equals("")) {
+ return annotation.notBeforeErrorMsgKey();
+ }
+ return annotation.validationErrorMsgKey();
+ }
+
+ private String getNotEqualErrorMsgKey(DateIs annotation) {
+ if (annotation.validationErrorMsgKey().equals("")) {
+ return annotation.notEqualErrorMsgKey();
+ }
+ return annotation.validationErrorMsgKey();
+ }
+}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/EqualsStrategy.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.crossval.strategy;
+
+import org.apache.myfaces.extensions.validator.crossval.CrossValidationStorageEntry;
+import org.apache.myfaces.extensions.validator.crossval.annotation.Equals;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Gerhard Petracek
+ */
+//TODO test custom message bundle
+public class EqualsStrategy extends AbstractCompareStrategy {
+
+ public boolean useTargetComponentToDisplayErrorMsg(CrossValidationStorageEntry crossValidationStorageEntry) {
+ return true;
+ }
+
+ protected String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent) {
+ return ((Equals) annotation).validationErrorMsgKey();
+ }
+
+ public boolean isViolation(Object object1, Object object2, Annotation annotation) {
+ return object1 != null && !object1.equals(object2);
+ }
+
+ public String[] getValidationTargets(Annotation annotation) {
+ return ((Equals) annotation).value();
+ }
+}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/NotEqualsStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/NotEqualsStrategy.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/NotEqualsStrategy.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/NotEqualsStrategy.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.crossval.strategy;
+
+import org.apache.myfaces.extensions.validator.crossval.annotation.NotEquals;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class NotEqualsStrategy extends EqualsStrategy {
+
+ @Override
+ protected String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent) {
+ return ((NotEquals) annotation).validationErrorMsgKey();
+ }
+
+ @Override
+ public boolean isViolation(Object object1, Object object2, Annotation annotation) {
+ return !super.isViolation(object1, object2, annotation);
+ }
+
+ @Override
+ public String[] getValidationTargets(Annotation annotation) {
+ return ((NotEquals) annotation).value();
+ }
+}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,55 @@
+/*
+ * 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.crossval.strategy;
+
+import org.apache.myfaces.extensions.validator.crossval.CrossValidationStorageEntry;
+import org.apache.myfaces.extensions.validator.crossval.annotation.RequiredIf;
+import org.apache.myfaces.extensions.validator.crossval.annotation.RequiredIfType;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class RequiredIfStrategy extends AbstractCompareStrategy {
+
+ public boolean useTargetComponentToDisplayErrorMsg(CrossValidationStorageEntry crossValidationStorageEntry) {
+ return false;
+ }
+
+ protected String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent) {
+ return ((RequiredIf) annotation).validationErrorMsgKey();
+ }
+
+ public boolean isViolation(Object object1, Object object2, Annotation annotation) {
+ boolean violationFound = false;
+
+ if (((RequiredIf) annotation).is().equals(RequiredIfType.empty)) {
+ violationFound = (object2 == null || object2.equals("")) && (object1 == null || object1.equals(""));
+ } else if (((RequiredIf) annotation).is().equals(RequiredIfType.not_empty)) {
+ violationFound = (object2 != null && !object2.equals("")) && (object1 == null || object1.equals(""));
+ }
+
+ return violationFound;
+ }
+
+ public String[] getValidationTargets(Annotation annotation) {
+ return ((RequiredIf) annotation).valueOf();
+ }
+}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/TargetAliasStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/TargetAliasStrategy.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/TargetAliasStrategy.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/TargetAliasStrategy.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.crossval.strategy;
+
+import org.apache.myfaces.extensions.validator.crossval.CrossValidationStorage;
+import org.apache.myfaces.extensions.validator.crossval.CrossValidationStorageEntry;
+
+import javax.faces.validator.ValidatorException;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class TargetAliasStrategy extends AbstractCrossValidationStrategy {
+ public void processCrossValidation(CrossValidationStorageEntry crossValidationStorageEntry, CrossValidationStorage crossValidationStorage) throws ValidatorException {
+ //do nothing - it's just a marker - the inherited functionality is required and enough
+ }
+
+ //TODO
+ protected String getValidationErrorMsgKey(Annotation annotation) {
+ //do nothing - it's just a marker - the inherited functionality is required and enough
+ return null;
+ }
+}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/java/org/apache/myfaces/extensions/validator/util/CrossValidationUtils.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.crossval.CrossValidationStorage;
+
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class CrossValidationUtils {
+ public static final String CROSS_VALIDATION_STORAGE_KEY = CrossValidationStorage.class.getName();
+
+ public static CrossValidationStorage getOrInitCrossValidationStorage() {
+ Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+
+ if (!requestMap.containsKey(CROSS_VALIDATION_STORAGE_KEY)) {
+ resetCrossValidationStorage();
+ }
+
+ return (CrossValidationStorage) requestMap.get(CROSS_VALIDATION_STORAGE_KEY);
+ }
+
+ public static void resetCrossValidationStorage() {
+ FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(CROSS_VALIDATION_STORAGE_KEY, new CrossValidationStorage());
+ }
+}
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/LICENSE.txt
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/LICENSE.txt?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/LICENSE.txt (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/LICENSE.txt Mon Jul 14 10:58:09 2008
@@ -0,0 +1,174 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/NOTICE.txt
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/NOTICE.txt?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/NOTICE.txt (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/cross-validation/src/main/resources/NOTICE.txt Mon Jul 14 10:58:09 2008
@@ -0,0 +1,9 @@
+Apache MyFaces Extensions Validator
+Copyright 2007-2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+------------------------------------------------------------------------
+See the file LICENSE.txt
+------------------------------------------------------------------------
\ No newline at end of file
Added: myfaces/extensions/validator/branches/jsf_1.1/validation-modules/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/jsf_1.1/validation-modules/pom.xml?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/jsf_1.1/validation-modules/pom.xml (added)
+++ myfaces/extensions/validator/branches/jsf_1.1/validation-modules/pom.xml Mon Jul 14 10:58:09 2008
@@ -0,0 +1,34 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <packaging>pom</packaging>
+
+ <groupId>org.apache.myfaces.extensions.validator.validation-modules</groupId>
+ <artifactId>validation-modules-project</artifactId>
+
+ <name>MyFaces Extensions-Validator Validation-Modules</name>
+ <version>${build.version}</version>
+
+ <parent>
+ <groupId>org.apache.myfaces.extensions.validator</groupId>
+ <artifactId>validator-project</artifactId>
+ <version>${build.version}</version>
+ </parent>
+
+ <modules>
+ <module>base-validation</module>
+ <module>cross-validation</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.myfaces.extensions.validator</groupId>
+ <artifactId>myfaces-extval-core</artifactId>
+ <version>${build.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: myfaces/extensions/validator/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/pom.xml?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/pom.xml (added)
+++ myfaces/extensions/validator/trunk/core/pom.xml Mon Jul 14 10:58:09 2008
@@ -0,0 +1,82 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+
+ <groupId>org.apache.myfaces.extensions.validator</groupId>
+ <artifactId>myfaces-extval-core</artifactId>
+ <name>MyFaces Extensions-Validator Core</name>
+ <version>${build.version}</version>
+
+ <parent>
+ <groupId>org.apache.myfaces.extensions.validator</groupId>
+ <artifactId>validator-project</artifactId>
+ <version>${build.version}</version>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.myfaces.core</groupId>
+ <artifactId>myfaces-api</artifactId>
+ <version>${jsf.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.1_3</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/config</directory>
+ <includes>
+ <include>**/*xml</include>
+ </includes>
+ <targetPath>/META-INF</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>LICENSE.txt</include>
+ <include>NOTICE.txt</include>
+ </includes>
+ <targetPath>/META-INF</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*properties</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <inherited>true</inherited>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: myfaces/extensions/validator/trunk/core/src/main/config/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/config/faces-config.xml?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/config/faces-config.xml (added)
+++ myfaces/extensions/validator/trunk/core/src/main/config/faces-config.xml Mon Jul 14 10:58:09 2008
@@ -0,0 +1,30 @@
+<!--
+ * 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.
+-->
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
+ version="1.2">
+ <factory>
+ <application-factory>org.apache.myfaces.extensions.validator.core.ExtValApplicationFactory</application-factory>
+ </factory>
+ <lifecycle>
+ <phase-listener>org.apache.myfaces.extensions.validator.core.ProxyMappingPhaseListener</phase-listener>
+ </lifecycle>
+</faces-config>
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/ExtValInformation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/ExtValInformation.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/ExtValInformation.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/ExtValInformation.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+/**
+ * dont't move to an other package!!!
+ *
+ * @author Gerhard Petracek
+ */
+public interface ExtValInformation {
+ static final String EXTENSIONS_VALIDATOR_BASE_PACKAGE_NAME = ExtValInformation.class.getPackage().getName();
+ static final String WEBXML_PARAM_PREFIX = ExtValInformation.class.getPackage().getName();
+ static final String VERSION = "1.2.1";
+}
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractStartupConfigListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractStartupConfigListener.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractStartupConfigListener.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/AbstractStartupConfigListener.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Gerhard Petracek
+ */
+public abstract class AbstractStartupConfigListener implements PhaseListener {
+ protected final Log logger = LogFactory.getLog(getClass());
+ //don't remove - it's a fallback if there is a problem with deregistration
+ //target: don't process init logic more than once
+ private static List<Class> initializedListeners = new ArrayList<Class>();
+
+ public void afterPhase(PhaseEvent event) {
+ }
+
+ public void beforePhase(PhaseEvent event) {
+ synchronized (AbstractStartupConfigListener.class) {
+ if (!initializedListeners.contains(getClass())) {
+ try {
+ init();
+
+ ExtValUtils.deregisterPhaseListener(this);
+ } catch (Throwable t) {
+ this.logger.warn("an exception occurred while deregistering the phase-listener" + getClass().getName() + " -> there is just a little overhead, but everything else works correctly. however, please inform the community about your configuration", t);
+ } finally {
+ initializedListeners.add(getClass());
+ }
+ }
+ }
+ }
+
+ public PhaseId getPhaseId() {
+ return PhaseId.RESTORE_VIEW;
+ }
+
+ protected abstract void init();
+}
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ClassMappingFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ClassMappingFactory.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ClassMappingFactory.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ClassMappingFactory.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,26 @@
+/*
+ * 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.core;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface ClassMappingFactory<P, R> {
+ R create(P source);
+}
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplication.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplication.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplication.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplication.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,273 @@
+/*
+ * 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.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.FactoryUtils;
+
+import javax.el.*;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.application.NavigationHandler;
+import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.el.*;
+import javax.faces.event.ActionListener;
+import javax.faces.validator.Validator;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * @author Gerhard Petracek
+ */
+@SuppressWarnings("deprecation,unchecked")
+public class ExtValApplication extends Application {
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ private Application wrapped;
+
+ public ExtValApplication() {
+ }
+
+ public ExtValApplication(Application wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ public UIComponent createComponent(ValueBinding componentBinding,
+ FacesContext context, String componentType) throws FacesException {
+ UIComponent component = this.wrapped.createComponent(componentBinding, context, componentType);
+ return tryToSetExtValValidatingConverter(component);
+ }
+
+ private UIComponent tryToSetExtValValidatingConverter(UIComponent component) {
+ //if no converter is used add sev-en converter - so it isn't necessary to add sev-en converter manually within the page
+ if (component instanceof EditableValueHolder) {
+ //in order to access the wrapped application and and support other Application wrappers
+ ExtValUtils.setOriginalApplication(wrapped);
+
+ ((EditableValueHolder) component).setConverter(new ExtValConverter());
+ }
+ return component;
+ }
+
+ public Converter createConverter(String converterId) throws FacesException {
+ Converter converter = this.wrapped.createConverter(converterId);
+ return getExtValConverter(converter);
+ }
+
+ public Converter createConverter(Class targetClass) throws FacesException {
+ Converter converter = this.wrapped.createConverter(targetClass);
+
+ return getExtValConverter(converter);
+ }
+
+ private Converter getExtValConverter(Converter converter) {
+ if (converter == null) {
+ return new ExtValConverter();
+ }
+
+ if (!ExtValUtils.useFallbackAdapters()) {
+ return ExtValConverter.newInstance(converter);
+ } else {
+ //fallback adapter solution
+ //if there is a problem with the default approach (the phase-listener) or the alternative (the state-manager)
+ return FactoryUtils.getConverterAdapterFactory().create(converter);
+ }
+ }
+
+ public Iterator getConverterIds() {
+ return this.wrapped.getConverterIds();
+ }
+
+ public Iterator getConverterTypes() {
+ return this.wrapped.getConverterTypes();
+ }
+
+ public void addConverter(String converterId, String converterClass) {
+ this.wrapped.addConverter(converterId, converterClass);
+ }
+
+ public void addConverter(Class targetClass, String converterClass) {
+ this.wrapped.addConverter(targetClass, converterClass);
+ }
+
+ public Iterator getComponentTypes() {
+ return this.wrapped.getComponentTypes();
+ }
+
+ public ActionListener getActionListener() {
+ return this.wrapped.getActionListener();
+ }
+
+ public void setActionListener(ActionListener listener) {
+ this.wrapped.setActionListener(listener);
+ }
+
+ public Locale getDefaultLocale() {
+ return this.wrapped.getDefaultLocale();
+ }
+
+ public void setDefaultLocale(Locale locale) {
+ this.wrapped.setDefaultLocale(locale);
+ }
+
+ public String getDefaultRenderKitId() {
+ return this.wrapped.getDefaultRenderKitId();
+ }
+
+ public void setDefaultRenderKitId(String renderKitId) {
+ this.wrapped.setDefaultRenderKitId(renderKitId);
+ }
+
+ public String getMessageBundle() {
+ return this.wrapped.getMessageBundle();
+ }
+
+ public void setMessageBundle(String bundle) {
+ this.wrapped.setMessageBundle(bundle);
+ }
+
+ public NavigationHandler getNavigationHandler() {
+ return this.wrapped.getNavigationHandler();
+ }
+
+ public void setNavigationHandler(NavigationHandler handler) {
+ this.wrapped.setNavigationHandler(handler);
+ }
+
+ public PropertyResolver getPropertyResolver() {
+ return this.wrapped.getPropertyResolver();
+ }
+
+ public void setPropertyResolver(PropertyResolver resolver) {
+ this.wrapped.setPropertyResolver(resolver);
+ }
+
+ public VariableResolver getVariableResolver() {
+ return this.wrapped.getVariableResolver();
+ }
+
+ public void setVariableResolver(VariableResolver resolver) {
+ this.wrapped.setVariableResolver(resolver);
+ }
+
+ public ViewHandler getViewHandler() {
+ return this.wrapped.getViewHandler();
+ }
+
+ public void setViewHandler(ViewHandler handler) {
+ this.wrapped.setViewHandler(handler);
+ }
+
+ public StateManager getStateManager() {
+ return this.wrapped.getStateManager();
+ }
+
+ public void setStateManager(StateManager manager) {
+ this.wrapped.setStateManager(manager);
+ }
+
+ public void addComponent(String componentType, String componentClass) {
+ this.wrapped.addComponent(componentType, componentClass);
+ }
+
+ public UIComponent createComponent(String componentType) throws FacesException {
+ UIComponent component = this.wrapped.createComponent(componentType);
+
+ return tryToSetExtValValidatingConverter(component);
+ }
+
+ public MethodBinding createMethodBinding(String ref, Class[] params)
+ throws ReferenceSyntaxException {
+ return this.wrapped.createMethodBinding(ref, params);
+ }
+
+ public Iterator getSupportedLocales() {
+ return this.wrapped.getSupportedLocales();
+ }
+
+ public void setSupportedLocales(Collection locales) {
+ this.wrapped.setSupportedLocales(locales);
+ }
+
+ public void addValidator(String validatorId, String validatorClass) {
+ this.wrapped.addValidator(validatorId, validatorClass);
+ }
+
+ public Validator createValidator(String validatorId) throws FacesException {
+ return this.wrapped.createValidator(validatorId);
+ }
+
+ public Iterator getValidatorIds() {
+ return this.wrapped.getValidatorIds();
+ }
+
+ public ValueBinding createValueBinding(String ref)
+ throws ReferenceSyntaxException {
+ return this.wrapped.createValueBinding(ref);
+ }
+
+ /*
+ * jsf 1.2 methods
+ */
+ public void addELResolver(ELResolver elResolver) {
+ this.wrapped.addELResolver(elResolver);
+ }
+
+ public ELResolver getELResolver() {
+ return this.wrapped.getELResolver();
+ }
+
+ public ResourceBundle getResourceBundle(FacesContext facesContext, String s) throws FacesException, NullPointerException {
+ return this.wrapped.getResourceBundle(facesContext, s);
+ }
+
+ public UIComponent createComponent(ValueExpression valueExpression, FacesContext facesContext, String s) throws FacesException, NullPointerException {
+ UIComponent component = this.wrapped.createComponent(valueExpression, facesContext, s);
+ return tryToSetExtValValidatingConverter(component);
+ }
+
+ public ExpressionFactory getExpressionFactory() {
+ return this.wrapped.getExpressionFactory();
+ }
+
+ public void addELContextListener(ELContextListener elContextListener) {
+ this.wrapped.addELContextListener(elContextListener);
+ }
+
+ public void removeELContextListener(ELContextListener elContextListener) {
+ this.wrapped.removeELContextListener(elContextListener);
+ }
+
+ public ELContextListener[] getELContextListeners() {
+ return this.wrapped.getELContextListeners();
+ }
+
+ public Object evaluateExpressionGet(FacesContext facesContext, String s, Class aClass) throws ELException {
+ return this.wrapped.evaluateExpressionGet(facesContext, s, aClass);
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplicationFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplicationFactory.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplicationFactory.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValApplicationFactory.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,54 @@
+/*
+ * 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.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ExtValApplicationFactory extends ApplicationFactory {
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ private ApplicationFactory wrapped;
+
+ public ExtValApplicationFactory(ApplicationFactory applicationFactory) {
+ this.wrapped = applicationFactory;
+ setApplication(applicationFactory.getApplication());
+ logger.trace("myfaces-extension-validator application factory instantiated");
+ }
+
+ public Application getApplication() {
+ return this.wrapped.getApplication();
+ }
+
+ public void setApplication(Application application) {
+ if (!(application instanceof ExtValApplication)) {
+ logger.trace("myfaces-extension-validator application created");
+
+ this.wrapped.setApplication(new ExtValApplication(application));
+ } else {
+ this.wrapped.setApplication(application);
+ }
+ }
+}
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValConverter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValConverter.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValConverter.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValConverter.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,164 @@
+/*
+ * 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.core;
+
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.extensions.validator.core.annotation.AnnotationEntry;
+import org.apache.myfaces.extensions.validator.core.annotation.extractor.AnnotationExtractor;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
+import org.apache.myfaces.extensions.validator.util.ELUtils;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.FactoryUtils;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ExtValConverter implements Converter, MethodInterceptor, Serializable {
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ public static Converter newInstance(Converter wrappedConverter) {
+ Enhancer enhancer = new Enhancer();
+ enhancer.setSuperclass(wrappedConverter.getClass());
+ enhancer.setInterfaces(new Class[]{Converter.class, Serializable.class});
+ enhancer.setCallback(new ExtValConverter());
+
+ ExtValUtils.increaseProcessedConverterCount();
+
+ return (Converter) enhancer.create();
+ }
+
+ public ExtValConverter() {
+ logger.trace("myfaces-extension-validator converter instantiated");
+ }
+
+ public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
+
+ Object convertedObject = getConvertedObject(facesContext, uiComponent, s);
+
+ processExtValValidation(facesContext, uiComponent, convertedObject);
+
+ return convertedObject;
+ }
+
+ public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
+ //indirect approach for complex components
+ Converter converter = ExtValUtils.tryToCreateOriginalConverter(facesContext, uiComponent);
+ return (converter == null) ? (o == null) ? null : o.toString() : converter.getAsString(facesContext, uiComponent, o);
+ }
+
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+ Object convertedObject = proxy.invokeSuper(obj, args);
+
+ if (method.getName().equals("getAsObject")) {
+ processExtValValidation((FacesContext) args[0], (UIComponent) args[1], convertedObject);
+ } else if (method.getName().equals("getAsString")) {
+ storeComponentConverterMappingForProxies((FacesContext) args[0], (UIComponent) args[1], (Converter)obj);
+ }
+ return convertedObject;
+ }
+
+ protected Object getConvertedObject(FacesContext facesContext, UIComponent uiComponent, String s) {
+ //indirect approach for complex components
+ //TODO
+ Converter converter = ExtValUtils.tryToCreateOriginalConverter(facesContext, uiComponent);
+ return (converter != null) ? converter.getAsObject(facesContext, uiComponent, s) : s;
+ }
+
+ /*
+ * private methods
+ */
+ private void createValueBindingConvertedValueMapping(UIComponent uiComponent, Object convertedObject) {
+ //to support local cross-validation (within the same entity)
+ Map<String, ProcessedInformationEntry> valueBindingConvertedValueMapping = ExtValUtils.getOrInitValueBindingConvertedValueMapping();
+
+ String valueBindingExpression;
+ ProcessedInformationEntry entry;
+
+ valueBindingExpression = ELUtils.getReliableValueBindingExpression(uiComponent);
+
+ if (valueBindingExpression == null) {
+ return;
+ }
+
+ entry = new ProcessedInformationEntry();
+ entry.setBean(ELUtils.getBeanObject(valueBindingExpression, uiComponent));
+ entry.setConvertedValue(convertedObject);
+ entry.setComponent(uiComponent);
+
+ //for local cross-validation
+ if (valueBindingConvertedValueMapping.containsKey(valueBindingExpression) && !valueBindingConvertedValueMapping.get(valueBindingExpression).getBean().equals(entry.getBean())) {
+ //for the validation within a complex component e.g. a table
+ //don't override existing expression (style: #{entry.property}) - make a special mapping
+
+ List<ProcessedInformationEntry> furtherEntries = valueBindingConvertedValueMapping.get(valueBindingExpression).getFurtherEntries();
+ if (furtherEntries == null) {
+ furtherEntries = new ArrayList<ProcessedInformationEntry>();
+
+ valueBindingConvertedValueMapping.get(valueBindingExpression).setFurtherEntries(furtherEntries);
+ }
+
+ furtherEntries.add(entry);
+ } else {
+ //for normal validation
+ valueBindingConvertedValueMapping.put(valueBindingExpression, entry);
+ }
+ }
+
+ private void processExtValValidation(FacesContext facesContext, UIComponent uiComponent, Object convertedObject) {
+ if (uiComponent instanceof EditableValueHolder) {
+ ValidationStrategy validationStrategy;
+
+ AnnotationExtractor annotationExtractor = FactoryUtils.getAnnotationExtractorFactory().create();
+ for (AnnotationEntry entry : annotationExtractor.extractAnnotations(facesContext, uiComponent)) {
+ validationStrategy = FactoryUtils.getValidationStrategyFactory().create(entry.getAnnotation());
+
+ if (validationStrategy != null) {
+ validationStrategy.validate(facesContext, uiComponent, entry, convertedObject);
+ } else {
+ logger.trace("no validation strategy found for " + entry.getAnnotation().annotationType().getName());
+ }
+ }
+
+ //build mapping value-binding -> processed information entry
+ createValueBindingConvertedValueMapping(uiComponent, convertedObject);
+ }
+ }
+
+
+ private void storeComponentConverterMappingForProxies(FacesContext facesContext, UIComponent uiComponent, Converter converter) {
+ if (ExtValUtils.useProxyMapping()) {
+ ExtValUtils.getOrInitProxyMapping().put(uiComponent.getClientId(facesContext), converter);
+ ExtValUtils.decreaseProcessedConverterCount();
+ }
+ }
+}
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/InformationProviderBean.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,174 @@
+/*
+ * 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.core;
+
+import org.apache.myfaces.extensions.validator.ExtValInformation;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * centralized in order that these information arn't spread over the complete code base
+ * + some of them can be customized within a custom impl. of the bean (extend this class and provide it via convention or web.xml)
+ * <p/>
+ * the static api should only be used
+ *
+ * @author Gerhard Petracek
+ */
+public class InformationProviderBean {
+ public static final String BEAN_NAME = ExtValInformation.EXTENSIONS_VALIDATOR_BASE_PACKAGE_NAME + "." + InformationProviderBean.class.getSimpleName();
+ //custom class which is an optional replacement for this class (has to extend this class)
+ public static final String CUSTOM_BEAN = (ExtValInformation.EXTENSIONS_VALIDATOR_BASE_PACKAGE_NAME + ".custom." + InformationProviderBean.class.getSimpleName()).replace(".", "_");
+ private String basePackage = WebXmlParameter.CUSTOM_EXTENSION_BASE_PACKAGE;
+
+ public InformationProviderBean() {
+ if (this.basePackage == null) {
+ this.basePackage = ExtValInformation.EXTENSIONS_VALIDATOR_BASE_PACKAGE_NAME + ".custom.";
+ }
+ if (!this.basePackage.endsWith(".")) {
+ this.basePackage = this.basePackage + ".";
+ }
+ }
+
+ public String getBasePackage() {
+ return basePackage;
+ }
+
+ public String getCustomAnnotationExtractorFactory() {
+ return this.basePackage + "AnnotationExtractorFactory";
+ }
+
+ public String getCustomAnnotationExtractor() {
+ return this.basePackage + "AnnotationExtractor";
+ }
+
+ /*
+ * name mapper
+ */
+ public String getCustomValidationStrategyToMsgResolverNameMapper() {
+ return this.basePackage + "ValidationStrategyToMsgResolverNameMapper";
+ }
+
+ public String getCustomAnnotationToValidationStrategyNameMapper() {
+ return this.basePackage + "AnnotationToValidationStrategyNameMapper";
+ }
+
+ @Deprecated
+ public String getCustomAdapterNameMapper() {
+ return this.basePackage + "AdapterNameMapper";
+ }
+
+ /*
+ * factories
+ */
+ public String getCustomMessageResolverFactory() {
+ return this.basePackage + "MessageResolverFactory";
+ }
+
+ public String getCustomValidationStrategyFactory() {
+ return this.basePackage + "ValidationStrategyFactory";
+ }
+
+ @Deprecated
+ public String getCustomConverterAdapterFactory() {
+ return this.basePackage + "ConverterAdapterFactory";
+ }
+
+ //TODO
+ /*
+ * conventions (the rest of the conventions are built with the help of name mappers,...
+ */
+ public String getConventionForMessageBundle() {
+ return this.basePackage + "validation_messages";
+ }
+
+ /*
+ * static strategy mappings (name of property files)
+ */
+ public String getCustomStaticStrategyMappingSource() {
+ return this.basePackage + "strategy_mappings";
+ }
+
+ private List<String> staticStrategyMappings = new ArrayList<String>();
+
+ /*
+ * final methods
+ */
+ //TODO
+ public final String getConventionForModuleMessageBundle(String packageName) {
+ String newPackageName;
+ if (packageName.endsWith(".resolver")) {
+ newPackageName = packageName.replace(".resolver", ".bundle");
+ } else {
+ newPackageName = packageName.replace(".resolver.", ".bundle.");
+ }
+
+ return newPackageName + ".validation_messages";
+ }
+
+ public final List<String> getStaticStrategyMappingSources() {
+ return this.staticStrategyMappings;
+ }
+
+ public final void addStaticStrategyMappingSource(String resourceBundleName) {
+ synchronized (this) {
+ this.staticStrategyMappings.add(resourceBundleName);
+ }
+ }
+
+ public final boolean containsStaticStrategyMappingSource(String resourceBundleName) {
+ return this.staticStrategyMappings.contains(resourceBundleName);
+ }
+
+ /**
+ * use a custom name mapper to implement custom conventions
+ */
+ public final String getConventionNameForMessageResolverPackage(Class<? extends ValidationStrategy> validationStrategyClass, String targetClassName) {
+ String resolverName = validationStrategyClass.getName();
+
+ resolverName = resolverName.replace(".strategy.", ".message.resolver.");
+
+ if (targetClassName == null) {
+ //TODO
+ return null;
+ }
+ return resolverName.substring(0, resolverName.lastIndexOf(".")) + "." + targetClassName;
+ }
+
+ /**
+ * use a custom name mapper to implement custom conventions
+ */
+ public final String getConventionNameForMessageResolverClass(String strategyClassName) {
+ if (strategyClassName.endsWith("ValidationStrategy")) {
+ return strategyClassName.substring(0, strategyClassName.length() - 18) + "ValidationErrorMessageResolver";
+ } else if (strategyClassName.endsWith("Strategy")) {
+ return strategyClassName.substring(0, strategyClassName.length() - 8) + "ValidationErrorMessageResolver";
+ }
+ return strategyClassName;
+ }
+
+ /**
+ * use a custom name mapper to implement custom conventions
+ */
+ public final String getConventionNameForValidationStrategy(Annotation annotation) {
+ return annotation.annotationType().getName().replace(".annotation.", ".strategy.") + "Strategy";
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProcessedInformationEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProcessedInformationEntry.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProcessedInformationEntry.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProcessedInformationEntry.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,66 @@
+/*
+ * 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.core;
+
+import javax.faces.component.UIComponent;
+import java.util.List;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ProcessedInformationEntry {
+ private Object bean;
+ private Object convertedValue;
+ private UIComponent component;
+ //for complex components (e.g. a table there are multiple entries with the same key (here the el expression #{entry.property})
+ //however, don't override the previous entry - they arn't the same;
+ private List<ProcessedInformationEntry> furtherEntries;
+
+ public Object getBean() {
+ return bean;
+ }
+
+ public void setBean(Object bean) {
+ this.bean = bean;
+ }
+
+ public Object getConvertedValue() {
+ return convertedValue;
+ }
+
+ public void setConvertedValue(Object convertedValue) {
+ this.convertedValue = convertedValue;
+ }
+
+ public UIComponent getComponent() {
+ return component;
+ }
+
+ public void setComponent(UIComponent component) {
+ this.component = component;
+ }
+
+ public List<ProcessedInformationEntry> getFurtherEntries() {
+ return furtherEntries;
+ }
+
+ public void setFurtherEntries(List<ProcessedInformationEntry> furtherEntries) {
+ this.furtherEntries = furtherEntries;
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProxyMappingPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProxyMappingPhaseListener.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProxyMappingPhaseListener.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProxyMappingPhaseListener.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,99 @@
+/*
+ * 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.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.component.EditableValueHolder;
+
+/**
+ * due to a restriction at the state saving process
+ * a proxy gets a super-class which might impl. StateHolder
+ * -> saveState: a StateHolder impl. gets handled before Serializable -> callback doesn't get saved
+ * -> restoreState: restoreState of the super-class gets called - no callback -> no interceptor gets executed
+ * if a framework (such as trinidad) provides caching it's no problem
+ * -> use the web.xml context-param to deactivate the mechanism
+ *
+ * @author Gerhard Petracek
+ */
+public class ProxyMappingPhaseListener implements PhaseListener {
+ private boolean isInitialized = false;
+
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ public void afterPhase(PhaseEvent event) {
+ if (!isInitialized) {
+ //don't use DEACTIVATE_PROXY_MAPPING here to allow a different concept
+ String initParam = WebXmlParameter.DEACTIVATE_RESTORE_PROXY_PHASE_LISTENER;
+
+ if(initParam != null && initParam.equalsIgnoreCase("true")) {
+ ExtValUtils.deregisterPhaseListener(this);
+ }
+ isInitialized = true;
+ }
+
+ if(!event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
+ return;
+ }
+
+ Integer processedConverterCount = ExtValUtils.getProcessedConverterCount();
+ //don't change the comparison with 0 - in order to reduce the overhead.
+ //if everything works correctly it's not necessary to inspact the full tree
+ //it's just due to a ri bug - normally it's performed during ExtValConverter#intercept#getAsString
+ if(ExtValUtils.useProxyMapping() && (processedConverterCount != null && !processedConverterCount.equals(0))){
+ storeComponentConverterMappingForProxies(event.getFacesContext(), event.getFacesContext().getViewRoot());
+ }
+ }
+
+ public void beforePhase(PhaseEvent event) {
+ if(!event.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES)) {
+ return;
+ }
+
+ ExtValUtils.restoreProxies();
+ }
+
+ public PhaseId getPhaseId() {
+ return PhaseId.ANY_PHASE;
+ }
+
+ /**
+ * there is a ri bug (at least with jsp's) -> sometimes getAsString of converters aren't called
+ * -> there is no mapping -> if it's the case and there are unhandled editable value hoder components within the page
+ * -> search all these components and add the equivalent converter to the mapping
+ *
+ * @param facesContext reference to the current faces context
+ * @param uiComponent reference to the current component
+ */
+ private void storeComponentConverterMappingForProxies(FacesContext facesContext, UIComponent uiComponent) {
+ for(UIComponent child : uiComponent.getChildren()) {
+ if(child instanceof EditableValueHolder) {
+ ExtValUtils.getOrInitProxyMapping().put(child.getClientId(facesContext), ((EditableValueHolder)child).getConverter());
+ }
+ storeComponentConverterMappingForProxies(facesContext, child);
+ }
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java?rev=676664&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/WebXmlParameter.java Mon Jul 14 10:58:09 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.core;
+
+import org.apache.myfaces.extensions.validator.util.WebXmlUtils;
+
+/**
+ * centralized in order that these information arn't spread over the complete code base
+ *
+ * @author Gerhard Petracek
+ */
+public interface WebXmlParameter {
+ /*
+ * custom
+ */
+ static final String CUSTOM_MESSAGE_BUNDLE = WebXmlUtils.getInitParameter("CUSTOM_MESSAGE_BUNDLE");
+ static final String CUSTOM_EXTENSION_BASE_PACKAGE = WebXmlUtils.getInitParameter("CUSTOM_BASE_PACKAGE");
+ static final String CUSTOM_CONVENTION_INFO_PROVIDER_BEAN = WebXmlUtils.getInitParameter("CUSTOM_INFORMATION_PROVIDER_BEAN");
+
+ static final String CUSTOM_STRATEGY_TO_MESSAGE_RESOLVER_NAME_MAPPER = WebXmlUtils.getInitParameter("CUSTOM_STRATEGY_TO_MESSAGE_RESOLVER_NAME_MAPPER");
+ static final String CUSTOM_ANNOTATION_TO_VALIDATION_STRATEGY_NAME_MAPPER = WebXmlUtils.getInitParameter("CUSTOM_ANNOTATION_TO_VALIDATION_STRATEGY_NAME_MAPPER");
+
+ static final String CUSTOM_MESSAGE_RESOLVER_FACTORY = WebXmlUtils.getInitParameter("CUSTOM_MESSAGE_RESOLVER_FACTORY");
+ static final String CUSTOM_VALIDATION_STRATEGY_FACTORY = WebXmlUtils.getInitParameter("CUSTOM_VALIDATION_STRATEGY_FACTORY");
+ static final String CUSTOM_ANNOTATION_EXTRACTOR_FACTORY = WebXmlUtils.getInitParameter("CUSTOM_ANNOTATION_EXTRACTOR_FACTORY");
+
+ static final String CUSTOM_ANNOTATION_EXTRACTOR = WebXmlUtils.getInitParameter("CUSTOM_ANNOTATION_EXTRACTOR");
+
+ //TODO documentation
+ static final String CUSTOM_VALIDATIONSTRATEGY_MAPPING = WebXmlUtils.getInitParameter("CUSTOM_STATIC_VALIDATIONSTRATEGY_MAPPING");
+
+ /*
+ * deactivate
+ */
+ static final String DEACTIVATE_RESTORE_PROXY_PHASE_LISTENER = WebXmlUtils.getInitParameter("DEACTIVATE_RESTORE_PROXY_PHASE_LISTENER");
+ static final String DEACTIVATE_DEFAULT_CONVENTION = WebXmlUtils.getInitParameter("DEACTIVATE_DEFAULT_CONVENTION");
+ static final String DEACTIVATE_PROXY_MAPPING = WebXmlUtils.getInitParameter("DEACTIVATE_PROXY_MAPPING");
+
+ /*
+ * fallback lib - if the usage of cglib is a problem
+ */
+ @Deprecated
+ static final String CUSTOM_CONVERTER_TO_ADAPTER_NAME_MAPPER = WebXmlUtils.getInitParameter("CUSTOM_CONVERTER_TO_ADAPTER_NAME_MAPPER");
+ @Deprecated
+ static final String CUSTOM_CONVERTER_ADAPTER_FACTORY = WebXmlUtils.getInitParameter("CUSTOM_CONVERTER_ADAPTER_FACTORY");
+ @Deprecated
+ static final String USE_ADAPTERS = WebXmlUtils.getInitParameter("USE_ADAPTERS");
+}
\ No newline at end of file