Author: andreas
Date: Wed Sep 7 05:39:17 2005
New Revision: 279311
URL: http://svn.apache.org/viewcvs?rev=279311&view=rev
Log:
Removed custom Lenya validation code, using Cocoon validation
components instead.
Added:
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java
lenya/trunk/src/java/org/apache/lenya/xml/Schema.java
lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java
Removed:
lenya/trunk/src/java/org/apache/lenya/xml/JingValidator.java
lenya/trunk/src/java/org/apache/lenya/xml/RelaxNG.java
lenya/trunk/src/java/org/apache/lenya/xml/Validator.java
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java
lenya/trunk/src/java/org/apache/lenya/lenya.roles
lenya/trunk/src/modules/links/config/module.xconf
lenya/trunk/src/modules/search/config/module.xconf
lenya/trunk/src/modules/xhtml/config/module.xconf
lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
lenya/trunk/src/webapp/lenya/pubs/blog/config/resourcetypes.xconf
lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/webdav/Put.java
lenya/trunk/src/webapp/lenya/pubs/default/modules/homepage/config/module.xconf
lenya/trunk/src/webapp/lenya/pubs/default/sitemap.xmap
Added:
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java?rev=279311&view=auto
==============================================================================
---
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java
(added)
+++
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java
Wed Sep 7 05:39:17 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.cocoon.components.modules.input;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import
org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.util.ServletHelper;
+
+/**
+ * Resource type module.
+ */
+public class ResourceTypeModule extends AbstractInputModule
implements Serviceable {
+
+ public Object getAttribute(String name, Configuration modeConf,
Map objectModel)
+ throws ConfigurationException {
+ Object value = null;
+
+ try {
+ Request request =
ObjectModelHelper.getRequest(objectModel);
+ Session session = RepositoryUtil.getSession(request,
getLogger());
+ DocumentIdentityMap docFactory = new
DocumentIdentityMap(session,
+ this.manager,
+ getLogger());
+ String webappUrl = ServletHelper.getWebappURI(request);
+ Document document = docFactory.getFromURL(webappUrl);
+ ResourceType resourceType = document.getResourceType();
+
+ if (name.startsWith("format-")) {
+ String[] steps = name.split("-");
+ String format = steps[1];
+ value = resourceType.getFormatURI(format);
+ }
+ else {
+ throw new ConfigurationException("Attribute [" +
name + "] not supported!");
+ }
+
+ } catch (Exception e) {
+ throw new ConfigurationException("Resolving attribute ["
+ name + "] failed: ", e);
+ } finally {
+ }
+
+ return value;
+ }
+
+ protected ServiceManager manager;
+
+ public void service(ServiceManager manager) throws
ServiceException {
+ this.manager = manager;
+ }
+
+}
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
---
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java
(original)
+++
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/FormsEditor.java
Wed Sep 7 05:39:17 2005
@@ -45,14 +45,13 @@
import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
-import org.apache.lenya.cms.publication.ResourceType;
import org.apache.lenya.cms.usecase.DocumentUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.cms.usecase.UsecaseMessage;
import org.apache.lenya.cms.usecase.xml.UsecaseErrorHandler;
import org.apache.lenya.cms.workflow.WorkflowUtil;
import org.apache.lenya.xml.DocumentHelper;
-import org.apache.lenya.xml.Validator;
+import org.apache.lenya.xml.ValidationUtil;
import org.apache.lenya.xml.XPath;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xml.utils.PrefixResolverDefault;
@@ -144,10 +143,6 @@
xmlSource = (ModifiableSource)
resolver.resolveURI(getSourceDocument().getSourceURI());
- ResourceType resourceType =
getSourceDocument().getResourceType();
- String schemaUri =
resourceType.getSchemaDefinitionSourceURI();
- schemaSource = resolver.resolveURI(schemaUri);
-
unnumberTagsXslSource =
resolver.resolveURI(unnumberTagsXslUri);
numberTagsXslSource = resolver.resolveURI(numberTagsXslUri);
@@ -157,7 +152,7 @@
return;
}
- save(resolver, xmlSource, schemaSource,
unnumberTagsXslSource, numberTagsXslSource);
+ save(resolver, xmlSource, unnumberTagsXslSource,
numberTagsXslSource);
if (hasErrors()) {
setParameter(VALIDATION_ERRORS, getErrorMessages());
@@ -194,10 +189,10 @@
protected void doExecute() throws Exception {
super.doExecute();
- +
List errors = (List) getParameter(VALIDATION_ERRORS);
if (errors != null) {
- for (Iterator i = errors.iterator(); i.hasNext(); ) {
+ for (Iterator i = errors.iterator(); i.hasNext();) {
UsecaseMessage message = (UsecaseMessage) i.next();
addErrorMessage(message.getMessage(),
message.getParameters());
}
@@ -208,7 +203,6 @@
* Save the Form
* @param resolver
* @param xmlSource
- * @param schemaSource
* @param unnumberTagsXslSource
* @param numberTagsXslSource
* @throws ProcessingException
@@ -222,7 +216,7 @@
* @throws TransformerConfigurationException
* @throws TransformerException
*/
- private void save(SourceResolver resolver, ModifiableSource
xmlSource, Source schemaSource,
+ private void save(SourceResolver resolver, ModifiableSource
xmlSource,
Source unnumberTagsXslSource, Source numberTagsXslSource)
throws ProcessingException,
FactoryConfigurationError, ParserConfigurationException,
IOException, SAXException,
XPathQueryConfigurationException, Exception,
MalformedURLException,
@@ -249,11 +243,6 @@
String editSelect = processElements(document, xUpdateQuery);
setParameter("editSelect", editSelect);
- // validate against relax ng after the updates
- if (!schemaSource.exists()) {
- throw new ProcessingException("Schema [" +
schemaSource.getURI() + "] does not exist.");
- }
-
Source validationSource = null;
Source unnumberTagsSource = null;
@@ -266,7 +255,21 @@
unnumberTagsSource = resolver.resolveURI(unnumberTagsUri);
checkModifiability(unnumberTagsSource);
- validateDocument(document, schemaSource,
unnumberTagsXslSource);
+ javax.xml.transform.Source transformXmlSource = new
DOMSource(document);
+ javax.xml.transform.Source transformXslSource = new
StreamSource(unnumberTagsXslSource.getInputStream());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ StreamResult unnumberXmlResult = new StreamResult(out);
+
+ TransformerFactory factory =
TransformerFactory.newInstance();
+ Transformer transformer =
factory.newTransformer(transformXslSource);
+ transformer.transform(transformXmlSource,
unnumberXmlResult);
+
+ ByteArrayInputStream in = new
ByteArrayInputStream(out.toByteArray());
+ Document doc = DocumentHelper.readDocument(in);
+
+ ValidationUtil.validate(this.manager, doc,
getSourceDocument().getResourceType()
+ .getSchema(), new UsecaseErrorHandler(this));
} finally {
if (validationSource != null) {
@@ -625,46 +628,6 @@
getLogger().debug(".remove() REMOVE Node: " + pname);
return "<xupdate:modifications
xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + pname
+ "</xupdate:modifications>";
- }
-
- /**
- * Validates a document.
- * @param document The document.
- * @param schema The schema source.
- * @param unnumberTagsXsl The source of the unnumber XSL
stylesheet.
- * @throws UsecaseException if an error occurs.
- */
- private void validateDocument(Document document, Source schema,
Source unnumberTagsXsl)
- throws UsecaseException {
-
- Validator validator = null;
- try {
- javax.xml.transform.Source xmlSource = new
DOMSource(document);
- javax.xml.transform.Source unnumberTagsXslSource = new
StreamSource(unnumberTagsXsl.getInputStream());
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- StreamResult unnumberXmlResult = new StreamResult(out);
-
- TransformerFactory factory =
TransformerFactory.newInstance();
- Transformer transformer =
factory.newTransformer(unnumberTagsXslSource);
- transformer.transform(xmlSource, unnumberXmlResult);
-
- ByteArrayInputStream in = new
ByteArrayInputStream(out.toByteArray());
- InputSource unnumberXmlInputSource = new InputSource(in);
- InputSource schemaInputSource =
SourceUtil.getInputSource(schema);
-
- validator = (Validator)
this.manager.lookup(Validator.ROLE);
- validator.validate(unnumberXmlInputSource,
- schemaInputSource,
- new UsecaseErrorHandler(this));
-
- } catch (Exception e) {
- throw new UsecaseException(e);
- } finally {
- if (validator != null) {
- this.manager.release(validator);
- }
- }
}
/**
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
---
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
(original)
+++
lenya/trunk/src/java/org/apache/lenya/cms/editors/forms/OneFormEditor.java
Wed Sep 7 05:39:17 2005
@@ -24,10 +24,8 @@
import java.io.Writer;
import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.Request;
import org.apache.excalibur.source.ModifiableSource;
-import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.publication.ResourceType;
import org.apache.lenya.cms.usecase.DocumentUsecase;
@@ -35,8 +33,9 @@
import org.apache.lenya.cms.usecase.xml.UsecaseErrorHandler;
import org.apache.lenya.cms.workflow.WorkflowUtil;
import org.apache.lenya.xml.DocumentHelper;
-import org.apache.lenya.xml.Validator;
-import org.xml.sax.InputSource;
+import org.apache.lenya.xml.Schema;
+import org.apache.lenya.xml.ValidationUtil;
+import org.w3c.dom.Document;
import org.xml.sax.SAXException;
/**
@@ -90,40 +89,27 @@
// Save file temporarily
- ResourceType resourceType =
getSourceDocument().getResourceType();
- String schemaUri = resourceType.getSchemaDefinitionSourceURI();
- Source schemaSource = null;
ModifiableSource xmlSource = null;
SourceResolver resolver = null;
- Validator validator = null;
try {
resolver = (SourceResolver)
this.manager.lookup(SourceResolver.ROLE);
xmlSource = (ModifiableSource)
resolver.resolveURI(getSourceDocument().getSourceURI());
saveXMLFile(encoding, content, xmlSource);
+ + Document xmlDoc = null;
- boolean wellFormed = false;
try {
-
DocumentHelper.readDocument(xmlSource.getInputStream());
- wellFormed = true;
+ xmlDoc =
DocumentHelper.readDocument(xmlSource.getInputStream());
} catch (SAXException e) {
addErrorMessage("error-document-form", new String[] {
e.getMessage() });
}
- if (wellFormed) {
- schemaSource = resolver.resolveURI(schemaUri);
- if (!schemaSource.exists()) {
- throw new IllegalArgumentException("The schema
[" + schemaSource.getURI()
- + "] does not exist.");
- }
-
- InputSource schemaInputSource =
SourceUtil.getInputSource(schemaSource);
- InputSource xmlInputSource =
SourceUtil.getInputSource(xmlSource);
-
- validator = (Validator)
this.manager.lookup(Validator.ROLE);
- validator.validate(xmlInputSource,
- schemaInputSource,
- new UsecaseErrorHandler(this));
-
+ if (xmlDoc != null) {
+ ResourceType resourceType =
getSourceDocument().getResourceType();
+ Schema schema = resourceType.getSchema();
+ +
ValidationUtil.validate(this.manager, xmlDoc, schema, new
UsecaseErrorHandler(this));
+ if (!hasErrors()) {
WorkflowUtil.invoke(this.manager,
getSession(),
@@ -135,16 +121,10 @@
} finally {
if (resolver != null) {
- if (schemaSource != null) {
- resolver.release(schemaSource);
- }
if (xmlSource != null) {
resolver.release(xmlSource);
}
this.manager.release(resolver);
- }
- if (validator != null) {
- this.manager.release(validator);
}
}
}
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
---
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java
(original)
+++
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java
Wed Sep 7 05:39:17 2005
@@ -14,9 +14,26 @@
* limitations under the License.
*
*/
+/*
+ * Copyright 1999-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
package org.apache.lenya.cms.publication;
import org.apache.lenya.cms.authoring.NodeCreatorInterface;
+import org.apache.lenya.xml.Schema;
/**
* @version $Id:$
@@ -37,7 +54,7 @@
/**
* @return The source URI of the RelaxNG schema.
*/
- String getSchemaDefinitionSourceURI();
+ Schema getSchema();
/**
* Returns an array of XPaths representing attributes to be
rewritten
@@ -61,4 +78,15 @@
* @param name The name of the resource type.
*/
void setName(String name);
+ + /**
+ * @return All supported formats.
+ */
+ String[] getFormats();
+ + /**
+ * @param format The format.
+ * @return The URI to get the formatted content at.
+ */
+ String getFormatURI(String format);
}
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
---
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java
(original)
+++
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java
Wed Sep 7 05:39:17 2005
@@ -17,7 +17,10 @@
package org.apache.lenya.cms.publication;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -29,6 +32,8 @@
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.lenya.cms.authoring.DefaultBranchCreator;
import org.apache.lenya.cms.authoring.NodeCreatorInterface;
+import org.apache.lenya.xml.Schema;
+import org.xml.sax.ErrorHandler;
/**
* Resource type.
@@ -44,8 +49,12 @@
protected static final String ELEMENT_REWRITE_ATTRIBUTE =
"link-attribute";
protected static final String ATTRIBUTE_XPATH = "xpath";
protected static final String SAMPLE_NAME = "sample-name";
+ protected static final String ELEMENT_FORMAT = "format";
+ protected static final String ATTRIBUTE_URI = "uri";
+ protected static final String ATTRIBUTE_NAME = "name";
+ protected static final String ATTRIBUTE_LANGUAGE = "language";
- private String schemaUri = null;
+ private Schema schema = null;
private String sampleUri = null;
private String[] linkAttributeXPaths;
private NodeCreatorInterface creator;
@@ -60,7 +69,9 @@
Configuration schemaConf =
config.getChild(SCHEMA_ELEMENT, false);
if (schemaConf != null) {
- this.schemaUri =
schemaConf.getAttribute(SRC_ATTRIBUTE);
+ String uri = schemaConf.getAttribute(SRC_ATTRIBUTE);
+ String language =
schemaConf.getAttribute(ATTRIBUTE_LANGUAGE);
+ this.schema = new Schema(language, uri);
}
Configuration creatorConf =
config.getChild(CREATOR_ELEMENT, false);
@@ -89,6 +100,14 @@
xPaths.add(xPath);
}
this.linkAttributeXPaths = (String[]) xPaths.toArray(new
String[xPaths.size()]);
+ + Configuration[] formatConfigs =
config.getChildren(ELEMENT_FORMAT);
+ for (int i = 0; i < formatConfigs.length; i++) {
+ String name =
formatConfigs[i].getAttribute(ATTRIBUTE_NAME);
+ String uri =
formatConfigs[i].getAttribute(ATTRIBUTE_URI);
+ this.formats.put(name, new Format(uri));
+ }
+ } catch (Exception e) {
throw new ConfigurationException("Configuring resource
type failed: ", e);
}
@@ -104,8 +123,8 @@
this.manager = manager;
}
- public String getSchemaDefinitionSourceURI() {
- return this.schemaUri;
+ public Schema getSchema() {
+ return this.schema;
}
public String[] getLinkAttributeXPaths() {
@@ -128,6 +147,41 @@
public String getName() {
return this.name;
+ }
+ + private Map formats = new HashMap();
+
+ public String[] getFormats() {
+ Set names = this.formats.keySet();
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+
+ public String getFormatURI(String format) {
+ return ((Format) this.formats.get(format)).getURI();
+ }
+ + /**
+ * A format.
+ */
+ public static class Format {
+ + private String uri;
+ + /**
+ * Ctor.
+ * @param uri The uri.
+ */
+ public Format(String uri) {
+ this.uri = uri;
+ }
+ + /**
+ * @return The uri.
+ */
+ public String getURI() {
+ return this.uri;
+ }
+ }
}
Modified: lenya/trunk/src/java/org/apache/lenya/lenya.roles
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/lenya.roles?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/java/org/apache/lenya/lenya.roles Wed Sep 7
05:39:17 2005
@@ -174,10 +174,6 @@
shorthand="publication-manager"
default-class="org.apache.lenya.cms.publication.PublicationManagerImpl"/>
- <role name="org.apache.lenya.xml.Validator"
- shorthand="validator"
- default-class="org.apache.lenya.xml.JingValidator"/>
- <role name="org.apache.lenya.cms.repository.NodeFactory"
shorthand="node-factory"
default-class="org.apache.lenya.cms.repository.SourceNodeFactory"/>
Added: lenya/trunk/src/java/org/apache/lenya/xml/Schema.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/xml/Schema.java?rev=279311&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/xml/Schema.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/xml/Schema.java Wed Sep 7
05:39:17 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+/*
+ * Copyright 1999-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.xml;
+
+/**
+ * Validation schema.
+ */
+public class Schema {
+
+ /**
+ * Ctor.
+ * @param language The language, as defined by
+ * org.apache.cocoon.components.validation.Validator.
+ * @param schemaUri The schema URI.
+ * @see org.apache.cocoon.components.validation.Validator
+ */
+ public Schema(String language, String schemaUri) {
+ this.language = language;
+ this.uri = schemaUri;
+ }
+
+ private String language;
+
+ private String uri;
+
+ /**
+ * @return The language.
+ * @see org.apache.cocoon.components.validation.Validator
+ */
+ public String getLanguage() {
+ return this.language;
+ }
+
+ /**
+ * @return The URI to read the schema from.
+ */
+ public String getURI() {
+ return this.uri;
+ }
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java?rev=279311&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java
(added)
+++ lenya/trunk/src/java/org/apache/lenya/xml/ValidationUtil.java Wed
Sep 7 05:39:17 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.xml;
+
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.components.validation.SchemaParser;
+import org.apache.cocoon.components.validation.Validator;
+import org.apache.cocoon.xml.dom.DOMStreamer;
+import org.apache.excalibur.xml.sax.XMLConsumer;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.publication.Document;
+import org.xml.sax.ErrorHandler;
+
+/**
+ * Validation utility.
+ */
+public class ValidationUtil {
+
+ /**
+ * @param manager The service manager.
+ * @param document The document to validate.
+ * @param handler The SAX error handler.
+ * @throws Exception if an error occurs.
+ */
+ public static void validate(ServiceManager manager, Document
document, ErrorHandler handler)
+ throws Exception {
+
+ org.w3c.dom.Document xmlDoc =
SourceUtil.readDOM(document.getSourceURI(), manager);
+ validate(manager, xmlDoc,
document.getResourceType().getSchema(), handler);
+
+ }
+
+ /**
+ * @param manager The service manager.
+ * @param xmlDoc The XML document.
+ * @param schema The schema to use.
+ * @param handler The SAX error handler.
+ * @throws Exception if an error occurs.
+ */
+ public static void validate(ServiceManager manager,
org.w3c.dom.Document xmlDoc, Schema schema,
+ ErrorHandler handler) throws Exception {
+
+ Validator validator = null;
+ SchemaParser parser = null;
+ try {
+ validator = (Validator) manager.lookup(Validator.ROLE);
+ parser = (SchemaParser)
validator.select(schema.getLanguage());
+ org.apache.cocoon.components.validation.Schema
validationSchema = parser.getSchema(schema.getURI());
+ XMLConsumer consumer =
validationSchema.newValidator(handler);
+
+ DOMStreamer streamer = new DOMStreamer(consumer);
+ streamer.stream(xmlDoc);
+
+ } finally {
+ if (validator != null) {
+ if (parser != null) {
+ validator.release(parser);
+ }
+ manager.release(validator);
+ }
+ }
+ }
+
+}
Modified: lenya/trunk/src/modules/links/config/module.xconf
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/modules/links/config/module.xconf?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- lenya/trunk/src/modules/links/config/module.xconf (original)
+++ lenya/trunk/src/modules/links/config/module.xconf Wed Sep 7
05:39:17 2005
@@ -22,10 +22,11 @@
<component-instance name="links"
logger="lenya.resourcetypes.links"
class="org.apache.lenya.cms.publication.ResourceTypeImpl">
- <schema src="fallback://lenya/modules/links/schema/links.rng"/>
+ <schema src="fallback://lenya/modules/links/schema/links.rng"
language="http://relaxng.org/ns/structure/0.9"/>
<creator src="org.apache.lenya.cms.authoring.DefaultBranchCreator">
<sample-name>fallback://lenya/modules/links/samples/links.xml</sample-name>
</creator>
+ <format name="xhtml" uri="cocoon://modules/links/xhtml.xml"/>
</component-instance>
</xconf>
Modified: lenya/trunk/src/modules/search/config/module.xconf
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/modules/search/config/module.xconf?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- lenya/trunk/src/modules/search/config/module.xconf (original)
+++ lenya/trunk/src/modules/search/config/module.xconf Wed Sep 7
05:39:17 2005
@@ -22,7 +22,7 @@
<component-instance name="search"
logger="lenya.resourcetypes.search"
class="org.apache.lenya.cms.publication.ResourceTypeImpl">
- <schema src="fallback://lenya/resources/schemas/search.rng"/>
+ <schema src="fallback://lenya/resources/schemas/search.rng"
language="http://relaxng.org/ns/structure/0.9"/>
<creator src="org.apache.lenya.cms.authoring.DefaultBranchCreator">
<sample-name>fallback://lenya/modules/search/samples/search.xml</sample-name>
</creator>
Modified: lenya/trunk/src/modules/xhtml/config/module.xconf
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/modules/xhtml/config/module.xconf?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- lenya/trunk/src/modules/xhtml/config/module.xconf (original)
+++ lenya/trunk/src/modules/xhtml/config/module.xconf Wed Sep 7
05:39:17 2005
@@ -22,11 +22,12 @@
<component-instance name="xhtml"
logger="lenya.resourcetypes.xhtml"
class="org.apache.lenya.cms.publication.ResourceTypeImpl">
- <schema src="fallback://lenya/modules/xhtml/schemas/xhtml.rng"/>
+ <schema src="fallback://lenya/modules/xhtml/schemas/xhtml.rng"
language="http://relaxng.org/ns/structure/0.9"/>
<creator src="org.apache.lenya.cms.authoring.DefaultBranchCreator">
<sample-name>fallback://lenya/modules/xhtml/samples/xhtml.xml</sample-name>
</creator>
<link-attribute xpath="//*[namespace-uri() =
'http://www.w3.org/1999/xhtml']/@href"/>
+ <format name="xhtml" uri="cocoon://modules/xhtml/xhtml.xml"/>
</component-instance>
</xconf>
Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Wed Sep 7
05:39:17 2005
@@ -117,6 +117,9 @@
<component-instance name="proxy-url"
logger="sitemap.modules.input.proxy-url"
class="org.apache.lenya.cms.cocoon.components.modules.input.ProxyUrlModule"/>
+ <component-instance name="resource-type"
logger="sitemap.modules.input.resource-type"
+
class="org.apache.lenya.cms.cocoon.components.modules.input.ResourceTypeModule"/>
+ </xsl:copy>
</xsl:template>
Modified:
lenya/trunk/src/webapp/lenya/pubs/blog/config/resourcetypes.xconf
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/blog/config/resourcetypes.xconf?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/blog/config/resourcetypes.xconf
(original)
+++ lenya/trunk/src/webapp/lenya/pubs/blog/config/resourcetypes.xconf
Wed Sep 7 05:39:17 2005
@@ -19,10 +19,10 @@
<xconf xpath="/cocoon/resource-types"
unless="/cocoon/resource-types/[EMAIL PROTECTED] = 'entry']">
- <component-instance name="entry"
+ <component-instance name="entry-backup"
logger="lenya.resourcetypes.entry"
class="org.apache.lenya.cms.publication.ResourceTypeImpl">
- <schema src="fallback://lenya/resources/schemas/entry.rng"/>
+ <schema src="fallback://lenya/resources/schemas/entry.rng"
language="http://relaxng.org/ns/structure/0.9"/>
<creator src="org.apache.lenya.cms.authoring.NewBlogEntryCreator">
<sample-name>fallback://lenya/resources/samples/entry.xml</sample-name>
</creator>
Modified:
lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
---
lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf
(original)
+++
lenya/trunk/src/webapp/lenya/pubs/default/config/publication.xconf
Wed Sep 7 05:39:17 2005
@@ -37,6 +37,7 @@
<module name="links"/>
<module name="homepage"/>
<module name="search"/>
+ <module name="blog"/>
<!--
For information about these settings, read
Modified:
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/webdav/Put.java
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/webdav/Put.java?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
---
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/webdav/Put.java
(original)
+++
lenya/trunk/src/webapp/lenya/pubs/default/java/src/org/apache/lenya/defaultpub/cms/usecases/webdav/Put.java
Wed Sep 7 05:39:17 2005
@@ -22,6 +22,7 @@
import java.util.Map;
import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
@@ -30,11 +31,11 @@
import org.apache.lenya.cms.publication.DocumentIdToPathMapper;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.publication.PublicationUtil;
import org.apache.lenya.cms.publication.ResourceType;
import org.apache.lenya.cms.publication.util.DocumentSet;
-import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.repository.Node;
import org.apache.lenya.cms.site.SiteStructure;
import org.apache.lenya.cms.site.SiteUtil;
@@ -42,9 +43,9 @@
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.cms.usecase.xml.UsecaseErrorHandler;
import org.apache.lenya.workflow.WorkflowManager;
-import org.apache.excalibur.source.Source;
-import org.xml.sax.InputSource;
-import org.apache.lenya.xml.Validator;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.Schema;
+import org.apache.lenya.xml.ValidationUtil;
/**
* Supports WebDAV PUT.
@@ -60,7 +61,6 @@
super.doExecute();
SourceResolver resolver = null;
WorkflowManager wfManager = null;
- Validator validator = null;
try {
resolver = (SourceResolver)
this.manager.lookup(SourceResolver.ROLE);
@@ -132,20 +132,10 @@
// validity check
ResourceType resourceType = doc.getResourceType();
- String schemaUri =
resourceType.getSchemaDefinitionSourceURI();
- Source schemaSource = resolver.resolveURI(schemaUri);
- if (!schemaSource.exists()) {
- throw new IllegalArgumentException("The schema
[" + schemaSource.getURI()
- + "] does not exist.");
- }
-
- InputSource schemaInputSource =
org.apache.cocoon.components.source.SourceUtil.getInputSource(schemaSource);
- InputSource xmlInputSource =
org.apache.cocoon.components.source.SourceUtil.getInputSource(tempSource);
-
- validator = (Validator)
this.manager.lookup(Validator.ROLE);
- validator.validate(xmlInputSource,
- schemaInputSource,
- new UsecaseErrorHandler(this));
+ Schema schema = resourceType.getSchema();
+ + org.w3c.dom.Document xmlDoc =
DocumentHelper.readDocument(tempSource.getInputStream());
+ ValidationUtil.validate(this.manager, xmlDoc,
schema, new UsecaseErrorHandler(this));
if (SourceUtil.exists(tempSourceUri, this.manager)) {
SourceUtil.copy(resolver, tempSourceUri,
sourceUri, true);
@@ -160,9 +150,6 @@
}
if (wfManager != null) {
this.manager.release(wfManager);
- }
- if (validator != null) {
- this.manager.release(validator);
}
}
}
Modified:
lenya/trunk/src/webapp/lenya/pubs/default/modules/homepage/config/module.xconf
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/modules/homepage/config/module.xconf?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
---
lenya/trunk/src/webapp/lenya/pubs/default/modules/homepage/config/module.xconf
(original)
+++
lenya/trunk/src/webapp/lenya/pubs/default/modules/homepage/config/module.xconf
Wed Sep 7 05:39:17 2005
@@ -22,11 +22,12 @@
<component-instance name="homepage"
logger="lenya.resourcetypes.homepage"
class="org.apache.lenya.cms.publication.ResourceTypeImpl">
- <schema
src="fallback://lenya/modules/homepage/schemas/homepage.rng"/>
+ <schema
src="fallback://lenya/modules/homepage/schemas/homepage.rng"
language="http://relaxng.org/ns/structure/0.9"/>
<creator src="org.apache.lenya.cms.authoring.DefaultBranchCreator">
<sample-name>homepage.xml</sample-name>
</creator>
<link-attribute xpath="//*[namespace-uri() =
'http://www.w3.org/1999/xhtml']/@href"/>
+ <format name="xhtml" uri="cocoon://modules/homepage/xhtml.xml"/>
</component-instance>
</xconf>
Modified: lenya/trunk/src/webapp/lenya/pubs/default/sitemap.xmap
URL:
http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/sitemap.xmap?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/sitemap.xmap (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/sitemap.xmap Wed Sep 7
05:39:17 2005
@@ -128,7 +128,10 @@
<map:part
src="cocoon://modules/sitetree/{2}/{3}/tabs/{5}.xml"/>
<map:part
src="cocoon://modules/sitetree/{2}/{3}/menu/{5}.xml"/>
<map:part
src="cocoon://modules/sitetree/{2}/{3}/search/{5}.xml"/>
+ <!--
<map:part
src="cocoon://modules/{page-envelope:document-type}/{1}.xml"/>
+ -->
+ <map:part src="{resource-type:format-xhtml}"/>
</map:aggregate>
<map:select type="resource-exists">
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]