forked from Klortho/DtdAnalyzer
-
Notifications
You must be signed in to change notification settings - Fork 11
/
DtdModule.java
executable file
·86 lines (75 loc) · 2.05 KB
/
DtdModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* DtdModule.java
*/
package gov.ncbi.pmc.dtdanalyzer;
import java.util.*;
import org.xml.sax.Locator;
import java.net.*;
/**
* Holds information (the public and system identifier) of the main DTD module
*/
public class DtdModule {
private String publicId;
private String systemId;
private String relSysId;
private URI baseUri;
/**
* Constructor.
*/
public DtdModule( Locator locator ) {
publicId = locator.getPublicId();
systemId = locator.getSystemId();
int lastSlash = systemId.lastIndexOf("/");
relSysId = systemId.substring(lastSlash + 1);
String parentDir = systemId.substring(0, lastSlash);
try {
baseUri = new URI(parentDir);
}
catch (URISyntaxException e) {
// I don't think this should ever happen, so let's just report it and keep going.
System.err.println("ERROR trying to make a URI from dtd system id: " + e.getMessage());
}
}
/**
* Get the public ID
*/
public String getPublicId() {
return publicId;
}
/**
* Get the system ID
*/
public String getSystemId() {
return systemId;
}
/**
* Get the relative system ID of the DTD module itself. In other words, just the
* filename portion of it's URI.
*/
public String getRelSysId() {
return relSysId;
}
/**
* Get the base URI. This is the "directory" in which the DTD module resides.
*/
public URI getBaseUri() {
return baseUri;
}
/**
* Relativize some other URI to the baseUri here.
*/
public String relativize(String uri) {
if (baseUri == null) {
return uri;
}
else {
try {
return baseUri.relativize(new URI(uri)).toString();
}
catch (URISyntaxException e) {
// If there's any problem here, just return the original string
return uri;
}
}
}
}