KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > parser > Q_TextLiteral


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 /* Generated By:JJTree: Do not edit this line. Q_TextLiteral.java */
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 JavaDoc langTag = null ;
19     String JavaDoc 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 JavaDoc s)
30   {
31     seen = s ;
32     // Remove string quotes
33
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         // Must wait until any QName is resolved.
60
String JavaDoc tmp_datatype = null ;
61         if ( datatype != null )
62         {
63             datatype.postParse(query) ;
64             tmp_datatype = datatype.getURI() ;// .valueString() ;
65
}
66         
67         com.hp.hpl.jena.graph.Node n = null ;
68         
69         // Can't have type and lang tag.
70
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 JavaDoc asQuotedString()
81     {
82         return seen ;
83         //return super.asQuotedString() ;
84
}
85   
86   // Utility to remove escapes
87
static String JavaDoc unescape(String JavaDoc s, char escape)
88   {
89       for ( int i = 0 ; i < s.length() ; i++ )
90       {
91           if ( s.charAt(i) != escape )
92               continue ;
93           // Escape
94
if ( i >= s.length()-1 )
95               // At end - skip.
96
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           // Unicode \ u XXXX
103
// if ( ch2 == 'u' )
104
// {
105
//
106
// }
107

108           
109           // Other escapes are just the literal character (e.g. ' ")
110
s = s.substring(0,i)+ch2+s.substring(i+2) ;
111           // s got shorter so i now points to char after escape and i+1
112
// is after ch2. No fix up needed.
113
}
114       return s ;
115   }
116 }
117
118 /*
119  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
120  * All rights reserved.
121  *
122  * Redistribution and use in source and binary forms, with or without
123  * modification, are permitted provided that the following conditions
124  * are met:
125  * 1. Redistributions of source code must retain the above copyright
126  * notice, this list of conditions and the following disclaimer.
127  * 2. Redistributions in binary form must reproduce the above copyright
128  * notice, this list of conditions and the following disclaimer in the
129  * documentation and/or other materials provided with the distribution.
130  * 3. The name of the author may not be used to endorse or promote products
131  * derived from this software without specific prior written permission.
132  *
133  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
134  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
135  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
136  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
137  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
138  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
139  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
140  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
141  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
142  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
143  */

144
Popular Tags