1 16 package com.sun.org.apache.xerces.internal.xpointer; 17 18 import com.sun.org.apache.xerces.internal.impl.Constants; 19 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 20 import com.sun.org.apache.xerces.internal.util.SymbolTable; 21 import com.sun.org.apache.xerces.internal.xni.Augmentations; 22 import com.sun.org.apache.xerces.internal.xni.QName; 23 import com.sun.org.apache.xerces.internal.xni.XMLAttributes; 24 import com.sun.org.apache.xerces.internal.xni.XNIException; 25 import com.sun.org.apache.xerces.internal.xs.AttributePSVI; 26 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 27 28 39 class ShortHandPointer implements XPointerPart { 40 41 private String fShortHandPointer; 43 44 private boolean fIsFragmentResolved = false; 46 47 private SymbolTable fSymbolTable; 49 50 public ShortHandPointer() { 54 } 55 56 public ShortHandPointer(SymbolTable symbolTable) { 57 fSymbolTable = symbolTable; 58 } 59 60 65 public void parseXPointer(String part) throws XNIException { 66 fShortHandPointer = part; 67 fIsFragmentResolved = false; 69 } 70 71 78 int fMatchingChildCount = 0; 79 public boolean resolveXPointer(QName element, XMLAttributes attributes, 80 Augmentations augs, int event) throws XNIException { 81 82 if (fMatchingChildCount == 0) { 84 fIsFragmentResolved = false; 85 } 86 87 if (event == XPointerPart.EVENT_ELEMENT_START) { 90 if (fMatchingChildCount == 0) { 91 fIsFragmentResolved = hasMatchingIdentifier(element, attributes, augs, 92 event); 93 } 94 if (fIsFragmentResolved) { 95 fMatchingChildCount++; 96 } 97 } else if (event == XPointerPart.EVENT_ELEMENT_EMPTY) { 98 if (fMatchingChildCount == 0) { 99 fIsFragmentResolved = hasMatchingIdentifier(element, attributes, augs, 100 event); 101 } 102 } 103 else { 104 if (fIsFragmentResolved) { 107 fMatchingChildCount--; 108 } 109 } 110 111 return fIsFragmentResolved ; 112 } 113 114 123 private boolean hasMatchingIdentifier(QName element, 124 XMLAttributes attributes, Augmentations augs, int event) 125 throws XNIException { 126 String normalizedValue = null; 127 128 131 if (attributes != null) { 132 for (int i = 0; i < attributes.getLength(); i++) { 133 134 normalizedValue = getSchemaDeterminedID(attributes, i); 139 if (normalizedValue != null) { 140 break; 141 } 142 143 normalizedValue = getChildrenSchemaDeterminedID(attributes, i); 148 if (normalizedValue != null) { 149 break; 150 } 151 152 normalizedValue = getDTDDeterminedID(attributes, i); 158 if (normalizedValue != null) { 159 break; 160 } 161 } 163 } 164 165 if (normalizedValue != null 166 && normalizedValue.equals(fShortHandPointer)) { 167 return true; 168 } 169 170 return false; 171 } 172 173 181 public String getDTDDeterminedID(XMLAttributes attributes, int index) 182 throws XNIException { 183 184 if (attributes.getType(index).equals("ID")) { 185 return attributes.getValue(index); 186 } 187 return null; 188 } 189 190 199 public String getSchemaDeterminedID(XMLAttributes attributes, int index) 200 throws XNIException { 201 Augmentations augs = attributes.getAugmentations(index); 202 AttributePSVI attrPSVI = (AttributePSVI) augs 203 .getItem(Constants.ATTRIBUTE_PSVI); 204 205 if (attrPSVI != null) { 206 209 213 215 219 XSTypeDefinition typeDef = attrPSVI.getMemberTypeDefinition(); 220 if (typeDef != null) { 221 typeDef = attrPSVI.getTypeDefinition(); 222 } 223 224 if (typeDef != null && ((XSSimpleType) typeDef).isIDType()) { 226 return attrPSVI.getSchemaNormalizedValue(); 227 } 228 229 } 231 232 return null; 233 } 234 235 243 public String getChildrenSchemaDeterminedID(XMLAttributes attributes, 244 int index) throws XNIException { 245 return null; 246 } 247 248 252 public boolean isFragmentResolved() { 253 return fIsFragmentResolved; 254 } 255 256 260 public boolean isChildFragmentResolved() { 261 return fIsFragmentResolved & ( fMatchingChildCount > 0); 262 } 263 264 269 public String getSchemeName() { 270 return fShortHandPointer; 271 } 272 273 276 public String getSchemeData() { 277 return null; 278 } 279 280 283 public void setSchemeName(String schemeName) { 284 fShortHandPointer = schemeName; 285 } 286 287 290 public void setSchemeData(String schemeData) { 291 } 293 } | Popular Tags |