本文整理了Java中org.apache.jena.rdf.model.impl.Util.substituteEntitiesInElementContent()
方法的一些代码示例,展示了Util.substituteEntitiesInElementContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.substituteEntitiesInElementContent()
方法的具体详情如下:
包路径:org.apache.jena.rdf.model.impl.Util
类名称:Util
方法名:substituteEntitiesInElementContent
[英]Answer s
modified to replace <, >, and & by their corresponding entity references.
Implementation note: as a (possibly misguided) performance hack, the obvious cascade of replaceAll calls is replaced by an explicit loop that looks for all three special characters at once.
[中]答案s
修改为替换<、>、和&的相应实体引用。
实现说明:作为一种(可能被误导的)性能攻击,replaceAll调用的明显级联被一个显式循环所取代,该循环同时查找所有三个特殊字符。
代码示例来源:origin: apache/jena
public static String substituteStandardEntities( String s )
{
if (standardEntities.matcher( s ).find())
{
return substituteEntitiesInElementContent( s )
.replaceAll( "'", "'" )
.replaceAll( "\t","	" )
.replaceAll( "\n", "
" )
.replaceAll( "\r", "
" )
.replaceAll( "\"", """ )
;
}
else
return s;
}
代码示例来源:origin: apache/jena
static void writeText(IndentedWriter out, String string) {
string = Util.substituteEntitiesInElementContent(string) ;
out.print(string) ;
}
代码示例来源:origin: org.apache.jena/jena-core
public static String substituteStandardEntities( String s )
{
if (standardEntities.matcher( s ).find())
{
return substituteEntitiesInElementContent( s )
.replaceAll( "'", "'" )
.replaceAll( "\t","	" )
.replaceAll( "\n", "
" )
.replaceAll( "\r", "
" )
.replaceAll( "\"", """ )
;
}
else
return s;
}
代码示例来源:origin: org.apache.jena/jena-core
private void wValueString(Literal lt) {
String val = lt.getString();
print(Util.substituteEntitiesInElementContent(val));
}
代码示例来源:origin: apache/jena
private void wValueString(Literal lt) {
String val = lt.getString();
print(Util.substituteEntitiesInElementContent(val));
}
代码示例来源:origin: apache/jena
protected void writeLiteral( Literal l, PrintWriter writer ) {
String lang = l.getLanguage();
String form = l.getLexicalForm();
if (Util.isLangString(l)) {
writer.print(" xml:lang=" + attributeQuoted( lang ));
} else if (l.isWellFormedXML() && !blockLiterals) {
// RDF XML Literals inline.
writer.print(" " + rdfAt("parseType") + "=" + attributeQuoted( "Literal" )+">");
writer.print( form );
return ;
} else {
// Datatype (if not xsd:string and RDF 1.1)
String dt = l.getDatatypeURI();
if ( ! Util.isSimpleString(l) )
writer.print( " " + rdfAt( "datatype" ) + "=" + substitutedAttribute( dt ) );
}
// Content.
writer.print(">");
writer.print( Util.substituteEntitiesInElementContent( form ) );
}
代码示例来源:origin: org.apache.jena/jena-core
protected void writeLiteral( Literal l, PrintWriter writer ) {
String lang = l.getLanguage();
String form = l.getLexicalForm();
if (Util.isLangString(l)) {
writer.print(" xml:lang=" + attributeQuoted( lang ));
} else if (l.isWellFormedXML() && !blockLiterals) {
// RDF XML Literals inline.
writer.print(" " + rdfAt("parseType") + "=" + attributeQuoted( "Literal" )+">");
writer.print( form );
return ;
} else {
// Datatype (if not xsd:string and RDF 1.1)
String dt = l.getDatatypeURI();
if ( ! Util.isSimpleString(l) )
writer.print( " " + rdfAt( "datatype" ) + "=" + substitutedAttribute( dt ) );
}
// Content.
writer.print(">");
writer.print( Util.substituteEntitiesInElementContent( form ) );
}
代码示例来源:origin: apache/jena
public void testX()
assertEquals( "", Util.substituteEntitiesInElementContent( "" ) );
assertEquals( "abc", Util.substituteEntitiesInElementContent( "abc" ) );
assertEquals( "a<b", Util.substituteEntitiesInElementContent( "a<b" ) );
assertEquals( "a>b", Util.substituteEntitiesInElementContent( "a>b" ) );
assertEquals( "a&b", Util.substituteEntitiesInElementContent( "a&b" ) );
assertEquals( "a;b", Util.substituteEntitiesInElementContent( "a;b" ) );
assertEquals( "a b", Util.substituteEntitiesInElementContent( "a b" ) );
assertEquals( "a\nb", Util.substituteEntitiesInElementContent( "a\nb" ) );
assertEquals( "a'b", Util.substituteEntitiesInElementContent( "a'b" ) );
assertEquals( "a<b<c", Util.substituteEntitiesInElementContent( "a<b<c" ) );
assertEquals( "a<b>c", Util.substituteEntitiesInElementContent( "a<b>c" ) );
assertEquals( "a<b&c", Util.substituteEntitiesInElementContent( "a<b&c" ) );
assertEquals( "a&b&c", Util.substituteEntitiesInElementContent( "a&b&c" ) );
assertEquals( "a&b>c", Util.substituteEntitiesInElementContent( "a&b>c" ) );
assertEquals( "a&b<c", Util.substituteEntitiesInElementContent( "a&b<c" ) );
assertEquals( "
", Util.substituteEntitiesInElementContent( "\r" ) );
assertEquals( "\n", Util.substituteEntitiesInElementContent( "\n" ) );
代码示例来源:origin: org.apache.jena/jena-core
public void testX()
assertEquals( "", Util.substituteEntitiesInElementContent( "" ) );
assertEquals( "abc", Util.substituteEntitiesInElementContent( "abc" ) );
assertEquals( "a<b", Util.substituteEntitiesInElementContent( "a<b" ) );
assertEquals( "a>b", Util.substituteEntitiesInElementContent( "a>b" ) );
assertEquals( "a&b", Util.substituteEntitiesInElementContent( "a&b" ) );
assertEquals( "a;b", Util.substituteEntitiesInElementContent( "a;b" ) );
assertEquals( "a b", Util.substituteEntitiesInElementContent( "a b" ) );
assertEquals( "a\nb", Util.substituteEntitiesInElementContent( "a\nb" ) );
assertEquals( "a'b", Util.substituteEntitiesInElementContent( "a'b" ) );
assertEquals( "a<b<c", Util.substituteEntitiesInElementContent( "a<b<c" ) );
assertEquals( "a<b>c", Util.substituteEntitiesInElementContent( "a<b>c" ) );
assertEquals( "a<b&c", Util.substituteEntitiesInElementContent( "a<b&c" ) );
assertEquals( "a&b&c", Util.substituteEntitiesInElementContent( "a&b&c" ) );
assertEquals( "a&b>c", Util.substituteEntitiesInElementContent( "a&b>c" ) );
assertEquals( "a&b<c", Util.substituteEntitiesInElementContent( "a&b<c" ) );
assertEquals( "
", Util.substituteEntitiesInElementContent( "\r" ) );
assertEquals( "\n", Util.substituteEntitiesInElementContent( "\n" ) );
代码示例来源:origin: org.apache.jena/jena-core
private boolean wPropertyEltDatatype(WType wt, Property prop, Statement s,
RDFNode r) {
if (! (r instanceof Literal) )
return false ;
Literal lit = ((Literal) r) ;
if ( Util.isSimpleString(lit) )
return false;
if ( Util.isLangString(lit) )
return false;
// print out with "datatype="
done(s);
tab();
print("<");
wt.wTypeStart(prop);
wIdAttrReified(s);
maybeNewline();
wDatatype(((Literal) r).getDatatypeURI());
maybeNewline();
print(">");
print(Util.substituteEntitiesInElementContent(((Literal) r)
.getLexicalForm()));
print("</");
wt.wTypeEnd(prop);
print(">");
return true;
}
代码示例来源:origin: apache/jena
private boolean wPropertyEltDatatype(WType wt, Property prop, Statement s,
RDFNode r) {
if (! (r instanceof Literal) )
return false ;
Literal lit = ((Literal) r) ;
if ( Util.isSimpleString(lit) )
return false;
if ( Util.isLangString(lit) )
return false;
// print out with "datatype="
done(s);
tab();
print("<");
wt.wTypeStart(prop);
wIdAttrReified(s);
maybeNewline();
wDatatype(((Literal) r).getDatatypeURI());
maybeNewline();
print(">");
print(Util.substituteEntitiesInElementContent(((Literal) r)
.getLexicalForm()));
print("</");
wt.wTypeEnd(prop);
print(">");
return true;
}
内容来源于网络,如有侵权,请联系作者删除!