1 18 package org.apache.batik.css.engine.value.css2; 19 20 import org.apache.batik.css.engine.CSSEngine; 21 import org.apache.batik.css.engine.value.IdentifierManager; 22 import org.apache.batik.css.engine.value.ListValue; 23 import org.apache.batik.css.engine.value.StringMap; 24 import org.apache.batik.css.engine.value.StringValue; 25 import org.apache.batik.css.engine.value.URIValue; 26 import org.apache.batik.css.engine.value.Value; 27 import org.apache.batik.css.engine.value.ValueConstants; 28 import org.apache.batik.css.engine.value.ValueManager; 29 import org.apache.batik.util.CSSConstants; 30 31 import org.w3c.dom.css.CSSPrimitiveValue; 32 import org.w3c.dom.DOMException ; 33 import org.w3c.css.sac.LexicalUnit; 34 35 43 public class SrcManager extends IdentifierManager { 44 45 48 protected final static StringMap values = new StringMap(); 49 static { 50 values.put(CSSConstants.CSS_NONE_VALUE, 51 ValueConstants.NONE_VALUE); 52 } 53 54 public SrcManager() { 55 } 56 57 61 public boolean isInheritedProperty() { 62 return false; 63 } 64 65 69 public String getPropertyName() { 70 return CSSConstants.CSS_SRC_PROPERTY; 71 } 72 73 77 public Value getDefaultValue() { 78 return ValueConstants.NONE_VALUE; 79 } 80 81 82 85 public Value createValue(LexicalUnit lu, CSSEngine engine) 86 throws DOMException { 87 88 switch (lu.getLexicalUnitType()) { 89 case LexicalUnit.SAC_INHERIT: 90 return ValueConstants.INHERIT_VALUE; 91 92 default: 93 throw createInvalidLexicalUnitDOMException 94 (lu.getLexicalUnitType()); 95 96 case LexicalUnit.SAC_IDENT: 97 case LexicalUnit.SAC_STRING_VALUE: 98 case LexicalUnit.SAC_URI: 99 } 100 101 ListValue result = new ListValue(); 102 for (;;) { 103 switch (lu.getLexicalUnitType()) { 104 case LexicalUnit.SAC_STRING_VALUE: 105 result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, 106 lu.getStringValue())); 107 lu = lu.getNextLexicalUnit(); 108 break; 109 110 case LexicalUnit.SAC_URI: 111 String uri = resolveURI(engine.getCSSBaseURI(), 112 lu.getStringValue()); 113 114 result.append(new URIValue(lu.getStringValue(), uri)); 115 lu = lu.getNextLexicalUnit(); 116 if ((lu != null) && 117 (lu.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION)) { 118 if (!lu.getFunctionName().equalsIgnoreCase("format")) { 119 break; 120 } 121 123 lu = lu.getNextLexicalUnit(); 126 } 127 break; 128 129 case LexicalUnit.SAC_IDENT: 130 StringBuffer sb = new StringBuffer (lu.getStringValue()); 131 lu = lu.getNextLexicalUnit(); 132 if (lu != null && 133 lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) { 134 do { 135 sb.append(' '); 136 sb.append(lu.getStringValue()); 137 lu = lu.getNextLexicalUnit(); 138 } while (lu != null && 139 lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT); 140 result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, 141 sb.toString())); 142 } else { 143 String id = sb.toString(); 144 String s = id.toLowerCase().intern(); 145 Value v = (Value)values.get(s); 146 result.append((v != null) 147 ? v 148 : new StringValue 149 (CSSPrimitiveValue.CSS_STRING, id)); 150 } 151 break; 152 } 153 if (lu == null) { 154 return result; 155 } 156 if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { 157 throw createInvalidLexicalUnitDOMException 158 (lu.getLexicalUnitType()); 159 } 160 lu = lu.getNextLexicalUnit(); 161 if (lu == null) { 162 throw createMalformedLexicalUnitDOMException(); 163 } 164 } 165 } 166 167 170 public StringMap getIdentifiers() { 171 return values; 172 } 173 } 174 | Popular Tags |