org.apache.jena.rdf.model.impl.Util类的使用及代码示例

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

本文整理了Java中org.apache.jena.rdf.model.impl.Util类的一些代码示例,展示了Util类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util类的具体详情如下:
包路径:org.apache.jena.rdf.model.impl.Util
类名称:Util

Util介绍

[英]Some utility functions.
[中]一些实用功能。

代码示例

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

  1. /** Split point, according to XML qname rules.
  2. * This is the longest NCName at the end of the uri.
  3. * See {@link Util#splitNamespaceXML}.
  4. */
  5. public static int splitXML(String string) { return Util.splitNamespaceXML(string) ; }

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

  1. /**
  2. * Return true if this is a "plain" (i.e. old style, not typed) literal.
  3. * For RDF 1.1, the most compatible choice is "xsd:string" or "rdf:langString".
  4. */
  5. private boolean isPlainLiteral() {
  6. if ( JenaRuntime.isRDF11 )
  7. return Util.isLangString(this) || Util.isSimpleString(this) ;
  8. else
  9. return asNode().getLiteralDatatype() == null;
  10. }

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

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

代码示例来源: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: apache/jena

  1. /**
  2. * A Node is a simple string if:
  3. * <li>(RDF 1.0) No datatype and no language tag
  4. * <li>(RDF 1.1) xsd:string
  5. */
  6. public static boolean isSimpleString(Node n) { return Util.isSimpleString(n) ; }

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

  1. protected String substitutedAttribute( String s )
  2. {
  3. String substituted = Util.substituteStandardEntities( s );
  4. if (!showDoctypeDeclaration.booleanValue())
  5. return attributeQuoted( substituted );
  6. else
  7. {
  8. int split = Util.splitNamespaceXML( substituted );
  9. String namespace = substituted.substring( 0, split );
  10. String prefix = modelPrefixMapping.getNsURIPrefix( namespace );
  11. return prefix == null || isPredefinedEntityName( prefix )
  12. ? attributeQuoted( substituted )
  13. : attributeQuoted( "&" + strForPrefix(prefix) + ";" + substituted.substring( split ) )
  14. ;
  15. }
  16. }

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

  1. assertEquals( "", Util.substituteEntitiesInElementContent( "" ) );
  2. assertEquals( "abc", Util.substituteEntitiesInElementContent( "abc" ) );
  3. assertEquals( "a&lt;b", Util.substituteEntitiesInElementContent( "a<b" ) );
  4. assertEquals( "a&gt;b", Util.substituteEntitiesInElementContent( "a>b" ) );
  5. assertEquals( "a&amp;b", Util.substituteEntitiesInElementContent( "a&b" ) );
  6. assertEquals( "a;b", Util.substituteEntitiesInElementContent( "a;b" ) );
  7. assertEquals( "a b", Util.substituteEntitiesInElementContent( "a b" ) );
  8. assertEquals( "a\nb", Util.substituteEntitiesInElementContent( "a\nb" ) );
  9. assertEquals( "a'b", Util.substituteEntitiesInElementContent( "a'b" ) );
  10. assertEquals( "a&lt;b&lt;c", Util.substituteEntitiesInElementContent( "a<b<c" ) );
  11. assertEquals( "a&lt;b&gt;c", Util.substituteEntitiesInElementContent( "a<b>c" ) );
  12. assertEquals( "a&lt;b&amp;c", Util.substituteEntitiesInElementContent( "a<b&c" ) );
  13. assertEquals( "a&amp;b&amp;c", Util.substituteEntitiesInElementContent( "a&b&c" ) );
  14. assertEquals( "a&amp;b&gt;c", Util.substituteEntitiesInElementContent( "a&b>c" ) );
  15. assertEquals( "a&amp;b&lt;c", Util.substituteEntitiesInElementContent( "a&b<c" ) );
  16. assertEquals( "&#xD;", Util.substituteEntitiesInElementContent( "\r" ) );
  17. assertEquals( "\n", Util.substituteEntitiesInElementContent( "\n" ) );
  18. assertEquals( "", Util.substituteStandardEntities( "" ) );
  19. assertEquals( "&lt;", Util.substituteStandardEntities( "<" ) );
  20. assertEquals( "&gt;", Util.substituteStandardEntities( ">" ) );
  21. assertEquals( "&amp;", Util.substituteStandardEntities( "&" ) );
  22. assertEquals( "&apos;", Util.substituteStandardEntities( "\'" ) );
  23. assertEquals( "&quot;", Util.substituteStandardEntities( "\"" ) );
  24. assertEquals( "&#xA;", Util.substituteStandardEntities( "\n" ) );
  25. assertEquals( "&#xD;", Util.substituteStandardEntities( "\r" ) );
  26. assertEquals( "&#9;", Util.substituteStandardEntities( "\t" ) );

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

  1. /**
  2. * A Node is a language string if it has a language tag.
  3. * (RDF 1.0 and RDF 1.1)
  4. */
  5. public static boolean isLangString(Node n) { return Util.isLangString(n) ; }

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

  1. String regexPresent = it.next();
  2. assertTrue("Looking for /" + regexPresent + "/", Pattern
  3. .compile(Util.substituteStandardEntities(regexPresent),
  4. Pattern.DOTALL).matcher(contents).find()
  5. assertTrue(
  6. "Looking for (not) /" + regexAbsent + "/",
  7. !Pattern.compile("[\"']"+ Util.substituteStandardEntities(regexAbsent)+ "[\"']", Pattern.DOTALL)
  8. .matcher(contents).find()

代码示例来源: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. .filter(rn -> ! Util.isSimpleString(rn))
  2. .map(rn->rn.toString())
  3. .collect(toList());

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

  1. protected String substitutedAttribute( String s )
  2. {
  3. String substituted = Util.substituteStandardEntities( s );
  4. if (!showDoctypeDeclaration.booleanValue())
  5. return attributeQuoted( substituted );
  6. else
  7. {
  8. int split = Util.splitNamespaceXML( substituted );
  9. String namespace = substituted.substring( 0, split );
  10. String prefix = modelPrefixMapping.getNsURIPrefix( namespace );
  11. return prefix == null || isPredefinedEntityName( prefix )
  12. ? attributeQuoted( substituted )
  13. : attributeQuoted( "&" + strForPrefix(prefix) + ";" + substituted.substring( split ) )
  14. ;
  15. }
  16. }

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

  1. assertEquals( "", Util.substituteEntitiesInElementContent( "" ) );
  2. assertEquals( "abc", Util.substituteEntitiesInElementContent( "abc" ) );
  3. assertEquals( "a&lt;b", Util.substituteEntitiesInElementContent( "a<b" ) );
  4. assertEquals( "a&gt;b", Util.substituteEntitiesInElementContent( "a>b" ) );
  5. assertEquals( "a&amp;b", Util.substituteEntitiesInElementContent( "a&b" ) );
  6. assertEquals( "a;b", Util.substituteEntitiesInElementContent( "a;b" ) );
  7. assertEquals( "a b", Util.substituteEntitiesInElementContent( "a b" ) );
  8. assertEquals( "a\nb", Util.substituteEntitiesInElementContent( "a\nb" ) );
  9. assertEquals( "a'b", Util.substituteEntitiesInElementContent( "a'b" ) );
  10. assertEquals( "a&lt;b&lt;c", Util.substituteEntitiesInElementContent( "a<b<c" ) );
  11. assertEquals( "a&lt;b&gt;c", Util.substituteEntitiesInElementContent( "a<b>c" ) );
  12. assertEquals( "a&lt;b&amp;c", Util.substituteEntitiesInElementContent( "a<b&c" ) );
  13. assertEquals( "a&amp;b&amp;c", Util.substituteEntitiesInElementContent( "a&b&c" ) );
  14. assertEquals( "a&amp;b&gt;c", Util.substituteEntitiesInElementContent( "a&b>c" ) );
  15. assertEquals( "a&amp;b&lt;c", Util.substituteEntitiesInElementContent( "a&b<c" ) );
  16. assertEquals( "&#xD;", Util.substituteEntitiesInElementContent( "\r" ) );
  17. assertEquals( "\n", Util.substituteEntitiesInElementContent( "\n" ) );
  18. assertEquals( "", Util.substituteStandardEntities( "" ) );
  19. assertEquals( "&lt;", Util.substituteStandardEntities( "<" ) );
  20. assertEquals( "&gt;", Util.substituteStandardEntities( ">" ) );
  21. assertEquals( "&amp;", Util.substituteStandardEntities( "&" ) );
  22. assertEquals( "&apos;", Util.substituteStandardEntities( "\'" ) );
  23. assertEquals( "&quot;", Util.substituteStandardEntities( "\"" ) );
  24. assertEquals( "&#xA;", Util.substituteStandardEntities( "\n" ) );
  25. assertEquals( "&#xD;", Util.substituteStandardEntities( "\r" ) );
  26. assertEquals( "&#9;", Util.substituteStandardEntities( "\t" ) );

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

  1. /** Return true if the literal is a simple string.
  2. * <p>RDF 1.0 {@literal =>} it is a plain literal, with no language tag
  3. * <p>RDF 1.1 {@literal =>} it has datatype xsd:string
  4. */
  5. public static boolean isSimpleString(Literal lit) {
  6. Objects.requireNonNull(lit) ;
  7. String dtStr = lit.getDatatypeURI() ;
  8. if ( dtStr == null )
  9. return ! isLangString(lit) ;
  10. if ( JenaRuntime.isRDF11 )
  11. return dtStr.equals(XSDDatatype.XSDstring.getURI());
  12. return false ;
  13. }

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

  1. static void startTag(IndentedWriter out, String text, String attr, String attrValue) {
  2. out.print("<") ;
  3. out.print(text) ;
  4. out.print(" ") ;
  5. out.print(attr) ;
  6. out.print("=\"") ;
  7. attrValue = Util.substituteStandardEntities(attrValue) ;
  8. out.print(attrValue) ;
  9. out.print("\"") ;
  10. out.print(">") ;
  11. out.incIndent();
  12. }

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

  1. /** Split point, according to XML qname rules.
  2. * This is the longest NCName at the end of the uri.
  3. * See {@link Util#splitNamespaceXML}.
  4. */
  5. public static int splitXML(String string) { return Util.splitNamespaceXML(string) ; }

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

  1. /**
  2. * Return true if this is a "plain" (i.e. old style, not typed) literal.
  3. * For RDF 1.1, the most compatible choice is "xsd:string" or "rdf:langString".
  4. */
  5. private boolean isPlainLiteral() {
  6. if ( JenaRuntime.isRDF11 )
  7. return Util.isLangString(this) || Util.isSimpleString(this) ;
  8. else
  9. return asNode().getLiteralDatatype() == null;
  10. }

代码示例来源: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. }

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

  1. /** Format:: access:entry ("user1" <http://host/graphname1> <http://host/graphname2> ) ; */
  2. private void parseList(Multimap<String, Node> map, Resource root, GNode entry) {
  3. List<Node> members = GraphList.members(entry);
  4. // string, then URIs.
  5. if ( members.isEmpty() )
  6. throw new AssemblerException(root, "Found access:entry with an empty list");
  7. Node userNode = members.get(0);
  8. if ( ! Util.isSimpleString(userNode) )
  9. throw new AssemblerException(root, "User name is not a string: "+NodeFmtLib.str(userNode));
  10. String user = userNode.getLiteralLexicalForm();
  11. List<Node> graphs = members.subList(1, members.size());
  12. accessEntries(root, map, user, graphs);
  13. }

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

  1. /** Return true if the literal is a simple string.
  2. * <p>RDF 1.0 {@literal =>} it is a plain literal, with no language tag
  3. * <p>RDF 1.1 {@literal =>} it has datatype xsd:string
  4. */
  5. public static boolean isSimpleString(Literal lit) {
  6. Objects.requireNonNull(lit) ;
  7. String dtStr = lit.getDatatypeURI() ;
  8. if ( dtStr == null )
  9. return ! isLangString(lit) ;
  10. if ( JenaRuntime.isRDF11 )
  11. return dtStr.equals(XSDDatatype.XSDstring.getURI());
  12. return false ;
  13. }

相关文章