1 23 24 package org.apache.slide.search.basic.expression; 25 import org.apache.slide.search.basic.*; 26 27 import org.jdom.Element; 28 import org.apache.slide.search.InvalidQueryException; 29 import org.apache.slide.content.NodeProperty.NamespaceCache; 30 import org.apache.slide.common.PropertyName; 31 32 import java.util.List ; 33 import java.util.ArrayList ; 34 35 40 public class ComparedProperty { 41 42 43 private static final List NUMERIC_PROPERTIES = new ArrayList (); 44 static { 45 NUMERIC_PROPERTIES.add (new PropertyName ("getcontentlength", 46 NamespaceCache.DEFAULT_URI)); 47 } 48 49 50 protected String literal; 51 public void setLiteral (String literal) { 52 this.literal = literal; 53 } 54 public String getLiteral() { 55 return literal; 56 } 57 58 59 protected String property; 60 public void setProperty (String p) { 61 property = p; 62 } 63 public String getProperty() { 64 return property; 65 } 66 67 68 protected String propNamespace; 69 public void setPropNamespace (String p) { 70 propNamespace = p; 71 } 72 public String getPropNamespace() { 73 return propNamespace; 74 } 75 76 77 protected boolean casesensitive = true; 78 public boolean getCasesensitive() { 79 return casesensitive; 80 } 81 82 83 87 public ComparedProperty () { 88 } 89 90 97 public ComparedProperty (String property, String propNamespace) { 98 setProperty(property); 99 setPropNamespace(propNamespace); 100 } 101 102 103 109 public ComparedProperty (Element e) throws InvalidQueryException { 110 this (e, true); 111 } 112 113 121 public ComparedProperty (Element e, boolean withLiteral) throws InvalidQueryException { 122 setProperty(e); 123 if (withLiteral) { 124 literal = getLiteral (e); 125 } 126 } 127 128 134 public boolean isNumeric () { 135 return NUMERIC_PROPERTIES.contains (new PropertyName (property, propNamespace)); 136 } 137 138 149 private void setProperty (Element e) throws InvalidQueryException { 150 String casesensAttr = e.getAttributeValue (Literals.CASESENSITIVE, NamespaceCache.DEFAULT_NAMESPACE); 151 if (casesensAttr != null) { 152 if (casesensAttr.equals ("1")) 153 casesensitive = true; 154 else if (casesensAttr.equals ("0")) 155 casesensitive = false; 156 else 157 throw new InvalidQueryException ("casesensitive must be either \"0\" or \"1\""); 158 } 159 160 Element propListElement = e.getChild (Literals.PROP, NamespaceCache.DEFAULT_NAMESPACE); 161 if (propListElement == null) 162 throw new InvalidQueryException 163 ("No property element supplied"); 164 165 List propList = propListElement.getChildren(); 166 167 if (propList.size() != 1) 168 throw new InvalidQueryException 169 ("Expected exactly 1 prop element, found " + propList.size()); 170 171 Element propElement = ((Element)propList.get(0)); 172 property = propElement.getName(); 173 propNamespace = propElement.getNamespace().getURI(); 174 } 175 185 private String getLiteral(Element e) throws InvalidQueryException { 186 Element lit = e.getChild (Literals.LITERAL, NamespaceCache.DEFAULT_NAMESPACE); 187 if (lit == null) 188 throw new InvalidQueryException 189 ("No literal element supplied"); 190 191 return lit.getText (); 192 } 193 } 194 195 | Popular Tags |