ASF Bugzilla – Attachment 13966 Details for
Bug 33030
remove XPSAssembler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to remove XPSAssembler
remove-xpsassembler-patch.txt (text/plain), 143.09 KB, created by
Gregor J. Rothfuss
on 2005-01-10 18:13:50 UTC
(
hide
)
Description:
Patch to remove XPSAssembler
Filename:
MIME Type:
Creator:
Gregor J. Rothfuss
Created:
2005-01-10 18:13:50 UTC
Size:
143.09 KB
patch
obsolete
>Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPointerFactory.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPointerFactory.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPointerFactory.java (working copy) >@@ -1,332 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.io.FileNotFoundException; >-import java.io.PrintWriter; >-import java.util.Properties; >-import java.util.Vector; >- >-import org.apache.lenya.xml.xpointer.XPointer; >-import org.apache.log4j.Category; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >- >-public class XPointerFactory { >- static Category log = Category.getInstance(XPointerFactory.class); >- XPointer xpointer = null; >- >- /** >- * Creates a new XPointerFactory object. >- */ >- public XPointerFactory() { >- Properties properties = new Properties(); >- String propertiesFileName = "conf.properties"; >- >- try { >- properties.load(XPointerFactory.class.getResourceAsStream(propertiesFileName)); >- } catch (Exception e) { >- log.fatal(": Failed to load properties from resource: " + propertiesFileName); >- } >- >- String xpointerName = properties.getProperty("XPointer"); >- >- if (xpointerName == null) { >- log.fatal(": No XPointer specified in " + propertiesFileName); >- } >- >- try { >- Class xpointerClass = Class.forName(xpointerName); >- xpointer = (XPointer) xpointerClass.newInstance(); >- } catch (Exception e) { >- log.fatal(": " + e); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- XPointerFactory xpf = new XPointerFactory(); >- DOMParserFactory dpf = new DOMParserFactory(); >- >- if (args.length != 2) { >- System.err.println("Usage: java " + xpf.getClass().getName() + >- " example.xml \"/Example/People/Person[1]/Name\""); >- >- return; >- } >- >- Document document = null; >- >- try { >- document = dpf.getDocument(args[0]); >- } catch (FileNotFoundException e) { >- System.err.println("No such file or directory: " + e.getMessage()); >- } catch (Exception e) { >- System.err.println(e.getMessage()); >- } >- >- String xpath = args[1]; >- >- try { >- Vector nodes = xpf.select(document.getDocumentElement(), "xpointer(" + xpath + ")"); >- String[] values = xpf.getNodeValues(nodes); >- >- for (int i = 0; i < nodes.size(); i++) { >- System.out.println(((Node) nodes.elementAt(i)).getNodeName() + ": " + values[i]); >- } >- } catch (Exception e) { >- System.err.println(xpf.getClass().getName() + ".main(): " + e); >- } >- >- Document doc = xpf.employees(); >- >- try { >- Vector nodes = xpf.select(doc.getDocumentElement(), "xpointer(/Employees/Employee[2])"); >- String[] values = xpf.getNodeValues(nodes); >- >- for (int i = 0; i < nodes.size(); i++) { >- System.out.println(((Node) nodes.elementAt(i)).getNodeName() + ": " + values[i]); >- } >- >- Element leviElement = (Element) nodes.elementAt(0); >- leviElement.appendChild(dpf.newTextNode(doc, " Brucker")); >- } catch (Exception e) { >- System.err.println(xpf.getClass().getName() + ".main(): " + e); >- } >- >- new DOMWriter(new PrintWriter(System.out)).print(doc); >- System.out.println(""); >- } >- >- /** >- * Parse reference for xpointer and namespaces >- * >- * @param reference xmlns(...)xpointer(...)xpointer(...) >- * >- * @exception MalformedXPointerException xpointer(xpath) >- */ >- public void parse(String reference, Vector xpaths, Vector namespaces) throws MalformedXPointerException { >- tokenize(reference, xpaths, namespaces); >- } >- >- /** >- * Select nodes by xpointer >- * >- * @param node Document Node >- * @param reference xmls(...)xpointer(...) >- * >- * @return nodes >- * >- * @exception Exception ... >- */ >- public Vector select(Node node, String reference) throws Exception { >- Vector xpaths = new Vector(); >- Vector namespaces = new Vector(); >- parse(reference, xpaths, namespaces); >- >- Vector nodes = new Vector(); >- >- for (int i = 0; i < xpaths.size(); i++) { >- Vector n = xpointer.select(node, (String) xpaths.elementAt(i), namespaces); >- >- for (int j = 0; j < n.size(); j++) { >- nodes.addElement(n.elementAt(j)); >- } >- } >- >- return nodes; >- } >- >- /** >- * Select nodes by xpointer and return node at specific position >- * >- * @param node Document Node >- * @param reference xmls(...)xpointer(...) >- * >- * @return node >- * >- * @exception Exception ... >- */ >- public Node selectAt(Node node, String reference, int i) throws Exception { >- return (Node)select(node, reference).elementAt(i); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param xpointer DOCUMENT ME! >- * @param xpaths DOCUMENT ME! >- * >- * @exception MalformedXPointerException xpointer(xpath)xpointer(xpath) >- */ >- public void tokenize(String xpointer, Vector xpaths, Vector namespaces) throws MalformedXPointerException { >- if ((xpointer.indexOf("xpointer(") == 0) && (xpointer.charAt(xpointer.length() - 1) == ')')) { >- >- String substring = xpointer.substring(9, xpointer.length()); >- int i = substring.indexOf(")"); >- >- if (i >= 0) { >- log.debug("XPath: " + substring.substring(0, i)); >- xpaths.addElement(substring.substring(0, i)); >- tokenize(substring.substring(i + 1, substring.length()), xpaths, namespaces); >- } else { >- xpaths.addElement(substring.substring(0, substring.length() - 1)); >- return; >- } >- } else if ((xpointer.indexOf("xmlns(") == 0) && (xpointer.charAt(xpointer.length() - 1) == ')')) { >- String substring = xpointer.substring(6, xpointer.length()); >- int i = substring.indexOf(")"); >- >- if (i >= 0) { >- log.debug("Namespace: " + substring.substring(0, i)); >- namespaces.addElement(substring.substring(0, i)); >- tokenize(substring.substring(i + 1, substring.length()), xpaths, namespaces); >- } else { >- xpaths.addElement(substring.substring(0, substring.length() - 1)); >- return; >- } >- } else if (xpointer.equals("")) { >- return; >- } else { >- throw new MalformedXPointerException(xpointer); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param nodes DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public String[] getNodeValues(Vector nodes) throws Exception { >- String[] values = new String[nodes.size()]; >- >- for (int i = 0; i < values.length; i++) { >- Node node = (Node) nodes.elementAt(i); >- short type = node.getNodeType(); >- >- switch (type) { >- case Node.ELEMENT_NODE: { >- values[i] = getElementValue((Element) node); >- >- break; >- } >- >- case Node.ATTRIBUTE_NODE: { >- values[i] = node.getNodeValue(); >- >- break; >- } >- >- default: >- values[i] = ""; >- throw new Exception("Neither ELEMENT nor ATTRIBUTE: " + type); >- } >- } >- >- return values; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param element DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String getElementValue(Element element) { >- String value = ""; >- NodeList nl = element.getChildNodes(); >- >- for (int k = 0; k < nl.getLength(); k++) { >- short nodeType = nl.item(k).getNodeType(); >- >- if (nodeType == Node.TEXT_NODE) { >- value = value + nl.item(k).getNodeValue(); >- } else if (nodeType == Node.ELEMENT_NODE) { >- value = value + getElementValue((Element) nl.item(k)); >- } else { >- System.err.println("EXCEPTION: " + this.getClass().getName() + >- ".getElementValue(): No TEXT_NODE"); >- } >- } >- >- return value; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param element DOCUMENT ME! >- * @param text DOCUMENT ME! >- */ >- public void getElementValue(Element element, Vector text) { >- NodeList nl = element.getChildNodes(); >- >- for (int k = 0; k < nl.getLength(); k++) { >- short nodeType = nl.item(k).getNodeType(); >- >- if (nodeType == Node.TEXT_NODE) { >- text.addElement(nl.item(k).getNodeValue()); >- } else if (nodeType == Node.ELEMENT_NODE) { >- getElementValue((Element) nl.item(k), text); >- } else { >- System.err.println("EXCEPTION: " + this.getClass().getName() + >- ".getElementValue(): No TEXT_NODE"); >- } >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Document employees() { >- DOMParserFactory dpf = new DOMParserFactory(); >- Document doc = dpf.getDocument(); >- Element michi = dpf.newElementNode(doc, "Employee"); >- michi.setAttribute("Id", "0"); >- michi.appendChild(dpf.newTextNode(doc, "Michi")); >- >- Element levi = dpf.newElementNode(doc, "Employee"); >- levi.setAttribute("Id", "1"); >- levi.appendChild(dpf.newTextNode(doc, "Levi")); >- >- Element employees = dpf.newElementNode(doc, "Employees"); >- employees.appendChild(dpf.newTextNode(doc, "\n")); >- employees.appendChild(michi); >- employees.appendChild(dpf.newTextNode(doc, "\n")); >- employees.appendChild(levi); >- employees.appendChild(dpf.newTextNode(doc, "\n")); >- doc.appendChild(employees); >- >- return doc; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/Normalize.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/Normalize.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/Normalize.java (working copy) >@@ -1,266 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >- >-/** >- * @deprecated >- */ >-public class Normalize { >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- System.out.println(Normalize.normalize("&")); >- System.out.println(Normalize.denormalize("Zürich")); >- System.out.println(Normalize.denormalize("Z&252;rich & Region̓djŤ")); >- } >- >- /** >- * >- */ >- public static String normalize(String s) { >- StringBuffer sb = new StringBuffer(); >- >- for (int i = 0; i < s.length(); i++) { >- char ch = s.charAt(i); >- >- switch (ch) { >- case '&': // 38 >- { >- sb.append("&"); >- >- break; >- } >- >- case 60: // < >- { >- sb.append("<"); >- >- break; >- } >- >- case 62: // > >- { >- sb.append(">"); >- >- break; >- } >- >- case 139: // < >- { >- sb.append("‹"); >- >- break; >- } >- >- case 155: // > >- { >- sb.append("›"); >- >- break; >- } >- >- case 160: // nbsp >- { >- sb.append(" "); >- >- break; >- } >- >- case 171: // << >- { >- sb.append("«"); >- >- break; >- } >- >- case 183: // . >- { >- sb.append("·"); >- >- break; >- } >- >- case 187: // >> >- { >- sb.append("»"); >- >- break; >- } >- >- case 196: // Ae >- { >- sb.append("Ä"); >- >- break; >- } >- >- case 214: // Oe >- { >- sb.append("Ö"); >- >- break; >- } >- >- case 220: // Ue >- { >- sb.append("Ü"); >- >- break; >- } >- >- case 223: // Scharfes S >- { >- sb.append("ß"); >- >- break; >- } >- >- case 225: // aacute >- { >- sb.append("á"); >- >- break; >- } >- >- case 228: // ae >- { >- sb.append("ä"); >- >- break; >- } >- >- case 232: // egrave >- { >- sb.append("è"); >- >- break; >- } >- >- case 233: // eacute >- { >- sb.append("é"); >- >- break; >- } >- >- case 234: // ecirc >- { >- sb.append("ê"); >- >- break; >- } >- >- case 244: // ocirc >- { >- sb.append("ô"); >- >- break; >- } >- >- case 246: // oe >- { >- sb.append("ö"); >- >- break; >- } >- >- case 252: // ue >- { >- sb.append("ü"); >- >- break; >- } >- >- default:sb.append(ch); >- } >- } >- >- return sb.toString(); >- } >- >- /** >- * >- */ >- public static String denormalize(String s) { >- StringBuffer sb = new StringBuffer(); >- >- for (int i = 0; i < s.length(); i++) { >- char ch = s.charAt(i); >- >- if (ch == '&') { >- StringBuffer substring = new StringBuffer(); >- int length = i + 6; >- >- if (length > s.length()) { >- length = s.length(); >- } >- >- for (int k = i; k < length; k++) { >- substring.append(s.charAt(k)); >- >- if (s.charAt(k) == ';') { >- break; >- } >- } >- >- if (substring.length() > 3) { >- if ((substring.charAt(1) != '#') || >- (substring.charAt(substring.length() - 1) != ';')) { >- sb.append(ch); >- } else { >- int ascii = 0; >- int power = 1; >- >- for (int j = substring.length() - 2; j >= 2; j--) { >- try { >- Integer integer = new Integer("" + substring.charAt(j)); >- ascii = ascii + (power * integer.intValue()); >- } catch (Exception e) { >- ascii = -1; >- >- break; >- } >- >- power = power * 10; >- } >- >- if (ascii >= 0) { >- char character = (char) ascii; >- sb.append(character); >- i = (i + substring.length()) - 1; >- } else { >- sb.append(ch); >- } >- } >- } else { >- sb.append(ch); >- } >- } else { >- sb.append(ch); >- } >- } >- >- return sb.toString(); >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/conf.properties >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/conf.properties (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/conf.properties (working copy) >@@ -1,20 +0,0 @@ >-# Copyright 1999-2004 The Apache Software Foundation >-# >-# Licensed under the Apache License, Version 2.0 (the "License"); >-# you may not use this file except in compliance with the License. >-# You may obtain a copy of the License at >-# >-# http://www.apache.org/licenses/LICENSE-2.0 >-# >-# Unless required by applicable law or agreed to in writing, software >-# distributed under the License is distributed on an "AS IS" BASIS, >-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >-# See the License for the specific language governing permissions and >-# limitations under the License. >- >-# DOM Parser >-Parser=org.apache.lenya.xml.parser.XercesParser >-# SAX Parser >-SAXParser=org.apache.xerces.parsers.SAXParser >-# XPointer, XPath >-XPointer=org.apache.lenya.xml.xpointer.XalanXPointer >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPSSourceInformation.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPSSourceInformation.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPSSourceInformation.java (working copy) >@@ -1,218 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.io.File; >-import java.io.IOException; >-import java.net.MalformedURLException; >-import java.net.URL; >-import java.util.Vector; >- >-import org.apache.log4j.Category; >- >-public class XPSSourceInformation { >- static Category log = Category.getInstance(XPSSourceInformation.class); >- public int lineNumber = -1; >- public URL url = null; >- public XPSSourceInformation parentInfo = null; >- public Vector children = null; >- String offset = null; >- String cocoon = null; >- >- /** >- * Creates a new XPSSourceInformation object. >- * >- * @param fileURL DOCUMENT ME! >- * @param cocoon DOCUMENT ME! >- */ >- public XPSSourceInformation(String fileURL, String cocoon) { >- this.cocoon = cocoon; >- >- parentInfo = null; >- offset = "++"; >- children = new Vector(); >- >- try { >- url = new URL(fileURL); >- } catch (MalformedURLException e) { >- log.error(e); >- } >- } >- >- /** >- * Creates a new XPSSourceInformation object. >- * >- * @param urlString DOCUMENT ME! >- * @param parentInfo DOCUMENT ME! >- * @param cocoon DOCUMENT ME! >- */ >- public XPSSourceInformation(String urlString, XPSSourceInformation parentInfo, String cocoon) { >- this.cocoon = cocoon; >- >- this.parentInfo = parentInfo; >- offset = "++"; >- children = new Vector(); >- >- try { >- if (urlString.indexOf("/") == 0) { >- url = new URL("file:" + urlString); >- } else if (urlString.indexOf("cocoon:") == 0) { >- if (cocoon != null) { >- url = new URL(cocoon + "/" + urlString.substring(7)); // remove "cocoon:" protocol >- log.warn("Protocol 7789: COCOON (" + urlString + >- ") -- will be transformed into http: " + url); >- } else { >- log.error("No cocoon base set!"); >- } >- } else { >- url = new URL(urlString); >- } >- >- String p = url.getProtocol(); >- >- // Does not make sense, because it will be either file or http, and else an Exception will be thrown! >- if (!(p.equals("http") || p.equals("file") || p.equals("class"))) { >- log.error("This type of protocol is not supported yet: " + p); >- } >- } catch (MalformedURLException e) // let's hope it's a relative path >- { >- log.debug("1079: " + e + " -- Let's hope it's a relative path!"); >- >- File parent = new File(parentInfo.url.getFile()); >- >- // transform URI to system-independent path and create absolute path >- try { >- int index = urlString.indexOf("#"); >- String xpointer = ""; >- String relativePath = urlString; >- >- if (index != -1) { >- relativePath = urlString.substring(0, index); >- xpointer = urlString.substring(index); >- } >- >- relativePath = relativePath.replace('/', File.separatorChar); >- >- File file = new File(parent.getParentFile(), relativePath); >- >- url = new URL("file", null, -1, file.getCanonicalPath() + xpointer); >- >- log.info("Concatenated URL: " + url); >- } catch (MalformedURLException exception) { >- log.error(exception); >- } catch (IOException exception) { >- log.error(exception); >- } >- } >- >- if (url.getProtocol().equals("http")) { >- } else if (url.getProtocol().equals("file")) { >- if (parentInfo.url.getProtocol().equals("http")) { >- String protocol = parentInfo.url.getProtocol(); >- String host = parentInfo.url.getHost(); >- int port = parentInfo.url.getPort(); >- >- try { >- if (url.getRef() != null) { >- url = new URL(protocol, host, port, url.getFile() + "#" + url.getRef()); >- } else { >- url = new URL(protocol, host, port, url.getFile()); >- } >- } catch (MalformedURLException e) { >- log.error(e); >- } >- } >- } else { >- log.error("EXCEPTION: 0.2.21"); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- String cocoon = null; >- XPSSourceInformation xpssf = new XPSSourceInformation(args[0], cocoon); >- System.out.println(xpssf); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param child DOCUMENT ME! >- */ >- public void addChild(XPSSourceInformation child) { >- children.addElement(child); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String toString() { >- return toString("", offset); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param index DOCUMENT ME! >- * @param offset DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String toString(String index, String offset) { >- String s = index + url.toString() + "\n"; >- >- for (int i = 0; i < children.size(); i++) { >- XPSSourceInformation child = (XPSSourceInformation) children.elementAt(i); >- s = s + child.toString(index + offset, offset); >- } >- >- return s; >- } >- >- /** >- * Check for XInclude Loops >- * >- * @param xpssf DOCUMENT ME! >- * @param url DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public boolean checkLoop(XPSSourceInformation xpssf, URL url) { >- if (xpssf.url.getFile().equals(url.getFile())) { >- if (xpssf.parentInfo != null) { >- return true; >- } else { >- return false; // This is just the request (it can be dummy.xml but also something real) >- } >- } >- >- if (xpssf.parentInfo != null) { >- return checkLoop(xpssf.parentInfo, url); >- } >- >- return false; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/Configuration.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/Configuration.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/Configuration.java (working copy) >@@ -1,155 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.net.URL; >-import java.util.Properties; >- >-import org.apache.log4j.Category; >- >- >-/** >- * Reads xpsconf.properties >- * @deprecated replaced by config/ directory >- */ >-public class Configuration { >- static Category log = Category.getInstance(Configuration.class); >- public static final String DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/xml/xpsconf.properties"; >- public static final String DEFAULT_CONFIGURATION_KEY = "xps.configuration"; >- public static final String OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.xps.configuration"; >- public String cacheFolder = null; >- public boolean cacheHTTP = false; >- public String INCLUDE = null; >- public String JAVA_ZONE = null; >- public String proxyHost = null; >- public String proxyPort = null; >- >- /** >- * Creates a new Configuration object. >- */ >- public Configuration() { >- getProperties(load()); >- } >- >- /** >- * http://www.artima.com/java/answers/Mar2001/messages/164.html export >- * CLASSPATH=/home/lenya/src/xps/build/properties:... java >- * -Doverride.xps.configuration=org/apache/lenya/xps/altconf.properties org.apache.lenya.xps.Configuration >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- Configuration conf = new Configuration(); >- >- System.out.println("Caching directory: " + conf.cacheFolder); >- System.out.println("Cache xml from http connections: " + conf.cacheHTTP); >- >- if ((conf.proxyHost != null) && (conf.proxyHost != null)) { >- System.out.println("Proxy set:"); >- System.out.println(conf.proxyHost); >- System.out.println(conf.proxyPort); >- } else { >- System.out.println("No proxy set."); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public static Properties load() { >- String resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY); >- >- if (resourcePathRelativeToClasspath == null) { >- resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY, >- DEFAULT_CONFIGURATION_FILE); >- log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); >- } else { >- log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); >- } >- >- ClassLoader cl = ClassLoader.getSystemClassLoader(); >- >- // FIXME: >- URL url = org.apache.log4j.helpers.Loader.getResource("hallo"); >- >- if (url == null) { >- //return null; >- } >- >- log.debug(url); >- >- Properties properties = new Properties(); >- >- try { >- properties.load(Configuration.class.getResourceAsStream("xpsconf.properties")); >- } catch (Exception e) { >- log.error(".load(): " + e); >- } >- >- return properties; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param properties DOCUMENT ME! >- */ >- public void getProperties(Properties properties) { >- if (properties != null) { >- cacheFolder = getProperty(properties, >- "org.apache.lenya.xps.XLinkInterpreter.cacheFolder"); >- cacheHTTP = false; >- INCLUDE = getProperty(properties, "Include"); >- JAVA_ZONE = getProperty(properties, "JavaZone"); >- proxyHost = null; >- proxyPort = null; >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param properties DOCUMENT ME! >- * @param key DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String getProperty(Properties properties, String key) { >- String value = properties.getProperty(key); >- >- if (value != null) { >- log.debug(key + "=" + value); >- >- return value; >- } else { >- log.debug(".getProperty(): No such property: " + key); >- } >- >- return null; >- } >- >- /** >- * DOCUMENT ME! >- */ >- public static void register() { >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XInclude.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XInclude.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XInclude.java (working copy) >@@ -1,35 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.util.Vector; >- >-public interface XInclude { >- /** >- * The Lenya XInclude implementation. It improves on the Cocoon implementation by supporting nested includes and >- * better error handling. >- * >- * @param args DOCUMENT ME! >- * @param parentInfo DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Vector include(String[] args, XPSSourceInformation parentInfo); >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/parser/XercesParser.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/parser/XercesParser.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/parser/XercesParser.java (working copy) >@@ -1,204 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml.parser; >- >-import java.io.InputStream; >-import java.io.PrintWriter; >-import java.io.Reader; >- >-import org.apache.lenya.xml.DOMWriter; >-import org.apache.xerces.dom.CDATASectionImpl; >-import org.apache.xerces.dom.CommentImpl; >-import org.apache.xerces.dom.DocumentImpl; >-import org.apache.xerces.dom.ElementImpl; >-import org.apache.xerces.dom.TextImpl; >-import org.apache.xerces.parsers.DOMParser; >-import org.w3c.dom.CDATASection; >-import org.w3c.dom.Comment; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.Text; >- >- >-/** >- * Xerces Parser Implementation >- */ >-public class XercesParser implements Parser { >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- Parser parser = new XercesParser(); >- >- if (args.length != 1) { >- System.err.println("Usage: java " + parser.getClass().getName() + " example.xml"); >- >- return; >- } >- >- Document doc = null; >- >- try { >- doc = parser.getDocument(args[0]); >- } catch (Exception e) { >- System.err.println(e); >- } >- >- new DOMWriter(new PrintWriter(System.out)).print(doc); >- System.out.println(""); >- >- Document document = parser.getDocument(); >- Element michi = parser.newElementNode(document, "Employee"); >- michi.setAttribute("Id", "michi"); >- michi.appendChild(parser.newTextNode(document, "Michi")); >- >- Element employees = parser.newElementNode(document, "Employees"); >- employees.appendChild(parser.newTextNode(document, "\n")); >- employees.appendChild(michi); >- employees.appendChild(parser.newTextNode(document, "\n")); >- document.appendChild(employees); >- new DOMWriter(new PrintWriter(System.out)).print(document); >- System.out.println(""); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param filename DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public Document getDocument(String filename) throws Exception { >- DOMParser parser = new DOMParser(); >- >- org.xml.sax.InputSource in = new org.xml.sax.InputSource(filename); >- parser.parse(in); >- >- return parser.getDocument(); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param is DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public Document getDocument(InputStream is) throws Exception { >- DOMParser parser = new DOMParser(); >- org.xml.sax.InputSource in = new org.xml.sax.InputSource(is); >- parser.parse(in); >- >- return parser.getDocument(); >- } >- >- /** >- * Creates a document from a reader. >- * >- * @param is DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public Document getDocument(Reader reader) throws Exception { >- DOMParser parser = new DOMParser(); >- org.xml.sax.InputSource in = new org.xml.sax.InputSource(reader); >- parser.parse(in); >- >- return parser.getDocument(); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Document getDocument() { >- return new DocumentImpl(); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param name DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Element newElementNode(Document document, String name) { >- return new ElementImpl((DocumentImpl) document, name); >- } >- >- /** >- * Creates an element with namespace support. >- * >- * @param document The owner document. >- * @param namespaceUri The namespace URI of the element. >- * @param qualifiedName The qualified name of the element. >- * >- * @return An element. >- */ >- public Element newElementNSNode(Document document, String namespaceUri, String qualifiedName) { >- return document.createElementNS(namespaceUri, qualifiedName); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param data DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Text newTextNode(Document document, String data) { >- return new TextImpl((DocumentImpl) document, data); >- } >- >- /** >- * CDATA >- * >- * @param document DOM Document >- * @param data Text >- * >- * @return CDATASection >- */ >- public CDATASection newCDATASection(Document document, String data) { >- return new CDATASectionImpl((DocumentImpl) document, data); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param data DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Comment newCommentNode(Document document, String data) { >- return new CommentImpl((DocumentImpl) document, data); >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/parser/Parser.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/parser/Parser.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/parser/Parser.java (working copy) >@@ -1,127 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml.parser; >- >-import java.io.InputStream; >-import java.io.Reader; >- >-import org.w3c.dom.CDATASection; >-import org.w3c.dom.Comment; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.Text; >- >- >-/** >- * DOM Parser interface >- */ >-public interface Parser { >- /** >- * DOCUMENT ME! >- * >- * @param filename DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- Document getDocument(String filename) throws Exception; >- >- /** >- * DOCUMENT ME! >- * >- * Create a document from a reader. >- * @param is DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- Document getDocument(Reader reader) throws Exception; >- >- /** >- * DOCUMENT ME! >- * >- * @param is DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- Document getDocument(InputStream is) throws Exception; >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- Document getDocument(); >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param name DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- Element newElementNode(Document document, String name); >- >- /** >- * Creates an element with namespace support. >- * >- * @param document The owner document. >- * @param namespaceUri The namespace URI of the element. >- * @param qualifiedName The qualified name of the element. >- * >- * @return An element. >- */ >- Element newElementNSNode(Document document, String namespaceUri, String qualifiedName); >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param data DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- Text newTextNode(Document document, String data); >- >- /** >- * CDATA >- * >- * @param document DOM Document >- * @param data Text >- * >- * @return CDATASection >- */ >- CDATASection newCDATASection(Document document, String data); >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param data DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- Comment newCommentNode(Document document, String data); >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMWriter.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMWriter.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMWriter.java (working copy) >@@ -1,359 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.io.BufferedWriter; >-import java.io.FileNotFoundException; >-import java.io.OutputStream; >-import java.io.OutputStreamWriter; >-import java.io.PrintWriter; >-import java.util.Vector; >- >-import org.apache.log4j.Category; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.NamedNodeMap; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >- >- >-/** >- * DOCUMENT ME! >- * @deprecated replaced by DocumentHelper >- */ >-public class DOMWriter { >- static Category log = Category.getInstance(DOMWriter.class); >- PrintWriter out = null; >- String encoding = null; >- >- /** >- * Creates a new DOMWriter object. >- * >- * @param out DOCUMENT ME! >- */ >- public DOMWriter(PrintWriter out) { >- this.out = out; >- } >- >- /** >- * Creates a new DOMWriter object. >- * >- * @param out DOCUMENT ME! >- * @param encoding DOCUMENT ME! >- */ >- public DOMWriter(PrintWriter out, String encoding) { >- this(out); >- this.encoding = encoding; >- } >- >- /** >- * Creates a new DOMWriter object. >- * >- * @param os DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public DOMWriter(OutputStream os) throws Exception { >- this(os, "utf-8"); >- } >- >- /** >- * Creates a new DOMWriter object. >- * >- * @param os DOCUMENT ME! >- * @param encoding DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public DOMWriter(OutputStream os, String encoding) >- throws Exception { >- out = new PrintWriter(new BufferedWriter( >- new OutputStreamWriter(os, XMLEncToJavaEnc.getJava(encoding)))); >- this.encoding = encoding; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- if (args.length != 1) { >- System.err.println("Usage: java org.apache.lenya.xml.DOMWriter \"file.xml\""); >- System.err.println("Description: Reads \"file.xml\" and writes it to standard output"); >- >- return; >- } >- >- DOMParserFactory dpf = new DOMParserFactory(); >- Document document = null; >- >- try { >- document = dpf.getDocument(args[0]); >- } catch (FileNotFoundException e) { >- System.err.println("No such file: " + e.getMessage()); >- >- return; >- } catch (Exception e) { >- System.err.println(e.getMessage()); >- >- return; >- } >- >- try { >- new DOMWriter(System.out, "iso-8859-1").printWithoutFormatting(document); >- } catch (Exception e) { >- System.err.println(e.getMessage()); >- >- return; >- } >- >- log.fatal("\n"); >- >- log.fatal(".main(): System.exit(0)"); >- System.exit(0); >- >- new DOMWriter(new PrintWriter(System.out)).print(document); >- System.out.print("\n"); >- >- XPointerFactory xpf = new XPointerFactory(); >- >- try { >- Vector nodes = xpf.select(document.getDocumentElement(), >- "xpointer(/Example/People/Person/City)"); >- String[] values = xpf.getNodeValues(nodes); >- >- for (int i = 0; i < values.length; i++) { >- System.out.println(values[i]); >- } >- >- Document doc = dpf.getDocument(); >- Element root = dpf.newElementNode(doc, "Root"); >- >- // >- for (int i = 0; i < values.length; i++) { >- root.appendChild(dpf.newTextNode(doc, values[i])); >- } >- >- doc.appendChild(root); >- new DOMWriter(new PrintWriter(System.out)).print(doc); >- System.out.print("\n"); >- } catch (Exception e) { >- System.err.println(e); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param node DOCUMENT ME! >- */ >- public void print(Node node) { >- if (node == null) { >- return; >- } >- >- short type = node.getNodeType(); >- >- switch (type) { >- case Node.DOCUMENT_NODE: { >- out.print("<?xml version=\"1.0\""); >- >- if (encoding != null) { >- out.print(" encoding=\"" + encoding + "\""); >- } >- >- out.print("?>\n\n"); >- print(((Document) node).getDocumentElement()); >- out.flush(); >- >- break; >- } >- >- case Node.ELEMENT_NODE: { >- out.print("<" + node.getNodeName()); >- >- NamedNodeMap attributes = node.getAttributes(); >- >- for (int i = 0; i < attributes.getLength(); i++) { >- Node attribute = attributes.item(i); >- out.print(" " + attribute.getNodeName() + "=\"" + >- Normalize.normalize(attribute.getNodeValue()) + "\""); >- } >- >- if (node.hasChildNodes()) { >- out.print(">"); >- >- NodeList children = node.getChildNodes(); >- >- for (int i = 0; i < children.getLength(); i++) { >- print(children.item(i)); >- } >- >- out.print("</" + node.getNodeName() + ">"); >- } else { >- out.print("/>"); >- } >- >- break; >- } >- >- case Node.TEXT_NODE: { >- out.print(Normalize.normalize(node.getNodeValue())); >- >- break; >- } >- >- case Node.COMMENT_NODE: { >- out.print("<!--" + node.getNodeValue() + "-->"); >- >- break; >- } >- >- default: { >- System.err.println(this.getClass().getName() + ".print(): Node type not implemented: " + >- type); >- >- break; >- } >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param node DOCUMENT ME! >- */ >- public void printWithoutFormatting(Node node) { >- if (node == null) { >- return; >- } >- >- short type = node.getNodeType(); >- >- switch (type) { >- case Node.DOCUMENT_NODE: { >- out.print("<?xml version=\"1.0\""); >- >- if (encoding != null) { >- out.print(" encoding=\"" + encoding + "\""); >- } >- >- out.print("?>\n\n"); >- >- Element root = ((Document) node).getDocumentElement(); >- root.setAttribute("xmlns:xlink", XLink.XLINK_NAMESPACE); >- printWithoutFormatting(root); >- out.flush(); >- >- break; >- } >- >- case Node.ELEMENT_NODE: { >- out.print("<" + node.getNodeName()); >- >- NamedNodeMap attributes = node.getAttributes(); >- >- for (int i = 0; i < attributes.getLength(); i++) { >- Node attribute = attributes.item(i); >- out.print(" " + attribute.getNodeName() + "=\"" + >- replaceSpecialCharacters(attribute.getNodeValue()) + "\""); >- } >- >- if (node.hasChildNodes()) { >- out.print(">"); >- >- NodeList children = node.getChildNodes(); >- >- for (int i = 0; i < children.getLength(); i++) { >- printWithoutFormatting(children.item(i)); >- } >- >- out.print("</" + node.getNodeName() + ">"); >- } else { >- out.print("/>"); >- } >- >- break; >- } >- >- case Node.TEXT_NODE: { >- out.print(replaceSpecialCharacters(node.getNodeValue())); >- >- break; >- } >- >- case Node.COMMENT_NODE: { >- out.print("<!--" + node.getNodeValue() + "-->"); >- >- break; >- } >- >- default: { >- System.err.println(this.getClass().getName() + ".print(): Node type not implemented: " + >- type); >- >- break; >- } >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param s DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String replaceSpecialCharacters(String s) { >- StringBuffer str = new StringBuffer(); >- >- int len = (s != null) ? s.length() : 0; >- >- for (int i = 0; i < len; i++) { >- char ch = s.charAt(i); >- >- switch (ch) { >- case '<': { >- str.append("<"); >- >- break; >- } >- >- case '>': { >- str.append(">"); >- >- break; >- } >- >- case '&': { >- str.append("&"); >- >- break; >- } >- >- default: >- str.append(ch); >- } >- } >- >- return (str.toString()); >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMUtil.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMUtil.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMUtil.java (working copy) >@@ -1,515 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.io.StringReader; >-import java.util.Vector; >- >-import org.apache.log4j.Category; >-import org.apache.xpath.XPathAPI; >-import org.w3c.dom.Attr; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >- >-/** >- * This class is a utility class for miscellaneous DOM functions, similar to >- * org.apache.cocoon.xml.dom.DOMUtil FIXME: Merge classes or extend functionality >- */ >-public class DOMUtil { >- static Category log = Category.getInstance(DOMUtil.class); >- >- DOMParserFactory dpf = null; >- >- XPointerFactory xpf = null; >- >- /** >- * Ctor. >- */ >- public DOMUtil() { >- dpf = new DOMParserFactory(); >- xpf = new XPointerFactory(); >- } >- >- /** >- * Main method, used to test the class. >- * @param args The command line arguments. >- */ >- public static void main(String[] args) { >- try { >- DOMUtil du = new DOMUtil(); >- Document document = du >- .create("<?xml version=\"1.0\"?><Artikel><Datum><Monat Name=\"Juli\"/><Tag>23</Tag></Datum><Content/></Artikel>"); >- new DOMWriter(System.out).printWithoutFormatting(document); >- du.setElementValue(document, "/Artikel/Datum/Tag", "25"); >- du.setElementValue(document, "/Artikel/Datum/Monat", "7"); >- du.setElementValue(document, "/Artikel/Datum/Monat", "9"); >- du.setElementValue(document, "/Artikel/Datm/Mont", "13"); >- du.setAttributeValue(document, "/Artikel/Datum/Monat/@Name", "Oktober"); >- du.setAttributeValue(document, "/Artikel/Datu/Monat/@Nam", "August"); >- du.setElementValue(document, "/Artikel/Datu/Monat", "8"); >- du.addElement(document, "/Artikel/Datum/Tag", "26"); >- du.setElementValue(document, "/Artikel/Datum/Tag", "24"); >- >- new DOMWriter(System.out).printWithoutFormatting(document); >- System.out.print("\n"); >- System.out.print("\n"); >- >- String[] elements = du.getAllElementValues(document, new XPath("/Artikel/Datum/Monat")); >- >- for (int i = 0; i < elements.length; i++) { >- System.out.println("Elements=" + elements[i]); >- } >- >- System.out.print("\n"); >- System.out.println("Datum/Monat=" >- + du.getElementValue(document.getDocumentElement(), new XPath("Datum/Monat"))); >- System.out.println("Datm=" >- + du.getElementValue(document.getDocumentElement(), new XPath("Datm"))); >- >- System.out.println("Datum/Monat/@Name=" >- + du.getAttributeValue(document.getDocumentElement(), new XPath( >- "Datum/Monat/@Name"))); >- } catch (Exception e) { >- System.err.println(e); >- } >- } >- >- /** >- * Creates a DOM document from a string. >- * >- * @param xml The string. >- * @return A DOM document. >- * @throws Exception if an error occurs. >- * >- * @deprecated Use {@link DocumentHelper#readDocument(java.lang.String)} instead. >- */ >- public Document create(String xml) throws Exception { >- return dpf.getDocument(new StringReader(xml)); >- } >- >- /** >- * Selects an array of elements using an XPath. >- * >- * @param document The document. >- * @param xpath The XPath. >- * @return An array of elements. >- * @throws Exception if the XPath does not return a <code>NodeList</code> consisting of elements. >- * >- * @deprecated Use >- * {@link org.apache.xpath.XPathAPI#selectNodeList(org.w3c.dom.Node, java.lang.String)} >- * instead. >- */ >- public Element[] select(Document document, String xpath) throws Exception { >- log.debug(".select(): " + xpath); >- >- Vector nodes = xpf.select(document, "xpointer(" + xpath + ")"); >- Element[] elements = new Element[nodes.size()]; >- >- for (int i = 0; i < nodes.size(); i++) { >- elements[i] = (Element) nodes.elementAt(i); >- } >- >- return elements; >- } >- >- /** >- * <p> >- * This method removes all child nodes from an element and inserts a text node instead. >- * </p> >- * <p> >- * Caution: Child elements are removed as well! >- * </p> >- * @param element The element. >- * @param text The string to insert as a text node. >- */ >- public void replaceText(Element element, String text) { >- NodeList nl = element.getChildNodes(); >- >- for (int i = nl.getLength() - 1; i >= 0; i--) { >- element.removeChild(nl.item(i)); >- } >- >- element.appendChild(dpf.newTextNode(element.getOwnerDocument(), text)); >- } >- >- /** >- * Returns the concatenation string of all text nodes which are children of an element. >- * The XPath is resolved against the document element. >- * >- * @param document The document. >- * @param xpath The XPath of the element to resolve. >- * @return A string. >- * @throws Exception if an error occurs. >- * >- * @deprecated Use {@link DocumentHelper#getSimpleElementText(org.w3c.dom.Element) instead.} >- */ >- public String getElementValue(Document document, XPath xpath) throws Exception { >- return getElementValue(document.getDocumentElement(), xpath); >- } >- >- /** >- * Returns the concatenation string of all text nodes which are children of an element. >- * The XPath is resolved against a certain element. >- * >- * @param element The element to resolve the XPath against. >- * @param xpath The XPath of the element to resolve. >- * @return A string. >- * @throws Exception if an error occurs. >- * >- * @deprecated Use {@link DocumentHelper#getSimpleElementText(org.w3c.dom.Element) instead.} >- */ >- public String getElementValue(Element element, XPath xpath) throws Exception { >- String value = ""; >- NodeList nl = getElement(element, xpath).getChildNodes(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- short nodeType = nl.item(i).getNodeType(); >- >- if (nodeType == Node.TEXT_NODE) { >- value = value + nl.item(i).getNodeValue(); >- } else { >- log.warn("XPath " + xpath + " contains node types other than just TEXT_NODE"); >- } >- } >- >- return value; >- } >- >- /** >- * Check if elements exists This method just checks the root element! TODO: Implementation is >- * not really finished, or is it! >- * >- * Replacement code: >- * >- * <code> >- * Node node = XPathAPI.selectSingleNode(element, xPath); >- * if (node != null && node instanceof Element) { >- * exists = true; >- * } >- * </code> >- * >- * @deprecated See replacement code. >- */ >- public boolean elementExists(Element element, XPath xpath) throws Exception { >- log.debug(xpath); >- >- if (xpath.parts.length > 0) { >- NodeList nl = element.getElementsByTagName(xpath.parts[0]); >- >- if (nl.getLength() == 0) { >- return false; >- } else if (nl.getLength() == 1) { >- return true; >- } >- } >- return false; >- } >- >- /** >- * Get element via XPath. >- * >- * @deprecated Use >- * {@link org.apache.xpath.XPathAPI#selectSingleNode(org.w3c.dom.Node, java.lang.String)} >- * instead. >- */ >- public Element getElement(Element element, XPath xpath) throws Exception { >- log.debug(xpath); >- >- if (xpath.parts.length > 0) { >- NodeList nl = element.getElementsByTagName(xpath.parts[0]); >- >- if (nl.getLength() == 0) { >- throw new Exception("There are no elements with Name \"" + xpath.parts[0] + "\"."); >- } else if (nl.getLength() == 1) { >- log.debug("There is one element with Name \"" + xpath.parts[0] + "\" (" >- + xpath.parts.length + ")."); >- >- if (xpath.parts.length == 1) { >- return (Element) nl.item(0); >- } else { >- String newXPathString = xpath.parts[1]; >- >- for (int i = 2; i < xpath.parts.length; i++) { >- newXPathString = newXPathString + "/" + xpath.parts[i]; >- } >- >- return getElement((Element) nl.item(0), new XPath(newXPathString)); >- } >- } else { >- throw new Exception("There are more elements than one with Name \"" >- + xpath.parts[0] + "\"."); >- } >- } >- >- return null; >- } >- >- /** >- * get all elements with |xpath|, xpath has to start with the root node >- * >- * @param document a value of type 'Document' >- * @param xpath a value of type 'XPath' >- * >- * @return a value of type 'Element[]' >- * >- * @exception Exception if an error occurs >- * >- * @deprecated Use >- * {@link org.apache.xpath.XPathAPI#selectNodeList(org.w3c.dom.Node, java.lang.String)} >- * instead. >- */ >- public Element[] getAllElements(Document document, XPath xpath) throws Exception { >- Vector nodes = xpf.select(document.getDocumentElement(), "xpointer(" + xpath.toString() >- + ")"); >- Element[] elements = new Element[nodes.size()]; >- >- for (int i = 0; i < nodes.size(); i++) { >- elements[i] = (Element) nodes.elementAt(i); >- } >- >- return elements; >- } >- >- /** >- * get all elements values from |xpath|, xpath has to start with the root node >- * >- * @param document a value of type 'Document' >- * @param xpath a value of type 'XPath' >- * >- * @return a value of type 'String[]' >- * >- * @exception Exception if an error occurs >- */ >- public String[] getAllElementValues(Document document, XPath xpath) throws Exception { >- Vector nodes = xpf.select(document.getDocumentElement(), "xpointer(" + xpath.toString() >- + ")"); >- log.debug("n elements " + nodes.size()); >- >- String[] values = new String[nodes.size()]; >- >- for (int i = 0; i < nodes.size(); i++) { >- values[i] = getElementValue((Element) nodes.elementAt(i)); >- } >- >- return values; >- } >- >- /** >- * Returns the concatenation string of all text nodes which are children of an element. >- * >- * @param element The element. >- * @return A string. >- * @throws Exception if an error occurs. >- * >- * Replacement code: >- * >- * <code> >- * Element element = (Element) XPathAPI.selectSingleNode(document, xPath); >- * String value = DocumentHelper.getSimpleElementText(element, "..."); >- * </code> >- * >- * @deprecated See replacement code. >- */ >- public String getElementValue(Element element) throws Exception { >- String value = ""; >- NodeList nl = element.getChildNodes(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- short nodeType = nl.item(i).getNodeType(); >- >- if (nodeType == Node.TEXT_NODE) { >- value = value + nl.item(i).getNodeValue(); >- } else { >- log.warn("Element " + element.getNodeName() >- + " contains node types other than just TEXT_NODE"); >- } >- } >- >- return value; >- } >- >- /** >- * Return the value of an attribte named e.g. "this/myelement/(at)myattribute" >- * >- * @param element a value of type 'Element' >- * @param xpath a value of type 'XPath' >- * >- * @return a value of type 'String' >- * >- * Replacement code: >- * >- * <code> >- * Element element = (Element) XPathAPI.selectSingleNode(document, xPath); >- * String value = element.getAttribute("..."); >- * </code> >- * >- * @deprecated See replacement code. >- */ >- public String getAttributeValue(Element element, XPath xpath) throws Exception { >- Element el = getElement(element, new XPath(xpath.getElementName())); >- >- return el.getAttribute(xpath.getName()); >- } >- >- /** >- * Describe 'setElementValue' method here. >- * >- * @param document a value of type 'Document' >- * @param xpath a value of type 'String' >- * @param value a value of type 'String' >- * >- * @exception Exception if an error occurs >- * >- * Replacement code: >- * >- * <code> >- * Element element = (Element) XPathAPI.selectSingleNode(document, xPath); >- * DocumentHelper.setSimpleElementText(element, "..."); >- * </code> >- * >- * @deprecated See replacement code. >- */ >- public void setElementValue(Document document, String xpath, String value) throws Exception { >- Element[] elements = select(document, xpath); >- >- if (elements.length >= 1) { >- if (elements.length > 1) { >- log.warn("There are more elements than one with XPath \"" + xpath >- + "\". The value of the first element will be replaced"); >- } >- >- replaceText(elements[0], value); >- } else { >- XPath xp = new XPath(xpath); >- log.warn("XPath does not exist, but will be created: " + xp); >- >- Element element = (Element) createNode(document, xp); >- replaceText(element, value); >- } >- } >- >- /** >- * Replacement code: >- * >- * <code> >- * Element parent = (Element) XPathAPI.selectSingleNode(document, xPath); >- * Element child = NamespaceHelper.createElement("...", "..."); >- * parent.appendChild(child); >- * </code> >- * >- * @deprecated See replacement code. >- */ >- public void addElement(Document document, String xpath, String value) throws Exception { >- XPath xp = new XPath(xpath); >- Node parent = createNode(document, xp.getParent()); >- Element element = dpf.newElementNode(document, xp.getName()); >- parent.appendChild(element); >- >- if (value != null) { >- element.appendChild(dpf.newTextNode(element.getOwnerDocument(), value)); >- } >- } >- >- /** >- * Replacement code: >- * >- * <code> >- * Element element = (Element) XPathAPI.selectSingleNode(document, xPath); >- * element.setAttribute("...", "..."); >- * </code> >- * >- * @deprecated See replacement code. >- */ >- public void setAttributeValue(Document document, String xpath, String value) throws Exception { >- Vector nodes = xpf.select(document, "xpointer(" + xpath + ")"); >- >- if (nodes.size() >= 1) { >- Attr attribute = (Attr) nodes.elementAt(0); >- attribute.setValue(value); >- } else { >- XPath xp = new XPath(xpath); >- log.debug("XPath does not exist, but will be created: " + xp); >- >- Attr attribute = (Attr) createNode(document, xp); >- attribute.setValue(value); >- } >- } >- >- /** >- * <ul> >- * <li>If the XPath expression denotes an element, the child nodes of this element are replaced by a single >- * text node.</li> >- * <li>If the XPath expression denotes an attribute, the attribute value is set.</li> >- * <li>Otherwise, an error is logged.</li> >- * </ul> >- * >- * @param document The document to resolve the XPath against. >- * @param xpath The XPath. >- * @param value A string. >- * @throws Exception if an error occurs. >- */ >- public void setValue(Document document, XPath xpath, String value) throws Exception { >- short type = xpath.getType(); >- >- if (type == Node.ATTRIBUTE_NODE) { >- setAttributeValue(document, xpath.toString(), value); >- } else if (type == Node.ELEMENT_NODE) { >- setElementValue(document, xpath.toString(), value); >- } else { >- log.error("No such type: " + type); >- } >- } >- >- /** >- * Replacement code: >- * >- * <code> >- * Element parent = XPathAPI.selectSingleNode(...); >- * Element child = document.createElementNS("http://...", "..."); >- * parent.appendChild(child); >- * </code> >- * >- * @deprecated See replacement code. >- */ >- public Node createNode(Document document, XPath xpath) throws Exception { >- log.debug(xpath); >- >- Node node = null; >- Vector nodes = xpf.select(document, "xpointer(" + xpath + ")"); >- >- if (nodes.size() >= 1) { >- node = (Node) nodes.elementAt(0); >- } else { >- Node parentNode = createNode(document, xpath.getParent()); >- >- if (xpath.getType() == Node.ATTRIBUTE_NODE) { >- ((Element) parentNode).setAttribute(xpath.getNameWithoutPredicates(), "null"); >- node = ((Element) parentNode).getAttributeNode(xpath.getNameWithoutPredicates()); >- } else { >- node = dpf.newElementNode(document, xpath.getNameWithoutPredicates()); >- parentNode.appendChild(node); >- } >- } >- >- return node; >- } >-} >\ No newline at end of file >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/MalformedXPointerException.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/MalformedXPointerException.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/MalformedXPointerException.java (working copy) >@@ -1,41 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-/** >- * DOCUMENT ME! >- */ >-public class MalformedXPointerException extends Exception { >- /** >- * Creates a new MalformedXPointerException object. >- */ >- public MalformedXPointerException() { >- super(); >- } >- >- /** >- * Creates a new MalformedXPointerException object. >- * >- * @param s DOCUMENT ME! >- */ >- public MalformedXPointerException(String s) { >- super(s); >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XMLEncToJavaEnc.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XMLEncToJavaEnc.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XMLEncToJavaEnc.java (working copy) >@@ -1,105 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.util.Hashtable; >- >- >-/** >- * DOCUMENT ME! >- * @deprecated >- */ >-public class XMLEncToJavaEnc extends Hashtable { >- private static String DEFAULT_ENCODING = "utf-8"; >- >- private XMLEncToJavaEnc() { >- // JAVA supports a lot more... >- // http://www.w3.org/International/O-charset-list.html >- // >- put("ascii", "ASCII"); >- put("iso-8859-1", "ISO8859_1"); // Latin 1 >- put("iso-8859-2", "ISO8859_2"); // Latin 2 >- put("iso-8859-3", "ISO8859_3"); >- put("iso-8859-4", "ISO8859_4"); >- put("iso-8859-5", "ISO8859_5"); >- put("iso-8859-6", "ISO8859_6"); >- put("iso-8859-7", "ISO8859_7"); >- put("iso-8859-8", "ISO8859_8"); >- put("iso-8859-9", "ISO8859_9"); >- put("big-5", "Big5"); // Traditional Chinese >- >- put("cp-874", "Cp874"); // IBM Thai >- >- //put("cp-932",???); >- put("cp-950", "Cp950"); // PC Chinese (Hongkong, Taiwan) >- put("cp-1250", "Cp1250"); // Windows Eastern Europe >- put("cp-1251", "Cp1251"); // Windows Cyrillic >- put("cp-1252", "Cp1252"); // Windows Latin 1 >- put("cp-1253", "Cp1253"); // Windows Greek >- put("cp-1255", "Cp1255"); // Windows Hebrew >- put("cp-1256", "Cp1256"); // Windows Arabic >- put("cp-1257", "Cp1257"); // Windows Baltic >- put("cp-1258", "Cp1258"); // Windows Vietnamese >- put("euc-jp", "EUC_JP"); // JIS0201, 0208, 0212, EUC Encoding, Japanese >- put("euc-kr", "EUC_KR"); // KS C 5601, EUC Encoding, Korean >- >- put("iso-2022-jp", "ISO2022JP"); // JIS0201, 0208, 0212, ISO2022 Encoding, Japanese >- put("iso-2022-kr", "ISO2022KR"); // ISO 2022 KR, Korean >- >- put("koi8-r", "KOI8_R"); // KOI8-R, Russian >- put("shift_jis", "SJIS"); // Shift-JIS, Japanese >- >- put("utf-8", "UTF8"); >- >- put("euc-tw", "EUC_TW"); // CNS11643 (Plane 1-3), T. Chinese, EUC encoding >- put("x-mac-roman", "MacRoman"); // Macintosh Roman >- put("x-mac-ce", "MacCentralEurope"); // Macintosh Latin-2 >- put("x-mac-greek", "MacGreek"); // Macintosh Greek >- put("x-mac-turkish", "MacTurkish"); // Macintosh Turkish >- put("x-mac-cyrillic", "MacCyrillic"); // Macintosh Cyrillic >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- System.out.println(XMLEncToJavaEnc.getJava("utf-8")); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param xmlencoding DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public static String getJava(String xmlencoding) { >- >- try { >- return ((String) ((new XMLEncToJavaEnc()).get(xmlencoding.toLowerCase()))); >- } catch (Exception e) { >- System.err.println("Unsupported Encoding; reverting to " + DEFAULT_ENCODING); >- >- return DEFAULT_ENCODING; >- } >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMParserFactory.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMParserFactory.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/DOMParserFactory.java (working copy) >@@ -1,318 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.io.File; >-import java.io.FileNotFoundException; >-import java.io.InputStream; >-import java.io.Reader; >-import java.util.Properties; >- >-import org.apache.lenya.xml.parser.Parser; >-import org.apache.log4j.Category; >-import org.w3c.dom.CDATASection; >-import org.w3c.dom.Comment; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.NamedNodeMap; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >-import org.w3c.dom.Text; >-import org.xml.sax.SAXException; >- >- >-/** >- * Utility class for creating DOM documents >- * @deprecated replaced by DocumentHelper >- */ >-public class DOMParserFactory { >- static Category log = Category.getInstance(DOMParserFactory.class); >- public Parser parser = null; >- >- /** >- * Reads the properties and gets the parser >- */ >- public DOMParserFactory() { >- Properties properties = new Properties(); >- String propertiesFileName = "conf.properties"; >- >- try { >- properties.load(DOMParserFactory.class.getResourceAsStream(propertiesFileName)); >- } catch (Exception e) { >- log.fatal(": Failed to load properties from resource: " + propertiesFileName); >- } >- >- String parserName = properties.getProperty("Parser"); >- >- if (parserName == null) { >- log.fatal(": No Parser specified in " + propertiesFileName); >- } >- >- try { >- Class parserClass = Class.forName(parserName); >- parser = (Parser) parserClass.newInstance(); >- } catch (Exception e) { >- log.fatal(": " + e); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- DOMParserFactory dpf = new DOMParserFactory(); >- >- if (args.length != 1) { >- System.out.println("Usage: java " + dpf.getClass().getName() + " example.xml"); >- >- return; >- } >- >- Document doc = null; >- >- try { >- doc = dpf.getDocument(args[0]); >- } catch (FileNotFoundException e) { >- System.err.println("No such file or directory: " + e.getMessage()); >- >- return; >- } catch (SAXException e) { >- System.err.println(e); >- >- return; >- } catch (Exception e) { >- System.err.println(e.getMessage()); >- >- return; >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param filename DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws FileNotFoundException DOCUMENT ME! >- * @throws Exception DOCUMENT ME! >- */ >- public Document getDocument(String filename) throws FileNotFoundException, Exception { >- File file = new File(filename); >- >- if (!file.exists()) { >- log.error("No such file or directory: " + filename); >- throw new FileNotFoundException(filename); >- } >- >- return parser.getDocument(filename); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param inputStream DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public Document getDocument(InputStream inputStream) >- throws Exception { >- return parser.getDocument(inputStream); >- } >- >- /** >- * Create a document from a reader. >- * >- * @param inputStream DOCUMENT ME! >- * @return DOCUMENT ME! >- * @throws Exception DOCUMENT ME! >- */ >- public Document getDocument(Reader reader) throws Exception { >- return parser.getDocument(reader); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Document getDocument() { >- return parser.getDocument(); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param name DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Element newElementNode(Document document, String name) { >- return parser.newElementNode(document, name); >- } >- >- /** >- * Creates an element with namespace support. >- * >- * @param document The owner document. >- * @param namespaceUri The namespace URI of the element. >- * @param qualifiedName The qualified name of the element. >- * >- * @return An element. >- */ >- public Element newElementNSNode(Document document, String namespaceUri, String qualifiedName) { >- return parser.newElementNSNode(document, namespaceUri, qualifiedName); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param data DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Text newTextNode(Document document, String data) { >- return parser.newTextNode(document, data); >- } >- >- /** >- * CDATA >- * >- * @param document DOM document >- * @param data Text >- * >- * @return CDATASection >- */ >- public CDATASection newCDATASection(Document document, String data) { >- return parser.newCDATASection(document, data); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param data DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Comment newCommentNode(Document document, String data) { >- return parser.newCommentNode(document, data); >- } >- >- /** >- * Clone node, which means copy a node into another document >- * >- * @param document New document where original nodes shall be attached to >- * @param original Original node from original document >- * @param deep true means clone also all children >- * >- * @return New node, which is clone of original node >- */ >- public Node cloneNode(Document document, Node original, boolean deep) { >- Node node = null; >- short nodeType = original.getNodeType(); >- >- switch (nodeType) { >- case Node.ELEMENT_NODE: { >- Element element = newElementNSNode(document, original.getNamespaceURI(), original.getNodeName()); >- log.debug(".cloneNode(): Clone element: " + original.getNodeName()); >- NamedNodeMap attributes = original.getAttributes(); >- >- for (int i = 0; i < attributes.getLength(); i++) { >- Node attribute = attributes.item(i); >- log.debug(".cloneNode(): LocalName: " + attribute.getLocalName() + ", Prefix: " + attribute.getPrefix() + ", NamespaceURI: " + attribute.getNamespaceURI()); >- element.setAttributeNS(attribute.getNamespaceURI(), attribute.getNodeName(), attribute.getNodeValue()); >- } >- >- node = element; >- >- break; >- } >- >- case Node.TEXT_NODE: { >- Text text = newTextNode(document, original.getNodeValue()); >- >- node = text; >- >- break; >- } >- >- case Node.CDATA_SECTION_NODE: { >- CDATASection cdata = newCDATASection(document, original.getNodeValue()); >- >- node = cdata; >- >- break; >- } >- >- case Node.COMMENT_NODE: { >- Comment comment = newCommentNode(document, original.getNodeValue()); >- >- node = comment; >- >- break; >- } >- >- default: >- log.warn(".cloneNode(): Node type not implemented: " + nodeType); >- break; >- } >- >- if (deep && original.hasChildNodes()) { >- NodeList nl = original.getChildNodes(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- node.appendChild(cloneNode(document, nl.item(i), deep)); >- } >- } >- >- return node; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param element DOCUMENT ME! >- * @param value DOCUMENT ME! >- */ >- public void setElementValue(Document document, Element element, String value) { >- // remove all child nodes >- NodeList nl = element.getChildNodes(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- try { >- element.removeChild(nl.item(i)); >- } catch (Exception e) { >- System.err.println("EXCEPTION: " + this.getClass().getName() + >- ".setElementValue(): " + e); >- } >- } >- >- // add a new TextNode for storing the new value >- element.appendChild(newTextNode(document, value)); >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPath.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPath.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XPath.java (working copy) >@@ -1,119 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import java.util.StringTokenizer; >- >-import org.w3c.dom.Node; >- >-public class XPath { >- String xpath = null; >- String[] parts = null; >- >- /** >- * >- */ >- public XPath(String xpath) { >- this.xpath = xpath; >- >- StringTokenizer st = new StringTokenizer(xpath, "/"); >- int length = st.countTokens(); >- parts = new String[length]; >- >- for (int i = 0; i < length; i++) { >- parts[i] = st.nextToken(); >- } >- } >- >- /** >- * >- */ >- public XPath getParent() { >- String parentXPath = ""; >- >- for (int i = 0; i < (parts.length - 1); i++) { >- parentXPath = parentXPath + "/" + parts[i]; >- } >- >- return new XPath(parentXPath); >- } >- >- /** >- * >- */ >- public short getType() { >- if (parts[parts.length - 1].indexOf("@") == 0) { >- return Node.ATTRIBUTE_NODE; >- } >- >- return Node.ELEMENT_NODE; >- } >- >- /** >- * >- */ >- public String toString() { >- return xpath; >- } >- >- /** >- * >- */ >- public String getName() { >- if (getType() == Node.ATTRIBUTE_NODE) { >- return parts[parts.length - 1].substring(1); >- } >- >- return parts[parts.length - 1]; >- } >- >- /** >- * Describe 'getName' method here. >- * >- * @return a value of type 'String' >- */ >- public String getElementName() { >- if (getType() == Node.ATTRIBUTE_NODE) { >- return parts[parts.length - 2]; >- } >- >- return parts[parts.length - 1]; >- } >- >- /** >- * >- */ >- public String getNameWithoutPredicates() { >- return removePredicates(getName()); >- } >- >- /** >- * Remove predicates (square brackets), http://www.w3.org/TR/xpath >- */ >- public String removePredicates(String s) { >- int index = s.indexOf("["); >- >- if (index >= 0) { >- return s.substring(0, index); >- } >- >- return s; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XLink.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XLink.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XLink.java (working copy) >@@ -1,92 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >-import org.w3c.dom.Attr; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >- >-public class XLink { >- >- public String type = null; >- public String href = null; >- public String show = null; >- public String name = null; >- public Element element = null; >- >- public static final String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink"; >- public static final String ATTRIBUTE_HREF = "href"; >- public static final String ATTRIBUTE_SHOW = "show"; >- public static final String ATTRIBUTE_TYPE = "type"; >- >- /** >- * >- */ >- public XLink() { >- type = "simple"; >- show = "undefined"; >- } >- >- /** >- * >- */ >- public XLink(Element element) { >- this(); >- this.element = element; >- >- name = element.getNodeName(); >- >- Attr hrefAttribute = element.getAttributeNodeNS(XLINK_NAMESPACE, ATTRIBUTE_HREF); >- if (hrefAttribute != null) { >- href = hrefAttribute.getNodeValue(); >- } >- Attr typeAttribute = element.getAttributeNodeNS(XLINK_NAMESPACE, ATTRIBUTE_TYPE); >- if (typeAttribute != null) { >- type = typeAttribute.getNodeValue(); >- } >- Attr showAttribute = element.getAttributeNodeNS(XLINK_NAMESPACE, ATTRIBUTE_SHOW); >- if (showAttribute != null) { >- show = showAttribute.getNodeValue(); >- } >- >- } >- >- /** >- * >- */ >- public Element getXLink(Document document, DOMParserFactory dpf) { >- return (Element) dpf.cloneNode(document, element, true); >- } >- >- /** >- * >- */ >- public String toString() { >- return "XLink: type=\"" >- + type >- + "\", href=\"" >- + href >- + "\", show=\"" >- + show >- + "\", name=\"" >- + name >- + "\""; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpointer/XPointer.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpointer/XPointer.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpointer/XPointer.java (working copy) >@@ -1,43 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml.xpointer; >- >-import java.util.Vector; >- >-import org.w3c.dom.Node; >- >- >-/** >- * XPointer interface >- */ >-public interface XPointer { >- >- /** >- * DOCUMENT ME! >- * >- * @param node DOCUMENT ME! >- * @param selectString DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @exception Exception ... >- */ >- Vector select(Node node, String selectString, Vector namespaces) throws Exception; >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpointer/XalanXPointer.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpointer/XalanXPointer.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpointer/XalanXPointer.java (working copy) >@@ -1,132 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml.xpointer; >- >-import java.util.Vector; >- >-import org.apache.lenya.xml.DOMParserFactory; >-import org.apache.log4j.Category; >-import org.apache.xpath.XPathAPI; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >- >- >-/** >- * XPointer implementation >- */ >-public class XalanXPointer implements XPointer { >- private static Category log = Category.getInstance(XalanXPointer.class); >- >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- XPointer xpointer = new XalanXPointer(); >- >- if (args.length != 2) { >- System.err.println("Usage: java " + xpointer.getClass().getName() + >- " example.xml \"/Example/People/Person[position() < 2]/Street/@Number\""); >- >- return; >- } >- >- DOMParserFactory dpf = new DOMParserFactory(); >- Document document = null; >- >- try { >- document = dpf.getDocument(args[0]); >- } catch (Exception e) { >- System.err.println(xpointer.getClass().getName() + ".main(): " + e); >- } >- >- Element root = document.getDocumentElement(); >- String xpath = args[1]; >- >- try { >- Vector namespaces = new Vector(); >- Vector nodes = xpointer.select(root, xpath, namespaces); >- >- for (int i = 0; i < nodes.size(); i++) { >- Node node = (Node) nodes.elementAt(i); >- short type = node.getNodeType(); >- >- if (type == Node.ATTRIBUTE_NODE) { >- System.out.println("Attribute (" + node.getNodeName() + "): " + >- node.getNodeValue()); >- } else if (type == Node.ELEMENT_NODE) { >- System.out.println("Element (" + node.getNodeName() + "): " + >- node.getFirstChild().getNodeValue()); >- } >- } >- } catch (Exception e) { >- System.err.println(e); >- } >- } >- >- /** >- * Select node by specified XPath >- * >- * @param node Node to select from >- * @param xpath XPath to select nodes >- * >- * @return Selected nodes >- * >- * @exception Exception ... >- */ >- public Vector select(Node node, String xpath, Vector namespaces) throws Exception { >- NodeList children = node.getChildNodes(); >- >- log.debug("Select " + xpath + " from node " + node.getNodeName()); >- >- NodeList nl = null; >- if (namespaces.size() > 0) { >- org.w3c.dom.Document doc = org.apache.lenya.xml.DocumentHelper.createDocument("", "foo", null); >- for (int i = 0; i < namespaces.size(); i++) { >- String namespace = (String)namespaces.elementAt(i); >- String prefix = namespace.substring(0, namespace.indexOf("=")); >- String namespaceURI = namespace.substring(namespace.indexOf("=") + 1); >- log.debug("Namespace: " + prefix + " " + namespaceURI); >- >- doc.getDocumentElement().setAttribute("xmlns:" + prefix, namespaceURI); >- } >- nl = XPathAPI.selectNodeList(node, xpath, doc.getDocumentElement()); >- } else { >- nl = XPathAPI.selectNodeList(node, xpath); >- } >- >- >- if (nl != null && nl.getLength() == 0) { >- log.info("No such nodes: " + xpath); >- return new Vector(); >- } >- >- Vector nodes = new Vector(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- nodes.addElement(nl.item(i)); >- } >- >- return nodes; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpsconf.properties >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpsconf.properties (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/xpsconf.properties (working copy) >@@ -1,28 +0,0 @@ >-# Copyright 1999-2004 The Apache Software Foundation >-# >-# Licensed under the Apache License, Version 2.0 (the "License"); >-# you may not use this file except in compliance with the License. >-# You may obtain a copy of the License at >-# >-# http://www.apache.org/licenses/LICENSE-2.0 >-# >-# Unless required by applicable law or agreed to in writing, software >-# distributed under the License is distributed on an "AS IS" BASIS, >-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >-# See the License for the specific language governing permissions and >-# limitations under the License. >- >-# replace: the XLink will be replaced, embed: the XLink will be included, enclose: the XLink will enclose the returned NodeList >-Include=replace >-# Example: xlink:href=class:org.apache.lenya.xps.XPSIncludeHelloWorld >-JavaZone=class: >-# DEPRECATED Example: xlink:href=/java/org.apache.lenya.xps.XPSIncludeHelloWorld >-#JavaZone=/java/ >-# Directory where the XLink Interpreter is caching assembled documents >-#org.apache.lenya.xps.XLinkInterpreter.cacheFolder= >-# XML Documents received via HTTP Request will not be cached. Conflict with LastModified. Will be solved in the near future by saving LastModified separately. >-cacheHTTP=no >-# Proxy Host >-proxyHost=@xps.proxy.host@ >-# Proxy Port >-proxyPort=@xps.proxy.port@ >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XIncludeImpl.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XIncludeImpl.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/xml/XIncludeImpl.java (working copy) >@@ -1,603 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.xml; >- >- >-import java.io.File; >-import java.io.FileOutputStream; >-import java.io.IOException; >-import java.io.InputStream; >-import java.io.OutputStream; >-import java.net.URL; >-import java.util.Properties; >-import java.util.StringTokenizer; >-import java.util.Vector; >- >-import org.apache.lenya.net.ProxyManager; >-import org.apache.log4j.Category; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >- >- >-/** >- * XLink/XInclude Processor (Nesting, Caching, Java, Exceptions) >- */ >-public class XIncludeImpl implements XInclude { >- static Category log = Category.getInstance(XIncludeImpl.class); >- DOMParserFactory dpf = null; >- XPointerFactory xpf = null; >- Configuration conf = null; >- ProxyManager pm = null; >- String XPSEXCEPTION_ELEMENT_NAME = "XPSEXCEPTION"; // better would be a namespace xps:XLinkException >- >- /** >- * Creates a new XIncludeImpl object. >- */ >- public XIncludeImpl() { >- dpf = new DOMParserFactory(); >- xpf = new XPointerFactory(); >- conf = new Configuration(); >- pm = new ProxyManager(); >- >- if ((conf.proxyHost != null) && (conf.proxyPort != null)) { >- Properties sp = System.getProperties(); >- sp.put("proxySet", "true"); >- sp.put("proxyHost", conf.proxyHost); >- sp.put("proxyPort", conf.proxyPort); >- } >- } >- >- /** >- * Creates a new XIncludeImpl object. >- * >- * @param includeoption DOCUMENT ME! >- */ >- public XIncludeImpl(String includeoption) { >- this(); >- conf.INCLUDE = includeoption; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param reference DOCUMENT ME! >- * @param cocoon DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Document assemble(String reference, String cocoon) { >- File workingDirectory = new File(System.getProperty("user.dir")); >- XPSSourceInformation sourceInfo = new XPSSourceInformation("file:" + workingDirectory + >- "/dummy.xml", cocoon); >- String[] args = new String[1]; >- args[0] = reference; >- >- XPSSourceInformation currentInfo = new XPSSourceInformation(args[0], sourceInfo, cocoon); >- deleteFromCache(currentInfo.url); >- >- Vector nodes = include(args, sourceInfo); >- log.debug(sourceInfo); >- >- Node node = (Node) nodes.elementAt(0); >- >- return node.getOwnerDocument(); >- } >- >- /** >- * Remove file from cache >- * >- * @param url DOCUMENT ME! >- */ >- public void deleteFromCache(URL url) { >- if (conf.cacheFolder != null) { >- File cacheFile = getCacheFile(url); >- >- if (cacheFile.isFile()) { >- log.info(".deleteFromCache(): " + cacheFile.getAbsolutePath()); >- cacheFile.delete(); >- } else { >- log.warn(".deleteFromCache(): No such file in cache: " + >- cacheFile.getAbsolutePath()); >- } >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param document DOCUMENT ME! >- * @param reference DOCUMENT ME! >- * @param cocoon DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Document assemble(Document document, String reference, String cocoon) { >- //return document; >- Element root = document.getDocumentElement(); >- Document assembledDocument = dpf.getDocument(); >- Element assembledRoot = (Element) dpf.cloneNode(assembledDocument, root, false); >- assembledDocument.appendChild(assembledRoot); >- >- File workingDirectory = new File(System.getProperty("user.dir")); >- XPSSourceInformation sourceInfo = new XPSSourceInformation("file:" + workingDirectory + "/dummy.xml", cocoon); >- XPSSourceInformation currentInfo = new XPSSourceInformation(reference, sourceInfo, cocoon); >- NodeList nl = root.getChildNodes(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- traverse(assembledRoot, nl.item(i), sourceInfo, currentInfo); >- } >- >- return assembledDocument; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param currentInfo DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- * >- * @throws Exception DOCUMENT ME! >- */ >- public InputStream readXML(XPSSourceInformation currentInfo) >- throws Exception { >- InputStream is = null; >- File cacheFile = null; >- long originalFileLastModified = 0; >- >- String protocol = currentInfo.url.getProtocol(); >- >- URL url = null; >- >- if (conf.cacheFolder != null) // Check cache >- { >- cacheFile = getCacheFile(currentInfo.url); >- >- if (protocol.equals("file")) { >- File originalFile = new File(currentInfo.url.getFile()); >- originalFileLastModified = originalFile.lastModified(); >- } else if (protocol.equals("http")) { >- pm.set(currentInfo.url.getHost()); // install proxy if necessary >- originalFileLastModified = currentInfo.url.openConnection().getLastModified(); >- } else { >- log.error("No such protocol: " + protocol); >- } >- >- if (cacheFile.isFile() && (cacheFile.lastModified() >= originalFileLastModified)) { >- // File already exists in cache and is newer than original File >- url = new URL("file:" + cacheFile.getAbsolutePath()); >- } else { // File does not exist in cache >- url = new URL(currentInfo.url.toString()); >- } >- } else { // No cache folder specified >- url = new URL(currentInfo.url.toString()); >- } >- >- // Read Document >- is = url.openStream(); >- >- return is; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param currentInfo DOCUMENT ME! >- * @param newDocument DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public boolean tryWritingToCache(XPSSourceInformation currentInfo, Document newDocument) { >- File cacheFile = null; >- >- if (conf.cacheFolder != null) // Check cache >- { >- cacheFile = getCacheFile(currentInfo.url); >- } >- >- if (cacheFile != null) { >- String protocol = currentInfo.url.getProtocol(); >- >- if (!cacheFile.exists()) { // Write "Xlink" to cache >- >- return writeToCache(protocol, cacheFile, newDocument); >- } else { // cacheFile exists >- >- long originalFileLastModified = 0; >- String p = currentInfo.url.getProtocol(); >- >- if (p.equals("file")) { >- File originalFile = new File(currentInfo.url.getFile()); >- originalFileLastModified = originalFile.lastModified(); >- } else if (p.equals("http")) { >- try { >- originalFileLastModified = currentInfo.url.openConnection().getLastModified(); >- } catch (IOException e) { >- log.error("originalFileLastModified: " + e); >- } >- } else { >- log.error("No such protocol: " + p); >- } >- >- if (cacheFile.lastModified() < originalFileLastModified) { >- // File in cache is older than original File >- return writeToCache(protocol, cacheFile, newDocument); >- } >- } >- } >- >- return false; >- } >- >- /** >- * param args args[0]=url >- * >- * @param args DOCUMENT ME! >- * @param sourceInfo DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public Vector include(String[] args, XPSSourceInformation sourceInfo) { >- XPSSourceInformation currentInfo = new XPSSourceInformation(args[0], sourceInfo, sourceInfo.cocoon); >- >- sourceInfo.addChild(currentInfo); >- >- if (currentInfo.checkLoop(sourceInfo, currentInfo.url)) { >- log.warn("Loop detected: " + sourceInfo.url.getFile() + " " + currentInfo.url.getFile()); >- return null; >- } >- >- Document document = null; >- Vector nodes = new Vector(); >- Document newDocument = dpf.getDocument(); >- >- try { >- InputStream is = readXML(currentInfo); >- document = dpf.getDocument(is); >- } catch (Exception e) { >- log.warn(e + ", currentInfo: " + currentInfo.url.getFile() + " , sourceInfo: " + sourceInfo.url.getFile()); >- >- Element newRoot = dpf.newElementNode(newDocument, XPSEXCEPTION_ELEMENT_NAME); >- newRoot.appendChild(dpf.newTextNode(newDocument, "" + e)); >- nodes.addElement(newRoot); >- >- return nodes; >- } >- >- Element root = document.getDocumentElement(); >- Element newRoot = (Element) dpf.cloneNode(newDocument, root, false); >- newDocument.appendChild(newRoot); >- >- NodeList nl = root.getChildNodes(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- traverse(newRoot, nl.item(i), sourceInfo, currentInfo); >- } >- >- boolean writtenToCache = tryWritingToCache(currentInfo, newDocument); >- >- if (currentInfo.url.getRef() == null) { >- log.debug("No XPointer. Return the root node in order to add the whole document."); >- nodes.addElement(newRoot); >- } else { >- log.debug("XPointer: " + currentInfo.url.getRef()); >- try { >- nodes = xpf.select(newRoot, currentInfo.url.getRef()); >- >- for (int i = 0; i < nodes.size(); i++) { >- short nodeType = ((Node) nodes.elementAt(i)).getNodeType(); >- >- switch (nodeType) { >- case Node.ELEMENT_NODE: >- break; >- >- case Node.ATTRIBUTE_NODE: { >- Node attribute = (Node) nodes.elementAt(i); >- nodes.removeElementAt(i); >- nodes.insertElementAt(dpf.newTextNode(attribute.getOwnerDocument(), >- attribute.getNodeValue()), i); >- >- break; >- } >- >- default: { >- log.error(".include(): Node Type (" + nodeType + ") can't be a child of Element"); >- nodes.removeElementAt(i); >- >- break; >- } >- } >- } >- } catch (Exception e) { >- log.error("", e); >- } >- } >- >- return nodes; >- } >- >- /** >- * Traverses recursively and looks for XLinks and includes the returned NodeList >- * >- * @param newParent DOCUMENT ME! >- * @param orgChild DOCUMENT ME! >- * @param sourceInfo DOCUMENT ME! >- * @param currentInfo DOCUMENT ME! >- */ >- public void traverse(Node newParent, Node orgChild, XPSSourceInformation sourceInfo, >- XPSSourceInformation currentInfo) { >- Vector newChildren = new Vector(); >- short nodeType = orgChild.getNodeType(); >- boolean noXLink = true; >- >- switch (nodeType) { >- case Node.ELEMENT_NODE: { >- XLink xlink = new XLink((Element) orgChild); >- >- if (xlink.href == null) { >- Element newElement = (Element) dpf.cloneNode(newParent.getOwnerDocument(), orgChild, false); >- newChildren.addElement(newElement); >- } else { >- noXLink = false; >- log.debug(".traverse(): xlink:href=\"" + xlink.href + "\""); >- >- NodeList nl = processXLink(xlink, (Element) orgChild, currentInfo); >- >- for (int i = 0; i < nl.getLength(); i++) { >- newChildren.addElement(dpf.cloneNode(newParent.getOwnerDocument(), nl.item(i), true)); >- } >- } >- >- break; >- } >- >- case Node.COMMENT_NODE: { >- newChildren.addElement(dpf.newCommentNode(newParent.getOwnerDocument(), orgChild.getNodeValue())); >- >- break; >- } >- >- case Node.TEXT_NODE: { >- newChildren.addElement(dpf.newTextNode(newParent.getOwnerDocument(), orgChild.getNodeValue())); >- >- break; >- } >- >- case Node.CDATA_SECTION_NODE: { >- newChildren.addElement(dpf.newCDATASection(newParent.getOwnerDocument(), orgChild.getNodeValue())); >- >- break; >- } >- >- default: { >- log.error(".traverse(): Node type not implemented: " + nodeType + " (" + currentInfo.url + ")"); >- break; >- } >- } >- >- for (int i = 0; i < newChildren.size(); i++) { >- newParent.appendChild((Node) newChildren.elementAt(i)); >- } >- >- if (orgChild.hasChildNodes() && noXLink) { >- NodeList nl = orgChild.getChildNodes(); >- >- for (int i = 0; i < nl.getLength(); i++) { >- traverse((Node) newChildren.elementAt(0), nl.item(i), sourceInfo, currentInfo); >- } >- } >- } >- >- /** >- * Process XLink >- * >- * @param xlink DOCUMENT ME! >- * @param orgChild DOCUMENT ME! >- * @param currentInfo DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public NodeList processXLink(XLink xlink, Element orgChild, XPSSourceInformation currentInfo) { >- NodeList nl = null; >- >- // NOTE: if no show attribute is specified, then the value will be set to "undefined" >- if (!(xlink.show.equals("embed") || xlink.show.equals("enclose") || xlink.show.equals("replace"))) { >- log.warn("No such value of attribute \"show\" implemented: " + xlink.show); >- nl = noNodesReturnedFromXLink(xlink); >- } else { >- Vector args = new Vector(); >- String includeClassName = includeClassName(xlink.href, args); >- String[] arguments = new String[args.size()]; >- >- for (int i = 0; i < args.size(); i++) { >- arguments[i] = (String) args.elementAt(i); >- log.debug("Arguments: " + arguments[i]); >- } >- >- Vector newChildren = null; >- >- try { >- if (includeClassName.equals(this.getClass().getName())) { >- newChildren = include(arguments, currentInfo); >- } else { >- Class includeClass = Class.forName(includeClassName); >- XInclude xpsInclude = (XInclude) includeClass.newInstance(); >- newChildren = xpsInclude.include(arguments, currentInfo); >- } >- } catch (Exception e) { >- log.error(".processXLink(): " + e); >- } >- >- if (newChildren != null) // Returned nodes from XLink >- { >- if (newChildren.size() > 0) { >- Node firstChild = (Node) newChildren.elementAt(0); >- Document xlinkedDocument = firstChild.getOwnerDocument(); >- Element dummyRoot = dpf.newElementNode(xlinkedDocument, "DummyRoot"); >- >- if (xlink.show.equals("embed")) { >- //if (conf.INCLUDE.equals("embed")) { >- // WARNING: embed was actually meant to also include the actual xlink, but >- // it was never really implemented and hence led to the misinterpretation of replace >- // Therefore we treat it the same as replace >- //dummyRoot.appendChild(xlink.getXLink(xlinkedDocument, dpf)); >- >- for (int i = 0; i < newChildren.size(); i++) { >- dummyRoot.appendChild((Node) newChildren.elementAt(i)); >- } >- } else if (xlink.show.equals("replace")) { >- //} else if (conf.INCLUDE.equals("replace")) { >- for (int i = 0; i < newChildren.size(); i++) { >- dummyRoot.appendChild((Node) newChildren.elementAt(i)); >- } >- } else if (xlink.show.equals("enclose")) { >- //} else if (conf.INCLUDE.equals("enclose")) { >- Element xlinkCopy = xlink.getXLink(xlinkedDocument, dpf); >- >- for (int i = 0; i < newChildren.size(); i++) { >- xlinkCopy.appendChild((Node) newChildren.elementAt(i)); >- } >- dummyRoot.appendChild(xlinkCopy); >- } else { >- log.warn("No such attribute \"show\" or such value of attribute \"show\" implemented"); >- } >- >- nl = dummyRoot.getChildNodes(); >- } >- } >- >- if (nl == null) { >- nl = noNodesReturnedFromXLink(xlink); >- } >- >- if (nl.getLength() == 0) { >- nl = noNodesReturnedFromXLink(xlink); >- } >- } >- >- return nl; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param xlink DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public NodeList noNodesReturnedFromXLink(XLink xlink) { >- log.warn("No nodes returned from XLink: " + xlink); >- >- Document dummyDocument = dpf.getDocument(); >- Element dummyRoot = dpf.newElementNode(dummyDocument, "DummyRoot"); >- Element element = xlink.getXLink(dummyDocument, dpf); >- dummyRoot.appendChild(element); >- >- Element exceptionElement = dpf.newElementNode(dummyDocument, XPSEXCEPTION_ELEMENT_NAME); >- exceptionElement.appendChild(dpf.newElementNode(dummyDocument, "NoNodesReturnedFromXLink")); >- dummyRoot.appendChild(exceptionElement); >- >- return dummyRoot.getChildNodes(); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param href DOCUMENT ME! >- * @param args DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String includeClassName(String href, Vector args) { >- String icn = null; >- >- if (href.indexOf(conf.JAVA_ZONE) == 0) { >- log.debug(".includeClassName(): java class: " + href); >- icn = href.substring(conf.JAVA_ZONE.length(), href.length()); >- >- StringTokenizer st = new StringTokenizer(icn, "?"); >- icn = st.nextToken(); >- >- if (st.countTokens() == 1) { >- args.addElement(st.nextToken()); >- } >- } else { >- icn = this.getClass().getName(); >- args.addElement(href); >- } >- >- log.debug(".includeClassName(): class name: " + icn); >- >- return icn; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param url DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public File getCacheFile(URL url) { >- String cacheFile = null; >- String protocol = url.getProtocol(); >- >- if (protocol.equals("file")) { >- cacheFile = protocol + "/" + url.getFile(); >- } else if (protocol.equals("http")) { >- cacheFile = protocol + "/" + url.getHost() + "/" + url.getPort() + "/" + url.getFile(); >- } else { >- log.error("No such protocol: " + protocol); >- } >- >- return new File(conf.cacheFolder + "/" + cacheFile); >- } >- >- /** >- * >- */ >- public boolean writeToCache(String protocol, File cacheFile, Document newDocument) { >- if (protocol.equals("http") && !conf.cacheHTTP) { >- // Do not cache HTTP >- return false; >- } >- >- File cacheFileParent = new File(cacheFile.getParent()); >- >- if (!cacheFileParent.isDirectory()) { >- cacheFileParent.mkdirs(); >- } >- >- try { >- OutputStream out = new FileOutputStream(cacheFile.getAbsolutePath()); >- >- new DOMWriter(out, "iso-8859-1").printWithoutFormatting(newDocument); >- out.close(); >- >- return true; >- } catch (Exception e) { >- log.error(".include(): " + e); >- } >- >- return false; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/cms/cocoon/transformation/IncludeTransformer.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/cms/cocoon/transformation/IncludeTransformer.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/cms/cocoon/transformation/IncludeTransformer.java (working copy) >@@ -1,98 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.cms.cocoon.transformation; >- >-import org.apache.avalon.framework.configuration.Configurable; >-import org.apache.avalon.framework.configuration.Configuration; >-import org.apache.avalon.framework.configuration.ConfigurationException; >-import org.apache.cocoon.transformation.AbstractDOMTransformer; >-import org.apache.cocoon.environment.ObjectModelHelper; >-import org.apache.cocoon.environment.Request; >-import org.apache.excalibur.source.Source; >-import org.w3c.dom.Document; >- >- >-public class IncludeTransformer extends AbstractDOMTransformer implements Configurable { >- private String domain = "127.0.0.1"; >- private String context = null; >- private String publication = null; >- >- /** >- * DOCUMENT ME! >- * >- * @param conf DOCUMENT ME! >- * >- * @throws ConfigurationException DOCUMENT ME! >- */ >- public void configure(Configuration conf) throws ConfigurationException { >- if (conf != null) { >- publication = conf.getChild("publication").getAttribute("type"); >- getLogger().debug("PUBLICATION TYPE: " + publication); >- } else { >- getLogger().error("Configuration is null"); >- } >- } >- >- /** >- * (non-Javadoc) >- * @see org.apache.cocoon.transformation.AbstractDOMTransformer#transform(org.w3c.dom.Document) >- */ >- protected Document transform(Document doc) { >- try { >- Source input_source = this.resolver.resolveURI(""); >- String sitemapPath = input_source.getURI(); >- getLogger().debug("Absolute SITEMAP Directory: " + sitemapPath); >- >- String href = this.parameters.getParameter("href", null); >- >- if (href != null) { >- getLogger().debug("Parameter href = " + href); >- } else { >- getLogger().debug("No Parameter"); >- } >- >- Request request = ObjectModelHelper.getRequest(objectModel); >- >- String request_uri = request.getRequestURI(); >- String sitemap_uri = request.getSitemapURI(); >- getLogger().debug("REQUEST URI: " + request_uri); >- getLogger().debug("SITEMAP URI: " + sitemap_uri); >- >- context = request.getContextPath(); >- >- String context_publication = context + "/" + publication; >- int port = request.getServerPort(); >- String cocoon_base_request = "http://" + domain + ":" + port + context_publication; >- getLogger().debug("COCOON_BASE_REQUEST: " + cocoon_base_request); >- >- if (href != null) { >- return new org.apache.lenya.xml.XIncludeImpl().assemble(doc, sitemapPath + href, >- cocoon_base_request); >- } else { >- return new org.apache.lenya.xml.XIncludeImpl().assemble(doc, >- sitemapPath + sitemap_uri, cocoon_base_request); >- } >- } catch (Exception e) { >- getLogger().error(".transform(): " + e, e); >- } >- >- return doc; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/net/conf.properties >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/net/conf.properties (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/net/conf.properties (working copy) >@@ -1,19 +0,0 @@ >-# Copyright 1999-2004 The Apache Software Foundation >-# >-# Licensed under the Apache License, Version 2.0 (the "License"); >-# you may not use this file except in compliance with the License. >-# You may obtain a copy of the License at >-# >-# http://www.apache.org/licenses/LICENSE-2.0 >-# >-# Unless required by applicable law or agreed to in writing, software >-# distributed under the License is distributed on an "AS IS" BASIS, >-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >-# See the License for the specific language governing permissions and >-# limitations under the License. >- >-org.apache.lenya.net.SMTP.host=mail.apache.org >-org.apache.lenya.net.SMTP.port=25 >-org.apache.lenya.net.SMTP.domain=apache.org >- >-org.apache.lenya.net.ProxyManager.configurationPath=org/apache/lenya/net/proxyconf.xml >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyItem.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyItem.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyItem.java (working copy) >@@ -1,74 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.net; >- >-import org.apache.lenya.xml.XPointerFactory; >-import org.apache.regexp.RE; >-import org.apache.regexp.RESyntaxException; >-import org.w3c.dom.Element; >- >- >-/** >- * DOCUMENT ME! >- */ >-public class ProxyItem { >- RE filter = null; >- boolean action = false; >- >- /** >- * Creates a new ProxyItem object. >- * >- * @param itemElement DOCUMENT ME! >- */ >- public ProxyItem(Element itemElement) { >- XPointerFactory xpf = new XPointerFactory(); >- >- if (itemElement.getNodeName().equals("include")) { >- action = true; >- } else { >- action = false; >- } >- >- try { >- filter = new RE(xpf.getElementValue(itemElement)); >- } catch (RESyntaxException e) { >- System.err.println(this.getClass().getName() + ": " + e); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param hostname DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public int check(String hostname) { >- if (filter.match(hostname)) { >- if (action) { >- return 1; >- } else { >- return -1; >- } >- } else { >- return 0; >- } >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/net/proxyconf.xml >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/net/proxyconf.xml (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/net/proxyconf.xml (working copy) >@@ -1,31 +0,0 @@ >-<?xml version="1.0"?> >-<!-- >- Copyright 1999-2004 The Apache Software Foundation >- >- Licensed under the Apache License, Version 2.0 (the "License"); >- you may not use this file except in compliance with the License. >- You may obtain a copy of the License at >- >- http://www.apache.org/licenses/LICENSE-2.0 >- >- Unless required by applicable law or agreed to in writing, software >- distributed under the License is distributed on an "AS IS" BASIS, >- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- See the License for the specific language governing permissions and >- limitations under the License. >---> >- >-<conf xmlns:xlink="http://www.w3.org/1999/xlink"> >-<!-- >- <Proxy host="proxy1.example.com" port="8080"> >- <include>.*</include> >- <exclude>.*\.example\.com</exclude> >- <include>www\.example\.com</include> >- </Proxy> >- >- <Proxy host="proxy2.example.com" port="8888"> >- <include>.*</include> >- <exclude>xps\.example\.com</exclude> >- </Proxy> >---> >-</conf> >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyConf.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyConf.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyConf.java (working copy) >@@ -1,101 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.net; >- >-import java.util.Vector; >- >-import org.apache.lenya.xml.XPointerFactory; >-import org.w3c.dom.Element; >- >- >-/** >- * DOCUMENT ME! >- */ >-public class ProxyConf { >- String proxyHost = null; >- String proxyPort = null; >- Vector items = null; >- >- /** >- * Creates a new ProxyConf object. >- * >- * @param proxyElement DOCUMENT ME! >- */ >- public ProxyConf(Element proxyElement) { >- try { >- items = new Vector(); >- >- XPointerFactory xpf = new XPointerFactory(); >- >- proxyHost = proxyElement.getAttribute("host"); >- proxyPort = proxyElement.getAttribute("port"); >- >- Vector filterEls = xpf.select(proxyElement, "xpointer(include|exclude)"); >- >- for (int i = 0; i < filterEls.size(); i++) { >- ProxyItem item = new ProxyItem((Element) filterEls.elementAt(i)); >- items.addElement(item); >- } >- } catch (Exception e) { >- System.err.println(this.getClass().getName() + ": " + e); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param hostname DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public boolean check(String hostname) { >- boolean result = false; >- >- for (int i = 0; i < items.size(); i++) { >- int ires = ((ProxyItem) items.elementAt(i)).check(hostname); >- >- if (ires > 0) { >- result = true; >- } else if (ires < 0) { >- result = false; >- } >- } >- >- return result; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String getHostName() { >- return proxyHost; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String getHostPort() { >- return proxyPort; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/net/Configuration.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/net/Configuration.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/net/Configuration.java (working copy) >@@ -1,139 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.net; >- >-import java.net.URL; >-import java.util.Properties; >- >-import org.apache.log4j.Category; >- >- >-/** >- * Read configuration >- */ >-public class Configuration { >- static Category log = Category.getInstance(Configuration.class); >- public static final String DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/net/conf.properties"; >- public static final String DEFAULT_CONFIGURATION_KEY = "lenya.configuration"; >- public static final String OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.lenya.configuration"; >- public String configurationPath = null; >- public String smtpHost = null; >- public String smtpPort = null; >- public String smtpDomain = null; >- >- /** >- * Creates a new Configuration object. >- */ >- public Configuration() { >- getProperties(load()); >- } >- >- /** >- * http://www.artima.com/java/answers/Mar2001/messages/164.html export >- * CLASSPATH=/home/lenya/src/xps/build/properties:... java >- * -Doverride.lenya.configuration=org/apache/lenya/altconf.properties org.apache.lenya.net.Configuration >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- Configuration conf = new Configuration(); >- >- System.out.println("Proxy Manager Configuration Path: " + conf.configurationPath); >- System.out.println("SMTP Host: " + conf.smtpHost); >- System.out.println("SMTP Port: " + conf.smtpPort); >- System.out.println("SMTP Domain: " + conf.smtpDomain); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public static Properties load() { >- String resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY); >- >- if (resourcePathRelativeToClasspath == null) { >- resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY, DEFAULT_CONFIGURATION_FILE); >- log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); >- } else { >- log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); >- } >- >- URL url = Configuration.class.getClassLoader().getResource(resourcePathRelativeToClasspath); >- >- if (url == null) { >- log.error(".load(): Could not find resource on classpath: " + resourcePathRelativeToClasspath); >- } >- >- log.debug(url); >- >- Properties properties = new Properties(); >- >- try { >- properties.load(Configuration.class.getResourceAsStream("conf.properties")); >- } catch (Exception e) { >- log.error(e); >- } >- >- return properties; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param properties DOCUMENT ME! >- */ >- public void getProperties(Properties properties) { >- if (properties != null) { >- configurationPath = getProperty(properties, "org.apache.lenya.net.ProxyManager.configurationPath"); >- smtpHost = getProperty(properties, "org.apache.lenya.net.SMTP.host"); >- smtpPort = getProperty(properties, "org.apache.lenya.net.SMTP.port"); >- smtpDomain = getProperty(properties, "org.apache.lenya.net.SMTP.domain"); >- } >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param properties DOCUMENT ME! >- * @param key DOCUMENT ME! >- * >- * @return DOCUMENT ME! >- */ >- public String getProperty(Properties properties, String key) { >- String value = properties.getProperty(key); >- >- if (value != null) { >- log.debug(key + "=" + value); >- >- return value; >- } else { >- log.error("No such property: " + key); >- } >- >- return null; >- } >- >- /** >- * DOCUMENT ME! >- */ >- public static void register() { >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyManager.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyManager.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/net/ProxyManager.java (working copy) >@@ -1,164 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.net; >- >-import java.io.File; >-import java.util.Properties; >-import java.util.Vector; >- >-import org.apache.lenya.xml.DocumentHelper; >-import org.apache.lenya.xml.XPointerFactory; >-import org.apache.log4j.Category; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >- >- >-/** >- * The <code>ProxyManager</code> Class is used to set or unset the java systems proxy settings >- * based on the hostname of the host that want to be reached. >- */ >-public class ProxyManager { >- static Category log = Category.getInstance(ProxyManager.class); >- Vector proxies = null; >- >- /** >- * Creating an instance of ProxyManager without argurments reads the configuration from the >- * default configuration file ($XPS_HOME/xml/xps/proxyconf.xml) >- */ >- public ProxyManager() { >- log.debug("" + new Configuration().configurationPath); >- proxies = readConfig(new Configuration().configurationPath); >- } >- >- /** >- * The <code>ProxyManager</code> is created using the customized <code>conffile</code> >- * >- * @param conffile configuration file to use >- */ >- public ProxyManager(String conffile) { >- proxies = readConfig(conffile); >- } >- >- /** >- * DOCUMENT ME! >- * >- * @param args DOCUMENT ME! >- */ >- public static void main(String[] args) { >- if ((args.length > 2) || (args.length < 1)) { >- System.err.println( >- "Usage: java org.apache.lenya.net.ProxyManager host [configfile.xml]"); >- >- return; >- } >- >- ProxyManager pm = null; >- >- if (args.length > 1) { >- pm = new ProxyManager(args[1]); >- } else { >- pm = new ProxyManager(); >- } >- >- if (pm.set(args[0])) { >- System.out.println("Proxy set: "); >- } else { >- System.out.println("No proxy set."); >- } >- } >- >- /** >- * Check if one of the configured proxies is appropriate for this host and setup the system >- * configuration accordingly. >- * >- * @param host name of the host the connection should be initiated to >- * >- * @return DOCUMENT ME! >- */ >- public boolean set(String host) { >- Properties sp = System.getProperties(); >- >- for (int i = 0; i < proxies.size(); i++) { >- ProxyConf proxy = (ProxyConf) proxies.elementAt(i); >- >- if (proxy.check(host)) { >- sp.put("proxySet", "true"); >- sp.put("proxyHost", proxy.getHostName()); >- sp.put("proxyPort", proxy.getHostPort()); >- System.setProperties(sp); >- >- return true; >- } >- } >- >- sp.remove("proxySet"); >- sp.put("proxyHost", ""); >- sp.put("proxyPort", ""); >- System.setProperties(sp); >- >- return false; >- } >- >- /** >- * Read proxy configuration >- * >- * @param fname Filename of proxy configuration >- * >- * @return proxies >- */ >- public Vector readConfig(String fname) { >- Document document = null; >- File configFile = null; >- >- try { >- configFile = new File(new java.net.URI(ProxyManager.class.getClassLoader().getResource(fname).toString())); >- if (configFile.exists()) { >- document = DocumentHelper.readDocument(configFile); >- } else { >- log.warn("No such file or directory: " + configFile.getAbsolutePath()); >- return null; >- } >- } catch (Exception e) { >- log.error(e); >- return null; >- } >- >- >- Vector proxyElements = null; >- XPointerFactory xpf = new XPointerFactory(); >- >- try { >- proxyElements = xpf.select(document.getDocumentElement(), "xpointer(/conf/Proxy)"); >- if (proxyElements.size() == 0) log.info("No proxy defined (" + configFile + ")"); >- } catch (Exception e) { >- log.error(e); >- return null; >- } >- >- Vector proxies = new Vector(); >- for (int i = 0; i < proxyElements.size(); i++) { >- ProxyConf proxy = new ProxyConf((Element) proxyElements.elementAt(i)); >- >- proxies.addElement(proxy); >- } >- >- return proxies; >- } >-} >Index: C:/src/lenya-trunk/src/java/org/apache/lenya/util/XPSFileOutputStream.java >=================================================================== >--- C:/src/lenya-trunk/src/java/org/apache/lenya/util/XPSFileOutputStream.java (revision 124667) >+++ C:/src/lenya-trunk/src/java/org/apache/lenya/util/XPSFileOutputStream.java (working copy) >@@ -1,143 +0,0 @@ >-/* >- * Copyright 1999-2004 The Apache Software Foundation >- * >- * Licensed under the Apache License, Version 2.0 (the "License"); >- * you may not use this file except in compliance with the License. >- * You may obtain a copy of the License at >- * >- * http://www.apache.org/licenses/LICENSE-2.0 >- * >- * Unless required by applicable law or agreed to in writing, software >- * distributed under the License is distributed on an "AS IS" BASIS, >- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >- * See the License for the specific language governing permissions and >- * limitations under the License. >- * >- */ >- >-/* $Id$ */ >- >-package org.apache.lenya.util; >- >-import java.io.File; >-import java.io.FileDescriptor; >-import java.io.FileOutputStream; >-import java.io.IOException; >- >-import org.apache.avalon.excalibur.io.FileUtil; >-import org.apache.log4j.Category; >- >- >-/** >- * DOCUMENT ME! >- */ >-public class XPSFileOutputStream extends FileOutputStream { >- static Category log = Category.getInstance(XPSFileOutputStream.class); >- private static final String suffixBase = ".xpstemp"; >- protected String realFilename = null; >- protected String suffix = null; >- >- /** >- * Creates a new XPSFileOutputStream object. >- * >- * @param name DOCUMENT ME! >- * >- * @throws IOException DOCUMENT ME! >- */ >- public XPSFileOutputStream(String name) throws IOException { >- super(getTempFilename(name)); >- setRealFilename(name); >- } >- >- /** >- * Creates a new XPSFileOutputStream object. >- * >- * @param file DOCUMENT ME! >- * >- * @throws IOException DOCUMENT ME! >- */ >- public XPSFileOutputStream(File file) throws IOException { >- super(getTempFilename(file.getAbsolutePath())); >- setRealFilename(file.getAbsolutePath()); >- } >- >- /** >- * Creates a new XPSFileOutputStream object. >- * >- * @param filename DOCUMENT ME! >- * @param append DOCUMENT ME! >- * >- * @throws IOException DOCUMENT ME! >- */ >- public XPSFileOutputStream(String filename, boolean append) >- throws IOException { >- super(getTempFilename(filename), append); >- setRealFilename(filename); >- } >- >- /** >- * We cannot support this version of the constructer because we need to play tricks with the >- * filename. There is no filename available when starting with a FileDescriptor. >- * >- * @param fdObj DOCUMENT ME! >- * >- * @throws IOException DOCUMENT ME! >- */ >- public XPSFileOutputStream(FileDescriptor fdObj) throws IOException { >- super(fdObj); >- throw new IOException( >- "Constructing an XPSFileOutputStream using a FileDescriptor is not suported because we depend on a filename"); >- } >- >- /** >- * @param realname DOCUMENT ME! >- * @return DOCUMENT ME! >- */ >- // FIXME: the hashCode() is probably not good enough >- // We need to find a better source of a random >- // string that is available to a static method. >- // >- protected static String getTempFilename(String realname) { >- return realname + XPSFileOutputStream.suffixBase + "." + Runtime.getRuntime().hashCode(); >- } >- >- /** >- * @return DOCUMENT ME! >- */ >- protected String getRealFilename() { >- return this.realFilename; >- } >- >- /** >- * @param filename DOCUMENT ME! >- */ >- protected void setRealFilename(String filename) { >- this.realFilename = filename; >- } >- >- /** >- * DOCUMENT ME! >- * >- * @throws IOException DOCUMENT ME! >- */ >- public void close() throws IOException { >- super.close(); >- File temp = new File(getTempFilename(getRealFilename())); >- File file = new File(getRealFilename()); >- FileUtil.copyFile(temp, file); >- boolean deleted = temp.delete(); >- if (deleted) { >- log.debug("The temporary file "+temp.getAbsolutePath() +"is deleted"); >- } else { >- log.debug("The temporary file "+temp.getAbsolutePath() +" couldn't be deleted"); >- } >- log.debug(".close(): mv " + getTempFilename(getRealFilename()) + " " + getRealFilename()); >- } >- >- /** >- * DOCUMENT ME! >- */ >- public void flush() { >- log.debug("flush() called"); >- } >-} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 33030
: 13966