1 5 6 7 8 package com.hp.hpl.jena.rdql.parser; 9 10 11 import com.hp.hpl.jena.datatypes.RDFDatatype ; 12 import com.hp.hpl.jena.datatypes.TypeMapper; 13 import com.hp.hpl.jena.rdql.Query; 14 15 public class Q_TextLiteral extends ParsedLiteral { 16 17 Q_URI datatype = null ; 18 String langTag = null ; 19 String seen = null ; 20 21 Q_TextLiteral(int id) { 22 super(id); 23 } 24 25 Q_TextLiteral(RDQLParser p, int id) { 26 super(p, id); 27 } 28 29 void set(String s) 30 { 31 seen = s ; 32 s = s.substring(1,s.length()-1) ; 34 super._setString(unescape(s,'\\')) ; 35 } 36 37 public void jjtClose() 38 { 39 int n = jjtGetNumChildren(); 40 for (int i = 0; i < n; i++) 41 { 42 Node node = this.jjtGetChild(i); 43 44 if (node instanceof Q_Identifier) 45 langTag = ((Q_Identifier) node).id; 46 47 if (node instanceof Q_URI) 48 datatype = (Q_URI) node ; 49 } 50 if ( langTag != null ) 51 seen = seen+"@"+langTag ; 52 if ( datatype != null ) 53 seen = seen+"^^"+datatype.asQuotedString() ; 54 } 55 56 public void postParse(Query query) 57 { 58 super.postParse(query) ; 59 String tmp_datatype = null ; 61 if ( datatype != null ) 62 { 63 datatype.postParse(query) ; 64 tmp_datatype = datatype.getURI() ; } 66 67 com.hp.hpl.jena.graph.Node n = null ; 68 69 if ( tmp_datatype != null) 71 { 72 RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(tmp_datatype) ; 73 n = com.hp.hpl.jena.graph.Node.createLiteral(super.getString(), null, dType) ; 74 } 75 else 76 n = com.hp.hpl.jena.graph.Node.createLiteral(super.getString(), langTag, null) ; 77 super._setNode(n) ; 78 } 79 80 public String asQuotedString() 81 { 82 return seen ; 83 } 85 86 static String unescape(String s, char escape) 88 { 89 for ( int i = 0 ; i < s.length() ; i++ ) 90 { 91 if ( s.charAt(i) != escape ) 92 continue ; 93 if ( i >= s.length()-1 ) 95 continue ; 97 char ch2 = s.charAt(i+1) ; 98 if ( ch2 == 'n' ) ch2 = '\n' ; 99 if ( ch2 == 't' ) ch2 = '\t' ; 100 if ( ch2 == 'r' ) ch2 = '\r' ; 101 if ( ch2 == 'b' ) ch2 = '\b' ; 102 108 109 s = s.substring(0,i)+ch2+s.substring(i+2) ; 111 } 114 return s ; 115 } 116 } 117 118 144 | Popular Tags |