You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2008/10/14 15:04:22 UTC
svn commit: r704525 -
/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
Author: thorsten
Date: Tue Oct 14 06:04:22 2008
New Revision: 704525
URL: http://svn.apache.org/viewvc?rev=704525&view=rev
Log:
Fixing java class since we used imports that does not exist anymore
Modified:
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java?rev=704525&r1=704524&r2=704525&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java (original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/acting/ResourceTypeAction.java Tue Oct 14 06:04:22 2008
@@ -36,11 +36,16 @@
* <location src="{uri}" /><br>
* </act>
*/
+import java.io.File;
import java.io.IOException;
-import java.net.MalformedURLException;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
@@ -49,10 +54,13 @@
import org.apache.cocoon.acting.ServiceableAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.excalibur.source.SourceResolver;
-import org.apache.forrest.dispatcher.DispatcherException;
+import org.apache.forrest.dispatcher.exception.DispatcherException;
+import org.apache.xml.resolver.tools.CatalogResolver;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
public class ResourceTypeAction extends ServiceableAction
@@ -123,7 +131,7 @@
try {
src = resolver.resolveURI(uri);
if (src.exists()) {
- Document rawData = org.apache.forrest.dispatcher.util.SourceUtil.readDOM(
+ Document rawData = readDOM(
uri, resolver);
NodeList type = rawData.getElementsByTagNameNS(getResourceTypeElementNS(),getResourceTypeElement());
String typeString = type.item(0).getFirstChild().getNodeValue();
@@ -242,5 +250,51 @@
public void setResourceTypeElementNS(String resourceTypeElementNS) {
this.resourceTypeElementNS = resourceTypeElementNS;
}
-
+ /**
+ * Reads a DOM from a source.
+ * @param sourceUri The source URI.
+ * @param manager The service manager.
+ * @return A document or <code>null</code> if the source does not exist.
+ * @throws ServiceException if an error occurs.
+ * @throws SourceNotFoundException if an error occurs.
+ * @throws ParserConfigurationException if an error occurs.
+ * @throws SAXException if an error occurs.
+ * @throws IOException if an error occurs.
+ */
+ public static Document readDOM(String sourceUri, SourceResolver resolver)
+ throws ServiceException, SourceNotFoundException, ParserConfigurationException,
+ SAXException, IOException {
+ Source source = null;
+ Document document = null;
+ try {
+ source = resolver.resolveURI(sourceUri);
+ if (source.exists()) {
+ document = readDocument(source.getInputStream());
+ }
+ } finally {
+ if (source != null) {
+ resolver.release(source);
+ }
+ }
+ return document;
+ }
+ public static Document readDocument(InputStream stream) throws ParserConfigurationException,
+ SAXException, IOException {
+DocumentBuilder builder = createBuilder();
+return builder.parse(stream);
+}
+ /**
+ * Creates a non-validating and namespace-aware DocumentBuilder.
+ * @return A new DocumentBuilder object.
+ * @throws ParserConfigurationException if an error occurs
+ */
+ public static DocumentBuilder createBuilder() throws ParserConfigurationException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+
+ CatalogResolver cr = new CatalogResolver();
+ builder.setEntityResolver(cr);
+ return builder;
+ }
}