Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/java/org/protege/xmlcatalog/CatalogUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public static URI getRedirect(URI original, XMLCatalog catalog) {
UriRedirectVisitor visitor = new UriRedirectVisitor(original);
for (Entry subEntry : catalog.getEntries()) {
subEntry.accept(visitor);
if (visitor.getRedirect() != null) {
break;
}
}
return visitor.getRedirect() == null ? null : visitor.getRedirect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,26 @@
import org.apache.log4j.Logger;
import org.protege.xmlcatalog.EntryVisitor;
import org.protege.xmlcatalog.XMLCatalog;
import org.protege.xmlcatalog.entry.DelegatePublicEntry;
import org.protege.xmlcatalog.entry.DelegateSystemEntry;
import org.protege.xmlcatalog.entry.DelegateUriEntry;
import org.protege.xmlcatalog.entry.Entry;
import org.protege.xmlcatalog.entry.GroupEntry;
import org.protege.xmlcatalog.entry.NextCatalogEntry;
import org.protege.xmlcatalog.entry.PublicEntry;
import org.protege.xmlcatalog.entry.RewriteSystemEntry;
import org.protege.xmlcatalog.entry.RewriteUriEntry;
import org.protege.xmlcatalog.entry.SystemEntry;
import org.protege.xmlcatalog.entry.UriEntry;
import org.protege.xmlcatalog.entry.*;

public class UriRedirectVisitor implements EntryVisitor {
private static Logger log = Logger.getLogger(UriRedirectVisitor.class);
private URI original;
private URI redirect;
private URI rewritedUri;
private int rewriteBestSize = 0;

public UriRedirectVisitor(URI original) {
this.original = original;
}

public URI getRedirect() {
return redirect;
return rewritedUri == null ? redirect : rewritedUri;
}

public void visit(GroupEntry entry) {
for (Entry subEntry : entry.getEntries()) {
subEntry.accept(this);
if (redirect != null) {
break;
}
}
}

Expand Down Expand Up @@ -68,10 +57,17 @@ public void visit(UriEntry entry) {

public void visit(RewriteUriEntry entry) {
try {
String originalString = original.toString();
if (originalString.startsWith(entry.getUriStartString())) {
String suffix = originalString.substring(entry.getUriStartString().length());
redirect = URI.create(entry.getRewritePrefix().toString() + suffix);
String redirectedUri = redirect == null ? null : redirect.toString();
if(redirectedUri == null){
redirectedUri = original.toString();
}
if (redirectedUri.startsWith(entry.getUriStartString()) && entry.getUriStartString().length() > rewriteBestSize) {
String suffix = redirectedUri.substring(entry.getUriStartString().length());
rewritedUri = URI.create(entry.getRewritePrefix().toString() + suffix);
if(!rewritedUri.isAbsolute()){
rewritedUri = AbstractUriEntry.resolveUriAgainstXmlBase(rewritedUri, entry.getXmlBaseContext());
}
rewriteBestSize = entry.getUriStartString().length();
}
}
catch (Throwable e) {
Expand Down Expand Up @@ -105,9 +101,6 @@ public void visit(NextCatalogEntry entry) {
private void visitCatalog(XMLCatalog catalog) {
for (Entry subEntry : catalog.getEntries()) {
subEntry.accept(this);
if (redirect != null) {
break;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/protege/xmlcatalog/ResolveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public void test05() throws MalformedURLException, IOException, TransformerExcep

public void test06() throws MalformedURLException, IOException, TransformerException {
readCatalog("src/test/resources/catalog06.xml");
URI u = URI.create("http://www.tigraworld.com/protege/pizza.owl");
// Predicting redirect is hard because it's system dependent. Windows adds a "C:".
checkBothAlgorithmsSame(u, true);
URI u = URI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl");
URI redirect = URI.create("file:/home/tredmond/Shared/ontologies/protege/pizza.owl");
assertTrue(CatalogUtilities.getRedirect(u, catalog).equals(redirect));
}

public void test07() throws TransformerException, MalformedURLException, IOException {
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/catalog06.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
prefer="public">

<uri id="PizzaID" name="http://www.co-ode.org/ontologies/pizza/pizza.owl" uri="http://www.tigraworld.com/protege/pizza.owl"/>
<rewriteURI uriStartString="http://www.tigraworld"
rewritePrefix="file:/shouldNotBeUsed/ontologies"/>
<rewriteURI uriStartString="http://www.tigraworld.com"
rewritePrefix="file:/home/tredmond/Shared/ontologies"/>
</catalog>