You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/05/03 13:53:20 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/common XMLUnmarshaller.java
juergen 02/05/03 04:53:20
Modified: src/share/org/apache/slide/common XMLUnmarshaller.java
Log:
if in the domain file no revision element was specified, the init process did create the structure only. Now it creates a (simple) NRDs and a NRD, as if <revision/> would be specified.
Dirk, you had the file edited, could you please merge? (some imports, 5 lines and a method added)
Revision Changes Path
1.22 +101 -42 jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java
Index: XMLUnmarshaller.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- XMLUnmarshaller.java 25 Apr 2002 21:15:10 -0000 1.21
+++ XMLUnmarshaller.java 3 May 2002 11:53:20 -0000 1.22
@@ -1,13 +1,13 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java,v 1.21 2002/04/25 21:15:10 jericho Exp $
- * $Revision: 1.21 $
- * $Date: 2002/04/25 21:15:10 $
+ * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/XMLUnmarshaller.java,v 1.22 2002/05/03 11:53:20 juergen Exp $
+ * $Revision: 1.22 $
+ * $Date: 2002/05/03 11:53:20 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -15,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -23,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Slide", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -59,7 +59,7 @@
*
* [Additional notices, if required by prior licensing conditions]
*
- */
+ */
package org.apache.slide.common;
@@ -70,6 +70,8 @@
import java.util.Date;
import java.io.Reader;
import java.io.Writer;
+import java.io.StringReader;
+import java.io.IOException;
import org.apache.slide.structure.*;
import org.apache.slide.content.*;
import org.apache.slide.lock.*;
@@ -79,11 +81,24 @@
import org.apache.slide.util.conf.ConfigurationException;
import org.apache.slide.util.logger.Logger;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.xml.sax.*;
+import org.xml.sax.helpers.*;
+
+
+import org.apache.slide.util.conf.Configuration;
+import org.apache.slide.util.conf.ConfigurationElement;
+import org.apache.slide.util.conf.Populate;
+import org.apache.slide.util.conf.ConfigurationException;
+
+
+
/**
* XMLUnmarshaller class.
- *
+ *
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.21 $
+ * @version $Revision: 1.22 $
*/
public final class XMLUnmarshaller {
@@ -94,21 +109,21 @@
/**
* Import data from Avalon configuration object.
- *
+ *
* @param token CredentialsToken, used for access to the namespace
* @param dataConfiguration Configuration object
- * @exception ConfigurationException Something went wrong during the
+ * @exception ConfigurationException Something went wrong during the
* reading of the XML
* @exception UnknownObjectClassException Object class not found
* @exception ServiceAccessException Error accessing service
*/
- public static void unmarshal(NamespaceAccessToken accessToken,
- SlideToken token,
- Configuration dataConfiguration)
- throws ConfigurationException, UnknownObjectClassException,
+ public static void unmarshal(NamespaceAccessToken accessToken,
+ SlideToken token,
+ Configuration dataConfiguration)
+ throws ConfigurationException, UnknownObjectClassException,
ServiceAccessException {
- loadObjectNode(accessToken, token,
+ loadObjectNode(accessToken, token,
dataConfiguration.getConfiguration("objectnode"));
}
@@ -119,19 +134,19 @@
/**
* Loads a Slide Object.
- *
+ *
* @param token Credentials token
* @param objectDefinition Configuration object
- * @exception ServiceAccessException Object creation failed because
+ * @exception ServiceAccessException Object creation failed because
* a data access error occured
* @exception UnknownObjectClassException Object class not found
- * @exception ConfigurationException Something went wrong during the
+ * @exception ConfigurationException Something went wrong during the
* reading of the XML
*/
private static void loadObjectNode
- (NamespaceAccessToken accessToken, SlideToken token,
+ (NamespaceAccessToken accessToken, SlideToken token,
Configuration objectDefinition)
- throws ServiceAccessException, ConfigurationException,
+ throws ServiceAccessException, ConfigurationException,
UnknownObjectClassException {
String className = objectDefinition.getAttribute("classname");
@@ -159,7 +174,7 @@
// Instantiation failed for some reason
throw new UnknownObjectClassException(className);
} catch(IllegalAccessException e) {
- // The initializer could not be called because
+ // The initializer could not be called because
// of access restrictions
throw new UnknownObjectClassException(className);
}
@@ -170,10 +185,10 @@
try {
if (object instanceof LinkNode) {
- String linkedUri =
+ String linkedUri =
objectDefinition.getAttribute("linkedUri");
accessToken.getStructureHelper().createLink
- (token, (LinkNode) object, uri,
+ (token, (LinkNode) object, uri,
new SubjectNode(linkedUri));
} else {
accessToken.getStructureHelper().create
@@ -189,11 +204,11 @@
}
// Retrieving the list of permissions on the object
- Enumeration permissionDefinitions =
+ Enumeration permissionDefinitions =
objectDefinition.getConfigurations("permission");
// We've made sure that the object exists.
- // We now parse the permissions definition list, adding each
+ // We now parse the permissions definition list, adding each
// permission to the object's permission list.
while (permissionDefinitions.hasMoreElements()) {
@@ -201,7 +216,7 @@
(Configuration) permissionDefinitions.nextElement();
// Create the NodePermission object matching the Castor object
- String subjectUri =
+ String subjectUri =
permissionDefinition.getAttribute("subject");
String actionUri =
@@ -237,19 +252,26 @@
}
// Retrieve the list of revisions of the object
- Enumeration revisionDefinitions =
+ Enumeration revisionDefinitions =
objectDefinition.getConfigurations("revision");
+ boolean revisionDefinitionsFound = false;
// We parse the revision definition list
while (revisionDefinitions.hasMoreElements()) {
- Configuration revisionDefinition =
+ revisionDefinitionsFound = true;
+ Configuration revisionDefinition =
(Configuration) revisionDefinitions.nextElement();
- loadObjectRevision(accessToken, token, uri,
+ loadObjectRevision(accessToken, token, uri,
revisionDefinition);
}
+ if (!revisionDefinitionsFound) {
+ loadDefaultObjectRevision(accessToken, token, uri);
+ }
+
+
} catch (ObjectNotFoundException e) {
// Should NEVER happen
accessToken.getLogger().log(e,LOG_CHANNEL,Logger.WARNING);
@@ -268,11 +290,11 @@
LOG_CHANNEL,Logger.INFO);
}
- Enumeration childConfigurations =
+ Enumeration childConfigurations =
objectDefinition.getConfigurations("objectnode");
while(childConfigurations.hasMoreElements()) {
- Configuration childConfiguration =
+ Configuration childConfiguration =
(Configuration) childConfigurations.nextElement();
loadObjectNode(accessToken, token, childConfiguration);
}
@@ -280,19 +302,56 @@
}
+
+ /**
+ * Create the SlideProperties object associated with a ObjectNode.
+ *
+ * @param slideObject ObjectNode
+ * @param propertiesDef Castor object describing the properties associated
+ * with the ObjectNode
+ * @exception SlideException A data access error occured
+ */
+ private static void loadDefaultObjectRevision(NamespaceAccessToken accessToken,
+ SlideToken token, String uri)
+ throws ServiceAccessException, ConfigurationException,
+ AccessDeniedException, ObjectNotFoundException,
+ LinkedObjectNotFoundException {
+
+
+ try
+ {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(false);
+ factory.setValidating(false);
+ SAXParser parser = factory.newSAXParser();
+ Populate pop = new Populate();
+ Configuration slideConfiguration =
+ new ConfigurationElement(
+ pop.load(
+ new InputSource(
+ new StringReader("<revision/>")), parser.getXMLReader()));
+ loadObjectRevision(accessToken, token, uri, slideConfiguration);
+ }
+ catch (IOException e) { e.printStackTrace(); }
+ catch (SAXException e) { e.printStackTrace(); }
+ catch (javax.xml.parsers.ParserConfigurationException e) {e.printStackTrace(); }
+ }
+
+
+
/**
* Create the SlideProperties object associated with a ObjectNode.
- *
+ *
* @param slideObject ObjectNode
- * @param propertiesDef Castor object describing the properties associated
+ * @param propertiesDef Castor object describing the properties associated
* with the ObjectNode
* @exception SlideException A data access error occured
*/
- private static void loadObjectRevision(NamespaceAccessToken accessToken,
+ private static void loadObjectRevision(NamespaceAccessToken accessToken,
SlideToken token, String uri,
Configuration revisionDefinition)
- throws ServiceAccessException, ConfigurationException,
- AccessDeniedException, ObjectNotFoundException,
+ throws ServiceAccessException, ConfigurationException,
+ AccessDeniedException, ObjectNotFoundException,
LinkedObjectNotFoundException {
// Retrieving the list of properties
@@ -312,7 +371,7 @@
} catch (ObjectLockedException e) {
// Ignore
}
- if ((revisionDescriptors != null)
+ if ((revisionDescriptors != null)
&& (revisionDescriptors.hasRevisions())) {
try {
revisionDescriptor = accessToken.getContentHelper().retrieve
@@ -328,7 +387,7 @@
}
while (propertyDefinitions.hasMoreElements()) {
- Configuration propertyDefinition =
+ Configuration propertyDefinition =
(Configuration) propertyDefinitions.nextElement();
String propertyName = propertyDefinition.getAttribute("name");
String propertyValue = propertyDefinition.getValue();
@@ -343,7 +402,7 @@
NodeRevisionContent revisionContent = null;
- if ((revisionDescriptors != null)
+ if ((revisionDescriptors != null)
&& (revisionDescriptors.hasRevisions())) {
try {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>