📄 ntriple.java
字号:
case 't' :
arp.getHandlers().setStatementHandler(getSH(false));
break;
case 'r' :
options.setEmbedding(false);
break;
case 'R' :
options.setEmbedding(true);
break;
case 'n' :
numbers = true;
break;
case 'E':
arp.getHandlers().setErrorHandler(new ErrorHandler(){
public void warning(SAXParseException exception) { /* ignore */ }
public void error(SAXParseException exception) { /* ignore */ }
public void fatalError(SAXParseException exception) { /* ignore */ }
});
arp.setBadStatementHandler(new SH(System.err));
break;
case 'b' :
xmlBase = nextArg;
break;
case 'e' :
setErrorMode(nextArg, EM_ERROR);
break;
case 'i' :
setErrorMode(nextArg, EM_IGNORE);
break;
case 'w' :
setErrorMode(nextArg, EM_WARNING);
break;
case 'f' :
for (int j = 0; j < 400; j++) {
if (options.setErrorMode(j, -1) == EM_ERROR)
options.setErrorMode(j, EM_FATAL);
}
break;
case 'u' :
options.setErrorMode(WARN_UNQUALIFIED_ATTRIBUTE, EM_IGNORE);
options.setErrorMode(WARN_UNQUALIFIED_RDF_ATTRIBUTE, EM_IGNORE);
break;
default :
usage();
}
}
return usedNext ? 1 : 0;
}
static private void setErrorMode(String numbers, int mode) {
int n[] = new int[3];
int j = 0;
numbers += ",";
for (int i = 0; i < numbers.length(); i++) {
char c = numbers.charAt(i);
switch (c) {
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
if (j == 3)
usage();
n[j++] = c - '0';
break;
case ' ' :
case ';' :
case ',' :
if (i == 0)
usage();
switch (j) {
case 0 :
break;
case 3 :
arp.getOptions().setErrorMode(
n[0] * 100 + n[1] * 10 + n[2],
mode);
j = 0;
break;
default :
usage();
}
break;
default :
usage();
}
}
}
static private void process(String surl) {
InputStream in;
URL url;
String baseURL;
try {
File ff = new File(surl);
in = new FileInputStream(ff);
url = ff.toURL();
baseURL = url.toExternalForm();
if (baseURL.startsWith("file:/")
&& !baseURL.startsWith("file://")) {
baseURL = "file://" + baseURL.substring(5);
}
} catch (Exception ignore) {
try {
url = new URL(surl);
in = url.openStream();
baseURL = url.toExternalForm();
} catch (Exception e) {
System.err.println("ARP: Failed to open: " + surl);
System.err.println(
" " + ParseException.formatMessage(ignore));
System.err.println(" " + ParseException.formatMessage(e));
return;
}
}
process(in, baseURL, surl);
}
static private void process(InputStream in, String xmlBasex, String surl) {
String xmlBasey = xmlBase == null ? xmlBasex : xmlBase;
try {
arp.load(in, xmlBasey);
} catch (IOException e) {
System.err.println(
"Error: " + surl + ": " + ParseException.formatMessage(e));
} catch (SAXParseException e) {
// already reported.
} catch (SAXException sax) {
System.err.println(
"Error: " + surl + ": " + ParseException.formatMessage(sax));
}
}
private static class TwoSH implements StatementHandler {
final StatementHandler a, b;
public void statement(AResource subj, AResource pred, AResource obj) {
a.statement(subj, pred, obj);
b.statement(subj, pred, obj);
}
public void statement(AResource subj, AResource pred, ALiteral lit) {
a.statement(subj, pred, lit);
b.statement(subj, pred, lit);
}
TwoSH(StatementHandler A, StatementHandler B) {
a = A;
b = B;
}
}
private static class NoSH implements StatementHandler {
// private int ix = 0;
// private void userData(AResource n){
// if (n.isAnonymous()) {
//// n.setUserData(new Integer(ix++));
// }
// }
public void statement(AResource subj, AResource pred, AResource obj) {
// userData(subj);
// userData(pred);
// userData(obj);
}
public void statement(AResource subj, AResource pred, ALiteral lit) {
// userData(subj);
// userData(pred);
}
}
private static class SH implements StatementHandler {
PrintStream out;
SH(PrintStream out){
this.out = out;
}
public void statement(AResource subj, AResource pred, AResource obj) {
lineNumber();
resource(subj);
resource(pred);
resource(obj);
line.append('.');
out.println(line);
line.setLength(0);
}
public void statement(AResource subj, AResource pred, ALiteral lit) {
// String lang = lit.getLang();
// String parseType = lit.getParseType();
lineNumber();
/*
if (parseType != null) {
System.out.print("# ");
if (parseType != null)
System.out.print("'" + parseType + "'");
System.out.println();
}
*/
resource(subj);
resource(pred);
literal(lit);
line.append('.');
out.println(line);
line.setLength(0);
}
}
static private void print(String s) {
line.append(s);
}
static private void resource(AResource r) {
if (r.isAnonymous()) {
print("_:j");
print(r.getAnonymousID());
print(" ");
} else {
print("<");
escapeURI(r.getURI());
print("> ");
}
}
static private void escape(String s) {
int lg = s.length();
for (int i = 0; i < lg; i++) {
char ch = s.charAt(i);
switch (ch) {
case '\\' :
print("\\\\");
break;
case '"' :
print("\\\"");
break;
case '\n' :
print("\\n");
break;
case '\r' :
print("\\r");
break;
case '\t' :
print("\\t");
break;
default :
if (ch >= 32 && ch <= 126)
line.append(ch);
else {
print("\\u");
String hexstr = Integer.toHexString(ch).toUpperCase();
int pad = 4 - hexstr.length();
for (; pad > 0; pad--)
print("0");
print(hexstr);
}
}
}
}
static private boolean okURIChars[] = new boolean[128];
static {
for (int i = 32; i < 127; i++)
okURIChars[i] = true;
okURIChars['<'] = false;
okURIChars['>'] = false;
okURIChars['\\'] = false;
}
static private void escapeURI(String s) {
int lg = s.length();
for (int i = 0; i < lg; i++) {
char ch = s.charAt(i);
if (ch < okURIChars.length && okURIChars[ch]) {
line.append(ch);
} else {
print("\\u");
String hexstr = Integer.toHexString(ch).toUpperCase();
int pad = 4 - hexstr.length();
for (; pad > 0; pad--)
print("0");
print(hexstr);
}
}
}
static private void literal(ALiteral l) {
//if (l.isWellFormedXML())
// System.out.print("xml");
line.append('"');
escape(l.toString());
line.append('"');
String lang = l.getLang();
if (lang != null && !lang.equals("")) {
line.append('@');
print(lang);
}
String dt = l.getDatatypeURI();
if (dt != null && !dt.equals("")) {
print("^^<");
escapeURI(dt);
line.append('>');
}
line.append(' ');
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -