Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbateman2010-05-25 15:15:11 +0000
committercbateman2010-05-25 15:15:11 +0000
commit32d649746fe653ae117b64d06ea071940fb33354 (patch)
treed656c9a8901180f95f7bb86a2128e19d65d476ae
parentacb61c8229f1e15f3b0b182f6e11112160b795a5 (diff)
downloadwebtools.jsf-32d649746fe653ae117b64d06ea071940fb33354.tar.gz
webtools.jsf-32d649746fe653ae117b64d06ea071940fb33354.tar.xz
webtools.jsf-32d649746fe653ae117b64d06ea071940fb33354.zip
Fix for PMC_approved https://bugs.eclipse.org/bugs/show_bug.cgi?id=312942.
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/META-INF/MANIFEST.MF3
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TagModelLoader.java126
2 files changed, 121 insertions, 8 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/META-INF/MANIFEST.MF b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/META-INF/MANIFEST.MF
index 9051f9ceb..69cf636ca 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/META-INF/MANIFEST.MF
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/META-INF/MANIFEST.MF
@@ -26,7 +26,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jst.j2ee.web;bundle-version="1.1.200",
org.eclipse.wst.validation;bundle-version="1.2.0",
org.eclipse.debug.core;bundle-version="[3.5.0,4.0.0)",
- org.eclipse.emf.ecore.xmi;bundle-version="2.5.0"
+ org.eclipse.emf.ecore.xmi;bundle-version="2.5.0",
+ org.eclipse.wst.xml.core;bundle-version="1.1.500"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.eclipse.jdt.core,
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TagModelLoader.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TagModelLoader.java
index b411d7ba9..2ec287de9 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TagModelLoader.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TagModelLoader.java
@@ -1,20 +1,37 @@
package org.eclipse.jst.jsf.facelet.core.internal.registry.taglib;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.core.runtime.URIUtil;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ContentHandler;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.emf.ecore.resource.URIHandler;
+import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.resource.impl.URIHandlerImpl;
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.jst.jsf.facelet.core.internal.FaceletCorePlugin;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.DocumentRoot;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglib;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibPackage;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.util.FaceletTaglibResourceFactoryImpl;
+import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
+import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
+import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry;
+import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog;
/**
* Loads the facelet taglib file model using EMF.
@@ -28,27 +45,46 @@ public class TagModelLoader
private final String _resourceUri;
private DocumentRoot _docRoot;
private FaceletTaglib _faceletTaglib;
+ private final static List<URIHandler> DEFAULT_URI_HANDLERS;
+ static
+ {
+ final List<URIHandler> handlers = new ArrayList<URIHandler>();
+ final URIHandler handleFacelet = new DefaultFaceletURIHandler();
+ handlers.add(handleFacelet);
+ handlers.addAll(URIHandler.DEFAULT_HANDLERS);
+ DEFAULT_URI_HANDLERS = handlers;
+ }
/**
* @param resourceUri
*/
public TagModelLoader(final String resourceUri)
{
+ this(resourceUri, new ExtensibleURIConverterImpl(DEFAULT_URI_HANDLERS,
+ ContentHandler.Registry.INSTANCE.contentHandlers()));
+ }
+
+ /**
+ * @param resourceUri
+ * @param uriConverter
+ */
+ public TagModelLoader(final String resourceUri,
+ final URIConverter uriConverter)
+ {
_resourceUri = resourceUri;
_resSet = new ResourceSetImpl();
-
_resSet.getPackageRegistry().put("http://java.sun.com/xml/ns/javaee", //$NON-NLS-1$
FaceletTaglibPackage.eINSTANCE);
_resSet.getPackageRegistry().put(
"http://java.sun.com/xml/ns/javaee/web-facelettaglibrary.xsd", //$NON-NLS-1$
FaceletTaglibPackage.eINSTANCE);
+ _resSet.setURIConverter(uriConverter);
final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(
_resSet.getPackageRegistry());
_resSet.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
extendedMetaData);
- _resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
- "xml", new FaceletTaglibResourceFactoryImpl()); //$NON-NLS-1$
-
+ _resSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+ .put("xml", new FaceletTaglibResourceFactoryImpl()); //$NON-NLS-1$
}
/**
@@ -91,11 +127,10 @@ public class TagModelLoader
}
}
-
/**
* @param faceletTaglib
*/
- public final void setTaglib(FaceletTaglib faceletTaglib)
+ public final void setTaglib(final FaceletTaglib faceletTaglib)
{
_faceletTaglib = faceletTaglib;
}
@@ -103,7 +138,7 @@ public class TagModelLoader
/**
* @param docRoot
*/
- public final void setDocRoot(DocumentRoot docRoot)
+ public final void setDocRoot(final DocumentRoot docRoot)
{
_docRoot = docRoot;
}
@@ -124,4 +159,81 @@ public class TagModelLoader
return _docRoot;
}
+ /**
+ * Handles facelet taglib dtd resolver requests
+ *
+ */
+ private static final class DefaultFaceletURIHandler extends URIHandlerImpl
+ {
+ @Override
+ public boolean canHandle(final URI uri)
+ {
+ return "http://java.sun.com/dtd/facelet-taglib_1_0.dtd".equals(uri.toString()); //$NON-NLS-1$
+ }
+
+ @Override
+ public InputStream createInputStream(final URI uri, final Map<?, ?> options)
+ throws IOException
+ {
+ try
+ {
+ return findFaceletDtdInCatalog();
+ } catch (final URISyntaxException e)
+ {
+ FaceletCorePlugin.log(
+ "While trying to load facelet dtd from catalog", e); //$NON-NLS-1$
+ // fall through
+ }
+ return null;
+ }
+
+ private InputStream findFaceletDtdInCatalog() throws URISyntaxException, IOException
+ {
+ final ICatalog xmlCatalog = XMLCorePlugin.getDefault()
+ .getDefaultXMLCatalog();
+ if (xmlCatalog != null)
+ {
+ ICatalog systemCatalog = null;
+ final INextCatalog[] nextCatalogs = xmlCatalog.getNextCatalogs();
+ for (final INextCatalog catalog : nextCatalogs)
+ {
+ final ICatalog referencedCatalog = catalog
+ .getReferencedCatalog();
+ if (referencedCatalog != null)
+ {
+ if (XMLCorePlugin.SYSTEM_CATALOG_ID
+ .equals(referencedCatalog.getId()))
+ {
+ systemCatalog = referencedCatalog;
+ }
+ }
+ }
+ if (systemCatalog != null)
+ {
+ ICatalogEntry foundEntry = null;
+ for (final ICatalogEntry entry : systemCatalog.getCatalogEntries())
+ {
+ if ("-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" //$NON-NLS-1$
+ .equals(entry.getKey()))
+ {
+ foundEntry = entry;
+ break;
+ }
+ }
+ if (foundEntry != null)
+ {
+ final java.net.URI uri = new java.net.URI(foundEntry.getURI());
+ URL url = URIUtil.toURL(uri);
+ return url.openStream();
+// final String uriString = foundEntry.getURI();
+// if (URIUtil.isFileURI(uriString))
+// {
+// return new File(URIUtil.toFile(uriString));
+// }
+ }
+ }
+ }
+ return null;
+ }
+ }
}

Back to the top