KickJava   Java API By Example, From Geeks To Geeks.

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


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

5
6 /* Text literal but without the possibility of @ or ^^ */
7
8 package com.hp.hpl.jena.rdql.parser;
9
10
11 import com.hp.hpl.jena.rdql.Query;
12
13 public class Q_TextLiteral2 extends ParsedLiteral {
14
15     String JavaDoc seen = null ;
16
17   Q_TextLiteral2(int id) {
18     super(id);
19   }
20
21   Q_TextLiteral2(RDQLParser p, int id) {
22     super(p, id);
23   }
24
25   void set(String JavaDoc s)
26   {
27     seen = s ;
28     // Remove string quotes
29
s = s.substring(1,s.length()-1) ;
30     super._setString(unescape(s,'\\')) ;
31   }
32   
33     public void jjtClose()
34     {
35         // Unlike TextLiteral, this has no optional @ or ^^
36
}
37   
38     public void postParse(Query query)
39     {
40         super.postParse(query) ;
41         com.hp.hpl.jena.graph.Node n = null ;
42         n = com.hp.hpl.jena.graph.Node.createLiteral(super.getString(), null, null) ;
43         super._setNode(n) ;
44     }
45   
46     public String JavaDoc asQuotedString()
47     {
48         return seen ;
49         //return super.asQuotedString() ;
50
}
51   
52   // Utility to remove escapes
53
static String JavaDoc unescape(String JavaDoc s, char escape)
54   {
55       for ( int i = 0 ; i < s.length() ; i++ )
56       {
57           if ( s.charAt(i) != escape )
58               continue ;
59           // Escape
60
if ( i >= s.length()-1 )
61               // At end - skip.
62
continue ;
63           char ch2 = s.charAt(i+1) ;
64           if ( ch2 == 'n' ) ch2 = '\n' ;
65           if ( ch2 == 't' ) ch2 = '\t' ;
66           if ( ch2 == 'r' ) ch2 = '\r' ;
67           if ( ch2 == 'b' ) ch2 = '\b' ;
68           // Unicode \ u XXXX
69
// if ( ch2 == 'u' )
70
// {
71
//
72
// }
73

74           
75           // Other escapes are just the literal character (e.g. ' ")
76
s = s.substring(0,i)+ch2+s.substring(i+2) ;
77           // s got shorter so i now points to char after escape and i+1
78
// is after ch2. No fix up needed.
79
}
80       return s ;
81   }
82 }
83
84 /*
85  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
86  * All rights reserved.
87  *
88  * Redistribution and use in source and binary forms, with or without
89  * modification, are permitted provided that the following conditions
90  * are met:
91  * 1. Redistributions of source code must retain the above copyright
92  * notice, this list of conditions and the following disclaimer.
93  * 2. Redistributions in binary form must reproduce the above copyright
94  * notice, this list of conditions and the following disclaimer in the
95  * documentation and/or other materials provided with the distribution.
96  * 3. The name of the author may not be used to endorse or promote products
97  * derived from this software without specific prior written permission.
98  *
99  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
100  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
101  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
102  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
103  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
104  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
105  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
107  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
108  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109  */

110
Popular Tags