You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by fi...@apache.org on 2006/03/24 09:23:38 UTC
svn commit: r388451 [3/4] - in /jackrabbit/branches/1.0:
contrib/bdb-persistence/ contrib/classloader/
contrib/jcr-ext/src/java/org/apache/jackrabbit/session/
contrib/jcr-ext/src/java/org/apache/jackrabbit/session/nodetype/
contrib/jcr-ext/src/java/org...
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder?rev=388451&r1=388450&r2=388451&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder Fri Mar 24 00:23:34 2006
@@ -1,22 +1,22 @@
-# Copyright 2004-2005 The Apache Software Foundation or its licensors,
-# as applicable.
-#
-# 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.
-
-#
-# This file lists all available query language implementations that are shipped
-# with Jackrabbit.
-#
-
-org.apache.jackrabbit.core.query.xpath.QueryBuilder
-org.apache.jackrabbit.core.query.sql.QueryBuilder
+# Copyright 2004-2005 The Apache Software Foundation or its licensors,
+# as applicable.
+#
+# 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.
+
+#
+# This file lists all available query language implementations that are shipped
+# with Jackrabbit.
+#
+
+org.apache.jackrabbit.core.query.xpath.QueryBuilder
+org.apache.jackrabbit.core.query.sql.QueryBuilder
Propchange: jackrabbit/branches/1.0/jackrabbit/src/main/java/META-INF/services/org.apache.jackrabbit.core.query.QueryTreeBuilder
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitRepository.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitRepository.java?rev=388451&r1=388450&r2=388451&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitRepository.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitRepository.java Fri Mar 24 00:23:34 2006
@@ -1,39 +1,39 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.jackrabbit.api;
-
-import javax.jcr.Repository;
-
-/**
- * The Jackrabbit repository interface. This interface contains the
- * Jackrabbit-specific extensions to the JCR {@link Repository} interface.
- */
-public interface JackrabbitRepository extends Repository {
-
- /**
- * Shuts down the repository. A Jackrabbit repository instance contains
- * a acquired resources and cached data that needs to be released and
- * persisted when the repository is no longer used. This method handles
- * all these shutdown tasks and <em>must</em> therefore be called by the
- * client application once the repository instance is no longer used.
- * <p>
- * Possible errors are logged rather than thrown as exceptions as there
- * is little that a client application could do in such a case.
- */
- void shutdown();
-
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.jackrabbit.api;
+
+import javax.jcr.Repository;
+
+/**
+ * The Jackrabbit repository interface. This interface contains the
+ * Jackrabbit-specific extensions to the JCR {@link Repository} interface.
+ */
+public interface JackrabbitRepository extends Repository {
+
+ /**
+ * Shuts down the repository. A Jackrabbit repository instance contains
+ * a acquired resources and cached data that needs to be released and
+ * persisted when the repository is no longer used. This method handles
+ * all these shutdown tasks and <em>must</em> therefore be called by the
+ * client application once the repository instance is no longer used.
+ * <p>
+ * Possible errors are logged rather than thrown as exceptions as there
+ * is little that a client application could do in such a case.
+ */
+ void shutdown();
+
+}
Propchange: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitRepository.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java?rev=388451&r1=388450&r2=388451&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java Fri Mar 24 00:23:34 2006
@@ -1,58 +1,58 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.jackrabbit.api;
-
-import org.xml.sax.InputSource;
-
-import javax.jcr.AccessDeniedException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Workspace;
-
-/**
- * The Jackrabbit workspace interface. This interface contains the
- * Jackrabbit-specific extensions to the JCR {@link Workspace} interface.
- */
-public interface JackrabbitWorkspace extends Workspace {
-
- /**
- * Creates a workspace with the given name.
- *
- * @param workspaceName name of the new workspace
- * @throws AccessDeniedException if the current session is not allowed to
- * create the workspace
- * @throws RepositoryException if a workspace with the given name
- * already exists or if another error occurs
- * @see #getAccessibleWorkspaceNames()
- */
- void createWorkspace(String workspaceName)
- throws AccessDeniedException, RepositoryException;
-
- /**
- * Creates a workspace with the given name and a workspace configuration
- * template.
- *
- * @param workspaceName name of the new workspace
- * @param workspaceTemplate the configuration template of the new workspace
- * @throws AccessDeniedException if the current session is not allowed to
- * create the workspace
- * @throws RepositoryException if a workspace with the given name
- * already exists or if another error occurs
- * @see #getAccessibleWorkspaceNames()
- */
- public void createWorkspace(String workspaceName, InputSource workspaceTemplate)
- throws AccessDeniedException, RepositoryException;
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.jackrabbit.api;
+
+import org.xml.sax.InputSource;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Workspace;
+
+/**
+ * The Jackrabbit workspace interface. This interface contains the
+ * Jackrabbit-specific extensions to the JCR {@link Workspace} interface.
+ */
+public interface JackrabbitWorkspace extends Workspace {
+
+ /**
+ * Creates a workspace with the given name.
+ *
+ * @param workspaceName name of the new workspace
+ * @throws AccessDeniedException if the current session is not allowed to
+ * create the workspace
+ * @throws RepositoryException if a workspace with the given name
+ * already exists or if another error occurs
+ * @see #getAccessibleWorkspaceNames()
+ */
+ void createWorkspace(String workspaceName)
+ throws AccessDeniedException, RepositoryException;
+
+ /**
+ * Creates a workspace with the given name and a workspace configuration
+ * template.
+ *
+ * @param workspaceName name of the new workspace
+ * @param workspaceTemplate the configuration template of the new workspace
+ * @throws AccessDeniedException if the current session is not allowed to
+ * create the workspace
+ * @throws RepositoryException if a workspace with the given name
+ * already exists or if another error occurs
+ * @see #getAccessibleWorkspaceNames()
+ */
+ public void createWorkspace(String workspaceName, InputSource workspaceTemplate)
+ throws AccessDeniedException, RepositoryException;
+}
Propchange: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/api/JackrabbitWorkspace.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/Constants.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/Constants.java?rev=388451&r1=388450&r2=388451&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/Constants.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/Constants.java Fri Mar 24 00:23:34 2006
@@ -1,96 +1,96 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.jackrabbit.core.nodetype.xml;
-
-/**
- * Name constants for the node type XML elements and attributes.
- */
-public interface Constants {
-
- /** Name of the node type definition root element. */
- String NODETYPES_ELEMENT = "nodeTypes";
-
- /** Name of the node type definition element. */
- String NODETYPE_ELEMENT = "nodeType";
-
- /** Name of the child node definition element. */
- String CHILDNODEDEFINITION_ELEMENT = "childNodeDefinition";
-
- /** Name of the property definition element. */
- String PROPERTYDEFINITION_ELEMENT = "propertyDefinition";
-
- /** Name of the <code>isMixin</code> attribute. */
- String ISMIXIN_ATTRIBUTE = "isMixin";
-
- /** Name of the <code>hasOrderableChildNodes</code> attribute. */
- String HASORDERABLECHILDNODES_ATTRIBUTE = "hasOrderableChildNodes";
-
- /** Name of the primary item name attribute. */
- String PRIMARYITEMNAME_ATTRIBUTE = "primaryItemName";
-
- /** Name of the supertypes element. */
- String SUPERTYPES_ELEMENT = "supertypes";
-
- /** Name of the supertype element. */
- String SUPERTYPE_ELEMENT = "supertype";
-
- /** Name of the <code>name</code> attribute. */
- String NAME_ATTRIBUTE = "name";
-
- /** Name of the <code>autoCreated</code> attribute. */
- String AUTOCREATED_ATTRIBUTE = "autoCreated";
-
- /** Name of the <code>mandatory</code> attribute. */
- String MANDATORY_ATTRIBUTE = "mandatory";
-
- /** Name of the <code>onParentVersion</code> attribute. */
- String ONPARENTVERSION_ATTRIBUTE = "onParentVersion";
-
- /** Name of the <code>protected</code> attribute. */
- String PROTECTED_ATTRIBUTE = "protected";
-
- /** Name of the required type attribute. */
- String REQUIREDTYPE_ATTRIBUTE = "requiredType";
-
- /** Name of the value constraints element. */
- String VALUECONSTRAINTS_ELEMENT = "valueConstraints";
-
- /** Name of the value constraint element. */
- String VALUECONSTRAINT_ELEMENT = "valueConstraint";
-
- /** Name of the default values element. */
- String DEFAULTVALUES_ELEMENT = "defaultValues";
-
- /** Name of the default value element. */
- String DEFAULTVALUE_ELEMENT = "defaultValue";
-
- /** Name of the <code>multiple</code> attribute. */
- String MULTIPLE_ATTRIBUTE = "multiple";
-
- /** Name of the required primary types element. */
- String REQUIREDPRIMARYTYPES_ELEMENT = "requiredPrimaryTypes";
-
- /** Name of the required primary type element. */
- String REQUIREDPRIMARYTYPE_ELEMENT = "requiredPrimaryType";
-
- /** Name of the default primary type attribute. */
- String DEFAULTPRIMARYTYPE_ATTRIBUTE = "defaultPrimaryType";
-
- /** Name of the <code>sameNameSiblings</code> attribute. */
- String SAMENAMESIBLINGS_ATTRIBUTE = "sameNameSiblings";
-
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.jackrabbit.core.nodetype.xml;
+
+/**
+ * Name constants for the node type XML elements and attributes.
+ */
+public interface Constants {
+
+ /** Name of the node type definition root element. */
+ String NODETYPES_ELEMENT = "nodeTypes";
+
+ /** Name of the node type definition element. */
+ String NODETYPE_ELEMENT = "nodeType";
+
+ /** Name of the child node definition element. */
+ String CHILDNODEDEFINITION_ELEMENT = "childNodeDefinition";
+
+ /** Name of the property definition element. */
+ String PROPERTYDEFINITION_ELEMENT = "propertyDefinition";
+
+ /** Name of the <code>isMixin</code> attribute. */
+ String ISMIXIN_ATTRIBUTE = "isMixin";
+
+ /** Name of the <code>hasOrderableChildNodes</code> attribute. */
+ String HASORDERABLECHILDNODES_ATTRIBUTE = "hasOrderableChildNodes";
+
+ /** Name of the primary item name attribute. */
+ String PRIMARYITEMNAME_ATTRIBUTE = "primaryItemName";
+
+ /** Name of the supertypes element. */
+ String SUPERTYPES_ELEMENT = "supertypes";
+
+ /** Name of the supertype element. */
+ String SUPERTYPE_ELEMENT = "supertype";
+
+ /** Name of the <code>name</code> attribute. */
+ String NAME_ATTRIBUTE = "name";
+
+ /** Name of the <code>autoCreated</code> attribute. */
+ String AUTOCREATED_ATTRIBUTE = "autoCreated";
+
+ /** Name of the <code>mandatory</code> attribute. */
+ String MANDATORY_ATTRIBUTE = "mandatory";
+
+ /** Name of the <code>onParentVersion</code> attribute. */
+ String ONPARENTVERSION_ATTRIBUTE = "onParentVersion";
+
+ /** Name of the <code>protected</code> attribute. */
+ String PROTECTED_ATTRIBUTE = "protected";
+
+ /** Name of the required type attribute. */
+ String REQUIREDTYPE_ATTRIBUTE = "requiredType";
+
+ /** Name of the value constraints element. */
+ String VALUECONSTRAINTS_ELEMENT = "valueConstraints";
+
+ /** Name of the value constraint element. */
+ String VALUECONSTRAINT_ELEMENT = "valueConstraint";
+
+ /** Name of the default values element. */
+ String DEFAULTVALUES_ELEMENT = "defaultValues";
+
+ /** Name of the default value element. */
+ String DEFAULTVALUE_ELEMENT = "defaultValue";
+
+ /** Name of the <code>multiple</code> attribute. */
+ String MULTIPLE_ATTRIBUTE = "multiple";
+
+ /** Name of the required primary types element. */
+ String REQUIREDPRIMARYTYPES_ELEMENT = "requiredPrimaryTypes";
+
+ /** Name of the required primary type element. */
+ String REQUIREDPRIMARYTYPE_ELEMENT = "requiredPrimaryType";
+
+ /** Name of the default primary type attribute. */
+ String DEFAULTPRIMARYTYPE_ATTRIBUTE = "defaultPrimaryType";
+
+ /** Name of the <code>sameNameSiblings</code> attribute. */
+ String SAMENAMESIBLINGS_ATTRIBUTE = "sameNameSiblings";
+
+}
Propchange: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/Constants.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java?rev=388451&r1=388450&r2=388451&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java Fri Mar 24 00:23:34 2006
@@ -1,335 +1,335 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.jackrabbit.core.nodetype.xml;
-
-import org.apache.jackrabbit.core.nodetype.InvalidConstraintException;
-import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
-import org.apache.jackrabbit.core.nodetype.ItemDef;
-import org.apache.jackrabbit.core.nodetype.NodeDef;
-import org.apache.jackrabbit.core.nodetype.NodeDefImpl;
-import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
-import org.apache.jackrabbit.core.nodetype.PropDef;
-import org.apache.jackrabbit.core.nodetype.PropDefImpl;
-import org.apache.jackrabbit.core.nodetype.ValueConstraint;
-import org.apache.jackrabbit.core.util.DOMWalker;
-import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.UnknownPrefixException;
-
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.version.OnParentVersionAction;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-import java.util.Vector;
-
-/**
- * Node type definition reader. This class is used to read the
- * persistent node type definition files used by Jackrabbit.
- */
-public class NodeTypeReader {
-
- /**
- * Reads a node type definition file. The file contents are read from
- * the given input stream and the parsed node type definitions are
- * returned.
- *
- * @param xml XML input stream
- * @return node type definitions
- * @throws IOException if the node type definitions
- * cannot be read
- * @throws InvalidNodeTypeDefException if the node type definition
- * format is invalid
- */
- public static NodeTypeDef[] read(InputStream xml)
- throws IOException, InvalidNodeTypeDefException {
- try {
- NodeTypeReader reader = new NodeTypeReader(xml);
- return reader.getNodeTypeDefs();
- } catch (IllegalNameException e) {
- throw new InvalidNodeTypeDefException(
- "Invalid namespace reference in a node type definition", e);
- } catch (UnknownPrefixException e) {
- throw new InvalidNodeTypeDefException(
- "Invalid namespace reference in a node type definition", e);
- }
- }
-
- /** The node type document walker. */
- private final DOMWalker walker;
-
- /** The namespaces associated with the node type XML document. */
- private final Properties namespaces;
-
- /** The namespace resolver. */
- private final NamespaceResolver resolver;
-
- /**
- * Creates a node type definition file reader.
- *
- * @param xml node type definition file
- * @throws IOException if the node type definition file cannot be read
- */
- public NodeTypeReader(InputStream xml) throws IOException {
- walker = new DOMWalker(xml);
- namespaces = walker.getNamespaces();
- resolver = new AdditionalNamespaceResolver(namespaces);
- }
-
- /**
- * Returns the namespaces declared in the node type definition
- * file.
- */
- public Properties getNamespaces() {
- return namespaces;
- }
-
- /**
- * Returns all node type definitions specified by node type elements
- * under the current element.
- *
- * @return node type definitions
- * @throws InvalidNodeTypeDefException if a definition is invalid
- * @throws IllegalNameException if a definition contains an
- * illegal name
- * @throws UnknownPrefixException if a definition contains an
- * unknown namespace prefix
- */
- public NodeTypeDef[] getNodeTypeDefs()
- throws InvalidNodeTypeDefException, IllegalNameException,
- UnknownPrefixException {
- Vector defs = new Vector();
- while (walker.iterateElements(Constants.NODETYPE_ELEMENT)) {
- defs.add(getNodeTypeDef());
- }
- return (NodeTypeDef[]) defs.toArray(new NodeTypeDef[defs.size()]);
- }
-
- /**
- * Returns the node type definition specified by the current element.
- *
- * @return node type definition
- * @throws InvalidNodeTypeDefException if the definition is invalid
- * @throws IllegalNameException if the definition contains an
- * illegal name
- * @throws UnknownPrefixException if the definition contains an
- * unknown namespace prefix
- */
- private NodeTypeDef getNodeTypeDef()
- throws InvalidNodeTypeDefException, IllegalNameException,
- UnknownPrefixException {
- NodeTypeDef type = new NodeTypeDef();
-
- type.setName(QName.fromJCRName(
- walker.getAttribute(Constants.NAME_ATTRIBUTE), resolver));
- type.setMixin(Boolean.valueOf(
- walker.getAttribute(Constants.ISMIXIN_ATTRIBUTE))
- .booleanValue());
- type.setOrderableChildNodes(Boolean.valueOf(
- walker.getAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE))
- .booleanValue());
- String primaryItemName =
- walker.getAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE);
- if (primaryItemName != null && primaryItemName.length() > 0) {
- type.setPrimaryItemName(
- QName.fromJCRName(primaryItemName, resolver));
- }
-
- // supertype declarations
- if (walker.enterElement(Constants.SUPERTYPES_ELEMENT)) {
- Vector supertypes = new Vector();
- while (walker.iterateElements(Constants.SUPERTYPE_ELEMENT)) {
- supertypes.add(
- QName.fromJCRName(walker.getContent(), resolver));
- }
- type.setSupertypes((QName[])
- supertypes.toArray(new QName[supertypes.size()]));
- walker.leaveElement();
- }
-
- // property definitions
- Vector properties = new Vector();
- while (walker.iterateElements(Constants.PROPERTYDEFINITION_ELEMENT)) {
- PropDefImpl def = getPropDef();
- def.setDeclaringNodeType(type.getName());
- properties.add(def);
- }
- type.setPropertyDefs((PropDef[])
- properties.toArray(new PropDef[properties.size()]));
-
- // child node definitions
- Vector nodes = new Vector();
- while (walker.iterateElements(Constants.CHILDNODEDEFINITION_ELEMENT)) {
- NodeDefImpl def = getChildNodeDef();
- def.setDeclaringNodeType(type.getName());
- nodes.add(def);
- }
- type.setChildNodeDefs((NodeDef[])
- nodes.toArray(new NodeDef[nodes.size()]));
-
- return type;
- }
-
- /**
- * Returns the property definition specified by the current element.
- *
- * @return property definition
- * @throws InvalidNodeTypeDefException if the definition is invalid
- * @throws IllegalNameException if the definition contains an
- * illegal name
- * @throws UnknownPrefixException if the definition contains an
- * unknown namespace prefix
- */
- private PropDefImpl getPropDef()
- throws InvalidNodeTypeDefException, IllegalNameException,
- UnknownPrefixException {
- PropDefImpl def = new PropDefImpl();
- String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
- if (name.equals("*")) {
- def.setName(ItemDef.ANY_NAME);
- } else {
- def.setName(QName.fromJCRName(name, resolver));
- }
-
- // simple attributes
- def.setAutoCreated(Boolean.valueOf(
- walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE))
- .booleanValue());
- def.setMandatory(Boolean.valueOf(
- walker.getAttribute(Constants.MANDATORY_ATTRIBUTE))
- .booleanValue());
- def.setProtected(Boolean.valueOf(
- walker.getAttribute(Constants.PROTECTED_ATTRIBUTE))
- .booleanValue());
- def.setOnParentVersion(OnParentVersionAction.valueFromName(
- walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
- def.setMultiple(Boolean.valueOf(
- walker.getAttribute(Constants.MULTIPLE_ATTRIBUTE))
- .booleanValue());
- def.setRequiredType(PropertyType.valueFromName(
- walker.getAttribute(Constants.REQUIREDTYPE_ATTRIBUTE)));
-
- // value constraints
- if (walker.enterElement(Constants.VALUECONSTRAINTS_ELEMENT)) {
- Vector constraints = new Vector();
- int type = def.getRequiredType();
- while (walker.iterateElements(Constants.VALUECONSTRAINT_ELEMENT)) {
- String constraint = walker.getContent();
- try {
- constraints.add(ValueConstraint.create(
- type, constraint.trim(), resolver));
- } catch (InvalidConstraintException e) {
- throw new InvalidNodeTypeDefException(
- "Invalid value constraint " + constraint, e);
- }
- }
- def.setValueConstraints((ValueConstraint[]) constraints.toArray(
- new ValueConstraint[constraints.size()]));
- walker.leaveElement();
- }
-
- // default values
- if (walker.enterElement(Constants.DEFAULTVALUES_ELEMENT)) {
- Vector values = new Vector();
- int type = def.getRequiredType();
- if (type == PropertyType.UNDEFINED) {
- type = PropertyType.STRING;
- }
- while (walker.iterateElements(Constants.DEFAULTVALUE_ELEMENT)) {
- String value = walker.getContent();
- try {
- values.add(InternalValue.create(value, type, resolver));
- } catch (RepositoryException e) {
- throw new InvalidNodeTypeDefException(
- "Unable to create default value: " + value, e);
- }
- }
- def.setDefaultValues((InternalValue[])
- values.toArray(new InternalValue[values.size()]));
- walker.leaveElement();
- }
-
- return def;
- }
-
- /**
- * Returns the child node definition specified by the current element.
- *
- * @return child node definition
- * @throws IllegalNameException if the definition contains an
- * illegal name
- * @throws UnknownPrefixException if the definition contains an
- * unknown namespace prefix
- */
- private NodeDefImpl getChildNodeDef()
- throws IllegalNameException, UnknownPrefixException {
- NodeDefImpl def = new NodeDefImpl();
- String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
- if (name.equals("*")) {
- def.setName(ItemDef.ANY_NAME);
- } else {
- def.setName(QName.fromJCRName(name, resolver));
- }
-
- // simple attributes
- def.setAutoCreated(Boolean.valueOf(
- walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE))
- .booleanValue());
- def.setMandatory(Boolean.valueOf(
- walker.getAttribute(Constants.MANDATORY_ATTRIBUTE))
- .booleanValue());
- def.setProtected(Boolean.valueOf(
- walker.getAttribute(Constants.PROTECTED_ATTRIBUTE))
- .booleanValue());
- def.setOnParentVersion(OnParentVersionAction.valueFromName(
- walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
- def.setAllowsSameNameSiblings(Boolean.valueOf(
- walker.getAttribute(Constants.SAMENAMESIBLINGS_ATTRIBUTE))
- .booleanValue());
-
- // default primary type
- String type =
- walker.getAttribute(Constants.DEFAULTPRIMARYTYPE_ATTRIBUTE);
- if (type != null && type.length() > 0) {
- def.setDefaultPrimaryType(QName.fromJCRName(type, resolver));
- }
-
- // required primary types
- if (walker.enterElement(Constants.REQUIREDPRIMARYTYPES_ELEMENT)) {
- Vector types = new Vector();
- while (walker.iterateElements(Constants.REQUIREDPRIMARYTYPE_ELEMENT)) {
- types.add(QName.fromJCRName(walker.getContent(), resolver));
- }
- def.setRequiredPrimaryTypes(
- (QName[]) types.toArray(new QName[types.size()]));
- walker.leaveElement();
- } else {
- /* Default to nt:base?
- throw new InvalidNodeTypeDefException(
- "Required primary type(s) not defined for child node "
- + def.getName() + " of node type "
- + def.getDeclaringNodeType());
- */
- }
-
- return def;
- }
-
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.jackrabbit.core.nodetype.xml;
+
+import org.apache.jackrabbit.core.nodetype.InvalidConstraintException;
+import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
+import org.apache.jackrabbit.core.nodetype.ItemDef;
+import org.apache.jackrabbit.core.nodetype.NodeDef;
+import org.apache.jackrabbit.core.nodetype.NodeDefImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.PropDef;
+import org.apache.jackrabbit.core.nodetype.PropDefImpl;
+import org.apache.jackrabbit.core.nodetype.ValueConstraint;
+import org.apache.jackrabbit.core.util.DOMWalker;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.name.IllegalNameException;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.UnknownPrefixException;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * Node type definition reader. This class is used to read the
+ * persistent node type definition files used by Jackrabbit.
+ */
+public class NodeTypeReader {
+
+ /**
+ * Reads a node type definition file. The file contents are read from
+ * the given input stream and the parsed node type definitions are
+ * returned.
+ *
+ * @param xml XML input stream
+ * @return node type definitions
+ * @throws IOException if the node type definitions
+ * cannot be read
+ * @throws InvalidNodeTypeDefException if the node type definition
+ * format is invalid
+ */
+ public static NodeTypeDef[] read(InputStream xml)
+ throws IOException, InvalidNodeTypeDefException {
+ try {
+ NodeTypeReader reader = new NodeTypeReader(xml);
+ return reader.getNodeTypeDefs();
+ } catch (IllegalNameException e) {
+ throw new InvalidNodeTypeDefException(
+ "Invalid namespace reference in a node type definition", e);
+ } catch (UnknownPrefixException e) {
+ throw new InvalidNodeTypeDefException(
+ "Invalid namespace reference in a node type definition", e);
+ }
+ }
+
+ /** The node type document walker. */
+ private final DOMWalker walker;
+
+ /** The namespaces associated with the node type XML document. */
+ private final Properties namespaces;
+
+ /** The namespace resolver. */
+ private final NamespaceResolver resolver;
+
+ /**
+ * Creates a node type definition file reader.
+ *
+ * @param xml node type definition file
+ * @throws IOException if the node type definition file cannot be read
+ */
+ public NodeTypeReader(InputStream xml) throws IOException {
+ walker = new DOMWalker(xml);
+ namespaces = walker.getNamespaces();
+ resolver = new AdditionalNamespaceResolver(namespaces);
+ }
+
+ /**
+ * Returns the namespaces declared in the node type definition
+ * file.
+ */
+ public Properties getNamespaces() {
+ return namespaces;
+ }
+
+ /**
+ * Returns all node type definitions specified by node type elements
+ * under the current element.
+ *
+ * @return node type definitions
+ * @throws InvalidNodeTypeDefException if a definition is invalid
+ * @throws IllegalNameException if a definition contains an
+ * illegal name
+ * @throws UnknownPrefixException if a definition contains an
+ * unknown namespace prefix
+ */
+ public NodeTypeDef[] getNodeTypeDefs()
+ throws InvalidNodeTypeDefException, IllegalNameException,
+ UnknownPrefixException {
+ Vector defs = new Vector();
+ while (walker.iterateElements(Constants.NODETYPE_ELEMENT)) {
+ defs.add(getNodeTypeDef());
+ }
+ return (NodeTypeDef[]) defs.toArray(new NodeTypeDef[defs.size()]);
+ }
+
+ /**
+ * Returns the node type definition specified by the current element.
+ *
+ * @return node type definition
+ * @throws InvalidNodeTypeDefException if the definition is invalid
+ * @throws IllegalNameException if the definition contains an
+ * illegal name
+ * @throws UnknownPrefixException if the definition contains an
+ * unknown namespace prefix
+ */
+ private NodeTypeDef getNodeTypeDef()
+ throws InvalidNodeTypeDefException, IllegalNameException,
+ UnknownPrefixException {
+ NodeTypeDef type = new NodeTypeDef();
+
+ type.setName(QName.fromJCRName(
+ walker.getAttribute(Constants.NAME_ATTRIBUTE), resolver));
+ type.setMixin(Boolean.valueOf(
+ walker.getAttribute(Constants.ISMIXIN_ATTRIBUTE))
+ .booleanValue());
+ type.setOrderableChildNodes(Boolean.valueOf(
+ walker.getAttribute(Constants.HASORDERABLECHILDNODES_ATTRIBUTE))
+ .booleanValue());
+ String primaryItemName =
+ walker.getAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE);
+ if (primaryItemName != null && primaryItemName.length() > 0) {
+ type.setPrimaryItemName(
+ QName.fromJCRName(primaryItemName, resolver));
+ }
+
+ // supertype declarations
+ if (walker.enterElement(Constants.SUPERTYPES_ELEMENT)) {
+ Vector supertypes = new Vector();
+ while (walker.iterateElements(Constants.SUPERTYPE_ELEMENT)) {
+ supertypes.add(
+ QName.fromJCRName(walker.getContent(), resolver));
+ }
+ type.setSupertypes((QName[])
+ supertypes.toArray(new QName[supertypes.size()]));
+ walker.leaveElement();
+ }
+
+ // property definitions
+ Vector properties = new Vector();
+ while (walker.iterateElements(Constants.PROPERTYDEFINITION_ELEMENT)) {
+ PropDefImpl def = getPropDef();
+ def.setDeclaringNodeType(type.getName());
+ properties.add(def);
+ }
+ type.setPropertyDefs((PropDef[])
+ properties.toArray(new PropDef[properties.size()]));
+
+ // child node definitions
+ Vector nodes = new Vector();
+ while (walker.iterateElements(Constants.CHILDNODEDEFINITION_ELEMENT)) {
+ NodeDefImpl def = getChildNodeDef();
+ def.setDeclaringNodeType(type.getName());
+ nodes.add(def);
+ }
+ type.setChildNodeDefs((NodeDef[])
+ nodes.toArray(new NodeDef[nodes.size()]));
+
+ return type;
+ }
+
+ /**
+ * Returns the property definition specified by the current element.
+ *
+ * @return property definition
+ * @throws InvalidNodeTypeDefException if the definition is invalid
+ * @throws IllegalNameException if the definition contains an
+ * illegal name
+ * @throws UnknownPrefixException if the definition contains an
+ * unknown namespace prefix
+ */
+ private PropDefImpl getPropDef()
+ throws InvalidNodeTypeDefException, IllegalNameException,
+ UnknownPrefixException {
+ PropDefImpl def = new PropDefImpl();
+ String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
+ if (name.equals("*")) {
+ def.setName(ItemDef.ANY_NAME);
+ } else {
+ def.setName(QName.fromJCRName(name, resolver));
+ }
+
+ // simple attributes
+ def.setAutoCreated(Boolean.valueOf(
+ walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE))
+ .booleanValue());
+ def.setMandatory(Boolean.valueOf(
+ walker.getAttribute(Constants.MANDATORY_ATTRIBUTE))
+ .booleanValue());
+ def.setProtected(Boolean.valueOf(
+ walker.getAttribute(Constants.PROTECTED_ATTRIBUTE))
+ .booleanValue());
+ def.setOnParentVersion(OnParentVersionAction.valueFromName(
+ walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
+ def.setMultiple(Boolean.valueOf(
+ walker.getAttribute(Constants.MULTIPLE_ATTRIBUTE))
+ .booleanValue());
+ def.setRequiredType(PropertyType.valueFromName(
+ walker.getAttribute(Constants.REQUIREDTYPE_ATTRIBUTE)));
+
+ // value constraints
+ if (walker.enterElement(Constants.VALUECONSTRAINTS_ELEMENT)) {
+ Vector constraints = new Vector();
+ int type = def.getRequiredType();
+ while (walker.iterateElements(Constants.VALUECONSTRAINT_ELEMENT)) {
+ String constraint = walker.getContent();
+ try {
+ constraints.add(ValueConstraint.create(
+ type, constraint.trim(), resolver));
+ } catch (InvalidConstraintException e) {
+ throw new InvalidNodeTypeDefException(
+ "Invalid value constraint " + constraint, e);
+ }
+ }
+ def.setValueConstraints((ValueConstraint[]) constraints.toArray(
+ new ValueConstraint[constraints.size()]));
+ walker.leaveElement();
+ }
+
+ // default values
+ if (walker.enterElement(Constants.DEFAULTVALUES_ELEMENT)) {
+ Vector values = new Vector();
+ int type = def.getRequiredType();
+ if (type == PropertyType.UNDEFINED) {
+ type = PropertyType.STRING;
+ }
+ while (walker.iterateElements(Constants.DEFAULTVALUE_ELEMENT)) {
+ String value = walker.getContent();
+ try {
+ values.add(InternalValue.create(value, type, resolver));
+ } catch (RepositoryException e) {
+ throw new InvalidNodeTypeDefException(
+ "Unable to create default value: " + value, e);
+ }
+ }
+ def.setDefaultValues((InternalValue[])
+ values.toArray(new InternalValue[values.size()]));
+ walker.leaveElement();
+ }
+
+ return def;
+ }
+
+ /**
+ * Returns the child node definition specified by the current element.
+ *
+ * @return child node definition
+ * @throws IllegalNameException if the definition contains an
+ * illegal name
+ * @throws UnknownPrefixException if the definition contains an
+ * unknown namespace prefix
+ */
+ private NodeDefImpl getChildNodeDef()
+ throws IllegalNameException, UnknownPrefixException {
+ NodeDefImpl def = new NodeDefImpl();
+ String name = walker.getAttribute(Constants.NAME_ATTRIBUTE);
+ if (name.equals("*")) {
+ def.setName(ItemDef.ANY_NAME);
+ } else {
+ def.setName(QName.fromJCRName(name, resolver));
+ }
+
+ // simple attributes
+ def.setAutoCreated(Boolean.valueOf(
+ walker.getAttribute(Constants.AUTOCREATED_ATTRIBUTE))
+ .booleanValue());
+ def.setMandatory(Boolean.valueOf(
+ walker.getAttribute(Constants.MANDATORY_ATTRIBUTE))
+ .booleanValue());
+ def.setProtected(Boolean.valueOf(
+ walker.getAttribute(Constants.PROTECTED_ATTRIBUTE))
+ .booleanValue());
+ def.setOnParentVersion(OnParentVersionAction.valueFromName(
+ walker.getAttribute(Constants.ONPARENTVERSION_ATTRIBUTE)));
+ def.setAllowsSameNameSiblings(Boolean.valueOf(
+ walker.getAttribute(Constants.SAMENAMESIBLINGS_ATTRIBUTE))
+ .booleanValue());
+
+ // default primary type
+ String type =
+ walker.getAttribute(Constants.DEFAULTPRIMARYTYPE_ATTRIBUTE);
+ if (type != null && type.length() > 0) {
+ def.setDefaultPrimaryType(QName.fromJCRName(type, resolver));
+ }
+
+ // required primary types
+ if (walker.enterElement(Constants.REQUIREDPRIMARYTYPES_ELEMENT)) {
+ Vector types = new Vector();
+ while (walker.iterateElements(Constants.REQUIREDPRIMARYTYPE_ELEMENT)) {
+ types.add(QName.fromJCRName(walker.getContent(), resolver));
+ }
+ def.setRequiredPrimaryTypes(
+ (QName[]) types.toArray(new QName[types.size()]));
+ walker.leaveElement();
+ } else {
+ /* Default to nt:base?
+ throw new InvalidNodeTypeDefException(
+ "Required primary type(s) not defined for child node "
+ + def.getName() + " of node type "
+ + def.getDeclaringNodeType());
+ */
+ }
+
+ return def;
+ }
+
+}
Propchange: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java?rev=388451&r1=388450&r2=388451&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java Fri Mar 24 00:23:34 2006
@@ -1,280 +1,280 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.jackrabbit.core.nodetype.xml;
-
-import org.apache.jackrabbit.core.nodetype.NodeDef;
-import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
-import org.apache.jackrabbit.core.nodetype.PropDef;
-import org.apache.jackrabbit.core.nodetype.ValueConstraint;
-import org.apache.jackrabbit.core.util.DOMBuilder;
-import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
-import org.apache.jackrabbit.name.QName;
-
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.version.OnParentVersionAction;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * Node type definition writer. This class is used to write the
- * persistent node type definition files used by Jackrabbit.
- */
-public final class NodeTypeWriter {
-
- /**
- * Writes a node type definition file. The file contents are written
- * to the given output stream and will contain the given node type
- * definitions. The given namespace registry is used for namespace
- * mappings.
- *
- * @param xml XML output stream
- * @param registry namespace registry
- * @param types node types
- * @throws IOException if the node type definitions cannot
- * be written
- * @throws RepositoryException on repository errors
- */
- public static void write(
- OutputStream xml, NodeTypeDef[] types, NamespaceRegistry registry)
- throws IOException, RepositoryException {
- try {
- NodeTypeWriter writer = new NodeTypeWriter(registry);
- for (int i = 0; i < types.length; i++) {
- writer.addNodeTypeDef(types[i]);
- }
- writer.write(xml);
- } catch (ParserConfigurationException e) {
- throw new IOException(e.getMessage());
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(
- "Invalid namespace reference in a node type definition", e);
- }
- }
-
- /** The node type document builder. */
- private final DOMBuilder builder;
-
- /** The namespace resolver. */
- private final NamespaceResolver resolver;
-
- /**
- * Creates a node type definition file writer. The given namespace
- * registry is used for the XML namespace bindings.
- *
- * @param registry namespace registry
- * @throws ParserConfigurationException if the node type definition
- * document cannot be created
- * @throws RepositoryException if the namespace mappings cannot
- * be retrieved from the registry
- */
- private NodeTypeWriter(NamespaceRegistry registry)
- throws ParserConfigurationException, RepositoryException {
- builder = new DOMBuilder(Constants.NODETYPES_ELEMENT);
-
- String[] prefixes = registry.getPrefixes();
- for (int i = 0; i < prefixes.length; i++) {
- if (!"".equals(prefixes[i])) {
- String uri = registry.getURI(prefixes[i]);
- builder.setAttribute("xmlns:" + prefixes[i], uri);
- }
- }
-
- resolver = new AdditionalNamespaceResolver(registry);
- }
-
- /**
- * Builds a node type definition element under the current element.
- *
- * @param def node type definition
- * @throws RepositoryException if the default property values
- * cannot be serialized
- * @throws NoPrefixDeclaredException if the node type definition contains
- * invalid namespace references
- */
- private void addNodeTypeDef(NodeTypeDef def)
- throws RepositoryException, NoPrefixDeclaredException {
- builder.startElement(Constants.NODETYPE_ELEMENT);
-
- // simple attributes
- builder.setAttribute(
- Constants.NAME_ATTRIBUTE, def.getName().toJCRName(resolver));
- builder.setAttribute(
- Constants.ISMIXIN_ATTRIBUTE, def.isMixin());
- builder.setAttribute(
- Constants.HASORDERABLECHILDNODES_ATTRIBUTE,
- def.hasOrderableChildNodes());
-
- // primary item name
- QName item = def.getPrimaryItemName();
- if (item != null) {
- builder.setAttribute(
- Constants.PRIMARYITEMNAME_ATTRIBUTE,
- item.toJCRName(resolver));
- } else {
- builder.setAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE, "");
- }
-
- // supertype declarations
- QName[] supertypes = def.getSupertypes();
- if (supertypes != null && supertypes.length > 0) {
- builder.startElement(Constants.SUPERTYPES_ELEMENT);
- for (int i = 0; i < supertypes.length; i++) {
- builder.addContentElement(
- Constants.SUPERTYPE_ELEMENT,
- supertypes[i].toJCRName(resolver));
- }
- builder.endElement();
- }
-
- // property definitions
- PropDef[] properties = def.getPropertyDefs();
- for (int i = 0; i < properties.length; i++) {
- addPropDef(properties[i]);
- }
-
- // child node definitions
- NodeDef[] nodes = def.getChildNodeDefs();
- for (int i = 0; i < nodes.length; i++) {
- addChildNodeDef(nodes[i]);
- }
-
- builder.endElement();
- }
-
- /**
- * Builds a property definition element under the current element.
- *
- * @param def property definition
- * @throws RepositoryException if the default values cannot
- * be serialized
- * @throws NoPrefixDeclaredException if the property definition contains
- * invalid namespace references
- */
- private void addPropDef(PropDef def)
- throws RepositoryException, NoPrefixDeclaredException {
- builder.startElement(Constants.PROPERTYDEFINITION_ELEMENT);
-
- // simple attributes
- builder.setAttribute(
- Constants.NAME_ATTRIBUTE, def.getName().toJCRName(resolver));
- builder.setAttribute(
- Constants.AUTOCREATED_ATTRIBUTE, def.isAutoCreated());
- builder.setAttribute(
- Constants.MANDATORY_ATTRIBUTE, def.isMandatory());
- builder.setAttribute(
- Constants.PROTECTED_ATTRIBUTE, def.isProtected());
- builder.setAttribute(
- Constants.ONPARENTVERSION_ATTRIBUTE,
- OnParentVersionAction.nameFromValue(def.getOnParentVersion()));
- builder.setAttribute(
- Constants.MULTIPLE_ATTRIBUTE, def.isMultiple());
- builder.setAttribute(
- Constants.REQUIREDTYPE_ATTRIBUTE,
- PropertyType.nameFromValue(def.getRequiredType()));
-
- // value constraints
- ValueConstraint[] constraints = def.getValueConstraints();
- if (constraints != null && constraints.length > 0) {
- builder.startElement(Constants.VALUECONSTRAINTS_ELEMENT);
- for (int i = 0; i < constraints.length; i++) {
- builder.addContentElement(
- Constants.VALUECONSTRAINT_ELEMENT,
- constraints[i].getDefinition(resolver));
- }
- builder.endElement();
- }
-
- // default values
- InternalValue[] defaults = def.getDefaultValues();
- if (defaults != null && defaults.length > 0) {
- builder.startElement(Constants.DEFAULTVALUES_ELEMENT);
- for (int i = 0; i < defaults.length; i++) {
- builder.addContentElement(
- Constants.DEFAULTVALUE_ELEMENT,
- defaults[i].toJCRValue(resolver).getString());
- }
- builder.endElement();
- }
-
- builder.endElement();
- }
-
- /**
- * Builds a child node definition element under the current element.
- *
- * @param def child node definition
- * @throws NoPrefixDeclaredException if the child node definition contains
- * invalid namespace references
- */
- private void addChildNodeDef(NodeDef def)
- throws NoPrefixDeclaredException {
- builder.startElement(Constants.CHILDNODEDEFINITION_ELEMENT);
-
- // simple attributes
- builder.setAttribute(
- Constants.NAME_ATTRIBUTE, def.getName().toJCRName(resolver));
- builder.setAttribute(
- Constants.AUTOCREATED_ATTRIBUTE, def.isAutoCreated());
- builder.setAttribute(
- Constants.MANDATORY_ATTRIBUTE, def.isMandatory());
- builder.setAttribute(
- Constants.PROTECTED_ATTRIBUTE, def.isProtected());
- builder.setAttribute(
- Constants.ONPARENTVERSION_ATTRIBUTE,
- OnParentVersionAction.nameFromValue(def.getOnParentVersion()));
- builder.setAttribute(
- Constants.SAMENAMESIBLINGS_ATTRIBUTE, def.allowsSameNameSiblings());
-
- // default primary type
- QName type = def.getDefaultPrimaryType();
- if (type != null) {
- builder.setAttribute(
- Constants.DEFAULTPRIMARYTYPE_ATTRIBUTE,
- type.toJCRName(resolver));
- } else {
- builder.setAttribute(Constants.DEFAULTPRIMARYTYPE_ATTRIBUTE, "");
- }
-
- // required primary types
- QName[] requiredTypes = def.getRequiredPrimaryTypes();
- builder.startElement(Constants.REQUIREDPRIMARYTYPES_ELEMENT);
- for (int i = 0; i < requiredTypes.length; i++) {
- builder.addContentElement(
- Constants.REQUIREDPRIMARYTYPE_ELEMENT,
- requiredTypes[i].toJCRName(resolver));
- }
- builder.endElement();
-
- builder.endElement();
- }
-
- /**
- * Writes the node type definition document to the given output stream.
- *
- * @param xml XML output stream
- * @throws IOException if the node type document could not be written
- */
- private void write(OutputStream xml) throws IOException {
- builder.write(xml);
- }
-
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.jackrabbit.core.nodetype.xml;
+
+import org.apache.jackrabbit.core.nodetype.NodeDef;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.PropDef;
+import org.apache.jackrabbit.core.nodetype.ValueConstraint;
+import org.apache.jackrabbit.core.util.DOMBuilder;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+import org.apache.jackrabbit.name.QName;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.OnParentVersionAction;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Node type definition writer. This class is used to write the
+ * persistent node type definition files used by Jackrabbit.
+ */
+public final class NodeTypeWriter {
+
+ /**
+ * Writes a node type definition file. The file contents are written
+ * to the given output stream and will contain the given node type
+ * definitions. The given namespace registry is used for namespace
+ * mappings.
+ *
+ * @param xml XML output stream
+ * @param registry namespace registry
+ * @param types node types
+ * @throws IOException if the node type definitions cannot
+ * be written
+ * @throws RepositoryException on repository errors
+ */
+ public static void write(
+ OutputStream xml, NodeTypeDef[] types, NamespaceRegistry registry)
+ throws IOException, RepositoryException {
+ try {
+ NodeTypeWriter writer = new NodeTypeWriter(registry);
+ for (int i = 0; i < types.length; i++) {
+ writer.addNodeTypeDef(types[i]);
+ }
+ writer.write(xml);
+ } catch (ParserConfigurationException e) {
+ throw new IOException(e.getMessage());
+ } catch (NoPrefixDeclaredException e) {
+ throw new RepositoryException(
+ "Invalid namespace reference in a node type definition", e);
+ }
+ }
+
+ /** The node type document builder. */
+ private final DOMBuilder builder;
+
+ /** The namespace resolver. */
+ private final NamespaceResolver resolver;
+
+ /**
+ * Creates a node type definition file writer. The given namespace
+ * registry is used for the XML namespace bindings.
+ *
+ * @param registry namespace registry
+ * @throws ParserConfigurationException if the node type definition
+ * document cannot be created
+ * @throws RepositoryException if the namespace mappings cannot
+ * be retrieved from the registry
+ */
+ private NodeTypeWriter(NamespaceRegistry registry)
+ throws ParserConfigurationException, RepositoryException {
+ builder = new DOMBuilder(Constants.NODETYPES_ELEMENT);
+
+ String[] prefixes = registry.getPrefixes();
+ for (int i = 0; i < prefixes.length; i++) {
+ if (!"".equals(prefixes[i])) {
+ String uri = registry.getURI(prefixes[i]);
+ builder.setAttribute("xmlns:" + prefixes[i], uri);
+ }
+ }
+
+ resolver = new AdditionalNamespaceResolver(registry);
+ }
+
+ /**
+ * Builds a node type definition element under the current element.
+ *
+ * @param def node type definition
+ * @throws RepositoryException if the default property values
+ * cannot be serialized
+ * @throws NoPrefixDeclaredException if the node type definition contains
+ * invalid namespace references
+ */
+ private void addNodeTypeDef(NodeTypeDef def)
+ throws RepositoryException, NoPrefixDeclaredException {
+ builder.startElement(Constants.NODETYPE_ELEMENT);
+
+ // simple attributes
+ builder.setAttribute(
+ Constants.NAME_ATTRIBUTE, def.getName().toJCRName(resolver));
+ builder.setAttribute(
+ Constants.ISMIXIN_ATTRIBUTE, def.isMixin());
+ builder.setAttribute(
+ Constants.HASORDERABLECHILDNODES_ATTRIBUTE,
+ def.hasOrderableChildNodes());
+
+ // primary item name
+ QName item = def.getPrimaryItemName();
+ if (item != null) {
+ builder.setAttribute(
+ Constants.PRIMARYITEMNAME_ATTRIBUTE,
+ item.toJCRName(resolver));
+ } else {
+ builder.setAttribute(Constants.PRIMARYITEMNAME_ATTRIBUTE, "");
+ }
+
+ // supertype declarations
+ QName[] supertypes = def.getSupertypes();
+ if (supertypes != null && supertypes.length > 0) {
+ builder.startElement(Constants.SUPERTYPES_ELEMENT);
+ for (int i = 0; i < supertypes.length; i++) {
+ builder.addContentElement(
+ Constants.SUPERTYPE_ELEMENT,
+ supertypes[i].toJCRName(resolver));
+ }
+ builder.endElement();
+ }
+
+ // property definitions
+ PropDef[] properties = def.getPropertyDefs();
+ for (int i = 0; i < properties.length; i++) {
+ addPropDef(properties[i]);
+ }
+
+ // child node definitions
+ NodeDef[] nodes = def.getChildNodeDefs();
+ for (int i = 0; i < nodes.length; i++) {
+ addChildNodeDef(nodes[i]);
+ }
+
+ builder.endElement();
+ }
+
+ /**
+ * Builds a property definition element under the current element.
+ *
+ * @param def property definition
+ * @throws RepositoryException if the default values cannot
+ * be serialized
+ * @throws NoPrefixDeclaredException if the property definition contains
+ * invalid namespace references
+ */
+ private void addPropDef(PropDef def)
+ throws RepositoryException, NoPrefixDeclaredException {
+ builder.startElement(Constants.PROPERTYDEFINITION_ELEMENT);
+
+ // simple attributes
+ builder.setAttribute(
+ Constants.NAME_ATTRIBUTE, def.getName().toJCRName(resolver));
+ builder.setAttribute(
+ Constants.AUTOCREATED_ATTRIBUTE, def.isAutoCreated());
+ builder.setAttribute(
+ Constants.MANDATORY_ATTRIBUTE, def.isMandatory());
+ builder.setAttribute(
+ Constants.PROTECTED_ATTRIBUTE, def.isProtected());
+ builder.setAttribute(
+ Constants.ONPARENTVERSION_ATTRIBUTE,
+ OnParentVersionAction.nameFromValue(def.getOnParentVersion()));
+ builder.setAttribute(
+ Constants.MULTIPLE_ATTRIBUTE, def.isMultiple());
+ builder.setAttribute(
+ Constants.REQUIREDTYPE_ATTRIBUTE,
+ PropertyType.nameFromValue(def.getRequiredType()));
+
+ // value constraints
+ ValueConstraint[] constraints = def.getValueConstraints();
+ if (constraints != null && constraints.length > 0) {
+ builder.startElement(Constants.VALUECONSTRAINTS_ELEMENT);
+ for (int i = 0; i < constraints.length; i++) {
+ builder.addContentElement(
+ Constants.VALUECONSTRAINT_ELEMENT,
+ constraints[i].getDefinition(resolver));
+ }
+ builder.endElement();
+ }
+
+ // default values
+ InternalValue[] defaults = def.getDefaultValues();
+ if (defaults != null && defaults.length > 0) {
+ builder.startElement(Constants.DEFAULTVALUES_ELEMENT);
+ for (int i = 0; i < defaults.length; i++) {
+ builder.addContentElement(
+ Constants.DEFAULTVALUE_ELEMENT,
+ defaults[i].toJCRValue(resolver).getString());
+ }
+ builder.endElement();
+ }
+
+ builder.endElement();
+ }
+
+ /**
+ * Builds a child node definition element under the current element.
+ *
+ * @param def child node definition
+ * @throws NoPrefixDeclaredException if the child node definition contains
+ * invalid namespace references
+ */
+ private void addChildNodeDef(NodeDef def)
+ throws NoPrefixDeclaredException {
+ builder.startElement(Constants.CHILDNODEDEFINITION_ELEMENT);
+
+ // simple attributes
+ builder.setAttribute(
+ Constants.NAME_ATTRIBUTE, def.getName().toJCRName(resolver));
+ builder.setAttribute(
+ Constants.AUTOCREATED_ATTRIBUTE, def.isAutoCreated());
+ builder.setAttribute(
+ Constants.MANDATORY_ATTRIBUTE, def.isMandatory());
+ builder.setAttribute(
+ Constants.PROTECTED_ATTRIBUTE, def.isProtected());
+ builder.setAttribute(
+ Constants.ONPARENTVERSION_ATTRIBUTE,
+ OnParentVersionAction.nameFromValue(def.getOnParentVersion()));
+ builder.setAttribute(
+ Constants.SAMENAMESIBLINGS_ATTRIBUTE, def.allowsSameNameSiblings());
+
+ // default primary type
+ QName type = def.getDefaultPrimaryType();
+ if (type != null) {
+ builder.setAttribute(
+ Constants.DEFAULTPRIMARYTYPE_ATTRIBUTE,
+ type.toJCRName(resolver));
+ } else {
+ builder.setAttribute(Constants.DEFAULTPRIMARYTYPE_ATTRIBUTE, "");
+ }
+
+ // required primary types
+ QName[] requiredTypes = def.getRequiredPrimaryTypes();
+ builder.startElement(Constants.REQUIREDPRIMARYTYPES_ELEMENT);
+ for (int i = 0; i < requiredTypes.length; i++) {
+ builder.addContentElement(
+ Constants.REQUIREDPRIMARYTYPE_ELEMENT,
+ requiredTypes[i].toJCRName(resolver));
+ }
+ builder.endElement();
+
+ builder.endElement();
+ }
+
+ /**
+ * Writes the node type definition document to the given output stream.
+ *
+ * @param xml XML output stream
+ * @throws IOException if the node type document could not be written
+ */
+ private void write(OutputStream xml) throws IOException {
+ builder.write(xml);
+ }
+
+}
Propchange: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/util/DOMBuilder.java
URL: http://svn.apache.org/viewcvs/jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/util/DOMBuilder.java?rev=388451&r1=388450&r2=388451&view=diff
==============================================================================
--- jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/util/DOMBuilder.java (original)
+++ jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/util/DOMBuilder.java Fri Mar 24 00:23:34 2006
@@ -1,156 +1,156 @@
-/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * 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.jackrabbit.core.util;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * Document builder class. This class provides an intuitive
- * interface for incrementally building DOM documents.
- */
-public final class DOMBuilder {
-
- /** Static factory for creating DOM DocumentBuilder instances. */
- private static final DocumentBuilderFactory BUILDER_FACTORY =
- DocumentBuilderFactory.newInstance();
-
- /** Static factory for creating document to output stream transformers. */
- private static final TransformerFactory TRANSFORMER_FACTORY =
- TransformerFactory.newInstance();
-
- /** The DOM document being built by this builder. */
- private final Document document;
-
- /** The current element. */
- private Element current;
-
- /**
- * Creates a builder for a new DOM document. A new DOM document is
- * instantiated and initialized to contain a root element with the given
- * name. The root element is set as the current element of this builder.
- *
- * @param name name of the root element
- * @throws ParserConfigurationException if a document cannot be created
- */
- public DOMBuilder(String name) throws ParserConfigurationException {
- DocumentBuilder builder = BUILDER_FACTORY.newDocumentBuilder();
- document = builder.newDocument();
- current = document.createElement(name);
- document.appendChild(current);
- }
-
-
- /**
- * Writes the document built by this builder into the given output stream.
- * This method is normally invoked only when the document is fully built.
- *
- * @param xml XML output stream
- * @throws IOException if the document could not be written
- */
- public void write(OutputStream xml) throws IOException {
- try {
- Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
- transformer.transform(
- new DOMSource(document), new StreamResult(xml));
- } catch (TransformerConfigurationException e) {
- throw new IOException(e.getMessage());
- } catch (TransformerException e) {
- throw new IOException(e.getMessage());
- }
- }
-
- /**
- * Creates a new element with the given name as the child of the
- * current element and makes the created element current. The
- * {@link #endElement() endElement} method needs to be called
- * to return back to the original element.
- *
- * @param name name of the new element
- */
- public void startElement(String name) {
- Element element = document.createElement(name);
- current.appendChild(element);
- current = element;
- }
-
- /**
- * Makes the parent element current. This method should be invoked
- * after a child element created with the
- * {@link #startElement(String) startElement} method has been fully
- * built.
- */
- public void endElement() {
- current = (Element) current.getParentNode();
- }
-
- /**
- * Sets the named attribute of the current element.
- *
- * @param name attribute name
- * @param value attribute value
- */
- public void setAttribute(String name, String value) {
- current.setAttribute(name, value);
- }
-
- /**
- * Sets the named boolean attribute of the current element.
- *
- * @param name attribute name
- * @param value boolean attribute value
- */
- public void setAttribute(String name, boolean value) {
- setAttribute(name, String.valueOf(value));
- }
-
- /**
- * Adds the given string as text content to the current element.
- *
- * @param content text content
- */
- public void addContent(String content) {
- current.appendChild(document.createTextNode(content));
- }
-
- /**
- * Adds a new child element with the given name and text content.
- * The created element will contain no attributes and no child elements
- * of its own.
- *
- * @param name child element name
- * @param content child element content
- */
- public void addContentElement(String name, String content) {
- startElement(name);
- addContent(content);
- endElement();
- }
-
-}
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * 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.jackrabbit.core.util;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Document builder class. This class provides an intuitive
+ * interface for incrementally building DOM documents.
+ */
+public final class DOMBuilder {
+
+ /** Static factory for creating DOM DocumentBuilder instances. */
+ private static final DocumentBuilderFactory BUILDER_FACTORY =
+ DocumentBuilderFactory.newInstance();
+
+ /** Static factory for creating document to output stream transformers. */
+ private static final TransformerFactory TRANSFORMER_FACTORY =
+ TransformerFactory.newInstance();
+
+ /** The DOM document being built by this builder. */
+ private final Document document;
+
+ /** The current element. */
+ private Element current;
+
+ /**
+ * Creates a builder for a new DOM document. A new DOM document is
+ * instantiated and initialized to contain a root element with the given
+ * name. The root element is set as the current element of this builder.
+ *
+ * @param name name of the root element
+ * @throws ParserConfigurationException if a document cannot be created
+ */
+ public DOMBuilder(String name) throws ParserConfigurationException {
+ DocumentBuilder builder = BUILDER_FACTORY.newDocumentBuilder();
+ document = builder.newDocument();
+ current = document.createElement(name);
+ document.appendChild(current);
+ }
+
+
+ /**
+ * Writes the document built by this builder into the given output stream.
+ * This method is normally invoked only when the document is fully built.
+ *
+ * @param xml XML output stream
+ * @throws IOException if the document could not be written
+ */
+ public void write(OutputStream xml) throws IOException {
+ try {
+ Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
+ transformer.transform(
+ new DOMSource(document), new StreamResult(xml));
+ } catch (TransformerConfigurationException e) {
+ throw new IOException(e.getMessage());
+ } catch (TransformerException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ /**
+ * Creates a new element with the given name as the child of the
+ * current element and makes the created element current. The
+ * {@link #endElement() endElement} method needs to be called
+ * to return back to the original element.
+ *
+ * @param name name of the new element
+ */
+ public void startElement(String name) {
+ Element element = document.createElement(name);
+ current.appendChild(element);
+ current = element;
+ }
+
+ /**
+ * Makes the parent element current. This method should be invoked
+ * after a child element created with the
+ * {@link #startElement(String) startElement} method has been fully
+ * built.
+ */
+ public void endElement() {
+ current = (Element) current.getParentNode();
+ }
+
+ /**
+ * Sets the named attribute of the current element.
+ *
+ * @param name attribute name
+ * @param value attribute value
+ */
+ public void setAttribute(String name, String value) {
+ current.setAttribute(name, value);
+ }
+
+ /**
+ * Sets the named boolean attribute of the current element.
+ *
+ * @param name attribute name
+ * @param value boolean attribute value
+ */
+ public void setAttribute(String name, boolean value) {
+ setAttribute(name, String.valueOf(value));
+ }
+
+ /**
+ * Adds the given string as text content to the current element.
+ *
+ * @param content text content
+ */
+ public void addContent(String content) {
+ current.appendChild(document.createTextNode(content));
+ }
+
+ /**
+ * Adds a new child element with the given name and text content.
+ * The created element will contain no attributes and no child elements
+ * of its own.
+ *
+ * @param name child element name
+ * @param content child element content
+ */
+ public void addContentElement(String name, String content) {
+ startElement(name);
+ addContent(content);
+ endElement();
+ }
+
+}
Propchange: jackrabbit/branches/1.0/jackrabbit/src/main/java/org/apache/jackrabbit/core/util/DOMBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native