Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2015-09-13 06:01:32 -0400
committerCarsten Hiesserich2015-09-17 13:49:13 -0400
commit3caa5c6414f986afbf618eee0c0ea6d5f6163c4c (patch)
treeafd5b045dd3401d185ff1e4028904c2ad9a81a08
parent9646378a712f1a93a66f8d6f861c7864b15451b7 (diff)
downloadorg.eclipse.mylyn.docs.vex-3caa5c6414f986afbf618eee0c0ea6d5f6163c4c.tar.gz
org.eclipse.mylyn.docs.vex-3caa5c6414f986afbf618eee0c0ea6d5f6163c4c.tar.xz
org.eclipse.mylyn.docs.vex-3caa5c6414f986afbf618eee0c0ea6d5f6163c4c.zip
add URI attribute to plugin doctype definition
The build-in document types use catalog contributions to map public or system id's to the dtd file. In plugin projects, the user defined document types had to use the file name as system id to be resolved. This commit adds an additional 'uri' attribute to the plugin config to config the file name independently. Change-Id: Ib26e3b93607a2a4d54dcb3b2ae146f8d1e8db2d7 Signed-off-by: Carsten Hiesserich <carsten.hie@gmail.com>
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginDoctypeConfigTest.java143
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java16
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypeFactory.java11
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypePropertyPage.java12
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java1
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/messages.properties4
6 files changed, 181 insertions, 6 deletions
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginDoctypeConfigTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginDoctypeConfigTest.java
new file mode 100644
index 00000000..230dd2a8
--- /dev/null
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginDoctypeConfigTest.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.vex.ui.internal.config.ConfigLoaderJob;
+import org.eclipse.vex.ui.internal.config.ConfigurationRegistry;
+import org.eclipse.vex.ui.internal.config.ConfigurationRegistryImpl;
+import org.eclipse.vex.ui.internal.config.DoctypePropertyPage;
+import org.eclipse.vex.ui.internal.config.DocumentType;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Tests for the doctype definition in a Vex Plugin Project
+ *
+ */
+public class PluginDoctypeConfigTest {
+ private IProject project;
+ private ConfigurationRegistry configurationRegistry;
+
+ private static final String SIMPLE_DTD = "<!ELEMENT el1 ANY><!ELEMENT el2 ANY>";
+
+ @After
+ public void dispose() {
+ if (project != null) {
+ try {
+ project.delete(true, null);
+ } catch (final CoreException e) {
+ }
+ }
+ project = null;
+
+ if (configurationRegistry != null) {
+ configurationRegistry.dispose();
+ }
+ configurationRegistry = null;
+ }
+
+ /**
+ * Make sure the property page is created without errors.
+ */
+ @Test
+ public void testDtdPropertyPage() throws CoreException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ project = PluginProjectTest.createVexPluginProject("DtdPropertyPageTest");
+ final InputStream is = new ByteArrayInputStream(SIMPLE_DTD.getBytes(StandardCharsets.UTF_8));
+ project.getFile(PluginProjectTest.DTD_FILE_NAME).setContents(is, true, false, null);
+
+ final Display display = Display.getCurrent();
+ final Shell shell = new Shell(display);
+ final DoctypePropertyPage page = new DoctypePropertyPage();
+
+ final IFile dtdFile = project.getFile(PluginProjectTest.DTD_FILE_NAME);
+ page.setElement(dtdFile);
+ page.createControl(shell);
+
+ // Make sure the table contains the style declared in the plugin project
+ final Field f = page.getClass().getDeclaredField("rootElementsTable");
+ f.setAccessible(true);
+ final Table table = (Table) f.get(page);
+ assertEquals("Displayed root elements", 2, table.getItems().length);
+
+ page.dispose();
+ }
+
+ @Test
+ public void testAddDoctype() throws Exception {
+ project = PluginProjectTest.createVexPluginProject("DoctypePropertyPageTest");
+
+ final Display display = Display.getCurrent();
+ final Shell shell = new Shell(display);
+ final DoctypePropertyPage page = new DoctypePropertyPage();
+
+ // Create a new .dtd file and open the property page
+ final IFile file = project.getFile("test_new.dtd");
+ final InputStream is = new ByteArrayInputStream(SIMPLE_DTD.getBytes(StandardCharsets.UTF_8));
+ file.create(is, true, null);
+ page.setElement(file);
+ page.createControl(shell);
+
+ // Select a root element
+ Field f = page.getClass().getDeclaredField("rootElementsTable");
+ f.setAccessible(true);
+ final Table table = (Table) f.get(page);
+ for (final TableItem item : table.getItems()) {
+ if (item.getText().equals("el2")) {
+ item.setChecked(true);
+ }
+ }
+
+ // Set the styles's name
+ f = page.getClass().getDeclaredField("nameText");
+ f.setAccessible(true);
+ final Text nameText = (Text) f.get(page);
+ nameText.setText("dtd test name");
+
+ // Set a public id
+ f = page.getClass().getDeclaredField("publicIdText");
+ f.setAccessible(true);
+ final Text publicIdText = (Text) f.get(page);
+ publicIdText.setText("test public id");
+
+ // Write the changed configuration
+ page.performOk();
+ page.dispose();
+
+ // Reload the project
+ project.close(null);
+ project.open(null);
+
+ //
+ configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
+ configurationRegistry.loadConfigurations();
+
+ final DocumentType doctype = configurationRegistry.getDocumentType("test public id", null);
+ assertNotNull("New style should be present", doctype);
+ assertEquals("test_new.dtd", doctype.getResourceUri().toString());
+ assertEquals("test_new.dtd", doctype.getSystemId()); // The system id should match the filename by default
+ }
+}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java
index 024a6037..b1dc228a 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 John Krasnay and others.
+ * Copyright (c) 2004, 2015 John Krasnay 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
@@ -203,7 +203,7 @@ public abstract class ConfigSource {
* URI of the resource, relative to the base URL of this configuration.
*/
public Object getParsedResource(final URI uri) {
- return parsedResources.get(uri);
+ return parsedResources.get(resolveRelativeURI(uri));
}
/**
@@ -245,7 +245,7 @@ public abstract class ConfigSource {
public void parseResources(final IBuildProblemHandler problemHandler) {
parsedResources.clear();
for (final ConfigItem item : items) {
- final URI uri = item.getResourceUri();
+ final URI uri = resolveRelativeURI(item.getResourceUri());
if (uri == null || parsedResources.containsKey(uri)) {
continue;
}
@@ -267,4 +267,14 @@ public abstract class ConfigSource {
return uriResolver.resolve(getBaseUrl().toString(), publicId, systemId);
}
+ private final URI resolveRelativeURI(final URI relUri) {
+ URI uri = null;
+ try {
+ // Make the relative resource URI absolute
+ uri = getBaseUrl().toURI().resolve(relUri);
+ } catch (final URISyntaxException e) {
+ e.printStackTrace();
+ }
+ return uri;
+ }
} \ No newline at end of file
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 93862d6c..48199026 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
@@ -31,6 +31,7 @@ public class DoctypeFactory implements IConfigItemFactory {
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 ATTR_URI = "uri"; //$NON-NLS-1$
private static final String ELT_ROOT_ELEMENT = "rootElement"; //$NON-NLS-1$
private static final String ATTR_NAME = "name"; //$NON-NLS-1$
@@ -39,6 +40,7 @@ public class DoctypeFactory implements IConfigItemFactory {
public IConfigElement[] createConfigurationElements(final ConfigItem item) {
final DocumentType doctype = (DocumentType) item;
final ConfigurationElement doctypeElement = new ConfigurationElement(ELT_DOCTYPE);
+ doctypeElement.setAttribute(ATTR_URI, doctype.getResourceUri().toString());
doctypeElement.setAttribute(ATTR_PUBLIC_ID, doctype.getPublicId());
doctypeElement.setAttribute(ATTR_SYSTEM_ID, doctype.getSystemId());
doctypeElement.setAttribute(ATTR_OUTLINE_PROVIDER, doctype.getOutlineProvider());
@@ -67,7 +69,14 @@ public class DoctypeFactory implements IConfigItemFactory {
final String systemId = configElement.getAttribute(ATTR_SYSTEM_ID);
doctype.setPublicId(publicId);
doctype.setSystemId(systemId);
- doctype.setResourceUri(newUri(config.resolve(publicId, systemId)));
+ final String resourceUri = configElement.getAttribute(ATTR_URI);
+ if (resourceUri != null && !resourceUri.trim().isEmpty()) {
+ // Use the URI given in the Plugin configuration
+ doctype.setResourceUri(newUri(resourceUri));
+ } else {
+ // Try to resolve the URI
+ doctype.setResourceUri(newUri(config.resolve(publicId, systemId)));
+ }
} else {
final String namespaceName = configElement.getAttribute(ATTR_NAMESPACE_NAME);
doctype.setNamespaceName(namespaceName);
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypePropertyPage.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypePropertyPage.java
index 05cc9e35..68652195 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypePropertyPage.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/DoctypePropertyPage.java
@@ -11,6 +11,8 @@
*******************************************************************************/
package org.eclipse.vex.ui.internal.config;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -113,7 +115,15 @@ public class DoctypePropertyPage extends PropertyPage {
doctype = (DocumentType) pluginProject.getItemForResource(file);
if (doctype == null) {
doctype = new DocumentType(pluginProject);
- doctype.setResourceUri(file.getLocationURI());
+ URI uri;
+ try {
+ uri = new URI(file.getProjectRelativePath().toString());
+ doctype.setResourceUri(uri);
+ doctype.setSystemId(uri.toString());
+ } catch (final URISyntaxException e) {
+ // This should never happen
+ VexPlugin.getDefault().log(IStatus.ERROR, Messages.getString("DoctypePropertyPage.uriError"), e);
+ }
pluginProject.addItem(doctype);
}
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 6d4637c3..40efc8e3 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
@@ -130,6 +130,7 @@ public class StylePropertyPage extends PropertyPage {
pluginProject.addItem(style);
} catch (final URISyntaxException e) {
// This should never happen
+ VexPlugin.getDefault().log(IStatus.ERROR, Messages.getString("StylePropertyPage.uriError"), e);
}
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/messages.properties b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/messages.properties
index 72f20043..39f378a4 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/messages.properties
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/messages.properties
@@ -1,5 +1,5 @@
# *******************************************************************************
-# * Copyright (c) 2004, 2008 John Krasnay and others.
+# * Copyright (c) 2004, 2015 John Krasnay 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
@@ -31,6 +31,7 @@ DoctypePropertyPage.name=Name:
DoctypePropertyPage.publicId=Public ID:
DoctypePropertyPage.systemId=System ID:
DoctypePropertyPage.rootElements=Root Elements:
+DoctypePropertyPage.uriError=Unexpected Exception when creating a new document type.
NewPluginProjectWizard.title=New Visual XML Plug-in Project
NewPluginProjectWizard.createError=Error creating plug-in project
PluginProject.malformedUrl=Project base URL is malformed.
@@ -43,3 +44,4 @@ PluginProjectBuilder.cantSaveConfig=Unable to save VexConfiguration for project
PluginProject.loadingError=Error loading {0}.
PluginProject.buildError=Error building project {0}.
StylePropertyPage.writeError=Error writing {0}.
+StylePropertyPage.uriError=Unexpected Exception when creating a new style.

Back to the top