Revision: 20002
http://sourceforge.net/p/gate/code/20002
Author: markagreenwood
Date: 2017-01-27 12:30:10 +0000 (Fri, 27 Jan 2017)
Log Message:
-----------
you can now create an instance using an absolute path even if you supply a
valid context
Modified Paths:
--------------
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
Modified:
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
2017-01-27 09:25:49 UTC (rev 20001)
+++
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
2017-01-27 12:30:10 UTC (rev 20002)
@@ -53,10 +53,10 @@
public ResourceReference(URL context, String path)
throws URISyntaxException, MalformedURLException {
- if(context != null) {
+ uri = new URI(path);
+
+ if(context != null && !uri.isAbsolute()) {
uri = (new URL(context, path)).toURI();
- } else {
- uri = new URI(path);
}
if(!uri.isAbsolute())
Modified:
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
2017-01-27 09:25:49 UTC (rev 20001)
+++
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
2017-01-27 12:30:10 UTC (rev 20002)
@@ -17,116 +17,140 @@
public class TestResourceReference extends TestCase {
- @Override
- public void setUp() throws Exception {
- // Initialise the GATE library and creole register
- Gate.init();
- }
+ private Plugin creolePlugin;
- public void testReadFromURL() throws Exception {
+ @Override
+ public void setUp() throws Exception {
+ // Initialise the GATE library and creole register
+ Gate.init();
- URL url =
getClass().getClassLoader().getResource("gate/resources/gate.ac.uk/creole/creole.xml");
- ResourceReference rr = new ResourceReference(url);
+ creolePlugin = new Plugin.Maven("group", "artifact", "version") {
- try (InputStream in = rr.openStream()) {
- String contents = IOUtils.toString(in);
+ @Override
+ public URL getBaseURL() {
+ try {
+ return new URL(TestDocument.getTestServerName() + "tests/");
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- assertEquals("Length of data read not as expected", 98,
contents.length());
- }
- }
+ @Override
+ public Document getCreoleXML() throws Exception, JDOMException {
+ Document doc = new Document();
+ doc.addContent(new Element("CREOLE-DIRECTORY"));
+ return doc;
+ }
+ };
+
+ Gate.getCreoleRegister().registerPlugin(creolePlugin);
+ }
- public void testReadFromURLPlugin() throws Exception {
- // find a URL for finding test files and add to the directory
set
- URL testURL = new URL(TestDocument.getTestServerName() +
"tests/");
- Plugin p = new Plugin.Directory(testURL);
- ResourceReference rr = new ResourceReference(p, "gate.xml");
+ public void testReadFromURL() throws Exception {
- try (InputStream in = rr.openStream()) {
- String contents = IOUtils.toString(in);
+ URL url = getClass().getClassLoader()
+ .getResource("gate/resources/gate.ac.uk/creole/creole.xml");
+ ResourceReference rr = new ResourceReference(url);
- assertEquals("Length of data read not as expected",
658, contents.length());
- }
- }
-
- public void testCreateFromURL() throws Exception {
- Resource resource = new AbstractResource() {
- ResourceReference rr = null;
-
- public ResourceReference getParam() {
- return rr;
- }
-
- @CreoleParameter
- public void setParam(ResourceReference rr) {
- this.rr = rr;
- }
- };
-
- URL url = new URL("http://gate.ac.uk");
- resource.setParameterValue("param", url);
-
- assertEquals("References do not match", url,
((ResourceReference)resource.getParameterValue("param")).toURL());
- }
-
- @SuppressWarnings("serial")
+ try (InputStream in = rr.openStream()) {
+ String contents = IOUtils.toString(in);
+
+ assertEquals("Length of data read not as expected", 98,
+ contents.length());
+ }
+ }
+
+ public void testReadFromURLPlugin() throws Exception {
+ // find a URL for finding test files and add to the directory set
+ URL testURL = new URL(TestDocument.getTestServerName() + "tests/");
+ Plugin p = new Plugin.Directory(testURL);
+ ResourceReference rr = new ResourceReference(p, "gate.xml");
+
+ try (InputStream in = rr.openStream()) {
+ String contents = IOUtils.toString(in);
+
+ assertEquals("Length of data read not as expected", 658,
+ contents.length());
+ }
+ }
+
+ public void testCreateFromURL() throws Exception {
+ Resource resource = new AbstractResource() {
+ ResourceReference rr = null;
+
+ public ResourceReference getParam() {
+ return rr;
+ }
+
+ @CreoleParameter
+ public void setParam(ResourceReference rr) {
+ this.rr = rr;
+ }
+ };
+
+ URL url = new URL("http://gate.ac.uk");
+ resource.setParameterValue("param", url);
+
+ assertEquals("References do not match", url,
+ ((ResourceReference)resource.getParameterValue("param")).toURL());
+ }
+
+ @SuppressWarnings("serial")
public void testRelativeReferences() throws Exception {
- URL testURL = new URL(TestDocument.getTestServerName() +
"tests/");
- URL creoleURL = new URL(TestDocument.getTestServerName() +
"tests/creole.xml");
-
- ResourceReference rr = new
ResourceReference(testURL,"./creole.xml");
- assertEquals("References do not match (1)", creoleURL,
rr.toURL());
-
- ResourceReference context = new ResourceReference(testURL);
- rr = new ResourceReference(context,"./creole.xml");
- assertEquals("References do not match (2)", creoleURL,
rr.toURL());
-
- Plugin plugin = new Plugin.Directory(testURL);
- context = new ResourceReference(plugin,"abc");
- rr = new ResourceReference(context,"./creole.xml");
- assertEquals("References do not match (3)", creoleURL,
rr.toURL());
-
- context = new ResourceReference(plugin,"html/");
- rr = new ResourceReference(context,"../creole.xml");
- assertEquals("References do not match (3)", creoleURL,
rr.toURL());
-
- URI creoleURI = new
URI("creole://group;artifact;version/creole.xml");
- plugin = new Plugin.Maven("group", "artifact", "version") {
-
- @Override
- public URL getBaseURL() {
- return testURL;
- }
-
- @Override
- public Document getCreoleXML() throws Exception,
JDOMException {
- Document doc = new Document();
- doc.addContent(new Element("CREOLE-DIRECTORY"));
- return doc;
- }
- };
-
- Gate.getCreoleRegister().registerPlugin(plugin);
- context = new ResourceReference(plugin,"folder/");
- rr = new ResourceReference(context,"../creole.xml");
- assertEquals("References do not match (4)", creoleURI,
rr.toURI());
- assertEquals("URLs do not match (4)", creoleURL, rr.toURL());
- }
-
- public void testCreateFromString() throws Exception {
- String path = "creole://group;artifact;version/creole.xml";
-
- ResourceReference rr = new ResourceReference((ResourceReference)null,
path);
- assertEquals("String representations don't match (1)",path,
rr.toString());
-
- rr = new ResourceReference((URL)null, path);
- assertEquals("String representations don't match (2)",path, rr.toString());
-
+ URL testURL = new URL(TestDocument.getTestServerName() + "tests/");
+ URL creoleURL =
+ new URL(TestDocument.getTestServerName() + "tests/creole.xml");
+
+ ResourceReference rr = new ResourceReference(testURL, "./creole.xml");
+ assertEquals("References do not match (1)", creoleURL, rr.toURL());
+
+ ResourceReference context = new ResourceReference(testURL);
+ rr = new ResourceReference(context, "./creole.xml");
+ assertEquals("References do not match (2)", creoleURL, rr.toURL());
+
+ Plugin plugin = new Plugin.Directory(testURL);
+ context = new ResourceReference(plugin, "abc");
+ rr = new ResourceReference(context, "./creole.xml");
+ assertEquals("References do not match (3)", creoleURL, rr.toURL());
+
+ context = new ResourceReference(plugin, "html/");
+ rr = new ResourceReference(context, "../creole.xml");
+ assertEquals("References do not match (3)", creoleURL, rr.toURL());
+
+ URI creoleURI = new URI("creole://group;artifact;version/creole.xml");
+
+ context = new ResourceReference(creolePlugin, "folder/");
+ rr = new ResourceReference(context, "../creole.xml");
+ assertEquals("References do not match (4)", creoleURI, rr.toURI());
+ assertEquals("URLs do not match (4)", creoleURL, rr.toURL());
+ }
+
+ public void testCreateFromString() throws Exception {
+ String path = "creole://group;artifact;version/test-file.xml";
+
+ ResourceReference rr = new ResourceReference((ResourceReference)null,
path);
+ assertEquals("String representations don't match (1)", path,
rr.toString());
+
+ rr = new ResourceReference((URL)null, path);
+ assertEquals("String representations don't match (2)", path,
rr.toString());
+
rr = new ResourceReference((URI)null, path);
- assertEquals("String representations don't match (3)",path, rr.toString());
-
+ assertEquals("String representations don't match (3)", path,
rr.toString());
+
rr = new ResourceReference((Plugin)null, path);
- assertEquals("String representations don't match (4)",path, rr.toString());
+ assertEquals("String representations don't match (4)", path,
rr.toString());
+
+ rr = new ResourceReference(
+ new ResourceReference(new URL("http://gate.ac.uk")), path);
+ assertEquals("String representations don't match (5)", path,
rr.toString());
+
+ rr = new ResourceReference(new URL("http://gate.ac.uk"), path);
+ assertEquals("String representations don't match (6)", path,
rr.toString());
+
+ rr = new ResourceReference(new URI("http://gate.ac.uk"), path);
+ assertEquals("String representations don't match (7)", path,
rr.toString());
-
- }
+ rr = new ResourceReference(creolePlugin, path);
+ assertEquals("String representations don't match (8)", path,
rr.toString());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs