[102068] taginfo: ResourceBundleHelper cant pick up translated files in nl fragments
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/CMDocumentImpl.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/CMDocumentImpl.java
index 740a360..7516441 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/CMDocumentImpl.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contentmodel/tld/CMDocumentImpl.java
@@ -27,6 +27,7 @@
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager;
import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap;
+import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileInfo;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileParser;
public class CMDocumentImpl implements TLDDocument {
@@ -107,12 +108,12 @@
if (fAnnotationMap == null) {
fAnnotationMap = new AnnotationMap();
- List annotationFiles = ContentModelManager.getInstance().getAnnotationFiles(getUri());
+ List annotationFiles = ContentModelManager.getInstance().getAnnotationFilesInfos(getUri());
for (Iterator i = annotationFiles.iterator(); i.hasNext();) {
try {
- String annotationFileURI = (String) i.next();
+ AnnotationFileInfo fileInfo = (AnnotationFileInfo) i.next();
AnnotationFileParser parser = new AnnotationFileParser();
- parser.parse(fAnnotationMap, annotationFileURI);
+ parser.parse(fAnnotationMap, fileInfo);
} catch (Exception e) {
Logger.log(Logger.WARNING_DEBUG, "Exception thrown in CMDocumentImpl#getAnnotationMap", e); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/PropertyProviderFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/PropertyProviderFactory.java
index dd5564a..38e2619 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/PropertyProviderFactory.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/PropertyProviderFactory.java
@@ -12,6 +12,7 @@
import java.util.Hashtable;
+import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties;
import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap;
@@ -62,7 +63,7 @@
* gets documentation for the element
*/
class PPTagInfo extends AbstractElementPropertyProvider {
- private final static String htmlAnnotationLoc = "platform:/plugin/org.eclipse.wst.html.core/data/htmref.xml"; //$NON-NLS-1$
+ private final static String htmlAnnotationLoc = "data/htmref.xml"; //$NON-NLS-1$
protected AnnotationMap fAnnotationMap = null;
public PPTagInfo() {
@@ -77,7 +78,7 @@
if (fAnnotationMap == null) {
fAnnotationMap = new AnnotationMap();
try {
- fAnnotationMap.load(htmlAnnotationLoc);
+ fAnnotationMap.load(htmlAnnotationLoc, HTMLCorePlugin.getDefault().getBundle().getSymbolicName());
}
catch (Exception e) {
// no annotation available
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/chtml/PropertyProviderFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/chtml/PropertyProviderFactory.java
index f37df45..2c7b1b9 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/chtml/PropertyProviderFactory.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/contentmodel/chtml/PropertyProviderFactory.java
@@ -12,6 +12,7 @@
import java.util.Hashtable;
+import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
import org.eclipse.wst.html.core.internal.contentmodel.HTMLElementDeclaration;
import org.eclipse.wst.html.core.internal.contentmodel.HTMLPropertyDeclaration;
import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties;
@@ -64,7 +65,7 @@
* gets documentation for the element
*/
class PPTagInfo extends AbstractElementPropertyProvider {
- private final static String htmlAnnotationLoc = "platform:/plugin/org.eclipse.wst.html.core/data/htmref.xml"; //$NON-NLS-1$
+ private final static String htmlAnnotationLoc = "data/htmref.xml"; //$NON-NLS-1$
protected AnnotationMap fAnnotationMap = null;
public PPTagInfo() {
@@ -79,7 +80,7 @@
if (fAnnotationMap == null) {
fAnnotationMap = new AnnotationMap();
try {
- fAnnotationMap.load(htmlAnnotationLoc);
+ fAnnotationMap.load(htmlAnnotationLoc, HTMLCorePlugin.getDefault().getBundle().getSymbolicName());
}
catch (Exception e) {
// no annotation available
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/ContentModelManager.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/ContentModelManager.java
index 1868c18..df00d0e 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/ContentModelManager.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/ContentModelManager.java
@@ -66,11 +66,10 @@
}
- public List getAnnotationFiles(String publicId) {
- return getAnnotationFileRegistry().getAnnotationFiles(publicId);
+ public List getAnnotationFilesInfos(String publicId) {
+ return getAnnotationFileRegistry().getAnnotationFilesInfos(publicId);
}
-
private AnnotationFileRegistry getAnnotationFileRegistry() {
if (annotationFileRegistry == null) {
annotationFileRegistry = new AnnotationFileRegistry();
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/AnnotationMap.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/AnnotationMap.java
index c44d154..5c94ac8 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/AnnotationMap.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/AnnotationMap.java
@@ -1,17 +1,17 @@
/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ */
package org.eclipse.wst.xml.core.internal.contentmodel.annotation;
-
+
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
@@ -19,98 +19,83 @@
import java.util.Vector;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
+import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileInfo;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileParser;
/**
* AnnotationMap
*/
-public class AnnotationMap
-{
- protected List list = new Vector();
- protected Hashtable hashtable = new Hashtable();
- protected boolean isCaseSensitive = true;
+public class AnnotationMap {
+ protected List list = new Vector();
+ protected Hashtable hashtable = new Hashtable();
+ protected boolean isCaseSensitive = true;
- public AnnotationMap()
- {
- }
+ public AnnotationMap() {
+ }
- public void setCaseSensitive(boolean isCaseSensitive)
- {
- this.isCaseSensitive = isCaseSensitive;
- }
+ public void setCaseSensitive(boolean isCaseSensitive) {
+ this.isCaseSensitive = isCaseSensitive;
+ }
- public void addAnnotation(Annotation annotation)
- {
- String spec = annotation.getSpec();
- if (spec != null)
- {
- list.add(annotation);
- StringTokenizer st = new StringTokenizer(spec, "[]|\t\n\r\f "); //$NON-NLS-1$
- while (st.hasMoreTokens())
- {
- String cmNodeSpec = st.nextToken();
- addAnnotationForCMNodeSpec(cmNodeSpec, annotation);
- }
- }
- }
+ public void addAnnotation(Annotation annotation) {
+ String spec = annotation.getSpec();
+ if (spec != null) {
+ list.add(annotation);
+ StringTokenizer st = new StringTokenizer(spec, "[]|\t\n\r\f "); //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String cmNodeSpec = st.nextToken();
+ addAnnotationForCMNodeSpec(cmNodeSpec, annotation);
+ }
+ }
+ }
- protected void addAnnotationForCMNodeSpec(String cmNodeSpec, Annotation annotation)
- {
- String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase();
- List list = (List)hashtable.get(key);
- if (list == null)
- {
- list = new Vector();
+ protected void addAnnotationForCMNodeSpec(String cmNodeSpec, Annotation annotation) {
+ String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase();
+ List list = (List) hashtable.get(key);
+ if (list == null) {
+ list = new Vector();
- hashtable.put(key, list);
- }
- list.add(annotation);
- }
-
- public String getProperty(String cmNodeSpec, String propertyName)
- {
- String result = null;
- String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase();
- List annotationList = (List)hashtable.get(key);
- if (annotationList != null)
- {
- for (Iterator i = annotationList.iterator(); i.hasNext(); )
- {
- Annotation annotation = (Annotation)i.next();
- result = annotation.getProperty(propertyName);
- if (result != null)
- {
- break;
- }
- }
- }
- return result;
- }
+ hashtable.put(key, list);
+ }
+ list.add(annotation);
+ }
- public String getProperty(CMNode cmNode, String propertyName)
- {
- String result = null;
- String cmNodeSpec = (String)cmNode.getProperty("spec"); //$NON-NLS-1$
- if (cmNodeSpec == null)
- {
- cmNodeSpec = cmNode.getNodeName();
- }
- if (cmNodeSpec != null)
- {
- result = getProperty(cmNodeSpec, propertyName);
- }
- return result;
- }
+ public String getProperty(String cmNodeSpec, String propertyName) {
+ String result = null;
+ String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase();
+ List annotationList = (List) hashtable.get(key);
+ if (annotationList != null) {
+ for (Iterator i = annotationList.iterator(); i.hasNext();) {
+ Annotation annotation = (Annotation) i.next();
+ result = annotation.getProperty(propertyName);
+ if (result != null) {
+ break;
+ }
+ }
+ }
+ return result;
+ }
- public List getAnnotations()
- {
- return list;
- }
+ public String getProperty(CMNode cmNode, String propertyName) {
+ String result = null;
+ String cmNodeSpec = (String) cmNode.getProperty("spec"); //$NON-NLS-1$
+ if (cmNodeSpec == null) {
+ cmNodeSpec = cmNode.getNodeName();
+ }
+ if (cmNodeSpec != null) {
+ result = getProperty(cmNodeSpec, propertyName);
+ }
+ return result;
+ }
- public void load(String uri) throws Exception
- {
- AnnotationFileParser parser = new AnnotationFileParser();
- parser.parse(this, uri);
- }
+ public List getAnnotations() {
+ return list;
+ }
+
+ public void load(String uri, String bundleId) throws Exception {
+ AnnotationFileParser parser = new AnnotationFileParser();
+ AnnotationFileInfo fileInfo = new AnnotationFileInfo(uri, bundleId);
+ parser.parse(this, fileInfo);
+ }
}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileInfo.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileInfo.java
new file mode 100644
index 0000000..7eab4f2
--- /dev/null
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileInfo.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ */
+package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation;
+
+/**
+ * Contains information about annotation files
+ */
+public class AnnotationFileInfo {
+ private String fAnnotationFileLocation;
+ private String fBundleId;
+
+ public AnnotationFileInfo(String annotationFileLocation, String bundleId) {
+ fAnnotationFileLocation = annotationFileLocation;
+ fBundleId = bundleId;
+ }
+
+ /**
+ * Get the location of the annotation file as originally specified.
+ *
+ * @return String
+ */
+ public String getAnnotationFileLocation() {
+ return fAnnotationFileLocation;
+ }
+
+ /**
+ * Get the bundle id where the annotation file is located.
+ *
+ * @return String
+ */
+ public String getBundleId() {
+ return fBundleId;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileParser.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileParser.java
index c7e9d8a..11279e9 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileParser.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileParser.java
@@ -1,26 +1,30 @@
/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ */
package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintStream;
import java.net.URL;
+import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.xml.core.internal.Logger;
import org.eclipse.wst.xml.core.internal.contentmodel.annotation.Annotation;
import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap;
import org.xml.sax.Attributes;
@@ -32,190 +36,172 @@
/**
*
*/
-public class AnnotationFileParser
-{
- public static final String TAG_ID_ANNOTATIONS = "abstractGrammarAnnotations"; //$NON-NLS-1$
- public static final String TAG_ID_ANNOTATION = "annotation"; //$NON-NLS-1$
- public static final String TAG_ID_PROPERTY = "property"; //$NON-NLS-1$
+public class AnnotationFileParser {
+ public static final String TAG_ID_ANNOTATIONS = "abstractGrammarAnnotations"; //$NON-NLS-1$
+ public static final String TAG_ID_ANNOTATION = "annotation"; //$NON-NLS-1$
+ public static final String TAG_ID_PROPERTY = "property"; //$NON-NLS-1$
- /**
- * This method is called to parse an annotation file and store the contents into an annotationMap
- */
- protected void parse(AnnotationMap annotationMap, InputStream input, String baseURI) throws Exception
- {
- // move to Xerces-2.... add 'contextClassLoader' stuff
- ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(true);
- SAXParser parser = factory.newSAXParser();
- parser.parse(new InputSource(input), new AnnotationMapContentHandler(annotationMap, baseURI));
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(prevClassLoader);
- }
- }
+ /**
+ * This method is called to parse an annotation file and store the
+ * contents into an annotationMap
+ */
+ private void parse(AnnotationMap annotationMap, InputStream input, AnnotationFileInfo fileInfo) throws Exception {
+ // move to Xerces-2.... add 'contextClassLoader' stuff
+ ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ SAXParser parser = factory.newSAXParser();
+ parser.parse(new InputSource(input), new AnnotationMapContentHandler(annotationMap, fileInfo));
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(prevClassLoader);
+ }
+ }
- /**
- * This method is called to parse an annotation file and store the contents into an annotationMap
- */
- public void parse(AnnotationMap map, String uri) throws Exception
- {
- InputStream inputStream = null;
- try
- {
- URL url = new URL(uri);
- inputStream = url.openStream();
- int index = uri.lastIndexOf("/"); //$NON-NLS-1$
- if (index == -1)
- {
- throw new Exception("malformed url " + uri); //$NON-NLS-1$
- }
- String baseURI = uri.substring(0, index);
- parse(map, inputStream, baseURI);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw(e);
- }
- finally
- {
- try
- { if(inputStream != null)
- {
- inputStream.close();
- }
- }
- catch (IOException e)
- {
- }
- }
- }
-
+ /**
+ * This method is called to parse an annotation file and store the
+ * contents into an annotationMap
+ */
+ public void parse(AnnotationMap map, AnnotationFileInfo fileInfo) throws Exception {
+ InputStream inputStream = null;
+ try {
+ URL url = Platform.find(Platform.getBundle(fileInfo.getBundleId()), Path.fromOSString(fileInfo.getAnnotationFileLocation()));
+ if (url != null) {
+ inputStream = url.openStream();
+ parse(map, inputStream, fileInfo);
+ }
+ }
+ catch (Exception e) {
+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
+ throw (e);
+ }
+ finally {
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ catch (IOException e) {
+ }
+ }
+ }
- protected String quote(String string)
- {
- return "\"" + string + "\""; //$NON-NLS-1$ //$NON-NLS-2$
- }
+ protected class AnnotationMapContentHandler extends DefaultHandler {
+ private AnnotationMap annotationMap;
+ private Annotation currentAnnotation;
+ private String currentPropertyName;
+ private StringBuffer propertyValueBuffer;
+ private ResourceBundle resourceBundle;
+ private AnnotationFileInfo fFileInfo;
+ public AnnotationMapContentHandler(AnnotationMap annotationMap, AnnotationFileInfo fileInfo) {
+ this.annotationMap = annotationMap;
+ this.fFileInfo = fileInfo;
+ }
- protected void printlnIndented(PrintStream out, int indent, String string)
- {
- for (int i = 0; i < indent; i++)
- {
- out.print(" "); //$NON-NLS-1$
- }
- out.println(string);
- }
+ private URL generatePropertiesFileURL(AnnotationFileInfo fileInfo, String propertiesLocation) {
+ URL propertiesURL = null;
+ // prepend $nl$ variable to location
+ IPath annotationPath = Path.fromOSString("$nl$/" + fileInfo.getAnnotationFileLocation()); //$NON-NLS-1$
+ // remove the annotation.xml file
+ IPath annotationFolder = annotationPath.removeLastSegments(1);
+ // append location of propertiles file
+ IPath propertiesFile = annotationFolder.append(propertiesLocation);
+ // append .properties extension if needed
+ if (propertiesFile.getFileExtension() == null)
+ propertiesFile = propertiesFile.addFileExtension("properties"); //$NON-NLS-1$
+ // create a URL out of the properties file location
+ propertiesURL = Platform.find(Platform.getBundle(fileInfo.getBundleId()), propertiesFile);
+ return propertiesURL;
+ }
- protected class AnnotationMapContentHandler extends DefaultHandler
- {
- protected AnnotationMap annotationMap;
- protected Annotation currentAnnotation;
- protected String currentPropertyName;
- protected StringBuffer propertyValueBuffer;
- protected ResourceBundle resourceBundle;
- protected String baseURI;
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ propertyValueBuffer = new StringBuffer();
+ if (localName.equals(TAG_ID_ANNOTATIONS)) {
+ int attributesLength = attributes.getLength();
+ for (int i = 0; i < attributesLength; i++) {
+ String attributeName = attributes.getLocalName(i);
+ String attributeValue = attributes.getValue(i);
+ if (attributeName.equals("propertiesLocation")) //$NON-NLS-1$
+ {
+ URL bundleURL = generatePropertiesFileURL(fFileInfo, attributeValue);
+ if (bundleURL != null) {
+ InputStream bundleStream = null;
+ try {
+ bundleStream = bundleURL.openStream();
+ resourceBundle = new PropertyResourceBundle(bundleStream);
+ }
+ catch (IOException e) {
+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
+ }
+ finally {
+ try {
+ if (bundleStream != null)
+ bundleStream.close();
+ }
+ catch (IOException x) {
+ Logger.log(Logger.WARNING_DEBUG, x.getMessage(), x);
+ }
+ }
+ }
+ }
+ else if (attributeName.equals("caseSensitive")) //$NON-NLS-1$
+ {
+ if (attributeValue.trim().equals("false")) //$NON-NLS-1$
+ {
+ annotationMap.setCaseSensitive(false);
+ }
+ }
+ }
+ }
+ else if (localName.equals(TAG_ID_ANNOTATION)) {
+ currentAnnotation = null;
+ String specValue = attributes.getValue("spec"); //$NON-NLS-1$
+ if (specValue != null) {
+ currentAnnotation = new Annotation();
+ currentAnnotation.setSpec(specValue);
+ }
+ annotationMap.addAnnotation(currentAnnotation);
+ }
+ else if (localName.equals(TAG_ID_PROPERTY)) {
+ if (currentAnnotation != null) {
+ currentPropertyName = attributes.getValue("name"); //$NON-NLS-1$
+ }
+ }
+ }
- public AnnotationMapContentHandler(AnnotationMap annotationMap, String baseURI)
- {
- this.annotationMap = annotationMap;
- this.baseURI = baseURI;
- }
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ if (currentPropertyName != null && currentAnnotation != null) {
+ String propertyValue = propertyValueBuffer.toString();
+ if (propertyValue != null) {
+ if (propertyValue.startsWith("%") && resourceBundle != null) //$NON-NLS-1$
+ {
+ try {
+ propertyValue = resourceBundle.getString(propertyValue.substring(1));
+ }
+ catch (Exception e) {
+ // ignore any exception that occurs while trying
+ // to fetch a resource
+ }
+ }
+ currentAnnotation.setProperty(currentPropertyName, propertyValue);
+ }
+ }
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
- {
- propertyValueBuffer = new StringBuffer();
- if (localName.equals(TAG_ID_ANNOTATIONS))
- {
- int attributesLength = attributes.getLength();
- for (int i = 0; i < attributesLength; i++)
- {
- String attributeName = attributes.getLocalName(i);
- String attributeValue = attributes.getValue(i);
- if (attributeName.equals("propertiesLocation")) //$NON-NLS-1$
- {
- String resourceURI = baseURI + "/" + attributeValue; //$NON-NLS-1$
- try
- {
- resourceBundle = ResourceBundleHelper.getResourceBundle(resourceURI);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- else if (attributeName.equals("caseSensitive")) //$NON-NLS-1$
- {
- if (attributeValue.trim().equals("false")) //$NON-NLS-1$
- {
- annotationMap.setCaseSensitive(false);
- }
- }
- }
- }
- else if (localName.equals(TAG_ID_ANNOTATION))
- {
- currentAnnotation = null;
- String specValue = attributes.getValue("spec"); //$NON-NLS-1$
- if (specValue != null)
- {
- currentAnnotation = new Annotation();
- currentAnnotation.setSpec(specValue);
- }
- annotationMap.addAnnotation(currentAnnotation);
- }
- else if (localName.equals(TAG_ID_PROPERTY))
- {
- if (currentAnnotation != null)
- {
- currentPropertyName = attributes.getValue("name"); //$NON-NLS-1$
- }
- }
- }
-
- public void endElement(String uri, String localName, String qName) throws SAXException
- {
- if (currentPropertyName != null && currentAnnotation != null)
- {
- String propertyValue = propertyValueBuffer.toString();
- if (propertyValue != null)
- {
- if (propertyValue.startsWith("%") && resourceBundle != null) //$NON-NLS-1$
- {
- try
- {
- propertyValue = resourceBundle.getString(propertyValue.substring(1));
- }
- catch (Exception e)
- {
- // ignore any exception that occurs while trying to fetch a resource
- }
- }
- currentAnnotation.setProperty(currentPropertyName, propertyValue);
- }
- }
+ if (localName.equals(TAG_ID_ANNOTATION)) {
+ currentAnnotation = null;
+ }
+ else if (localName.equals(TAG_ID_PROPERTY)) {
+ currentPropertyName = null;
+ }
+ }
- if (localName.equals(TAG_ID_ANNOTATION))
- {
- currentAnnotation = null;
- }
- else if (localName.equals(TAG_ID_PROPERTY))
- {
- currentPropertyName = null;
- }
- }
-
- public void characters(char[] ch, int start, int length)
- {
- if (currentPropertyName != null && currentAnnotation != null)
- {
- propertyValueBuffer.append(ch, start, length);
- }
- }
- }
+ public void characters(char[] ch, int start, int length) {
+ if (currentPropertyName != null && currentAnnotation != null) {
+ propertyValueBuffer.append(ch, start, length);
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistry.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistry.java
index 81680cc..e2d455b 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistry.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistry.java
@@ -1,15 +1,15 @@
/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ */
package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation;
import java.util.ArrayList;
@@ -18,41 +18,35 @@
import java.util.Map;
/**
- * This class is used to associate one or more annotation files with a grammar file.
- *
+ * This class is used to associate one or more annotation files with a grammar
+ * file.
+ *
*/
-public class AnnotationFileRegistry
-{
- protected Map map = new HashMap();
+public class AnnotationFileRegistry {
+ private Map map = new HashMap();
- public AnnotationFileRegistry()
- {
- new AnnotationFileRegistryReader(this).readRegistry();
- }
+ public AnnotationFileRegistry() {
+ new AnnotationFileRegistryReader(this).readRegistry();
+ }
+
+ public synchronized List getAnnotationFilesInfos(String publicId) {
+ List theList = (List) map.get(publicId);
+ return theList != null ? theList : new ArrayList();
+ }
+
+ public synchronized void addAnnotationFile(String publicId, AnnotationFileInfo fileInfo) {
+ List fileInfos = (List) map.get(publicId);
+ if (fileInfos == null) {
+ fileInfos = new ArrayList();
+ map.put(publicId, fileInfos);
+ }
+ fileInfos.add(fileInfo);
+ }
- public synchronized List getAnnotationFiles(String publicId)
- {
- Map fileTable = (Map) map.get(publicId);
- return fileTable != null ? new ArrayList(fileTable.values()) : new ArrayList();
- }
-
- public synchronized void addAnnotationFile(String publicId, String annotationFileURI)
- {
- Map fileTable = (Map) map.get(publicId);
- if (fileTable == null)
- {
- fileTable = new HashMap();
- map.put(publicId, fileTable);
- }
- fileTable.put(annotationFileURI, annotationFileURI);
- }
-
- public synchronized void removeAnnotationFile(String publicId, String annotationFileURI)
- {
- Map fileTable = (Map) map.get(publicId);
- if (fileTable != null)
- {
- fileTable.remove(annotationFileURI);
- }
- }
+ public synchronized void removeAnnotationFile(String publicId, AnnotationFileInfo fileInfo) {
+ List fileInfos = (List) map.get(publicId);
+ if (fileInfos != null) {
+ fileInfos.remove(fileInfo);
+ }
+ }
}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistryReader.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistryReader.java
index b15cb97..896acd6 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistryReader.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistryReader.java
@@ -1,93 +1,77 @@
/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ */
package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation;
-import java.net.URL;
-
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IPluginRegistry;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.xml.core.internal.Logger;
/**
-* This class reads the plugin manifests and adds each specified gramamr annotation file with the AnnotationProvider
-*/
-public class AnnotationFileRegistryReader
-{
- protected static final String EXTENSION_POINT_ID = "annotationFiles"; //$NON-NLS-1$
- protected static final String TAG_NAME = "annotationFile"; //$NON-NLS-1$
- protected static final String ATT_PUBLIC_ID = "publicId"; //$NON-NLS-1$
- protected static final String ATT_LOCATION = "location"; //$NON-NLS-1$
+ * This class reads the plugin manifests and adds each specified gramamr
+ * annotation file with the AnnotationProvider
+ */
+public class AnnotationFileRegistryReader {
+ protected static final String EXTENSION_POINT_ID = "annotationFiles"; //$NON-NLS-1$
+ protected static final String TAG_NAME = "annotationFile"; //$NON-NLS-1$
+ protected static final String ATT_PUBLIC_ID = "publicId"; //$NON-NLS-1$
+ protected static final String ATT_LOCATION = "location"; //$NON-NLS-1$
- private AnnotationFileRegistry annotationFileRegistry;
+ private AnnotationFileRegistry annotationFileRegistry;
- public AnnotationFileRegistryReader(AnnotationFileRegistry annotationFileRegistry)
- {
- this.annotationFileRegistry = annotationFileRegistry;
- }
+ public AnnotationFileRegistryReader(AnnotationFileRegistry annotationFileRegistry) {
+ this.annotationFileRegistry = annotationFileRegistry;
+ }
- /**
- * read from plugin registry and parse it.
- */
- public void readRegistry()
- {
- IPluginRegistry pluginRegistry = Platform.getPluginRegistry();
- String pluginId = "org.eclipse.wst.xml.core"; //$NON-NLS-1$
- IExtensionPoint point = pluginRegistry.getExtensionPoint(pluginId, EXTENSION_POINT_ID);
- if (point != null)
- {
- IConfigurationElement[] elements = point.getConfigurationElements();
- for (int i = 0; i < elements.length; i++)
- {
- readElement(elements[i]);
- }
- }
- }
+ /**
+ * read from plugin registry and parse it.
+ */
+ public void readRegistry() {
+ IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
+ String pluginId = "org.eclipse.wst.xml.core"; //$NON-NLS-1$
+ IExtensionPoint point = extensionRegistry.getExtensionPoint(pluginId, EXTENSION_POINT_ID);
+ if (point != null) {
+ IConfigurationElement[] elements = point.getConfigurationElements();
+ for (int i = 0; i < elements.length; i++) {
+ readElement(elements[i]);
+ }
+ }
+ }
- /**
- * readElement() - parse and deal with an extension like:
- *
- * <extension point="org.eclipse.wst.xml.core.internal.contentmodel.util_implementation">
- * <util_implementation class = corg.eclipse.wst.baseutil.CMUtilImplementationImpl />
- * </extension>
- */
- protected void readElement(IConfigurationElement element)
- {
- if (element.getName().equals(TAG_NAME))
- {
- String publicId = element.getAttribute(ATT_PUBLIC_ID);
- String location = element.getAttribute(ATT_LOCATION);
- if (publicId != null && location != null)
- {
- try
- {
- URL installURL = element.getDeclaringExtension().getDeclaringPluginDescriptor().getInstallURL();
- String qualifiedLocation = resolve(installURL, location);
- annotationFileRegistry.addAnnotationFile(publicId, qualifiedLocation);
- }
- catch (Exception e)
- {
- Logger.logException("problem adding annotation file " + location, e); //$NON-NLS-1$
- }
- }
- }
- }
-
- public String resolve(URL platformURL, String relativePath) throws Exception
- {
- URL resolvedURL = Platform.resolve(platformURL);
- return resolvedURL.toString() + relativePath;
- }
+ /**
+ * readElement() - parse and deal with an extension like:
+ *
+ * <extension
+ * point="org.eclipse.wst.xml.core.internal.contentmodel.util_implementation">
+ * <util_implementation class =
+ * corg.eclipse.wst.baseutil.CMUtilImplementationImpl /> </extension>
+ */
+ protected void readElement(IConfigurationElement element) {
+ if (element.getName().equals(TAG_NAME)) {
+ String publicId = element.getAttribute(ATT_PUBLIC_ID);
+ String location = element.getAttribute(ATT_LOCATION);
+ if (publicId != null && location != null) {
+ try {
+ String bundleId = element.getNamespace();
+ AnnotationFileInfo fileInfo = new AnnotationFileInfo(location, bundleId);
+ annotationFileRegistry.addAnnotationFile(publicId, fileInfo);
+ }
+ catch (Exception e) {
+ Logger.logException("problem adding annotation file " + location, e); //$NON-NLS-1$
+ }
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationUtility.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationUtility.java
index c932fed..90aeb12 100644
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationUtility.java
+++ b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationUtility.java
@@ -1,15 +1,15 @@
/*
-* Copyright (c) 2002 IBM Corporation and others.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Common Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/cpl-v10.html
-*
-* Contributors:
-* IBM - Initial API and implementation
-* Jens Lukowski/Innoopract - initial renaming/restructuring
-*
-*/
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ */
package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation;
import java.util.Iterator;
@@ -23,26 +23,20 @@
/**
*
*/
-public class AnnotationUtility
-{
- public static void loadAnnotationsForGrammar(String publicId, CMDocument cmDocument)
- {
- List annotationFiles = ContentModelManager.getInstance().getAnnotationFiles(publicId);
- AnnotationMap map = (AnnotationMap) cmDocument.getProperty("annotationMap"); //$NON-NLS-1$
- if (map != null)
- {
- for (Iterator i = annotationFiles.iterator(); i.hasNext();)
- {
- try
- {
- String annotationFileURI = (String) i.next();
- AnnotationFileParser parser = new AnnotationFileParser();
- parser.parse(map, annotationFileURI);
- }
- catch (Exception e)
- {
- }
- }
- }
- }
+public class AnnotationUtility {
+ public static void loadAnnotationsForGrammar(String publicId, CMDocument cmDocument) {
+ List annotationFiles = ContentModelManager.getInstance().getAnnotationFilesInfos(publicId);
+ AnnotationMap map = (AnnotationMap) cmDocument.getProperty("annotationMap"); //$NON-NLS-1$
+ if (map != null) {
+ for (Iterator i = annotationFiles.iterator(); i.hasNext();) {
+ try {
+ AnnotationFileInfo annotationFileInfo = (AnnotationFileInfo) i.next();
+ AnnotationFileParser parser = new AnnotationFileParser();
+ parser.parse(map, annotationFileInfo);
+ }
+ catch (Exception e) {
+ }
+ }
+ }
+ }
}