Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2013-10-10 16:41:03 +0000
committerCarsten Hiesserich2013-10-20 19:29:16 +0000
commit27d48271a59dcb1cc99c59efc1e356f68161f1e2 (patch)
tree70c49cc0780be4593ed5cfbbfbe975a6c53efa41
parentc3d21578f56f2d83f1961b10e534f88e46c6e14b (diff)
downloadorg.eclipse.mylyn.docs.vex-27d48271a59dcb1cc99c59efc1e356f68161f1e2.tar.gz
org.eclipse.mylyn.docs.vex-27d48271a59dcb1cc99c59efc1e356f68161f1e2.tar.xz
org.eclipse.mylyn.docs.vex-27d48271a59dcb1cc99c59efc1e356f68161f1e2.zip
cleanup document type handling and doctypes in docbook plugin
Change-Id: Ieae7693a39f1837cba4b822e316c08f6b3dd3864 Signed-off-by: Carsten Hiesserich <carsten.hie@gmail.com>
-rw-r--r--org.eclipse.vex.core.tests/plugin.xml8
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java7
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/testCatalog.css2
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java37
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/DTDValidatorTest.java11
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java2
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java64
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/DocumentContentModel.java144
-rw-r--r--org.eclipse.vex.docbook/plugin.properties4
-rw-r--r--org.eclipse.vex.docbook/plugin.xml138
-rw-r--r--org.eclipse.vex.ui.tests/plugin.xml38
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java48
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PreferencesTest.java52
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/VexDocumentContentModelTest.java106
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java4
-rw-r--r--org.eclipse.vex.ui.tests/testdata/test-doctype-id.css53
-rw-r--r--org.eclipse.vex.ui.tests/testdata/test-schema.css53
-rw-r--r--org.eclipse.vex.ui/schema/doctype.exsd282
-rw-r--r--org.eclipse.vex.ui/schema/style.exsd55
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java22
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigLoaderJob.java2
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistry.java42
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistryImpl.java46
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java4
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypeFactory.java24
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DocumentType.java38
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DomConfigurationElement.java2
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java2
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/DocumentTypeSelectionPage.java2
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java27
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java12
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/StyleMenu.java5
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java4
33 files changed, 900 insertions, 440 deletions
diff --git a/org.eclipse.vex.core.tests/plugin.xml b/org.eclipse.vex.core.tests/plugin.xml
index a23c4162..17a8faaf 100644
--- a/org.eclipse.vex.core.tests/plugin.xml
+++ b/org.eclipse.vex.core.tests/plugin.xml
@@ -13,10 +13,18 @@
name="http://www.eclipse.org/vex/test/content"
uri="testResources/content.xsd">
</uri>
+ <system
+ systemId="http://www.eclipse.org/vex/test/content.xsd"
+ uri="testResources/content.xsd">
+ </system>
<public
publicId="-//Eclipse Foundation//DTD Vex Test//EN"
uri="testResources/test1.dtd">
</public>
+ <uri
+ name="urn:org:eclipse:vex:styles:test:test.css"
+ uri="testResources/test.css">
+ </uri>
</catalogContribution>
</extension>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java
index a0e2cc3c..33892320 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/CssTest.java
@@ -12,6 +12,7 @@ package org.eclipse.vex.core.internal.css;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.net.URL;
@@ -582,4 +583,10 @@ public class CssTest {
element.setAttribute("attribute", "After");
assertEquals("After", styles.getContent(element).get(0));
}
+
+ @Test
+ public void testCatalogImport() throws Exception {
+ final StyleSheet ss = parseStyleSheetResource("testCatalog.css");
+ assertTrue(ss.getRules().size() > 0);
+ }
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/testCatalog.css b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/testCatalog.css
new file mode 100644
index 00000000..d9fc6871
--- /dev/null
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/css/testCatalog.css
@@ -0,0 +1,2 @@
+/* Stylesheet for unit testing */
+@import url(urn:org:eclipse:vex:styles:test:test.css)
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
index e643210e..52e3aa7a 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
@@ -16,8 +16,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.net.URL;
-
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.vex.core.internal.dom.Element;
import org.eclipse.vex.core.provisional.dom.DocumentContentModel;
@@ -99,17 +97,24 @@ public class DocumentContentModelTest {
}
@Test
- public void resolveSchemaIdentifier() throws Exception {
- final URL resolvedUrl = model.resolveSchemaIdentifier(TestResources.TEST_DTD);
+ public void resolveSchemaBySchemaLocation() throws Exception {
+ final String resolvedUrl = model.resolveResourceURI(null, "http://www.eclipse.org/vex/test/content.xsd");
assertNotNull(resolvedUrl);
- assertTrue(resolvedUrl.toString().contains(VEXCoreTestPlugin.PLUGIN_ID));
+ assertTrue(resolvedUrl.contains(VEXCoreTestPlugin.PLUGIN_ID) && resolvedUrl.endsWith("testResources/content.xsd"));
+ }
+
+ @Test
+ public void resolveSchemaByNamespace() throws Exception {
+ final String resolvedUrl = model.resolveResourceURI(null, "http://www.eclipse.org/vex/test/content");
+ assertNotNull(resolvedUrl);
+ assertTrue(resolvedUrl.contains(VEXCoreTestPlugin.PLUGIN_ID) && resolvedUrl.endsWith("testResources/content.xsd"));
}
@Test
public void onlySystemId() throws Exception {
model.initialize(null, null, TestResources.get("test1.dtd").toString(), null);
assertTrue(model.isDtdAssigned());
- assertNotNull(model.getDTD());
+ assertNotNull(model.getContentModelDocument());
}
@Test
@@ -117,8 +122,26 @@ public class DocumentContentModelTest {
final String baseUri = TestResources.get("test.css").toString();
model.initialize(baseUri, null, "test1.dtd", null);
assertTrue(model.isDtdAssigned());
- final CMDocument dtd = model.getDTD();
+ final CMDocument dtd = model.getContentModelDocument();
assertNotNull(dtd);
assertEquals(11, dtd.getElements().getLength());
}
+
+ @Test
+ public void onlyNamespace() throws Exception {
+ model.initialize(null, null, null, new Element(new QualifiedName("http://www.eclipse.org/vex/test/content", "rootElement")));
+ assertFalse(model.isDtdAssigned());
+ final CMDocument schema = model.getContentModelDocument();
+ assertNotNull(schema);
+ assertEquals(1, schema.getElements().getLength());
+ }
+
+ @Test
+ public void testExplicitNamespace() throws Exception {
+ model.setSchemaId(null, "http://www.eclipse.org/vex/test/content");
+ assertFalse(model.isDtdAssigned());
+ final CMDocument schema = model.getContentModelDocument();
+ assertNotNull(schema);
+ assertEquals(1, schema.getElements().getLength());
+ }
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/DTDValidatorTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/DTDValidatorTest.java
index 76d60b16..df646ed4 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/DTDValidatorTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/DTDValidatorTest.java
@@ -166,17 +166,6 @@ public class DTDValidatorTest {
assertInvalidSequence("document", "preface", "index");
}
- @Test
- public void testValidateDocumentWithDTDAndNamespaces() throws Exception {
- final IDocument doc = new Document(new QualifiedName("http://namespace/uri/is/not/registered", "section"));
- doc.setValidator(validator);
- doc.insertElement(2, new QualifiedName(null, "title"));
- doc.insertText(3, "ab");
- doc.insertElement(6, new QualifiedName(null, "para"));
-
- validator.getAttributeDefinitions(doc.getRootElement());
- }
-
private void assertFullyValidSequence(final String element, final String... sequence) {
// fully includes partially
assertValidSequence(true, element, true, true, sequence);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java
index 056c86dc..689761b1 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/io/DocumentBuilder.java
@@ -272,7 +272,7 @@ public class DocumentBuilder implements ContentHandler, LexicalHandler {
if (dtdPublicID != null && dtdSystemID != null || previousDocTypeID == null) {
// The content model is initialized only if the input document defines a DocType
// or if it has not been initialized already.
- // This way, a user selected is reapplied when the document is reloaded.
+ // This way, a user selected doctype is reapplied when the document is reloaded.
documentContentModel.initialize(baseUri, dtdPublicID, dtdSystemID, rootElement);
}
final StyleSheet styleSheet = styleSheetProvider.getStyleSheet(documentContentModel);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java
index 5153b9ab..7e374dcf 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/validator/WTPVEXValidator.java
@@ -41,7 +41,6 @@ import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
-import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator.ElementContentComparator;
import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator.ElementPathRecordingResult;
@@ -64,9 +63,7 @@ public class WTPVEXValidator implements IValidator {
private final DocumentContentModel documentContentModel;
- private CMDocument dtd;
-
- private final Map<URL, CMDocument> contentModelCache = new HashMap<URL, CMDocument>();
+ private final Map<String, CMDocument> contentModelCache = new HashMap<String, CMDocument>();
private final CMValidator validator = new CMValidator();
@@ -90,46 +87,27 @@ public class WTPVEXValidator implements IValidator {
return documentContentModel;
}
- private CMDocument getSchema(final String namespaceURI) {
- if (isDTDDefined()) {
- return getDTD();
- }
- if (namespaceURI == null) {
- /*
- * This can be the case if the document does neither contain a doctype declaration nor a default namespace
- * declaration.
- */
- return getSchema((URL) null);
+ private CMDocument getContentModelDoc(final String schemaURI) {
+ if (contentModelCache.containsKey(schemaURI)) {
+ return contentModelCache.get(schemaURI);
}
- final URL resolved = documentContentModel.resolveSchemaIdentifier(namespaceURI);
- return getSchema(resolved);
- }
- private CMDocument getSchema(final URL schemaUrl) {
- if (contentModelCache.containsKey(schemaUrl)) {
- return contentModelCache.get(schemaUrl);
- }
+ CMDocument contentModel;
- final CMDocument contentModel;
- if (schemaUrl != null) {
- final ContentModelManager modelManager = ContentModelManager.getInstance();
- contentModel = modelManager.createCMDocument(schemaUrl.toString(), null);
+ if (schemaURI == null) {
+ contentModel = documentContentModel.getContentModelDocument();
} else {
+ contentModel = documentContentModel.getContentModelDocument(schemaURI);
+ }
+
+ if (contentModel == null) {
+ // Schema could not be resolved - create a dummy instance
contentModel = new UnknownCMDocument(null);
}
- contentModelCache.put(schemaUrl, contentModel);
- return contentModel;
- }
- private boolean isDTDDefined() {
- return documentContentModel.isDtdAssigned();
- }
+ contentModelCache.put(schemaURI, contentModel);
- private CMDocument getDTD() {
- if (dtd == null && documentContentModel.isDtdAssigned()) {
- dtd = documentContentModel.getDTD();
- }
- return dtd;
+ return contentModel;
}
public AttributeDefinition getAttributeDefinition(final IAttribute attribute) {
@@ -190,7 +168,7 @@ public class WTPVEXValidator implements IValidator {
return null;
}
final String localName = element.getLocalName();
- final CMElementDeclaration declarationFromRoot = (CMElementDeclaration) getSchema(element.getQualifiedName().getQualifier()).getElements().getNamedItem(localName);
+ final CMElementDeclaration declarationFromRoot = (CMElementDeclaration) getContentModelDoc(element.getQualifiedName().getQualifier()).getElements().getNamedItem(localName);
if (declarationFromRoot != null) {
return declarationFromRoot;
}
@@ -346,7 +324,7 @@ public class WTPVEXValidator implements IValidator {
private Set<CMElementDeclaration> getValidRootElements(final String namespaceURI) {
final HashSet<CMElementDeclaration> result = new HashSet<CMElementDeclaration>();
- final Iterator<?> iter = getSchema(namespaceURI).getElements().iterator();
+ final Iterator<?> iter = getContentModelDoc(namespaceURI).getElements().iterator();
while (iter.hasNext()) {
final CMElementDeclaration element = (CMElementDeclaration) iter.next();
result.add(element);
@@ -368,7 +346,13 @@ public class WTPVEXValidator implements IValidator {
return true;
}
- final CMNode parent = getSchema(element.getQualifier()).getElements().getNamedItem(element.getLocalName());
+ final CMDocument document = getContentModelDoc(element.getQualifier());
+ if (document == null) {
+ System.out.println("Unable to resolve validation schema for " + element.getQualifier());
+ return true;
+ }
+ CMNode parent = null;
+ parent = document.getElements().getNamedItem(element.getLocalName());
if (!(parent instanceof CMElementDeclaration)) {
return true;
}
@@ -425,7 +409,7 @@ public class WTPVEXValidator implements IValidator {
private Set<String> getRequiredNamespaces(final String namespaceUri, final Set<CMNode> visitedNodes) {
final HashSet<String> result = new HashSet<String>();
result.add(namespaceUri);
- final CMDocument mainSchema = getSchema(namespaceUri);
+ final CMDocument mainSchema = getContentModelDoc(namespaceUri);
for (final Iterator<?> iter = mainSchema.getElements().iterator(); iter.hasNext();) {
final CMElementDeclaration elementDeclaration = (CMElementDeclaration) iter.next();
result.addAll(getRequiredNamespaces(elementDeclaration, visitedNodes));
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/DocumentContentModel.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/DocumentContentModel.java
index e74650f8..e8823aa2 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/DocumentContentModel.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/provisional/dom/DocumentContentModel.java
@@ -11,8 +11,6 @@
package org.eclipse.vex.core.provisional.dom;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.text.MessageFormat;
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
@@ -42,17 +40,45 @@ public class DocumentContentModel implements EntityResolver {
initialize(baseUri, publicId, systemId, rootElement);
}
+ /**
+ * Initialize the content model.
+ *
+ * @param baseUri
+ * The base uri of the loaded document
+ * @param publicId
+ * The PublicID of the DocumentTypeDefinition (DTD)
+ * @param systemId
+ * The SystemID of the DocumentTypeDefinition (DTD)
+ * @param rootElement
+ * If no DTD is defined (publicId and systemId are both null) the namespace of the root element is used
+ * to define the document type.
+ */
public void initialize(final String baseUri, final String publicId, final String systemId, final IElement rootElement) {
this.baseUri = baseUri;
this.publicId = publicId;
this.systemId = systemId;
- if (rootElement != null) {
+ if (publicId == null && systemId == null && rootElement != null) {
schemaId = rootElement.getQualifiedName().getQualifier();
} else {
schemaId = null;
}
}
+ /**
+ * Sets an explicit namespace.
+ *
+ * @param baseUri
+ * The base uri of the loaded document
+ * @param rootNamespace
+ * The default namespace to resolve the XML-Schema for validation.
+ */
+ public void setSchemaId(final String baseUri, final String rootNamespace) {
+ this.baseUri = baseUri;
+ publicId = null;
+ systemId = null;
+ schemaId = rootNamespace;
+ }
+
public String getMainDocumentTypeIdentifier() {
if (publicId != null) {
return publicId;
@@ -71,29 +97,76 @@ public class DocumentContentModel implements EntityResolver {
return systemId;
}
+ public String getSchemaId() {
+ return schemaId;
+ }
+
public boolean isDtdAssigned() {
return publicId != null || systemId != null;
}
- public CMDocument getDTD() {
- final URL resolvedPublicId = resolveSchemaIdentifier(publicId);
- if (resolvedPublicId != null) {
- return createCMDocument(resolvedPublicId);
+ /**
+ * Create and return the WTP CMDocument for the DTD or schema defined by this ContentModel.
+ *
+ * @return The resolved CMDocument.
+ */
+ public CMDocument getContentModelDocument() {
+ if (schemaId != null) {
+ return getContentModelDocument(schemaId);
+ }
+
+ String resolvedURI = null;
+ try {
+ resolvedURI = resolveResourceURI(publicId, systemId);
+ if (resolvedURI == null) {
+ return null;
+ }
+ return createCMDocument(resolvedURI);
+ } catch (final Exception e) {
+ throw new AssertionError(MessageFormat.format("Resolution of systemId ''{0}'' resulted in a exception:{1}. {2}", systemId, resolvedURI, e.getMessage()));
+ }
+ }
+
+ /**
+ * Create and return the WTP CMDocument for the XML-Schema at the given URI or namespace. The XML catalog is used to
+ * resolve the schema URI.
+ *
+ * @param schemaID
+ * The URI or the namespace of the XML-Schema.
+ * @return The resolved CMDocument.
+ */
+ public CMDocument getContentModelDocument(final String schemaId) {
+ String resolvedUri = null;
+ try {
+ resolvedUri = resolveResourceURI(null, schemaId);
+ if (resolvedUri == null) {
+ return null;
+ }
+ return createCMDocument(resolvedUri);
+ } catch (final Exception e) {
+ throw new AssertionError(MessageFormat.format("Resolution of resource URI ''{0}'' resulted in a exception:{1}. {2}", schemaId, resolvedUri, e.getMessage()));
}
- return createCMDocument(resolveSystemId(systemId));
}
- private CMDocument createCMDocument(final URL resolvedDtdUrl) {
- if (resolvedDtdUrl == null) {
+ /**
+ * Create a new CMDocument from the DTD or XML-Schema at the given URI.
+ *
+ * @param resourceURI
+ * The URI containing the schema or dtd.
+ * @return
+ */
+ private CMDocument createCMDocument(final String resourceURI) {
+ if (resourceURI == null) {
return null;
}
final ContentModelManager modelManager = ContentModelManager.getInstance();
- return modelManager.createCMDocument(resolvedDtdUrl.toString(), null);
+ final CMDocument cmDocument = modelManager.createCMDocument(resourceURI, null);
+ return cmDocument;
}
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
- final String resolved = URI_RESOLVER.resolve(baseUri, publicId, systemId);
- System.out.println("Resolved " + publicId + " " + systemId + " -> " + resolved);
+ final String resolved = resolveResourceURI(publicId, systemId);
+
if (resolved == null) {
return null;
}
@@ -103,36 +176,19 @@ public class DocumentContentModel implements EntityResolver {
return result;
}
- public URL resolveSchemaIdentifier(final String schemaIdentifier) {
- if (schemaIdentifier == null) {
- return null;
- }
- final String schemaLocation = URI_RESOLVER.resolve(baseUri, schemaIdentifier, null);
- if (schemaLocation == null) {
- /*
- * TODO this is a common case that should be handled somehow - a hint should be shown: the schema is not
- * available, the schema should be added to the catalog by the user - an inferred schema should be used, to
- * allow to at least display the document in the editor - this is not the right place to either check or
- * handle this
- */
- return null;
- }
- try {
- return new URL(schemaLocation);
- } catch (final MalformedURLException e) {
- throw new AssertionError(MessageFormat.format("Resolution of schema ''{0}'' resulted in a malformed URL: ''{1}''. {2}", schemaIdentifier, schemaLocation, e.getMessage()));
- }
- }
-
- public URL resolveSystemId(final String systemId) {
- final String schemaLocation = URI_RESOLVER.resolve(baseUri, null, systemId);
- if (schemaLocation == null) {
- return null;
- }
- try {
- return new URL(schemaLocation);
- } catch (final MalformedURLException e) {
- throw new AssertionError(MessageFormat.format("Resolution of systemId ''{0}'' resulted in a malformed URL: ''{1}''. {2}", systemId, schemaLocation, e.getMessage()));
- }
+ /**
+ * Resolve the URI for a given Resource with the XML-Catalog.
+ *
+ * @param publicId
+ * The public identifier (DTD) of the resource being referenced, may be null
+ * @param systemId
+ * The system identifier (DTD) or the namespace (XML-Schema) of the resource being referenced, may be
+ * null.
+ * @return A String containing the resolved URI.
+ * @throws IOException
+ */
+ public String resolveResourceURI(final String publicId, final String systemId) throws IOException {
+ final String resolved = URI_RESOLVER.resolve(baseUri, publicId, systemId);
+ return resolved;
}
}
diff --git a/org.eclipse.vex.docbook/plugin.properties b/org.eclipse.vex.docbook/plugin.properties
index 050fe5ad..6750db3c 100644
--- a/org.eclipse.vex.docbook/plugin.properties
+++ b/org.eclipse.vex.docbook/plugin.properties
@@ -13,9 +13,7 @@ providerName= Eclipse.org
doctype.docbook4_5=DocBook v4.5
doctype.docbook5_0_DTD=DocBook v5.0 (DTD)
-doctype.docbook5_0_XSD1=DocBook v5.0 (http://www.oasis-open.org/docbook/xml/5.0/xsd/docbook.xsd)
-doctype.docbook5_0_XSD2=DocBook v5.0 (http://docbook.org/xml/5.0/xsd/docbook.xsd)
-doctype.docbook5_0_XSD3=DocBook v5.0 (http://docbook.org/ns/docbook)
+doctype.docbook5_0_XSD2=DocBook v5.0 (XML Schema)
style.docbook-plain=DocBook Plain
contentType.name=DocBook XML Document
diff --git a/org.eclipse.vex.docbook/plugin.xml b/org.eclipse.vex.docbook/plugin.xml
index 1079b51e..7dae25e1 100644
--- a/org.eclipse.vex.docbook/plugin.xml
+++ b/org.eclipse.vex.docbook/plugin.xml
@@ -16,6 +16,14 @@
uri="4.5/docbookx.dtd"
webURL="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
</public>
+ <system
+ systemId="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
+ uri="4.5/docbookx.dtd">
+ </system>
+ <system
+ systemId="http://docbook.org/xml/4.5/docbookx.dtd"
+ uri="4.5/docbookx.dtd">
+ </system>
<uri
name="urn:org:eclipse:vex:styles:docbook:docbook-plain.css"
uri="styles/docbook-plain.css">
@@ -33,33 +41,41 @@
webURL="http://www.oasis-open.org/docbook/xml/5.0/docbook.dtd">
</public>
<uri
- name="http://www.oasis-open.org/docbook/xml/5.0/xsd/docbook.xsd"
+ name="http://docbook.org/ns/docbook"
uri="5.0/xsd/docbook.xsd">
</uri>
- <uri
- name="http://docbook.org/xml/5.0/xsd/docbook.xsd"
+ <system
+ systemId="http://www.oasis-open.org/docbook/xml/5.0/xsd/docbook.xsd"
uri="5.0/xsd/docbook.xsd">
- </uri>
- <uri
- name="http://docbook.org/ns/docbook"
+ </system>
+ <system
+ systemId="http://docbook.org/xml/5.0/xsd/docbook.xsd"
uri="5.0/xsd/docbook.xsd">
- </uri>
+ </system>
<uri
- name="http://www.oasis-open.org/docbook/xml/5.0/xsd/xlink.xsd"
+ name="http://www.w3.org/1999/xlink"
uri="5.0/xsd/xlink.xsd">
</uri>
- <uri
- name="http://docbook.org/xml/5.0/xsd/xlink.xsd"
+ <system
+ systemId="http://www.oasis-open.org/docbook/xml/5.0/xsd/xlink.xsd"
uri="5.0/xsd/xlink.xsd">
- </uri>
+ </system>
+ <system
+ systemId="http://docbook.org/xml/5.0/xsd/xlink.xsd"
+ uri="5.0/xsd/xlink.xsd">
+ </system>
<uri
- name="http://www.oasis-open.org/docbook/xml/5.0/xsd/xml.xsd"
+ name="http://www.w3.org/XML/1998/namespace"
uri="5.0/xsd/xml.xsd">
</uri>
- <uri
- name="http://docbook.org/xml/5.0/xsd/xml.xsd"
+ <system
+ systemId="http://www.oasis-open.org/docbook/xml/5.0/xsd/xml.xsd"
uri="5.0/xsd/xml.xsd">
- </uri>
+ </system>
+ <system
+ systemId="http://docbook.org/xml/5.0/xsd/xml.xsd"
+ uri="5.0/xsd/xml.xsd">
+ </system>
</catalogContribution>
</extension>
@@ -145,54 +161,13 @@
</doctype>
</extension>
- <extension
- id="docbook5_0_XSD1"
- name="%doctype.docbook5_0_XSD1"
- point="org.eclipse.vex.ui.doctypes">
- <doctype
- publicId="http://www.oasis-open.org/docbook/xml/5.0/xsd/docbook.xsd"
- systemId="5.0/xsd/docbook.xsd">
-
- <rootElement
- name="article">
- </rootElement>
- <rootElement
- name="appendix">
- </rootElement>
- <rootElement
- name="book">
- </rootElement>
- <rootElement
- name="chapter">
- </rootElement>
- <rootElement
- name="sect1">
- </rootElement>
- <rootElement
- name="sect2">
- </rootElement>
- <rootElement
- name="sect3">
- </rootElement>
- <rootElement
- name="sect4">
- </rootElement>
- <rootElement
- name="sect5">
- </rootElement>
- <rootElement
- name="section">
- </rootElement>
- </doctype>
- </extension>
<extension
id="docbook5_0_XSD2"
name="%doctype.docbook5_0_XSD2"
point="org.eclipse.vex.ui.doctypes">
- <doctype
- publicId="http://docbook.org/xml/5.0/xsd/docbook.xsd"
- systemId="5.0/xsd/docbook.xsd">
+ <schema
+ namespaceName="http://docbook.org/ns/docbook">
<rootElement
name="article">
@@ -224,49 +199,9 @@
<rootElement
name="section">
</rootElement>
- </doctype>
+ </schema>
</extension>
- <extension
- id="docbook5_0_XSD2"
- name="%doctype.docbook5_0_XSD3"
- point="org.eclipse.vex.ui.doctypes">
- <doctype
- publicId="http://docbook.org/ns/docbook"
- systemId="5.0/xsd/docbook.xsd">
-
- <rootElement
- name="article">
- </rootElement>
- <rootElement
- name="appendix">
- </rootElement>
- <rootElement
- name="book">
- </rootElement>
- <rootElement
- name="chapter">
- </rootElement>
- <rootElement
- name="sect1">
- </rootElement>
- <rootElement
- name="sect2">
- </rootElement>
- <rootElement
- name="sect3">
- </rootElement>
- <rootElement
- name="sect4">
- </rootElement>
- <rootElement
- name="sect5">
- </rootElement>
- <rootElement
- name="section">
- </rootElement>
- </doctype>
- </extension>
<extension
id="docbook-plain"
@@ -274,11 +209,12 @@
point="org.eclipse.vex.ui.styles">
<style
css="styles/docbook-plain.css">
+ <doctypeRef
+ publicId="docbook5_0_DTD">
+ </doctypeRef>
<doctypeRef publicId="-//OASIS//DTD Simplified DocBook XML V1.1//EN"/>
<doctypeRef publicId="-//OASIS//DTD DocBook XML V4.5//EN"/>
<doctypeRef publicId="-//OASIS//DTD DocBook XML 5.0//EN"/>
- <doctypeRef publicId="http://www.oasis-open.org/docbook/xml/5.0/xsd/docbook.xsd"/>
- <doctypeRef publicId="http://docbook.org/xml/5.0/xsd/docbook.xsd"/>
<doctypeRef publicId="http://docbook.org/ns/docbook"/>
</style>
</extension>
diff --git a/org.eclipse.vex.ui.tests/plugin.xml b/org.eclipse.vex.ui.tests/plugin.xml
index 657600e1..dd04ca3b 100644
--- a/org.eclipse.vex.ui.tests/plugin.xml
+++ b/org.eclipse.vex.ui.tests/plugin.xml
@@ -26,6 +26,14 @@
</doctype>
</extension>
<extension
+ id="test-schema-doctype"
+ name="test schema doctype"
+ point="org.eclipse.vex.ui.doctypes">
+ <schema
+ namespaceName="http://org.eclipse.vex/namespace">
+ </schema>
+ </extension>
+ <extension
id="test-style"
name="test style"
point="org.eclipse.vex.ui.styles">
@@ -36,5 +44,35 @@
</doctypeRef>
</style>
</extension>
+ <extension
+ id="test-style"
+ name="test style"
+ point="org.eclipse.vex.ui.styles">
+ <style
+ css="testdata/test-schema.css">
+ <doctypeRef
+ publicId="http://org.eclipse.vex/namespace">
+ </doctypeRef>
+ </style>
+ </extension>
+ <extension
+ id="test-style-doctype-id"
+ name="test style doctype id"
+ point="org.eclipse.vex.ui.styles">
+ <style
+ css="testdata/test-doctype-id.css">
+ <doctypeRef
+ publicId="test-schema-doctype2">
+ </doctypeRef>
+ </style>
+ </extension>
+ <extension
+ id="test-schema-doctype2"
+ name="test schema doctype2"
+ point="org.eclipse.vex.ui.doctypes">
+ <schema
+ namespaceName="http://org.eclipse.vex/namespace2">
+ </schema>
+ </extension>
</plugin>
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
index 933f56dc..83d6e9b7 100644
--- a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/ConfigurationRegistryTest.java
@@ -1,15 +1,17 @@
/*******************************************************************************
- * Copyright (c) 2010 Florian Thienel and others.
+ * Copyright (c) 2013 Florian Thienel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Florian Thienel - initial API and implementation
+ * Carsten Hiesserich - additional tests
*******************************************************************************/
package org.eclipse.vex.ui.internal.config.tests;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -20,10 +22,12 @@ import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.vex.ui.internal.config.ConfigEvent;
+import org.eclipse.vex.ui.internal.config.ConfigLoaderJob;
import org.eclipse.vex.ui.internal.config.ConfigSource;
import org.eclipse.vex.ui.internal.config.ConfigurationLoader;
import org.eclipse.vex.ui.internal.config.ConfigurationRegistry;
import org.eclipse.vex.ui.internal.config.ConfigurationRegistryImpl;
+import org.eclipse.vex.ui.internal.config.DocumentType;
import org.eclipse.vex.ui.internal.config.IConfigListener;
import org.eclipse.vex.ui.internal.config.PluginProject;
import org.junit.After;
@@ -116,6 +120,46 @@ public class ConfigurationRegistryTest {
assertNotNull(registry.getPluginProject(project));
}
+ @Test
+ public void testPluginDoctypeDefinition() throws Exception {
+ final ConfigurationRegistry configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
+ configurationRegistry.loadConfigurations();
+
+ final DocumentType doctype = configurationRegistry.getDocumentType("-//Vex//DTD Test//EN", null);
+ assertNotNull(doctype);
+ assertEquals("test.dtd", doctype.getSystemId());
+ }
+
+ @Test
+ public void testPluginNamespaceDefinition() throws Exception {
+ final ConfigurationRegistry configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
+ configurationRegistry.loadConfigurations();
+
+ final DocumentType doctype = configurationRegistry.getDocumentType("http://org.eclipse.vex/namespace", null);
+ assertNotNull(doctype);
+ assertEquals("test schema doctype", doctype.getName());
+ }
+
+ @Test
+ public void testGetDocumentTypesWithStyles() throws Exception {
+ final ConfigurationRegistry configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
+ configurationRegistry.loadConfigurations();
+
+ final DocumentType[] doctypes = configurationRegistry.getDocumentTypesWithStyles();
+ boolean dtdFound = false;
+ boolean schemaFound = false;
+ for (final DocumentType doctype : doctypes) {
+ if ("test doctype".equals(doctype.getName())) {
+ dtdFound = true;
+ }
+ if ("test schema doctype".equals(doctype.getName())) {
+ schemaFound = true;
+ }
+ }
+ assertTrue("DoctypeWithStyles should return Doctype with DTD ", dtdFound);
+ assertTrue("DoctypeWithStyles should return Docype with namespace ", schemaFound);
+ }
+
private static class MockConfigurationLoader implements ConfigurationLoader {
private final List<ConfigSource> loadedConfigSources;
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PreferencesTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PreferencesTest.java
new file mode 100644
index 00000000..de9b323d
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PreferencesTest.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Carsten Hiesserich and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Carsten Hiesserich - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.ui.internal.config.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URL;
+
+import org.eclipse.vex.ui.internal.VexPlugin;
+import org.eclipse.vex.ui.internal.VexPreferences;
+import org.eclipse.vex.ui.internal.config.ConfigSource;
+import org.eclipse.vex.ui.internal.config.DocumentType;
+import org.eclipse.vex.ui.internal.config.Style;
+import org.junit.Test;
+
+@SuppressWarnings("restriction")
+public class PreferencesTest {
+
+ @Test
+ public void testStylesheetPreference() throws Exception {
+ final VexPreferences preferences = VexPlugin.getDefault().getPreferences();
+ final DocumentType doctype = new DocumentType(new MockConfigSource());
+ doctype.setSimpleId("vex_test_doctype");
+ final Style style = new Style(new MockConfigSource());
+ style.setSimpleId("vex-test-style");
+ preferences.setPreferredStyleId(doctype, style.getUniqueId());
+
+ final String preferredStyleId = preferences.getPreferredStyleId(doctype);
+ assertEquals(style.getUniqueId(), preferredStyleId);
+ }
+
+ private class MockConfigSource extends ConfigSource {
+
+ public MockConfigSource() {
+ super("test_config");
+ }
+
+ @Override
+ public URL getBaseUrl() {
+ return null;
+ }
+
+ }
+}
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/VexDocumentContentModelTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/VexDocumentContentModelTest.java
new file mode 100644
index 00000000..59dafeda
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/VexDocumentContentModelTest.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Carsten Hiesserich and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Carsten Hiesserich - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.ui.internal.config.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.vex.core.internal.dom.Element;
+import org.eclipse.vex.ui.internal.config.Style;
+import org.eclipse.vex.ui.internal.editor.NoStyleForDoctypeException;
+import org.eclipse.vex.ui.internal.editor.VexDocumentContentModel;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("restriction")
+public class VexDocumentContentModelTest {
+
+ private VexDocumentContentModel model;
+
+ @Before
+ public void setUp() throws Exception {
+ model = new VexDocumentContentModel();
+ }
+
+ @Test
+ public void resolveDoctypeByPublicId() throws Exception {
+ try {
+ model.initialize(null, "-//Vex//DTD Test//EN", null, new Element(new QualifiedName("http://org.eclipse.vex/namespace", "rootElement")));
+ } catch (final NoStyleForDoctypeException e) {
+ // We are not interested in the StyleSheet here
+ }
+ assertTrue(model.isDtdAssigned());
+ assertNotNull(model.getDocumentType());
+ assertEquals("test doctype", model.getDocumentType().getName());
+ }
+
+ @Test
+ public void resolveDoctypeBySystemId() throws Exception {
+ try {
+ model.initialize(null, "UnknownPublicId", "test.dtd", new Element(new QualifiedName("http://org.eclipse.vex/namespace", "rootElement")));
+ } catch (final NoStyleForDoctypeException e) {
+ // We are not interested in the StyleSheet here
+ }
+ assertTrue(model.isDtdAssigned());
+ assertNotNull(model.getDocumentType());
+ assertEquals("test doctype", model.getDocumentType().getName());
+ }
+
+ @Test
+ public void resolveDoctypeByNamespace() throws Exception {
+ try {
+ model.initialize(null, null, null, new Element(new QualifiedName("http://org.eclipse.vex/namespace", "rootElement")));
+ } catch (final NoStyleForDoctypeException e) {
+ // We are not interested in the StyleSheet here
+ }
+ assertFalse(model.isDtdAssigned());
+ assertNotNull(model.getDocumentType());
+ assertEquals("test schema doctype", model.getDocumentType().getName());
+ }
+
+ @Test
+ public void resolveCSSByPublicId() throws Exception {
+ model.initialize(null, "-//Vex//DTD Test//EN", null, new Element(new QualifiedName("http://org.eclipse.vex/namespace", "rootElement")));
+ assertTrue(model.isDtdAssigned());
+ final Style style = model.getStyle();
+ assertNotNull(style);
+ assertTrue(style.getResourceUri().toString().endsWith("test.css"));
+ }
+
+ @Test
+ public void resolveCSSBySystemId() throws Exception {
+ model.initialize(null, null, "test.dtd", new Element(new QualifiedName("http://org.eclipse.vex/namespace", "rootElement")));
+ assertTrue(model.isDtdAssigned());
+ final Style style = model.getStyle();
+ assertNotNull(style);
+ assertTrue(style.getResourceUri().toString().endsWith("test.css"));
+ }
+
+ @Test
+ public void resolveCSSByPluginId() throws Exception {
+ model.initialize(null, null, null, new Element(new QualifiedName("http://org.eclipse.vex/namespace2", "rootElement")));
+ final Style style = model.getStyle();
+ assertNotNull(style);
+ assertTrue(style.getResourceUri().toString().endsWith("test-doctype-id.css"));
+ }
+
+ @Test
+ public void resolveCSSByNamespace() throws Exception {
+ model.initialize(null, null, null, new Element(new QualifiedName("http://org.eclipse.vex/namespace", "rootElement")));
+ assertFalse(model.isDtdAssigned());
+ final Style style = model.getStyle();
+ assertNotNull(style);
+ assertTrue(style.getResourceUri().toString().endsWith("test-schema.css"));
+ }
+}
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java
index e2fd051d..c97a42a0 100644
--- a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/tests/VexUiTestSuite.java
@@ -13,6 +13,8 @@ package org.eclipse.vex.ui.tests;
import org.eclipse.vex.ui.internal.config.tests.ConfigLoaderJobTest;
import org.eclipse.vex.ui.internal.config.tests.ConfigurationRegistryTest;
+import org.eclipse.vex.ui.internal.config.tests.PreferencesTest;
+import org.eclipse.vex.ui.internal.config.tests.VexDocumentContentModelTest;
import org.eclipse.vex.ui.internal.editor.tests.FindReplaceTargetTest;
import org.eclipse.vex.ui.internal.editor.tests.HandlerUtilTest;
import org.eclipse.vex.ui.internal.namespace.tests.EditNamespacesControllerTest;
@@ -23,6 +25,6 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ ConfigLoaderJobTest.class, ConfigurationRegistryTest.class, EditNamespacesControllerTest.class, FindReplaceTargetTest.class, OutlineProviderTest.class, OutlineFilterTest.class,
- HandlerUtilTest.class })
+ HandlerUtilTest.class, VexDocumentContentModelTest.class, PreferencesTest.class })
public class VexUiTestSuite {
}
diff --git a/org.eclipse.vex.ui.tests/testdata/test-doctype-id.css b/org.eclipse.vex.ui.tests/testdata/test-doctype-id.css
new file mode 100644
index 00000000..9a830317
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/testdata/test-doctype-id.css
@@ -0,0 +1,53 @@
+
+html {
+ display: block;
+}
+
+body {
+ display: block;
+}
+
+p {
+ display: block;
+}
+
+block {
+ display: block;
+}
+
+pre {
+ display: block;
+ white-space: pre;
+}
+
+
+/* Styles for positioning tests */
+root {
+ border: 3px 7px 11px 13px;
+ padding: 17px 19px 23px 29px;
+}
+
+small {
+ border-width: 1px 2px 3px 4px;
+ border-style: solid;
+ margin: 100px 200px 300px 400px;
+ padding: 10px 20px 30px 40px;
+ display: block;
+}
+
+medium {
+ border-width: 2px 4px 6px 8px;
+ border-style: solid;
+ margin: 200px 400px 600px 800px;
+ padding: 20px 40px 60px 80px;
+ display: block;
+}
+
+large {
+ border-width: 3px 6px 9px 12px;
+ border-style: solid;
+ margin: 300px 600px 900px 1200px;
+ padding: 30px 60px 90px 120px;
+ display: block;
+}
+
diff --git a/org.eclipse.vex.ui.tests/testdata/test-schema.css b/org.eclipse.vex.ui.tests/testdata/test-schema.css
new file mode 100644
index 00000000..9a830317
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/testdata/test-schema.css
@@ -0,0 +1,53 @@
+
+html {
+ display: block;
+}
+
+body {
+ display: block;
+}
+
+p {
+ display: block;
+}
+
+block {
+ display: block;
+}
+
+pre {
+ display: block;
+ white-space: pre;
+}
+
+
+/* Styles for positioning tests */
+root {
+ border: 3px 7px 11px 13px;
+ padding: 17px 19px 23px 29px;
+}
+
+small {
+ border-width: 1px 2px 3px 4px;
+ border-style: solid;
+ margin: 100px 200px 300px 400px;
+ padding: 10px 20px 30px 40px;
+ display: block;
+}
+
+medium {
+ border-width: 2px 4px 6px 8px;
+ border-style: solid;
+ margin: 200px 400px 600px 800px;
+ padding: 20px 40px 60px 80px;
+ display: block;
+}
+
+large {
+ border-width: 3px 6px 9px 12px;
+ border-style: solid;
+ margin: 300px 600px 900px 1200px;
+ padding: 30px 60px 90px 120px;
+ display: block;
+}
+
diff --git a/org.eclipse.vex.ui/schema/doctype.exsd b/org.eclipse.vex.ui/schema/doctype.exsd
index 3846319e..1d2aa3bf 100644
--- a/org.eclipse.vex.ui/schema/doctype.exsd
+++ b/org.eclipse.vex.ui/schema/doctype.exsd
@@ -1,133 +1,149 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="vex-editor" xmlns="http://www.w3.org/2001/XMLSchema">
-<annotation>
- <appinfo>
- <meta.schema plugin="vex-editor" id="doctype" name="Vex DocType"/>
- </appinfo>
- <documentation>
- Registers a new document type with Vex.
- </documentation>
- </annotation>
-
- <element name="extension">
- <annotation>
- <appinfo>
- <meta.element />
- </appinfo>
- </annotation>
- <complexType>
- <sequence>
- <element ref="doctype"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="doctype">
- <annotation>
- <appinfo>
- <meta.element labelAttribute="publicId"/>
- </appinfo>
- </annotation>
- <complexType>
- <sequence>
- <element ref="rootElement" minOccurs="0" maxOccurs="unbounded"/>
- </sequence>
- <attribute name="publicId" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="systemId" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="outlineProvider" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute kind="java" basedOn="net.sf.vex.editor.IOutlineProvider"/>
- </appinfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="rootElement">
- <complexType>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appinfo>
- <meta.section type="since"/>
- </appinfo>
- <documentation>
- [Enter the first release in which this extension point appears.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="examples"/>
- </appinfo>
- <documentation>
- [Enter extension point usage example here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="apiInfo"/>
- </appinfo>
- <documentation>
- [Enter API information here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="implementation"/>
- </appinfo>
- <documentation>
- [Enter information about supplied implementation of this extension point.]
- </documentation>
- </annotation>
-
-
-</schema>
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="vex-editor" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="vex-editor" id="doctype" name="Vex DocType"/>
+ </appinfo>
+ <documentation>
+ Registers a new document type with Vex.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <choice>
+ <element ref="doctype"/>
+ <element ref="schema"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="doctype">
+ <annotation>
+ <appinfo>
+ <meta.element labelAttribute="publicId"/>
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="rootElement" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="publicId" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="systemId" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="outlineProvider" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn="net.sf.vex.editor.IOutlineProvider"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="rootElement">
+ <complexType>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="schema">
+ <complexType>
+ <sequence minOccurs="0" maxOccurs="unbounded">
+ <element ref="rootElement"/>
+ </sequence>
+ <attribute name="namespaceName" type="string" use="required">
+ <annotation>
+ <documentation>
+ The namespace name that is the target of the defined XML-Schema
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiInfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/org.eclipse.vex.ui/schema/style.exsd b/org.eclipse.vex.ui/schema/style.exsd
index 26a3933c..5ce16ad3 100644
--- a/org.eclipse.vex.ui/schema/style.exsd
+++ b/org.eclipse.vex.ui/schema/style.exsd
@@ -1,16 +1,21 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
-<schema targetNamespace="vex-editor">
+<schema targetNamespace="vex-editor" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
- <appInfo>
+ <appinfo>
<meta.schema plugin="vex-editor" id="style" name="Vex Style"/>
- </appInfo>
+ </appinfo>
<documentation>
- Registers a new document type with Vex.
+ Registers a new CSS Stylesheet type with Vex.
</documentation>
</annotation>
<element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
<complexType>
<sequence>
<element ref="style"/>
@@ -49,9 +54,9 @@
<documentation>
</documentation>
- <appInfo>
+ <appinfo>
<meta.attribute kind="resource"/>
- </appInfo>
+ </appinfo>
</annotation>
</attribute>
</complexType>
@@ -62,7 +67,7 @@
<attribute name="publicId" type="string">
<annotation>
<documentation>
-
+ The PublicID (DTD) or namespace (XML-Schema) of the referenced document type.
</documentation>
</annotation>
</attribute>
@@ -70,48 +75,40 @@
</element>
<annotation>
- <appInfo>
- <meta.section type="since"/>
- </appInfo>
+ <appinfo>
+ <meta.section type="apiInfo"/>
+ </appinfo>
<documentation>
- [Enter the first release in which this extension point appears.]
+ [Enter API information here.]
</documentation>
</annotation>
<annotation>
- <appInfo>
- <meta.section type="examples"/>
- </appInfo>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
<documentation>
- [Enter extension point usage example here.]
+ [Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
- <appInfo>
- <meta.section type="apiInfo"/>
- </appInfo>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
<documentation>
- [Enter API information here.]
+ [Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
- <appInfo>
+ <appinfo>
<meta.section type="implementation"/>
- </appInfo>
+ </appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
- <annotation>
- <appInfo>
- <meta.section type="copyright"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
</schema>
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java
index a7599d0a..056b959c 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/VexPreferences.java
@@ -19,7 +19,9 @@ import org.eclipse.vex.core.internal.css.IStyleSheetProvider;
import org.eclipse.vex.core.internal.css.StyleSheet;
import org.eclipse.vex.core.provisional.dom.DocumentContentModel;
import org.eclipse.vex.ui.internal.config.ConfigurationRegistry;
+import org.eclipse.vex.ui.internal.config.DocumentType;
import org.eclipse.vex.ui.internal.config.Style;
+import org.eclipse.vex.ui.internal.editor.VexDocumentContentModel;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@@ -49,9 +51,9 @@ public class VexPreferences implements IStyleSheetProvider {
this.configurationRegistry = configurationRegistry;
}
- public void setPreferredStyleId(final String publicId, final String styleId) {
+ public void setPreferredStyleId(final DocumentType doctype, final String styleId) {
final Preferences preferences = InstanceScope.INSTANCE.getNode(VexPlugin.ID);
- final String key = getStylePreferenceKey(publicId);
+ final String key = getStylePreferenceKey(doctype.getUniqueId());
preferences.put(key, styleId);
try {
preferences.flush();
@@ -60,9 +62,9 @@ public class VexPreferences implements IStyleSheetProvider {
}
}
- public String getPreferredStyleId(final String publicId) {
+ public String getPreferredStyleId(final DocumentType doctype) {
final Preferences preferences = InstanceScope.INSTANCE.getNode(VexPlugin.ID);
- final String preferredStyleId = preferences.get(getStylePreferenceKey(publicId), null);
+ final String preferredStyleId = preferences.get(getStylePreferenceKey(doctype.getUniqueId()), null);
return preferredStyleId;
}
@@ -70,8 +72,8 @@ public class VexPreferences implements IStyleSheetProvider {
return publicId + PREFERRED_STYLE_SUFFIX;
}
- public Style getPreferredStyle(final String publicId) {
- return configurationRegistry.getStyle(publicId, getPreferredStyleId(publicId));
+ public Style getPreferredStyle(final DocumentType doctype) {
+ return configurationRegistry.getStyle(doctype, getPreferredStyleId(doctype));
}
public String getIndentationPattern() {
@@ -87,7 +89,13 @@ public class VexPreferences implements IStyleSheetProvider {
}
public StyleSheet getStyleSheet(final DocumentContentModel documentContentModel) {
- final Style style = getPreferredStyle(documentContentModel.getMainDocumentTypeIdentifier());
+ Style style = null;
+ if (documentContentModel instanceof VexDocumentContentModel) {
+ // We only support the VexDocumentContentModel
+ // If there will ever be another DocumentContentModel implememntation, it will
+ // have to define it's own method for resolving styles
+ style = getPreferredStyle(((VexDocumentContentModel) documentContentModel).getDocumentType());
+ }
if (style == null) {
return StyleSheet.NULL;
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigLoaderJob.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigLoaderJob.java
index e80e0873..a979bab9 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigLoaderJob.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigLoaderJob.java
@@ -108,7 +108,7 @@ public class ConfigLoaderJob extends Job implements ConfigurationLoader {
}
public boolean isLoading() {
- return getState() == Job.RUNNING;
+ return getState() == Job.RUNNING || getState() == Job.WAITING;
}
public void load(final Runnable whenDone) {
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistry.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistry.java
index ea8b2786..0b73b9f7 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistry.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistry.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Florian Thienel - initial API and implementation
*******************************************************************************/
@@ -35,15 +35,17 @@ public interface ConfigurationRegistry {
boolean isLoaded();
/**
- * The document type configuration for the given public identifier, or null if there is no configuration for the
- * given public identifier.
+ * The document type configuration for the given identifier.<br />
+ * This method tries to resolve by PublicId or namespace first. If this does not yield as result, a doctype with a
+ * matching SystemId is returned.
*
- * @param publicId
- * the public identifier
- * @return the document type configuration for the given public identifier, or null if there is no configuration for
- * the given public identifier.
+ * @param id
+ * the public/system identifier or namespace
+ * @param systemId
+ * the system id, only used when resolving the public id fails. May be null.
+ * @return the document type configuration for the identifier, or null if there is no doctype found.
*/
- DocumentType getDocumentType(final String publicId);
+ DocumentType getDocumentType(final String id, final String systemId);
/**
* @return all document type configurations
@@ -56,13 +58,18 @@ public interface ConfigurationRegistry {
DocumentType[] getDocumentTypesWithStyles();
/**
- * All styles for the document type with the given public identifier.
+ * All styles for the given document type. The returned styles are ordered by the way they are resolved:
+ * <ul>
+ * <li>1. document type id</li>
+ * <li>2. Public ID (DTD) or Namespace (XML-Schema)</li>
+ * <li>3. System ID (DTD)</li>
+ * </ul>
*
- * @param publicId
- * the document type's public identifier
- * @return all styles for the document type with the given public identifier
+ * @param doctype
+ * the document type
+ * @return all styles for the given document type
*/
- Style[] getStyles(final String publicId);
+ Style[] getStyles(final DocumentType doctype);
/**
* The style with the given id, or null if there is no style with this id.
@@ -74,16 +81,15 @@ public interface ConfigurationRegistry {
Style getStyle(final String styleId);
/**
- * An arbitrary style for the document type with the given public identifier. If available, the style with the given
- * style id is preferred.
+ * An arbitrary style for the given document type. If available, the style with the given style id is preferred.
*
- * @param publicId
- * the document type's public identifier
+ * @param pdoctype
+ * the document type
* @param preferredStyleId
* the preferred style's id
* @return a style for the given document type, or null if no style is configured for the given document type
*/
- Style getStyle(final String publicId, final String preferredStyleId);
+ Style getStyle(final DocumentType doctype, final String preferredStyleId);
/**
* The representation of the given plug-in project in the workspace.
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistryImpl.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistryImpl.java
index 2317d580..971e8cd0 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistryImpl.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationRegistryImpl.java
@@ -187,15 +187,22 @@ public class ConfigurationRegistryImpl implements ConfigurationRegistry {
configListeners.fireEvent("configLoaded", e); //$NON-NLS-1$
}
- public DocumentType getDocumentType(final String publicId) {
+ public DocumentType getDocumentType(final String id, final String systemId) {
final List<ConfigItem> configItems = getAllConfigItems(DocumentType.EXTENSION_POINT);
+ DocumentType systemDoctype = null;
+ // Try to resolve by PublicId or namespace first
for (final ConfigItem configItem : configItems) {
final DocumentType doctype = (DocumentType) configItem;
- if (doctype.getPublicId().equals(publicId)) {
+ if (id.equals(doctype.getPublicId()) || id.equals(doctype.getNamespaceName())) {
return doctype;
}
+ if (systemId != null && systemId.equals(doctype.getSystemId())) {
+ // Save the doctype resolved by SystemID
+ systemDoctype = doctype;
+ }
}
- return null;
+
+ return systemDoctype; // May be null
}
public DocumentType[] getDocumentTypes() {
@@ -210,21 +217,40 @@ public class ConfigurationRegistryImpl implements ConfigurationRegistry {
final List<DocumentType> result = new ArrayList<DocumentType>();
for (final ConfigItem configItem : getAllConfigItems(DocumentType.EXTENSION_POINT)) {
final DocumentType doctype = (DocumentType) configItem;
- if (getStyles(doctype.getPublicId()).length > 0) {
+ if (getStyles(doctype).length > 0) {
result.add(doctype);
}
}
return result.toArray(new DocumentType[result.size()]);
}
- public Style[] getStyles(final String publicId) {
- final ArrayList<Style> result = new ArrayList<Style>();
+ public Style[] getStyles(final DocumentType doctype) {
+ final ArrayList<Style> resultId = new ArrayList<Style>();
+ final ArrayList<Style> resultPublic = new ArrayList<Style>();
+ final ArrayList<Style> resultSystem = new ArrayList<Style>();
+ final ArrayList<Style> resultSchema = new ArrayList<Style>();
for (final ConfigItem configItem : getAllConfigItems(Style.EXTENSION_POINT)) {
final Style style = (Style) configItem;
- if (style.appliesTo(publicId)) {
- result.add(style);
+ if (style.appliesTo(doctype.getSimpleId())) {
+ resultId.add(style);
+ }
+ if (!doctype.isBlank(doctype.getPublicId()) && style.appliesTo(doctype.getPublicId())) {
+ resultPublic.add(style);
+ }
+ if (!doctype.isBlank(doctype.getSystemId()) && style.appliesTo(doctype.getSystemId())) {
+ resultSystem.add(style);
+ }
+ if (!doctype.isBlank(doctype.getNamespaceName()) && style.appliesTo(doctype.getNamespaceName())) {
+ resultSchema.add(style);
}
}
+
+ // The resolved stylesheet are returned in a defined order
+ final ArrayList<Style> result = new ArrayList<Style>();
+ result.addAll(resultId);
+ result.addAll(resultPublic);
+ result.addAll(resultSchema);
+ result.addAll(resultSystem);
return result.toArray(new Style[result.size()]);
}
@@ -238,8 +264,8 @@ public class ConfigurationRegistryImpl implements ConfigurationRegistry {
return null;
}
- public Style getStyle(final String publicId, final String preferredStyleId) {
- final Style[] styles = getStyles(publicId);
+ public Style getStyle(final DocumentType doctype, final String preferredStyleId) {
+ final Style[] styles = getStyles(doctype);
if (styles.length == 0) {
return null;
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java
index 65c289f9..7d3bda7e 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigurationView.java
@@ -77,7 +77,7 @@ public class ConfigurationView extends ViewPart {
return VexPlugin.getDefault().getConfigurationRegistry().getDocumentTypes();
}
if (parentElement instanceof DocumentType) {
- return VexPlugin.getDefault().getConfigurationRegistry().getStyles(((DocumentType) parentElement).getPublicId());
+ return VexPlugin.getDefault().getConfigurationRegistry().getStyles((DocumentType) parentElement);
}
return new Object[0];
}
@@ -87,7 +87,7 @@ public class ConfigurationView extends ViewPart {
return VexPlugin.getDefault().getConfigurationRegistry();
}
if (element instanceof Style) {
- return VexPlugin.getDefault().getConfigurationRegistry().getDocumentType(((Style) element).getDocumentTypes().iterator().next());
+ return VexPlugin.getDefault().getConfigurationRegistry().getDocumentType(((Style) element).getDocumentTypes().iterator().next(), null);
}
return null;
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypeFactory.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypeFactory.java
index bf7a2ffc..4cbed14c 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypeFactory.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypeFactory.java
@@ -27,9 +27,11 @@ public class DoctypeFactory implements IConfigItemFactory {
private static final String[] EXTS = new String[] { "dtd" }; //$NON-NLS-1$
private static final String ELT_DOCTYPE = "doctype"; //$NON-NLS-1$
+ private static final String ELT_SCHEMA = "schema"; //$NON-NLS-1$
private static final String ATTR_OUTLINE_PROVIDER = "outlineProvider"; //$NON-NLS-1$
private static final String ATTR_SYSTEM_ID = "systemId"; //$NON-NLS-1$
private static final String ATTR_PUBLIC_ID = "publicId"; //$NON-NLS-1$
+ private static final String ATTR_NAMESPACE_NAME = "namespaceName"; //$NON-NLS-1$
private static final String ELT_ROOT_ELEMENT = "rootElement"; //$NON-NLS-1$
private static final String ATTR_NAME = "name"; //$NON-NLS-1$
@@ -54,13 +56,23 @@ public class DoctypeFactory implements IConfigItemFactory {
if (configElements.length < 1) {
return null;
}
- final IConfigElement configElement = configElements[0];
- final String publicId = configElement.getAttribute(ATTR_PUBLIC_ID);
- final String systemId = configElement.getAttribute(ATTR_SYSTEM_ID);
final DocumentType doctype = new DocumentType(config);
- doctype.setPublicId(publicId);
- doctype.setSystemId(systemId);
- doctype.setResourceUri(newUri(config.resolve(publicId, systemId)));
+ final IConfigElement configElement = configElements[0];
+ if (configElement.getName() == null) {
+ System.out.println("configElement:" + configElement.getName());
+ }
+ if (configElement.getName().equals(ELT_DOCTYPE)) {
+ final String publicId = configElement.getAttribute(ATTR_PUBLIC_ID);
+ final String systemId = configElement.getAttribute(ATTR_SYSTEM_ID);
+ doctype.setPublicId(publicId);
+ doctype.setSystemId(systemId);
+ doctype.setResourceUri(newUri(config.resolve(publicId, systemId)));
+ } else {
+ final String namespaceName = configElement.getAttribute(ATTR_NAMESPACE_NAME);
+ doctype.setNamespaceName(namespaceName);
+ doctype.setResourceUri(newUri(config.resolve(null, namespaceName)));
+ }
+
doctype.setOutlineProvider(configElement.getAttribute(ATTR_OUTLINE_PROVIDER));
final IConfigElement[] rootElementRefs = configElement.getChildren();
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DocumentType.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DocumentType.java
index 9ec9bda4..ec7df87e 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DocumentType.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DocumentType.java
@@ -48,6 +48,30 @@ public class DocumentType extends ConfigItem {
return systemId;
}
+ /**
+ * Returns the namespace name of the document type.
+ */
+ public String getNamespaceName() {
+ return namespaceName;
+ }
+
+ /**
+ * Return the main type identifier of this document type.
+ */
+ public String getMainId() {
+ if (!isBlank(publicId)) {
+ return publicId;
+ }
+ if (!isBlank(namespaceName)) {
+ return namespaceName;
+ }
+ if (!isBlank(systemId)) {
+ return systemId;
+ }
+
+ return "";
+ }
+
@Override
public String getExtensionPointId() {
return EXTENSION_POINT;
@@ -83,13 +107,24 @@ public class DocumentType extends ConfigItem {
this.systemId = systemId;
}
+ /**
+ * Sets the namespace name of the document type. This is used when creating new documents but ignored otherwise.
+ *
+ * @param namespaceName
+ * new namespace name for the document type.
+ */
+ public void setNamespaceName(final String namespaceName) {
+ this.namespaceName = namespaceName;
+ }
+
public IValidator getValidator() {
return (IValidator) getConfig().getParsedResource(getResourceUri());
}
@Override
public boolean isValid() {
- return super.isValid() && !isBlank(publicId) && !isBlank(systemId) && getValidator() != null;
+ final boolean doctypeValid = !isBlank(publicId) && !isBlank(systemId) || !isBlank(namespaceName);
+ return super.isValid() && doctypeValid && getValidator() != null;
}
@Override
@@ -121,6 +156,7 @@ public class DocumentType extends ConfigItem {
private String publicId;
private String systemId;
+ private String namespaceName;
private String outlineProvider;
private String[] rootElements = EMPTY_STRING_ARRAY;
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DomConfigurationElement.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DomConfigurationElement.java
index 64eb8252..089cc0ce 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DomConfigurationElement.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DomConfigurationElement.java
@@ -63,7 +63,7 @@ public class DomConfigurationElement implements IConfigElement {
}
public String getName() {
- return element.getLocalName();
+ return element.getTagName();
}
public String getValue() {
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
index 9000db46..4d0be088 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
@@ -195,7 +195,7 @@ public class StylePropertyPage extends PropertyPage {
Arrays.sort(documentTypes);
for (final DocumentType documentType : documentTypes) {
if (selectedDoctypes.contains(documentType.getName())) {
- style.addDocumentType(documentType.getPublicId());
+ style.addDocumentType(documentType.getSimpleId());
}
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/DocumentTypeSelectionPage.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/DocumentTypeSelectionPage.java
index 6e6176af..a53f6fd6 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/DocumentTypeSelectionPage.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/DocumentTypeSelectionPage.java
@@ -89,7 +89,7 @@ public class DocumentTypeSelectionPage extends WizardPage {
final String[] typeNames = new String[doctypes.length];
for (int i = 0; i < doctypes.length; i++) {
typeNames[i] = doctypes[i].getName();
- if (doctypes[i].getPublicId().equals(publicId)) {
+ if (doctypes[i].getMainId().equals(publicId)) {
initSelection = i;
}
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
index 648b3913..3079730f 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexDocumentContentModel.java
@@ -35,18 +35,29 @@ public class VexDocumentContentModel extends DocumentContentModel {
this.shell = shell;
}
+ /**
+ * This constructor is only menat to be used for unit testing.
+ */
+ public VexDocumentContentModel() {
+ shell = null;
+ }
+
@Override
public void initialize(final String baseUri, final String publicId, final String systemId, final IElement rootElement) {
super.initialize(baseUri, publicId, systemId, rootElement);
final String mainDocumentTypeIdentifier = getMainDocumentTypeIdentifier();
documentType = getRegisteredDocumentType();
- if (documentType == null) {
+ if (documentType == null && shell != null) {
documentType = queryUserForDocumentType();
if (documentType == null) {
throw new NoRegisteredDoctypeException(mainDocumentTypeIdentifier, false);
}
// Reinitialize after the user selected a doctype
- super.initialize(baseUri, documentType.getPublicId(), documentType.getSystemId(), rootElement);
+ if (documentType.getNamespaceName() != null) {
+ setSchemaId(baseUri, documentType.getNamespaceName());
+ } else {
+ super.initialize(baseUri, documentType.getPublicId(), documentType.getSystemId(), null);
+ }
}
// TODO verify documentType URL???
@@ -55,15 +66,21 @@ public class VexDocumentContentModel extends DocumentContentModel {
// final String message = MessageFormat.format(Messages.getString("VexEditor.noUrlForDoctype"), mainDocumentTypeIdentifier);
// throw new RuntimeException(message);
// }
-
- style = VexPlugin.getDefault().getPreferences().getPreferredStyle(documentType.getPublicId());
+ style = VexPlugin.getDefault().getPreferences().getPreferredStyle(getDocumentType());
if (style == null) {
throw new NoStyleForDoctypeException();
}
}
private DocumentType getRegisteredDocumentType() {
- return VexPlugin.getDefault().getConfigurationRegistry().getDocumentType(getMainDocumentTypeIdentifier());
+ if (getMainDocumentTypeIdentifier() == null) {
+ return null;
+ }
+ final DocumentType doctype = VexPlugin.getDefault().getConfigurationRegistry().getDocumentType(getMainDocumentTypeIdentifier(), getSystemId());
+ if (doctype != null) {
+ return doctype;
+ }
+ return null;
}
private DocumentType queryUserForDocumentType() {
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
index 27464e83..081578bd 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
@@ -505,16 +505,6 @@ public class VexEditor extends EditorPart {
}
/**
- * Return a reasonable style for the given doctype.
- *
- * @param publicId
- * Public ID for which to return the style.
- */
- public Style getPreferredStyle(final String publicId) {
- return configurationRegistry.getStyle(publicId, preferences.getPreferredStyleId(publicId));
- }
-
- /**
* Returns the DocumentType associated with this editor.
*/
public DocumentType getDocumentType() {
@@ -864,7 +854,7 @@ public class VexEditor extends EditorPart {
this.style = style;
if (vexWidget != null) {
vexWidget.setStyleSheet(style.getStyleSheet());
- preferences.setPreferredStyleId(document.getPublicID(), style.getUniqueId());
+ preferences.setPreferredStyleId(doctype, style.getUniqueId());
}
vexEditorListeners.fireEvent("styleChanged", new VexEditorEvent(this)); //$NON-NLS-1$
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/StyleMenu.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/StyleMenu.java
index ffe13fcc..098c2f6e 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/StyleMenu.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/handlers/StyleMenu.java
@@ -20,6 +20,7 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.vex.ui.internal.VexPlugin;
+import org.eclipse.vex.ui.internal.config.DocumentType;
import org.eclipse.vex.ui.internal.config.Style;
import org.eclipse.vex.ui.internal.editor.VexEditor;
@@ -37,8 +38,8 @@ public class StyleMenu extends ContributionItem {
return;
}
- final String publicId = editor.getDocumentType().getPublicId();
- for (final Style style : VexPlugin.getDefault().getConfigurationRegistry().getStyles(publicId)) {
+ final DocumentType doctype = editor.getDocumentType();
+ for (final Style style : VexPlugin.getDefault().getConfigurationRegistry().getStyles(doctype)) {
final MenuItem menuItem = new MenuItem(menu, SWT.RADIO, index);
menuItem.setText(style.getName());
menuItem.setSelection(style == editor.getStyle());
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
index 5b8eea86..2c9fc146 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/wizards/NewDocumentWizard.java
@@ -74,7 +74,7 @@ public class NewDocumentWizard extends BasicNewResourceWizard {
try {
final IDocument doc = createDocument(typePage.getDocumentType(), typePage.getRootElementName());
- final Style style = VexPlugin.getDefault().getPreferences().getPreferredStyle(typePage.getDocumentType().getPublicId());
+ final Style style = VexPlugin.getDefault().getPreferences().getPreferredStyle(typePage.getDocumentType());
if (style == null) {
MessageDialog.openError(getShell(), Messages.getString("NewDocumentWizard.noStyles.title"), Messages.getString("NewDocumentWizard.noStyles.message")); //$NON-NLS-1$ //$NON-NLS-2$
return false;
@@ -136,7 +136,7 @@ public class NewDocumentWizard extends BasicNewResourceWizard {
}
private static IDocument createDocumentWithSchema(final DocumentType documentType, final String rootElementName) {
- final String defaultNamespaceUri = documentType.getPublicId();
+ final String defaultNamespaceUri = documentType.getNamespaceName();
final Document document = new Document(new QualifiedName(defaultNamespaceUri, rootElementName));
final IElement root = document.getRootElement();

Back to the top