org.apache.jena.rdf.model.impl.Util.substituteEntitiesInElementContent()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(167)

本文整理了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

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

  1. public static String substituteStandardEntities( String s )
  2. {
  3. if (standardEntities.matcher( s ).find())
  4. {
  5. return substituteEntitiesInElementContent( s )
  6. .replaceAll( "'", "&apos;" )
  7. .replaceAll( "\t","&#9;" )
  8. .replaceAll( "\n", "&#xA;" )
  9. .replaceAll( "\r", "&#xD;" )
  10. .replaceAll( "\"", "&quot;" )
  11. ;
  12. }
  13. else
  14. return s;
  15. }

代码示例来源:origin: apache/jena

  1. static void writeText(IndentedWriter out, String string) {
  2. string = Util.substituteEntitiesInElementContent(string) ;
  3. out.print(string) ;
  4. }

代码示例来源:origin: org.apache.jena/jena-core

  1. public static String substituteStandardEntities( String s )
  2. {
  3. if (standardEntities.matcher( s ).find())
  4. {
  5. return substituteEntitiesInElementContent( s )
  6. .replaceAll( "'", "&apos;" )
  7. .replaceAll( "\t","&#9;" )
  8. .replaceAll( "\n", "&#xA;" )
  9. .replaceAll( "\r", "&#xD;" )
  10. .replaceAll( "\"", "&quot;" )
  11. ;
  12. }
  13. else
  14. return s;
  15. }

代码示例来源:origin: org.apache.jena/jena-core

  1. private void wValueString(Literal lt) {
  2. String val = lt.getString();
  3. print(Util.substituteEntitiesInElementContent(val));
  4. }

代码示例来源:origin: apache/jena

  1. private void wValueString(Literal lt) {
  2. String val = lt.getString();
  3. print(Util.substituteEntitiesInElementContent(val));
  4. }

代码示例来源:origin: apache/jena

  1. protected void writeLiteral( Literal l, PrintWriter writer ) {
  2. String lang = l.getLanguage();
  3. String form = l.getLexicalForm();
  4. if (Util.isLangString(l)) {
  5. writer.print(" xml:lang=" + attributeQuoted( lang ));
  6. } else if (l.isWellFormedXML() && !blockLiterals) {
  7. // RDF XML Literals inline.
  8. writer.print(" " + rdfAt("parseType") + "=" + attributeQuoted( "Literal" )+">");
  9. writer.print( form );
  10. return ;
  11. } else {
  12. // Datatype (if not xsd:string and RDF 1.1)
  13. String dt = l.getDatatypeURI();
  14. if ( ! Util.isSimpleString(l) )
  15. writer.print( " " + rdfAt( "datatype" ) + "=" + substitutedAttribute( dt ) );
  16. }
  17. // Content.
  18. writer.print(">");
  19. writer.print( Util.substituteEntitiesInElementContent( form ) );
  20. }

代码示例来源:origin: org.apache.jena/jena-core

  1. protected void writeLiteral( Literal l, PrintWriter writer ) {
  2. String lang = l.getLanguage();
  3. String form = l.getLexicalForm();
  4. if (Util.isLangString(l)) {
  5. writer.print(" xml:lang=" + attributeQuoted( lang ));
  6. } else if (l.isWellFormedXML() && !blockLiterals) {
  7. // RDF XML Literals inline.
  8. writer.print(" " + rdfAt("parseType") + "=" + attributeQuoted( "Literal" )+">");
  9. writer.print( form );
  10. return ;
  11. } else {
  12. // Datatype (if not xsd:string and RDF 1.1)
  13. String dt = l.getDatatypeURI();
  14. if ( ! Util.isSimpleString(l) )
  15. writer.print( " " + rdfAt( "datatype" ) + "=" + substitutedAttribute( dt ) );
  16. }
  17. // Content.
  18. writer.print(">");
  19. writer.print( Util.substituteEntitiesInElementContent( form ) );
  20. }

