src/com/sun/org/apache/xerces/internal/xpointer/ElementSchemePointer.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2005 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at

  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 package com.sun.org.apache.xerces.internal.xpointer;
  21 
  22 import java.util.Hashtable;
  23 
  24 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  25 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  26 import com.sun.org.apache.xerces.internal.util.XMLChar;
  27 import com.sun.org.apache.xerces.internal.xni.Augmentations;
  28 import com.sun.org.apache.xerces.internal.xni.QName;
  29 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
  30 import com.sun.org.apache.xerces.internal.xni.XNIException;
  31 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
  32 
  33 /**
  34  * <p>
  35  * Implements the XPointerPart interface for element() scheme specific processing.
  36  * </p>
  37  *
  38  * @xerces.internal
  39  *
  40  * @version $Id: ElementSchemePointer.java,v 1.4 2009/06/11 23:51:50 joehw Exp $
  41  *
  42  */
  43 class ElementSchemePointer implements XPointerPart {
  44 
  45     // Fields
  46 
  47     // The Scheme Name i.e element
  48     private String fSchemeName;
  49 
  50     // The scheme Data
  51     private String fSchemeData;
  52 
  53     // The scheme Data & child sequence
  54     private String fShortHandPointerName;
  55 
  56     // Should we attempt to resolve the ChildSequence from the
  57     // current element position. If a ShortHand Pointer is present
  58     // attempt to resolve relative to the short hand pointer.
  59     private boolean fIsResolveElement = false;
  60 
  61     // Has the element been found
  62     private boolean fIsElementFound = false;
  63 


 329                     fIsElementFound = true;
 330                 } else if (((fCurrentChildDepth < fFoundDepth) && (fFoundDepth != 0))
 331                         || ((fCurrentChildDepth > fFoundDepth) // or empty element found
 332                         && (fFoundDepth == 0))) {
 333                     fIsElementFound = false;
 334                 }
 335 
 336                 // reset array position of last child
 337                 fCurrentChildSequence[fCurrentChildDepth] = 0;
 338 
 339                 fCurrentChildDepth--;
 340                 fCurrentChildPosition = fCurrentChildSequence[fCurrentChildDepth] + 1;
 341 
 342             } else if (event == XPointerPart.EVENT_ELEMENT_EMPTY) {
 343 
 344                 fCurrentChildSequence[fCurrentChildDepth] = fCurrentChildPosition;
 345                 fCurrentChildPosition++;
 346 
 347                 // Donot check for empty elements if the empty element is
 348                 // a child of a found parent element
 349                 //if (!fIsElementFound) {
 350                     if (checkMatch()) {
 351                         fIsElementFound = true;
 352                         fWasOnlyEmptyElementFound = true;
 353                     } else {




 354                         fIsElementFound = false;

 355                     }
 356                 //}
 357 
 358             }
 359         }
 360 
 361         return fIsElementFound;
 362     }
 363 
 364     /**
 365      * Matches the current position of the element being visited by checking
 366      * its position and previous elements against the element XPointer expression.
 367      * If a match is found it return true else false.
 368      *
 369      * @return boolean
 370      */
 371     protected boolean checkMatch() {
 372         // If the number of elements in the ChildSequence is greater than the
 373         // current child depth, there is not point in checking further
 374         if (!fIsShortHand) {
 375             // If a shorthand pointer is not present traverse the children
 376             // and compare
 377             if (fChildSequence.length <= fCurrentChildDepth + 1) {


 509         private static final int XPTRTOKEN_ELEM_NCNAME = 0;
 510 
 511         private static final int XPTRTOKEN_ELEM_CHILD = 1;
 512 
 513         // Token names
 514         private final String[] fgTokenNames = { "XPTRTOKEN_ELEM_NCNAME",
 515                 "XPTRTOKEN_ELEM_CHILD" };
 516 
 517         // Token count
 518         private static final int INITIAL_TOKEN_COUNT = 1 << 8;
 519 
 520         private int[] fTokens = new int[INITIAL_TOKEN_COUNT];
 521 
 522         private int fTokenCount = 0;
 523 
 524         // Current token position
 525         private int fCurrentTokenIndex;
 526 
 527         private SymbolTable fSymbolTable;
 528 
 529         private Hashtable fTokenNames = new Hashtable();
 530 
 531         /**
 532          * Constructor
 533          *
 534          * @param symbolTable SymbolTable
 535          */
 536         private Tokens(SymbolTable symbolTable) {
 537             fSymbolTable = symbolTable;
 538 
 539             fTokenNames.put(new Integer(XPTRTOKEN_ELEM_NCNAME),
 540                     "XPTRTOKEN_ELEM_NCNAME");
 541             fTokenNames.put(new Integer(XPTRTOKEN_ELEM_CHILD),
 542                     "XPTRTOKEN_ELEM_CHILD");
 543         }
 544 
 545         /*
 546          * Returns the token String
 547          * @param token The index of the token
 548          * @return String The token string
 549          */
 550         private String getTokenString(int token) {
 551             return (String) fTokenNames.get(new Integer(token));
 552         }
 553 
 554         /**
 555          * Returns the token String
 556          * @param token The index of the token
 557          * @return String The token string
 558          */
 559         private Integer getToken(int token) {
 560             return (Integer) fTokenNames.get(new Integer(token));
 561         }
 562 
 563         /**
 564          * Add the specified string as a token
 565          *
 566          * @param token The token string
 567          */
 568         private void addToken(String tokenStr) {
 569             Integer tokenInt = (Integer) fTokenNames.get(tokenStr);
 570             if (tokenInt == null) {
 571                 tokenInt = new Integer(fTokenNames.size());
 572                 fTokenNames.put(tokenInt, tokenStr);
 573             }
 574             addToken(tokenInt.intValue());

 575         }
 576 
 577         /**
 578          * Add the specified int token
 579          *
 580          * @param token The int specifying the token
 581          */
 582         private void addToken(int token) {
 583             try {
 584                 fTokens[fTokenCount] = token;
 585             } catch (ArrayIndexOutOfBoundsException ex) {
 586                 int[] oldList = fTokens;
 587                 fTokens = new int[fTokenCount << 1];
 588                 System.arraycopy(oldList, 0, fTokens, 0, fTokenCount);
 589                 fTokens[fTokenCount] = token;
 590             }
 591             fTokenCount++;
 592         }
 593 
 594         /**


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 package com.sun.org.apache.xerces.internal.xpointer;
  22 
  23 import java.util.HashMap;
  24 
  25 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  26 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  27 import com.sun.org.apache.xerces.internal.util.XMLChar;
  28 import com.sun.org.apache.xerces.internal.xni.Augmentations;
  29 import com.sun.org.apache.xerces.internal.xni.QName;
  30 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
  31 import com.sun.org.apache.xerces.internal.xni.XNIException;
  32 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
  33 
  34 /**
  35  * <p>
  36  * Implements the XPointerPart interface for element() scheme specific processing.
  37  * </p>
  38  *
  39  * @xerces.internal
  40  *
  41  * @version $Id: ElementSchemePointer.java,v 1.4 2009/06/11 23:51:50 joehw Exp $

  42  */
  43 final class ElementSchemePointer implements XPointerPart {
  44 
  45     // Fields
  46 
  47     // The Scheme Name i.e element
  48     private String fSchemeName;
  49 
  50     // The scheme Data
  51     private String fSchemeData;
  52 
  53     // The scheme Data & child sequence
  54     private String fShortHandPointerName;
  55 
  56     // Should we attempt to resolve the ChildSequence from the
  57     // current element position. If a ShortHand Pointer is present
  58     // attempt to resolve relative to the short hand pointer.
  59     private boolean fIsResolveElement = false;
  60 
  61     // Has the element been found
  62     private boolean fIsElementFound = false;
  63 


 329                     fIsElementFound = true;
 330                 } else if (((fCurrentChildDepth < fFoundDepth) && (fFoundDepth != 0))
 331                         || ((fCurrentChildDepth > fFoundDepth) // or empty element found
 332                         && (fFoundDepth == 0))) {
 333                     fIsElementFound = false;
 334                 }
 335 
 336                 // reset array position of last child
 337                 fCurrentChildSequence[fCurrentChildDepth] = 0;
 338 
 339                 fCurrentChildDepth--;
 340                 fCurrentChildPosition = fCurrentChildSequence[fCurrentChildDepth] + 1;
 341 
 342             } else if (event == XPointerPart.EVENT_ELEMENT_EMPTY) {
 343 
 344                 fCurrentChildSequence[fCurrentChildDepth] = fCurrentChildPosition;
 345                 fCurrentChildPosition++;
 346 
 347                 // Donot check for empty elements if the empty element is
 348                 // a child of a found parent element

 349                 if (checkMatch()) {
 350                     if (!fIsElementFound) {
 351                         fWasOnlyEmptyElementFound = true;
 352                     } else {
 353                         fWasOnlyEmptyElementFound = false;
 354                     }
 355                     fIsElementFound = true;
 356                 } else {
 357                     fIsElementFound = false;
 358                     fWasOnlyEmptyElementFound = false;
 359                 }


 360             }
 361         }
 362 
 363         return fIsElementFound;
 364     }
 365 
 366     /**
 367      * Matches the current position of the element being visited by checking
 368      * its position and previous elements against the element XPointer expression.
 369      * If a match is found it return true else false.
 370      *
 371      * @return boolean
 372      */
 373     protected boolean checkMatch() {
 374         // If the number of elements in the ChildSequence is greater than the
 375         // current child depth, there is not point in checking further
 376         if (!fIsShortHand) {
 377             // If a shorthand pointer is not present traverse the children
 378             // and compare
 379             if (fChildSequence.length <= fCurrentChildDepth + 1) {


 511         private static final int XPTRTOKEN_ELEM_NCNAME = 0;
 512 
 513         private static final int XPTRTOKEN_ELEM_CHILD = 1;
 514 
 515         // Token names
 516         private final String[] fgTokenNames = { "XPTRTOKEN_ELEM_NCNAME",
 517                 "XPTRTOKEN_ELEM_CHILD" };
 518 
 519         // Token count
 520         private static final int INITIAL_TOKEN_COUNT = 1 << 8;
 521 
 522         private int[] fTokens = new int[INITIAL_TOKEN_COUNT];
 523 
 524         private int fTokenCount = 0;
 525 
 526         // Current token position
 527         private int fCurrentTokenIndex;
 528 
 529         private SymbolTable fSymbolTable;
 530 
 531         private HashMap<Integer, String> fTokenNames = new HashMap<>();
 532 
 533         /**
 534          * Constructor
 535          *
 536          * @param symbolTable SymbolTable
 537          */
 538         private Tokens(SymbolTable symbolTable) {
 539             fSymbolTable = symbolTable;
 540 
 541             fTokenNames.put(new Integer(XPTRTOKEN_ELEM_NCNAME),
 542                     "XPTRTOKEN_ELEM_NCNAME");
 543             fTokenNames.put(new Integer(XPTRTOKEN_ELEM_CHILD),
 544                     "XPTRTOKEN_ELEM_CHILD");
 545         }
 546 
 547         /*
 548          * Returns the token String
 549          * @param token The index of the token
 550          * @return String The token string
 551          */
 552         private String getTokenString(int token) {
 553             return fTokenNames.get(new Integer(token));









 554         }
 555 
 556         /**
 557          * Add the specified string as a token
 558          *
 559          * @param token The token string
 560          */
 561         private void addToken(String tokenStr) {
 562             if (!fTokenNames.containsValue(tokenStr)) {
 563                 Integer tokenInt = new Integer(fTokenNames.size());

 564                 fTokenNames.put(tokenInt, tokenStr);

 565                 addToken(tokenInt.intValue());
 566             }
 567         }
 568 
 569         /**
 570          * Add the specified int token
 571          *
 572          * @param token The int specifying the token
 573          */
 574         private void addToken(int token) {
 575             try {
 576                 fTokens[fTokenCount] = token;
 577             } catch (ArrayIndexOutOfBoundsException ex) {
 578                 int[] oldList = fTokens;
 579                 fTokens = new int[fTokenCount << 1];
 580                 System.arraycopy(oldList, 0, fTokens, 0, fTokenCount);
 581                 fTokens[fTokenCount] = token;
 582             }
 583             fTokenCount++;
 584         }
 585 
 586         /**