You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by tc...@apache.org on 2002/03/26 20:56:45 UTC
cvs commit: xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints AbstractConstraint.java ChoiceConstraint.java RegexprConstraint.java
tcurdt 02/03/26 11:56:44
Modified: src/scratchpad/src/org/apache/cocoon/precept
InstanceTransformer.java
src/scratchpad/src/org/apache/cocoon/precept/preceptors
AbstractPreceptor.java
src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax
PreceptorBuilderImpl.java
src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints
AbstractConstraint.java ChoiceConstraint.java
RegexprConstraint.java
Log:
configure the constraints and pass them into the SAX stream
Revision Changes Path
1.3 +18 -10 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/InstanceTransformer.java
Index: InstanceTransformer.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/InstanceTransformer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InstanceTransformer.java 25 Mar 2002 23:23:38 -0000 1.2
+++ InstanceTransformer.java 26 Mar 2002 19:56:44 -0000 1.3
@@ -104,7 +104,6 @@
public final static String TAG_COMMON_ATTR_REF = "ref";
public final static String TAG_COMMON_ATTR_INSTANCE = "instance";
- private Logger log;
private Request request;
private Session session;
private Instance defaultInstance;
@@ -112,10 +111,9 @@
private String prefix;
public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException {
- log = getLogger();
request = ObjectModelHelper.getRequest(objectModel);
if (request == null) {
- log.debug("no request object");
+ getLogger().debug("no request object");
throw new ProcessingException("no request object");
}
@@ -136,17 +134,17 @@
if (session != null) {
String id = attributes.getValue(TAG_INSERTINSTANCE_ATTR_ID);
- log.debug("inserting instance [id=" + String.valueOf(id) + "]");
+ getLogger().debug("inserting instance [id=" + String.valueOf(id) + "]");
Instance instance = (Instance) session.getAttribute(id);
if (instance != null) {
instance.toSAX(this, true);
}
else {
- log.debug("could not find instance [id=" + String.valueOf(id) + "]");
+ getLogger().debug("could not find instance [id=" + String.valueOf(id) + "]");
}
}
else {
- log.debug("no session - no instance");
+ getLogger().debug("no session - no instance");
}
}
else if (TAG_INSERTVIOLATIONS.equals(name)) {
@@ -166,10 +164,10 @@
String id = attributes.getValue(TAG_INSTANCE_ATTR_ID);
defaultInstance = (Instance) session.getAttribute(id);
if (defaultInstance != null) {
- log.debug("using default instance [id=" + String.valueOf(id) + "]");
+ getLogger().debug("using default instance [id=" + String.valueOf(id) + "]");
}
else {
- log.error("could not find instance [id=" + String.valueOf(id) + "]");
+ getLogger().error("could not find instance [id=" + String.valueOf(id) + "]");
}
}
}
@@ -190,10 +188,10 @@
if (session != null) {
instance = (Instance) session.getAttribute(id);
if (instance != null) {
- log.debug("using instance [id=" + String.valueOf(id) + "]");
+ getLogger().debug("using instance [id=" + String.valueOf(id) + "]");
}
else {
- log.error("could not find instance [id=" + String.valueOf(id) + "]");
+ getLogger().error("could not find instance [id=" + String.valueOf(id) + "]");
}
}
}
@@ -210,6 +208,16 @@
super.characters(v.toCharArray(),0,v.length());
}
super.endElement(uri, "value", prefix + ":" + "value");
+
+ if (instance.getPreceptor() != null) {
+ List constraints = instance.getPreceptor().getConstraitsFor(ref);
+ if (constraints != null) {
+ for (Iterator it = constraints.iterator(); it.hasNext();) {
+ Constraint constraint = (Constraint) it.next();
+ constraint.toSAX(this);
+ }
+ }
+ }
}
catch (InvalidXPathSyntaxException e) {
throw new SAXException(e);
1.3 +4 -3 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/AbstractPreceptor.java
Index: AbstractPreceptor.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/AbstractPreceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractPreceptor.java 25 Mar 2002 23:23:54 -0000 1.2
+++ AbstractPreceptor.java 26 Mar 2002 19:56:44 -0000 1.3
@@ -54,7 +54,8 @@
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.framework.configuration.Configuration;
import org.apache.cocoon.precept.Preceptor;
/*
@@ -62,8 +63,8 @@
* @author: Torsten Curdt <tc...@dff.st>
*/
public abstract class AbstractPreceptor extends AbstractLoggable implements Preceptor, Composable {
- protected ComponentManager manager;
-
+ protected ComponentManager manager;
+
public void compose(ComponentManager manager) throws ComponentException {
this.manager = manager;
}
1.3 +10 -6 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/PreceptorBuilderImpl.java
Index: PreceptorBuilderImpl.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/PreceptorBuilderImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PreceptorBuilderImpl.java 25 Mar 2002 23:23:54 -0000 1.2
+++ PreceptorBuilderImpl.java 26 Mar 2002 19:56:44 -0000 1.3
@@ -145,7 +145,8 @@
parser.parse(source);
}
catch (Exception e) {
- e.printStackTrace(System.out);
+ e.printStackTrace(System.out);
+ getLogger().error("",e);
}
}
@@ -252,8 +253,9 @@
constraintName = attributes.getValue("name");
constraintContext = attributes.getValue("context");
- configurationHandler = new SAXConfigurationHandler();
- configurationHandler.startElement("", "configuration", "configuration", NOATTR);
+ configurationHandler = new SAXConfigurationHandler();
+
+ configurationHandler.startElement("", "constraint", "constraint", new AttributesImpl(attributes));
redirect = configurationHandler;
}
else if ("value".equals(name)) {
@@ -327,7 +329,7 @@
}
}
else if ("constraint".equals(name)) {
- configurationHandler.endElement("", "configuration", "configuration");
+ configurationHandler.endElement("", "constraint", "constraint");
if (constraintAliases.containsKey(constraintType)) {
List aliasConstraints = (List) constraintAliases.get(constraintType);
@@ -347,9 +349,11 @@
if (constraint instanceof Configurable) {
try {
- ((Configurable)constraint).configure(configurationHandler.getConfiguration());
+ ((Configurable)constraint).configure(configurationHandler.getConfiguration());
+ }
+ catch(Throwable t) {
+ getLogger().error("",t);
}
- catch(Throwable t) {};
}
if (constraint != null) {
1.3 +1 -1 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints/AbstractConstraint.java
Index: AbstractConstraint.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints/AbstractConstraint.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractConstraint.java 25 Mar 2002 23:23:54 -0000 1.2
+++ AbstractConstraint.java 26 Mar 2002 19:56:44 -0000 1.3
@@ -60,5 +60,5 @@
* @author: Torsten Curdt <tc...@dff.st>
*/
public abstract class AbstractConstraint extends AbstractLoggable implements Constraint, Component {
-
+ protected String id = null;
}
1.3 +40 -9 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints/ChoiceConstraint.java
Index: ChoiceConstraint.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints/ChoiceConstraint.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChoiceConstraint.java 25 Mar 2002 23:23:54 -0000 1.2
+++ ChoiceConstraint.java 26 Mar 2002 19:56:44 -0000 1.3
@@ -52,17 +52,16 @@
package org.apache.cocoon.precept.preceptors.easyrelax.constraints;
import org.apache.cocoon.precept.Context;
+import org.apache.cocoon.precept.ConfigurationHelper;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.thread.SingleThreaded;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
+import java.util.*;
/*
* @version: Mar 21, 2002
@@ -73,19 +72,34 @@
public Map validValuesDescription = new HashMap();
public void configure(Configuration configuration) throws ConfigurationException {
+ id = configuration.getAttribute("name");
+
+ getLogger().debug("configuring constraint [" + String.valueOf(id) + "]");
+
if (validValues.size() == 0) {
- validValues.add("linux"); validValuesDescription.put("linux","Linux");
- validValues.add("w2k"); validValuesDescription.put("w2k","Windows 2000");
+ Configuration[] choices = configuration.getChildren("choice");
+ for(int i=0;i<choices.length;i++) {
+ Configuration choice = choices[i];
+ String value = choice.getAttribute("value");
+ String valueDescription = choice.getValue();
+
+ getLogger().debug("registered choice [" + String.valueOf(value) + "] = [" + String.valueOf(valueDescription) + "]");
+
+ validValues.add(value);
+ validValuesDescription.put(value,valueDescription);
+ }
}
}
public boolean isSatisfiedBy(Object value, Context context ) {
- System.out.println("checking choice [" + String.valueOf(value) + "] contains [" + String.valueOf(validValues) + "]");
- return(validValues.contains(value));
+ boolean isValid = validValues.contains(value);
+ System.out.println("checking choice [" + String.valueOf(value) + "] contains [" + String.valueOf(validValues) + "] is " + isValid);
+ getLogger().debug("checking choice [" + String.valueOf(value) + "] contains [" + String.valueOf(validValues) + "] is " + isValid);
+ return(isValid);
}
public String getId() {
- return("os");
+ return(id);
}
public String getType() {
@@ -97,6 +111,23 @@
}
public void toSAX(ContentHandler handler) throws SAXException {
+ AttributesImpl attributes = new AttributesImpl();
+ attributes.addAttribute("","type","type","CDATA",getType());
+ attributes.addAttribute("","name","name","CDATA",id);
+
+ handler.startElement("","constraint","constraint",attributes);
+ for (Iterator it = validValues.iterator(); it.hasNext();) {
+ String value = (String) it.next();
+ String description = (String) validValuesDescription.get(value);
+
+ AttributesImpl choiceAttributes = new AttributesImpl();
+ choiceAttributes.addAttribute("","value","value","CDATA",value);
+
+ handler.startElement("","choice","choice",choiceAttributes);
+ handler.characters(description.toCharArray(),0,description.length());
+ handler.endElement("","choice","choice");
+ }
+ handler.endElement("","constraint","constraint");
}
}
1.3 +13 -5 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints/RegexprConstraint.java
Index: RegexprConstraint.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/precept/preceptors/easyrelax/constraints/RegexprConstraint.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RegexprConstraint.java 25 Mar 2002 23:23:54 -0000 1.2
+++ RegexprConstraint.java 26 Mar 2002 19:56:44 -0000 1.3
@@ -52,6 +52,7 @@
package org.apache.cocoon.precept.preceptors.easyrelax.constraints;
import org.apache.cocoon.precept.Context;
+import org.apache.cocoon.precept.ConfigurationHelper;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -71,7 +72,12 @@
private RE expression;
public void configure(Configuration configuration) throws ConfigurationException {
- expressionString = "^[a-zA-Z0-9]+[a-zA-Z0-9-_.]*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+$";
+ id = configuration.getAttribute("name");
+
+ expressionString = configuration.getValue();
+
+ getLogger().debug("expression [" + String.valueOf(expressionString) + "]");
+
try {
expression = new RE(expressionString);
}
@@ -81,12 +87,14 @@
}
public boolean isSatisfiedBy(Object value, Context context ) {
- System.out.println("checking regexpr [" + String.valueOf(value) + "] matches [" + String.valueOf(expressionString) + "]");
- return(expression.match(String.valueOf(value)));
+ boolean isValid = expression.match(String.valueOf(value));
+ System.out.println("checking regexpr [" + String.valueOf(value) + "] matches [" + String.valueOf(expressionString) + "] is " + isValid);
+ getLogger().debug("checking regexpr [" + String.valueOf(value) + "] matches [" + String.valueOf(expressionString) + "] is " + isValid);
+ return(isValid);
}
public String getId() {
- return("email");
+ return(id);
}
public String getType() {
@@ -94,7 +102,7 @@
}
public String toString() {
- return( String.valueOf(getType()) + "[" + String.valueOf(getId()) + "] -> [" + String.valueOf(expression) + "]");
+ return( String.valueOf(getType()) + "[" + String.valueOf(getId()) + "] -> [" + String.valueOf(expressionString) + "]");
}
public void toSAX(ContentHandler handler) throws SAXException {
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org