You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2005/04/07 22:03:42 UTC
svn commit: r160449 - in
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config:
ConfigurationParser.java RepositoryConfig.java
Author: jukka
Date: Thu Apr 7 13:03:40 2005
New Revision: 160449
URL: http://svn.apache.org/viewcvs?view=rev&rev=160449
Log:
JCR-54: Switched from JDOM to standard DOM in Jackrabbit configuration handling.
Modified:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java?view=diff&r1=160448&r2=160449
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java Thu Apr 7 13:03:40 2005
@@ -18,14 +18,18 @@
import java.io.File;
import java.io.IOException;
-import java.util.Iterator;
import java.util.Properties;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
/**
* Configuration parser. This class is used to parse the repository and
@@ -306,23 +310,28 @@
*/
private SearchConfig parseSearchConfig(Element parent)
throws ConfigurationException {
- Element element = parent.getChild(SEARCH_INDEX_ELEMENT);
- if (element != null) {
- // Search implementation class
- String className =
- getAttribute(element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
-
- // Search parameters
- Properties parameters = parseParameters(element);
-
- // File system implementation
- FileSystemConfig fsc = new FileSystemConfig(
- parseBeanConfig(element, FILE_SYSTEM_ELEMENT));
+ NodeList children = parent.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE
+ && SEARCH_INDEX_ELEMENT.equals(child.getNodeName())) {
+ Element element = (Element) child;
+
+ // Search implementation class
+ String className = getAttribute(
+ element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
+
+ // Search parameters
+ Properties parameters = parseParameters(element);
+
+ // File system implementation
+ FileSystemConfig fsc = new FileSystemConfig(
+ parseBeanConfig(element, FILE_SYSTEM_ELEMENT));
- return new SearchConfig(className, parameters, fsc);
- } else {
- return null;
+ return new SearchConfig(className, parameters, fsc);
+ }
}
+ return null;
}
/**
@@ -416,18 +425,22 @@
throws ConfigurationException {
Properties parameters = new Properties();
- Iterator iterator = element.getChildren(PARAM_ELEMENT).iterator();
- while (iterator.hasNext()) {
- Element parameter = (Element) iterator.next();
- String name = parameter.getAttributeValue(NAME_ATTRIBUTE);
- if (name == null) {
- throw new ConfigurationException("Parameter name not set.");
- }
- String value = parameter.getAttributeValue(VALUE_ATTRIBUTE);
- if (value == null) {
- throw new ConfigurationException("Parameter value not set.");
+ NodeList children = element.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE
+ && PARAM_ELEMENT.equals(child.getNodeName())) {
+ Element parameter = (Element) child;
+ String name = parameter.getAttribute(NAME_ATTRIBUTE);
+ if (name == null) {
+ throw new ConfigurationException("Parameter name not set");
+ }
+ String value = parameter.getAttribute(VALUE_ATTRIBUTE);
+ if (value == null) {
+ throw new ConfigurationException("Parameter value not set");
+ }
+ parameters.put(name, replaceVariables(value));
}
- parameters.put(name, replaceVariables(value));
}
return parameters;
@@ -487,11 +500,16 @@
*/
private Element parseXML(InputSource xml) throws ConfigurationException {
try {
- SAXBuilder builder = new SAXBuilder();
+ DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(new ConfigurationEntityResolver());
- Document document = builder.build(xml);
- return document.getRootElement();
- } catch (JDOMException e) {
+ Document document = builder.parse(xml);
+ return document.getDocumentElement();
+ } catch (ParserConfigurationException e) {
+ throw new ConfigurationException(
+ "Unable to create configuration XML parser", e);
+ } catch (SAXException e) {
throw new ConfigurationException(
"Configuration file syntax error.", e);
} catch (IOException e) {
@@ -510,14 +528,17 @@
*/
private Element getElement(Element parent, String name)
throws ConfigurationException {
- Element element = parent.getChild(name);
- if (element != null) {
- return element;
- } else {
- throw new ConfigurationException(
- "Configuration element " + name + " not found in "
- + parent.getName() + ".");
+ NodeList children = parent.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE
+ && name.equals(child.getNodeName())) {
+ return (Element) child;
+ }
}
+ throw new ConfigurationException(
+ "Configuration element " + name + " not found in "
+ + parent.getNodeName() + ".");
}
/**
@@ -530,13 +551,13 @@
*/
private String getAttribute(Element element, String name)
throws ConfigurationException {
- String value = element.getAttributeValue(name);
+ String value = element.getAttribute(name);
if (value != null) {
return value;
} else {
throw new ConfigurationException(
"Configuration attribute " + name + " not found in "
- + element.getName() + ".");
+ + element.getNodeName() + ".");
}
}
@@ -550,7 +571,7 @@
* @return attribute value, or the default value
*/
private String getAttribute(Element element, String name, String def) {
- String value = element.getAttributeValue(name);
+ String value = element.getAttribute(name);
if (value != null) {
return value;
} else {
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?view=diff&r1=160448&r2=160449
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java Thu Apr 7 13:03:40 2005
@@ -18,19 +18,22 @@
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.FileReader;
-import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import javax.xml.transform.OutputKeys;
+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 org.apache.jackrabbit.core.fs.FileSystem;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
+import org.w3c.dom.Element;
import org.xml.sax.InputSource;
/**
@@ -292,25 +295,22 @@
+ name + ".");
}
- // Create the workspace.xml file from the configuration template.
+ // Create the workspace.xml file using the configuration template.
try {
- Element element = (Element) template.clone();
- element.setAttribute("name", name);
- Document document = new Document(element);
- XMLOutputter outputter =
- new XMLOutputter(Format.getPrettyFormat());
-
- FileOutputStream fos =
- new FileOutputStream(new File(directory, WORKSPACE_XML));
- try {
- outputter.output(document, fos);
- } finally {
- try { fos.close(); } catch (Exception e) { }
- }
- } catch (IOException e) {
+ template.setAttribute("name", name);
+ File xml = new File(directory, WORKSPACE_XML);
+
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.transform(
+ new DOMSource(template), new StreamResult(xml));
+ } catch (TransformerConfigurationException e) {
+ throw new ConfigurationException(
+ "Cannot create a workspace configuration writer", e);
+ } catch (TransformerException e) {
throw new ConfigurationException(
- "Failed to create a configuration file for workspace "
- + name + ".", e);
+ "Cannot create a workspace configuration file", e);
}
// Load the created workspace configuration.