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 2009/11/15 00:04:14 UTC
svn commit: r836284 - in /myfaces/extensions/validator/trunk:
core/src/main/java/org/apache/myfaces/extensions/validator/core/
core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/
test-modules/core-tests/src/test/java/org/apache/myf...
Author: gpetracek
Date: Sat Nov 14 23:04:13 2009
New Revision: 836284
URL: http://svn.apache.org/viewvc?rev=836284&view=rev
Log:
EXTVAL-71 implementation and test cases
Added:
myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/DefaultProjectStageResolver.java
myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStage.java
myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStageResolver.java
myfaces/extensions/validator/trunk/test-modules/core-tests/src/test/java/org/apache/myfaces/extensions/validator/test/core/stage/
myfaces/extensions/validator/trunk/test-modules/core-tests/src/test/java/org/apache/myfaces/extensions/validator/test/core/stage/ProjectStageTestCase.java
Modified:
myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/DefaultProjectStageResolver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/DefaultProjectStageResolver.java?rev=836284&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/DefaultProjectStageResolver.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/DefaultProjectStageResolver.java Sat Nov 14 23:04:13 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class DefaultProjectStageResolver implements ProjectStageResolver
+{
+ public ProjectStage getCurrentProjectStage()
+ {
+ //don't use the default extval mechanism to avoid too early evaluation with mojarra
+ String result;
+ try
+ {
+ result = FacesContext.getCurrentInstance()
+ .getExternalContext().getInitParameter("javax.faces.PROJECT_STAGE");
+ }
+ catch (Throwable t)
+ {
+ return getDefaultProjectStage();
+ }
+
+ if(result == null || "".equals(result))
+ {
+ return getDefaultProjectStage();
+ }
+ return ProjectStage.valueOf(result.trim());
+ }
+
+ private ProjectStage getDefaultProjectStage()
+ {
+ return ProjectStage.Production;
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStage.java?rev=836284&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStage.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStage.java Sat Nov 14 23:04:13 2009
@@ -0,0 +1,53 @@
+/*
+ * 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.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+/**
+ * project stage equivalent to jsf 2.0
+ * extval 2.x has a special resolver which redirects the call to the new jsf api
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public enum ProjectStage
+{
+ Development, UnitTest, SystemTest, Production;
+
+ public static boolean is(ProjectStage projectStage)
+ {
+ return getCurrentProjectStage().equals(projectStage);
+ }
+
+ private static ProjectStage getCurrentProjectStage()
+ {
+ Object projectStageResolver = ExtValContext.getContext()
+ .getGlobalProperty(ProjectStageResolver.class.getName());
+
+ //set it to null to tweek the performance
+ if(projectStageResolver instanceof ProjectStageResolver)
+ {
+ return ((ProjectStageResolver)projectStageResolver).getCurrentProjectStage();
+ }
+ return ProjectStage.Production;
+ }
+}
Added: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStageResolver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStageResolver.java?rev=836284&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStageResolver.java (added)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/ProjectStageResolver.java Sat Nov 14 23:04:13 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public interface ProjectStageResolver
+{
+ ProjectStage getCurrentProjectStage();
+}
Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java?rev=836284&r1=836283&r2=836284&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java Sat Nov 14 23:04:13 2009
@@ -27,6 +27,8 @@
import org.apache.myfaces.extensions.validator.core.ExtValContext;
import org.apache.myfaces.extensions.validator.core.CustomInformation;
import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
+import org.apache.myfaces.extensions.validator.core.ProjectStageResolver;
+import org.apache.myfaces.extensions.validator.core.DefaultProjectStageResolver;
import org.apache.myfaces.extensions.validator.core.PhaseIdRecordingPhaseListener;
import org.apache.myfaces.extensions.validator.core.metadata.transformer.mapper
.BeanValidationStrategyToMetaDataTransformerNameMapper;
@@ -98,6 +100,7 @@
initViolationSeverityInterpreter();
initPropertyValidationInterceptors();
initPhaseListeners();
+ initProjectStageResolver();
executeCustomStartupListener();
}
@@ -202,4 +205,10 @@
{
JsfUtils.registerPhaseListener(new PhaseIdRecordingPhaseListener());
}
+
+ private void initProjectStageResolver()
+ {
+ ExtValContext.getContext()
+ .addGlobalProperty(ProjectStageResolver.class.getName(), new DefaultProjectStageResolver(), false);
+ }
}
Added: myfaces/extensions/validator/trunk/test-modules/core-tests/src/test/java/org/apache/myfaces/extensions/validator/test/core/stage/ProjectStageTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/test-modules/core-tests/src/test/java/org/apache/myfaces/extensions/validator/test/core/stage/ProjectStageTestCase.java?rev=836284&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/test-modules/core-tests/src/test/java/org/apache/myfaces/extensions/validator/test/core/stage/ProjectStageTestCase.java (added)
+++ myfaces/extensions/validator/trunk/test-modules/core-tests/src/test/java/org/apache/myfaces/extensions/validator/test/core/stage/ProjectStageTestCase.java Sat Nov 14 23:04:13 2009
@@ -0,0 +1,82 @@
+/*
+ * 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.test.core.stage;
+
+import org.apache.myfaces.extensions.validator.core.ProjectStage;
+import org.apache.myfaces.extensions.validator.test.core.AbstractExValCoreTestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class ProjectStageTestCase extends AbstractExValCoreTestCase
+{
+ private static final String PROJECT_STAGE = "javax.faces.PROJECT_STAGE";
+ public ProjectStageTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(ProjectStageTestCase.class);
+ }
+
+ public void testDevelopmentStage()
+ {
+ servletContext.addInitParameter(PROJECT_STAGE, "Development");
+ assertTrue(ProjectStage.is(ProjectStage.Development));
+ }
+
+ public void testUnitTestStage()
+ {
+ servletContext.addInitParameter(PROJECT_STAGE, "UnitTest");
+ assertTrue(ProjectStage.is(ProjectStage.UnitTest));
+ }
+
+ public void testSystemTestStage()
+ {
+ servletContext.addInitParameter(PROJECT_STAGE, "SystemTest");
+ assertTrue(ProjectStage.is(ProjectStage.SystemTest));
+ }
+
+ public void testProductionStage()
+ {
+ servletContext.addInitParameter(PROJECT_STAGE, "Production");
+ assertTrue(ProjectStage.is(ProjectStage.Production));
+ }
+
+ public void testDefaultStage()
+ {
+ assertTrue(ProjectStage.is(ProjectStage.Production));
+ }
+
+ public void testWrongDefaultStage1()
+ {
+ assertFalse(ProjectStage.is(ProjectStage.Development));
+ }
+
+ public void testWrongDefaultStage2()
+ {
+ assertFalse(ProjectStage.is(ProjectStage.UnitTest));
+ }
+
+ public void testWrongDefaultStage3()
+ {
+ assertFalse(ProjectStage.is(ProjectStage.SystemTest));
+ }
+}
\ No newline at end of file