[Yanel-commits] rev 28503 - in
public/yanel/trunk/src/core/java/org/wyona/yanel/core: map util
jon at wyona.com
jon at wyona.com
Mon Nov 5 18:44:21 CET 2007
Author: jon
Date: 2007-11-05 18:44:20 +0100 (Mon, 05 Nov 2007)
New Revision: 28503
Modified:
public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java
public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java
Log:
added patch for bug 5641. Thanks to Simon.
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java 2007-11-05 16:26:21 UTC (rev 28502)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/map/Realm.java 2007-11-05 17:44:20 UTC (rev 28503)
@@ -79,7 +79,7 @@
this.configFile = configFile;
proxySet = false;
-
+
if (configFile != null) {
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(true);
Configuration config;
@@ -92,7 +92,7 @@
log.error(errorMsg, e);
throw new Exception(errorMsg, e);
} catch (Exception e) {
- String errorMsg = "Could not configure realm [" + id + "] with config file: " +
+ String errorMsg = "Could not configure realm [" + id + "] with config file: " +
configFile + ": " + e.toString();
throw new Exception(errorMsg, e);
}
@@ -132,7 +132,7 @@
// Set IdentityManager for this realm
repoConfigElement = config.getChild("ac-identities", false);
if (repoConfigElement != null) {
-
+
IdentityManagerFactory imFactory = null;
IdentityManager identityManager = null;
try {
@@ -150,8 +150,8 @@
setIdentityManager(identityManager);
}
-
+
RepositoryFactory repoFactory = yanel.getRepositoryFactory("DefaultRepositoryFactory");
RepositoryFactory rtiRepoFactory = yanel.getRepositoryFactory("RTIRepositoryFactory");
RepositoryFactory extraRepoFactory = yanel.getRepositoryFactory("ExtraRepositoryFactory");
@@ -159,22 +159,22 @@
String repoConfigSrc = config.getChild("data", false).getValue();
repoConfig = FileUtil.resolve(getConfigFile(), new File(repoConfigSrc));
setRepository(repoFactory.newRepository(getID(), repoConfig));
-
+
repoConfigSrc = config.getChild("rti", false).getValue();
repoConfig = FileUtil.resolve(getConfigFile(), new File(repoConfigSrc));
setRTIRepository(rtiRepoFactory.newRepository(getID(), repoConfig));
-
-
-
-
+
+
+
+
Configuration configElement = config.getChild("default-language", false);
- if (configElement != null) {
+ if (configElement != null) {
setDefaultLanguage(configElement.getValue());
} else {
//Maintain backwards compatibility with realms
setDefaultLanguage("en");
}
-
+
Configuration languagesElement = config.getChild("languages", false);
ArrayList languages = new ArrayList();
if (languagesElement != null) {
@@ -185,7 +185,7 @@
}
}
setLanguages((String[])languages.toArray(new String[languages.size()]));
-
+
configElement = config.getChild("translation-manager", false);
TranslationManager translationManager = null;
if (configElement != null) {
@@ -196,7 +196,7 @@
}
translationManager.init(this);
setTranslationManager(translationManager);
-
+
configElement = config.getChild("language-handler", false);
LanguageHandler languageHandler = null;
if (configElement != null) {
@@ -206,8 +206,8 @@
languageHandler = (LanguageHandler)Class.forName("org.wyona.yanel.impl.DefaultLanguageHandler").newInstance();
}
setLanguageHandler(languageHandler);
-
-
+
+
Configuration rootDirConfig = config.getChild("root-dir", false);
if (rootDirConfig != null) {
setRootDir(FileUtil.resolve(getConfigFile(), new File(rootDirConfig.getValue())));
@@ -327,14 +327,14 @@
}
return descr;
}
-
+
/**
* Get data repository of realm
*/
public Repository getRepository() throws Exception {
return repository;
}
-
+
public void setRepository(Repository repository) throws Exception {
this.repository = repository;
}
@@ -345,7 +345,7 @@
public Repository getRTIRepository() throws Exception {
return rtiRepository;
}
-
+
public void setRTIRepository(Repository repository) throws Exception {
this.rtiRepository = repository;
}
@@ -380,7 +380,7 @@
public File getRootDir() {
return this.rootDir;
}
-
+
public void setRootDir(File rootDir) {
this.rootDir = rootDir;
}
@@ -421,7 +421,7 @@
public void setTranslationManager(TranslationManager translationManager) {
this.translationManager = translationManager;
}
-
+
public Repository getRepository(String id) throws Exception {
Yanel yanel = Yanel.getInstance();
RepositoryFactory extraRepoFactory = yanel.getRepositoryFactory("ExtraRepositoryFactory");
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java 2007-11-05 16:26:21 UTC (rev 28502)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java 2007-11-05 17:44:20 UTC (rev 28503)
@@ -1,129 +1,129 @@
-/*
- * Copyright 2007 Wyona
- *
- * 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.wyona.org/licenses/APACHE-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.wyona.yanel.core.util;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.log4j.Category;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * Configuration utility to copy an avalon configuration into a DOM document
- */
-public class ConfigurationUtil {
-
- /**
- * The log category instance
- */
- private static final Category log = Category.getInstance(ConfigurationUtil.class);
-
- /**
- * Create a DOM Document from a custom config element modelled with avalon
- *
- * @param confElement
- * The configuration element
- * @param rootName
- * The root element name
- * @param rootNamespace
- * The target namespace
- * @return
- */
- public static Document getCustomConfiguration(Configuration repoConfigElement, String rootName, String rootNamespace) {
- try {
- if (repoConfigElement == null || repoConfigElement.getChildren() == null || repoConfigElement.getChildren().length == 0) {
- if (repoConfigElement.getValue(null) == null) {
- log.warn("Did not find any child elements nor text within " + repoConfigElement);
- return null;
- }
- }
-
- if (log.isDebugEnabled()) log.debug("Creating custom config - rootName=" + rootName + ", rootNamespace=" + rootNamespace);
-
- Document doc = null;
- DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- javax.xml.parsers.DocumentBuilder parser = dbf.newDocumentBuilder();
- org.w3c.dom.DOMImplementation impl = parser.getDOMImplementation();
- org.w3c.dom.DocumentType doctype = null;
- doc = impl.createDocument(rootNamespace, rootName, doctype);
-
- // Copy the very first text node in order to stay backwards compatible
- Element rootElement = doc.getDocumentElement();
- if (repoConfigElement.getValue(null) != null) {
- if (log.isDebugEnabled()) log.debug("Very first text node: " + repoConfigElement.getValue());
- rootElement.appendChild(doc.createTextNode(repoConfigElement.getValue()));
- }
-
- // Copy elements
- Configuration[] children = repoConfigElement.getChildren();
- if (children.length > 0) {
- log.debug("root element " + rootElement);
- for (int i = 0; i < children.length; i++) {
- rootElement.appendChild(ConfigurationUtil.createElement(children[i], doc));
- }
- }
- return doc;
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- return null;
- }
-
- // original comment by michi:
- // avalon ConfigurationUtil doesn't seem to work properly
- /*
- * org.w3c.dom.Element element = ConfigurationUtil.toElement(customConfig);
- * log.error("DEBUG: element: " + element.getLocalName()); org.w3c.dom.Document doc =
- * element.getOwnerDocument(); org.w3c.dom.Element rootElement = doc.getDocumentElement();
- * rootElement.appendChild(element); return doc;
- */
- }
-
- /**
- * Parse a configuration node into a element and add it to the document. <br/>This method may
- * call itself recusively.
- *
- * @param conf
- * The configuration element to parse
- * @param doc
- * The DOM document to create elements for
- *
- * @return Returns the created element
- */
- private static Element createElement(Configuration config, Document doc) throws Exception {
-
- Element element = doc.createElementNS(config.getNamespace(), config.getName());
- String[] attrs = config.getAttributeNames();
- for (int i = 0; i < attrs.length; i++) {
- element.setAttributeNS(config.getNamespace(), attrs[i], config.getAttribute(attrs[i]));
- }
- // TODO: Does not work for elements with mixed content (text and
- // elements)
- try {
- element.appendChild(doc.createTextNode(config.getValue()));
- } catch (Exception e) {
- log.debug("No value: " + element.getLocalName() + " - skipped child creation");
- }
- Configuration[] children = config.getChildren();
- if (children.length > 0) {
- for (int i = 0; i < children.length; i++) {
- element.appendChild(ConfigurationUtil.createElement(children[i], doc));
- }
- }
- return element;
- }
-}
+/*
+ * Copyright 2007 Wyona
+ *
+ * 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.wyona.org/licenses/APACHE-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.wyona.yanel.core.util;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.log4j.Category;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Configuration utility to copy an avalon configuration into a DOM document
+ */
+public class ConfigurationUtil {
+
+ /**
+ * The log category instance
+ */
+ private static final Category log = Category.getInstance(ConfigurationUtil.class);
+
+ /**
+ * Create a DOM Document from a custom config element modelled with avalon
+ *
+ * @param confElement
+ * The configuration element
+ * @param rootName
+ * The root element name
+ * @param rootNamespace
+ * The target namespace
+ * @return
+ */
+ public static Document getCustomConfiguration(Configuration repoConfigElement, String rootName, String rootNamespace) {
+ try {
+ if (repoConfigElement == null || repoConfigElement.getChildren() == null || repoConfigElement.getChildren().length == 0) {
+ if (repoConfigElement.getValue(null) == null) {
+ log.warn("Did not find any child elements nor text within " + repoConfigElement);
+ return null;
+ }
+ }
+
+ if (log.isDebugEnabled()) log.debug("Creating custom config - rootName=" + rootName + ", rootNamespace=" + rootNamespace);
+
+ Document doc = null;
+ DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ javax.xml.parsers.DocumentBuilder parser = dbf.newDocumentBuilder();
+ org.w3c.dom.DOMImplementation impl = parser.getDOMImplementation();
+ org.w3c.dom.DocumentType doctype = null;
+ doc = impl.createDocument(rootNamespace, rootName, doctype);
+
+ // Copy the very first text node in order to stay backwards compatible
+ Element rootElement = doc.getDocumentElement();
+ if (repoConfigElement.getValue(null) != null) {
+ if (log.isDebugEnabled()) log.debug("Very first text node: " + repoConfigElement.getValue());
+ rootElement.appendChild(doc.createTextNode(repoConfigElement.getValue()));
+ }
+
+ // Copy elements
+ Configuration[] children = repoConfigElement.getChildren();
+ if (children.length > 0) {
+ log.debug("root element " + rootElement);
+ for (int i = 0; i < children.length; i++) {
+ rootElement.appendChild(ConfigurationUtil.createElement(children[i], doc));
+ }
+ }
+ return doc;
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ return null;
+ }
+
+ // original comment by michi:
+ // avalon ConfigurationUtil doesn't seem to work properly
+ /*
+ * org.w3c.dom.Element element = ConfigurationUtil.toElement(customConfig);
+ * log.error("DEBUG: element: " + element.getLocalName()); org.w3c.dom.Document doc =
+ * element.getOwnerDocument(); org.w3c.dom.Element rootElement = doc.getDocumentElement();
+ * rootElement.appendChild(element); return doc;
+ */
+ }
+
+ /**
+ * Parse a configuration node into a element and add it to the document. <br/>This method may
+ * call itself recusively.
+ *
+ * @param conf
+ * The configuration element to parse
+ * @param doc
+ * The DOM document to create elements for
+ *
+ * @return Returns the created element
+ */
+ private static Element createElement(Configuration config, Document doc) throws Exception {
+
+ Element element = doc.createElementNS(config.getNamespace(), config.getName());
+ String[] attrs = config.getAttributeNames();
+ for (int i = 0; i < attrs.length; i++) {
+ element.setAttributeNS(config.getNamespace(), attrs[i], config.getAttribute(attrs[i]));
+ }
+ // TODO: Does not work for elements with mixed content (text and
+ // elements)
+ try {
+ element.appendChild(doc.createTextNode(config.getValue()));
+ } catch (Exception e) {
+ log.debug("No value: " + element.getLocalName() + " - skipped child creation");
+ }
+ Configuration[] children = config.getChildren();
+ if (children.length > 0) {
+ for (int i = 0; i < children.length; i++) {
+ element.appendChild(ConfigurationUtil.createElement(children[i], doc));
+ }
+ }
+ return element;
+ }
+}
More information about the Yanel-commits
mailing list