代码示例来源:origin: apache/jena

  1. public void testX()
  2. assertEquals( "", Util.substituteEntitiesInElementContent( "" ) );
  3. assertEquals( "abc", Util.substituteEntitiesInElementContent( "abc" ) );
  4. assertEquals( "a&lt;b", Util.substituteEntitiesInElementContent( "a<b" ) );
  5. assertEquals( "a&gt;b", Util.substituteEntitiesInElementContent( "a>b" ) );
  6. assertEquals( "a&amp;b", Util.substituteEntitiesInElementContent( "a&b" ) );
  7. assertEquals( "a;b", Util.substituteEntitiesInElementContent( "a;b" ) );
  8. assertEquals( "a b", Util.substituteEntitiesInElementContent( "a b" ) );
  9. assertEquals( "a\nb", Util.substituteEntitiesInElementContent( "a\nb" ) );
  10. assertEquals( "a'b", Util.substituteEntitiesInElementContent( "a'b" ) );
  11. assertEquals( "a&lt;b&lt;c", Util.substituteEntitiesInElementContent( "a<b<c" ) );
  12. assertEquals( "a&lt;b&gt;c", Util.substituteEntitiesInElementContent( "a<b>c" ) );
  13. assertEquals( "a&lt;b&amp;c", Util.substituteEntitiesInElementContent( "a<b&c" ) );
  14. assertEquals( "a&amp;b&amp;c", Util.substituteEntitiesInElementContent( "a&b&c" ) );
  15. assertEquals( "a&amp;b&gt;c", Util.substituteEntitiesInElementContent( "a&b>c" ) );
  16. assertEquals( "a&amp;b&lt;c", Util.substituteEntitiesInElementContent( "a&b<c" ) );
  17. assertEquals( "&#xD;", Util.substituteEntitiesInElementContent( "\r" ) );
  18. assertEquals( "\n", Util.substituteEntitiesInElementContent( "\n" ) );

代码示例来源:origin: org.apache.jena/jena-core

  1. public void testX()
  2. assertEquals( "", Util.substituteEntitiesInElementContent( "" ) );
  3. assertEquals( "abc", Util.substituteEntitiesInElementContent( "abc" ) );
  4. assertEquals( "a&lt;b", Util.substituteEntitiesInElementContent( "a<b" ) );
  5. assertEquals( "a&gt;b", Util.substituteEntitiesInElementContent( "a>b" ) );
  6. assertEquals( "a&amp;b", Util.substituteEntitiesInElementContent( "a&b" ) );
  7. assertEquals( "a;b", Util.substituteEntitiesInElementContent( "a;b" ) );
  8. assertEquals( "a b", Util.substituteEntitiesInElementContent( "a b" ) );
  9. assertEquals( "a\nb", Util.substituteEntitiesInElementContent( "a\nb" ) );
  10. assertEquals( "a'b", Util.substituteEntitiesInElementContent( "a'b" ) );
  11. assertEquals( "a&lt;b&lt;c", Util.substituteEntitiesInElementContent( "a<b<c" ) );
  12. assertEquals( "a&lt;b&gt;c", Util.substituteEntitiesInElementContent( "a<b>c" ) );
  13. assertEquals( "a&lt;b&amp;c", Util.substituteEntitiesInElementContent( "a<b&c" ) );
  14. assertEquals( "a&amp;b&amp;c", Util.substituteEntitiesInElementContent( "a&b&c" ) );
  15. assertEquals( "a&amp;b&gt;c", Util.substituteEntitiesInElementContent( "a&b>c" ) );
  16. assertEquals( "a&amp;b&lt;c", Util.substituteEntitiesInElementContent( "a&b<c" ) );
  17. assertEquals( "&#xD;", Util.substituteEntitiesInElementContent( "\r" ) );
  18. assertEquals( "\n", Util.substituteEntitiesInElementContent( "\n" ) );

代码示例来源:origin: org.apache.jena/jena-core

  1. private boolean wPropertyEltDatatype(WType wt, Property prop, Statement s,
  2. RDFNode r) {
  3. if (! (r instanceof Literal) )
  4. return false ;
  5. Literal lit = ((Literal) r) ;
  6. if ( Util.isSimpleString(lit) )
  7. return false;
  8. if ( Util.isLangString(lit) )
  9. return false;
  10. // print out with "datatype="
  11. done(s);
  12. tab();
  13. print("<");
  14. wt.wTypeStart(prop);
  15. wIdAttrReified(s);
  16. maybeNewline();
  17. wDatatype(((Literal) r).getDatatypeURI());
  18. maybeNewline();
  19. print(">");
  20. print(Util.substituteEntitiesInElementContent(((Literal) r)
  21. .getLexicalForm()));
  22. print("</");
  23. wt.wTypeEnd(prop);
  24. print(">");
  25. return true;
  26. }

代码示例来源:origin: apache/jena

  1. private boolean wPropertyEltDatatype(WType wt, Property prop, Statement s,
  2. RDFNode r) {
  3. if (! (r instanceof Literal) )
  4. return false ;
  5. Literal lit = ((Literal) r) ;
  6. if ( Util.isSimpleString(lit) )
  7. return false;
  8. if ( Util.isLangString(lit) )
  9. return false;
  10. // print out with "datatype="
  11. done(s);
  12. tab();
  13. print("<");
  14. wt.wTypeStart(prop);
  15. wIdAttrReified(s);
  16. maybeNewline();
  17. wDatatype(((Literal) r).getDatatypeURI());
  18. maybeNewline();
  19. print(">");
  20. print(Util.substituteEntitiesInElementContent(((Literal) r)
  21. .getLexicalForm()));
  22. print("</");
  23. wt.wTypeEnd(prop);
  24. print(">");
  25. return true;
  26. }

相关文章