1 5 6 package com.hp.hpl.jena.rdql.parser; 7 8 9 import java.io.PrintWriter ; 10 import org.apache.oro.text.regex.Perl5Compiler ; 11 import com.hp.hpl.jena.graph.query.IndexValues ; 12 import com.hp.hpl.jena.graph.query.PatternLiteral; 13 import com.hp.hpl.jena.rdql.*; 14 15 16 public class Q_PatternLiteral extends ExprNode implements Expr, PatternLiteral 17 { 18 String patternString = null ; 19 String modifiers = "" ; 20 int mask ; 21 22 Q_PatternLiteral(int id) { 23 super(id); 24 } 25 26 Q_PatternLiteral(RDQLParser p, int id) { 27 super(p, id); 28 } 29 30 public void setPattern(String str) 31 { 32 patternString = str ; 36 } 37 38 public void setModifiers(String str) 39 { 40 modifiers = modifiers+str ; 41 for ( int i = 0 ; i < modifiers.length() ; i++ ) 42 { 43 switch(modifiers.charAt(i)) 44 { 45 case 'i' : mask |= Perl5Compiler.CASE_INSENSITIVE_MASK; break; 46 case 'm' : mask |= Perl5Compiler.MULTILINE_MASK; break; 47 case 's' : mask |= Perl5Compiler.SINGLELINE_MASK; break; 48 case 'x' : mask |= Perl5Compiler.EXTENDED_MASK; break; 49 } 52 } 53 } 54 55 public String toString() 56 { 57 if ( patternString.indexOf('/') == -1 ) 59 return "/"+patternString+"/"+modifiers ; 60 61 if ( patternString.indexOf('!') == -1 ) 62 return "m!"+patternString+"!"+modifiers ; 63 64 if ( patternString.indexOf('%') == -1 ) 65 return "m%"+patternString+"%"+modifiers ; 66 67 char marker = '!' ; 69 return "m"+marker+quote(patternString, marker)+marker+modifiers ; 70 } 71 72 private String quote(String pString, char marker) 73 { 74 int i = 0 ; 75 while(true) 76 { 77 int j = pString.indexOf(marker,i) ; 78 if ( j == -1 ) 79 break ; 80 pString = pString.substring(0, j)+"\\"+pString.substring(j) ; 81 i = j+2 ; 83 } 84 return pString ; 85 } 86 87 public String getPatternString() { return patternString ; } 88 public String getModifiers() { return modifiers ; } 89 90 93 public boolean isConstant() { return true; } 94 public Object getValue() { return toString(); } 96 98 public void print(PrintWriter pw, int level) 99 { 100 pw.print(toString()) ; 101 } 102 103 public NodeValue eval(Query q, IndexValues env) 104 { 105 throw new RDQL_InternalErrorException("Q_PatternLiteral.eval called!") ; 106 } 108 109 public String asPrefixString() 110 { 111 return toString() ; 112 } 113 114 public String asInfixString() 115 { 116 return toString() ; 117 } 118 119 122 public String getPatternModifiers() 123 { 124 return modifiers == null ? "" : modifiers; 125 } 126 127 130 public String getPatternLanguage() 131 { 132 return PatternLiteral.rdql; 133 } 134 135 } 136 137 163 | Popular Tags |