📄 xmlhandler.java
字号:
boolean ignoring(int eCode) {
return options.getErrorMode(eCode) == EM_IGNORE;
}
public boolean isError(int eCode) {
return options.getErrorMode(eCode) == EM_ERROR;
}
protected AbsXMLContext initialContext(String base, String lang)
throws SAXParseException {
return initialContextWithBase(base).withLang(this,lang);
}
private boolean allowRelativeReferences = false;
private AbsXMLContext initialContextWithBase(String base) throws SAXParseException {
allowRelativeReferences = false;
if (base == null) {
warning(null,IGN_NO_BASE_URI_SPECIFIED,
"Base URI not specified for input file; local URI references will be in error.");
return new XMLBaselessContext(this,
ERR_RESOLVING_URI_AGAINST_NULL_BASE);
} else if (base.equals("")) {
allowRelativeReferences = true;
warning(null,IGN_NO_BASE_URI_SPECIFIED,
"Base URI specified as \"\"; local URI references will not be resolved.");
return new XMLBaselessContext(this,
WARN_RESOLVING_URI_AGAINST_EMPTY_BASE);
} else {
// if (base.toLowerCase().startsWith("file:")
// && base.length()>5
// && base.charAt(5) != '/'
// ) {
// System.err.print(base);
// try {
// base = new File(base.substring(5)).toURL().toString();
// if (base.length()<=6
// || base.charAt(6)!= '/')
// base = "file://"+base.substring(5);
// } catch (MalformedURLException e) {
// // ignore, just leave it alone.
// }
// System.err.println(" ==> "+base);
//
// }
return new XMLBaselessContext(this,
ERR_RESOLVING_AGAINST_RELATIVE_BASE).withBase(this,base);
}
}
/*
private XMLContext initialContextWithBasex(String base)
throws SAXParseException {
XMLContext rslt = new XMLContext(this, base);
RDFURIReference b = rslt.getURI();
if (base == null) {
warning(null,IGN_NO_BASE_URI_SPECIFIED,
"Base URI not specified for input file; local URI references will be in error.");
} else if (base.equals("")) {
warning(null,IGN_NO_BASE_URI_SPECIFIED,
"Base URI specified as \"\"; local URI references will not be resolved.");
} else {
checkBadURI(null,b);
// Warnings on bad base.
// if (b.isVeryBad()||b.isRelative()) {
// return
}
return rslt;
}
*/
private ARPOptions options = new ARPOptions();
private ARPHandlers handlers = new ARPHandlers();
StatementHandler getStatementHandler() {
return handlers.getStatementHandler();
}
public ARPHandlers getHandlers() {
return handlers;
}
public ARPOptions getOptions() {
return options;
}
public void setOptionsWith(ARPOptions newOpts) {
options = newOpts.copy();
}
public void setHandlersWith(ARPHandlers newHh) {
handlers = new ARPHandlers();
handlers.setErrorHandler(newHh.getErrorHandler());
handlers.setExtendedHandler(newHh.getExtendedHandler());
handlers.setNamespaceHandler(newHh.getNamespaceHandler());
handlers.setStatementHandler(newHh.getStatementHandler());
}
private Map nodeIdUserData;
public void initParse(String base, String lang) throws SAXParseException {
nodeIdUserData = new HashMap();
idsUsed =
ignoring(WARN_REDEFINITION_OF_ID)?
null:
new HashMap();
idsUsedCount = 0;
if (options.getEmbedding())
frame = new LookingForRDF(this, initialContext(base, lang));
else
frame = new StartStateRDForDescription(this, initialContext(base,
lang));
}
/**
* This method must be always be called after parsing, e.g. in a finally
* block.
*
*/
void afterParse() {
while (frame != null) {
frame.abort();
frame = frame.getParent();
}
// endRDF();
endBnodeScope();
idsUsed = null;
}
void endBnodeScope() {
if (handlers.getExtendedHandler() != nullScopeHandler) {
Iterator it = nodeIdUserData.keySet().iterator();
while (it.hasNext()) {
String nodeId = (String) it.next();
ARPResource bn = new ARPResource(this, nodeId);
handlers.getExtendedHandler().endBNodeScope(bn);
}
}
}
public Location location() {
return new Location(locator);
}
private IRIFactory factory = IRIFactory.jenaImplementation();
IRIFactory iriFactory() {
if (factory == null) {
// TODO locator stuff
// factory = new IRIFactory();
// factory.useSpecificationRDF(false);
/*
if (locator != null)
factory = new IRIFactory(locator);
else
factory = new IRIFactory(new Locator() {
public int getColumnNumber() {
return locator == null ? -1 : locator.getColumnNumber();
}
public int getLineNumber() {
return locator == null ? -1 : locator.getLineNumber();
}
public String getPublicId() {
return locator == null ? null : locator.getPublicId();
}
public String getSystemId() {
return locator == null ? null : locator.getSystemId();
}
});
*/
}
return factory;
}
private void checkNamespaceURI(String uri) throws SAXParseException {
((Frame) frame).checkEncoding(null,uri);
if (uri.length() != 0)
{
IRI u = iriFactory().create(uri);
// if (u.isVeryBad()) {
// warning(null,
// WARN_BAD_NAMESPACE_URI,
// "The namespace URI: <"
// + uri
// + "> is not well formed.");
// return;
//
// }
if (!u.isAbsolute()) {
warning(null,
WARN_RELATIVE_NAMESPACE_URI_DEPRECATED,
"The namespace URI: <"
+ uri
+ "> is relative. Such use has been deprecated by the W3C, and may result in RDF interoperability failures. Use an absolute namespace URI.");
}
try {
if (!u.toASCIIString().equals(u.toString()))
warning(null,
WARN_BAD_NAMESPACE_URI,
"Non-ascii characters in a namespace URI may not be completely portable: <"
+ u.toString()
+ ">. Resulting RDF URI references are legal.");
} catch (MalformedURLException e) {
warning(null,
WARN_BAD_NAMESPACE_URI,
"toAscii failed for namespace URI: <"
+ u.toString()
+ ">. " + e.getMessage());
}
if (uri.startsWith(rdfns) && !uri.equals(rdfns))
warning(null,WARN_BAD_RDF_NAMESPACE_URI, "Namespace URI ref <"
+ uri + "> may not be used in RDF/XML.");
if (uri.startsWith(xmlns) && !uri.equals(xmlns))
warning(null,WARN_BAD_XML_NAMESPACE_URI, "Namespace URI ref <"
+ uri + "> may not be used in RDF/XML.");
}
}
public boolean allowRelativeURIs() {
return allowRelativeReferences;
}
private IRI sameDocRef;
public IRI sameDocRef() {
if (sameDocRef==null){
sameDocRef = iriFactory().create("");
}
return sameDocRef;
}
private StatementHandler badStatementHandler = nullStatementHandler;
public void setBadStatementHandler(StatementHandler sh) {
badStatementHandler = sh;
}
final public static StatementHandler nullStatementHandler =
new StatementHandler() {
public void statement(AResource s, AResource p, AResource o) {
}
public void statement(AResource s, AResource p, ALiteral o) {
}
};
final public static ExtendedHandler nullScopeHandler = new ExtendedHandler() {
public void endBNodeScope(AResource bnode) {
}
public void startRDF() {
}
public void endRDF() {
}
public boolean discardNodesWithNodeID() {
return true;
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -