Exemplo n.º 1
0
  private void addNamespaceDeclarations() {
    String prefix = null;
    String localpart = null;
    String rawname = null;
    String nsPrefix = null;
    String nsURI = null;

    final Iterator iter = fDeclaredPrefixes.iterator();
    while (iter.hasNext()) {
      nsPrefix = (String) iter.next();
      nsURI = fNamespaceContext.getURI(nsPrefix);
      if (nsPrefix.length() > 0) {
        prefix = XMLSymbols.PREFIX_XMLNS;
        localpart = nsPrefix;
        fStringBuffer.clear();
        fStringBuffer.append(prefix);
        fStringBuffer.append(':');
        fStringBuffer.append(localpart);
        rawname =
            fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
      } else {
        prefix = XMLSymbols.EMPTY_STRING;
        localpart = XMLSymbols.PREFIX_XMLNS;
        rawname = XMLSymbols.PREFIX_XMLNS;
      }
      fAttributeQName.setValues(prefix, localpart, rawname, NamespaceContext.XMLNS_URI);
      fAttributes.addAttribute(
          fAttributeQName,
          XMLSymbols.fCDATASymbol,
          (nsURI != null) ? nsURI : XMLSymbols.EMPTY_STRING);
    }
  }
Exemplo n.º 2
0
 /** Fills in a QName object. */
 final void fillQName(QName toFill, String uri, String localpart, String prefix) {
   uri = (uri != null && uri.length() > 0) ? fSymbolTable.addSymbol(uri) : null;
   localpart = (localpart != null) ? fSymbolTable.addSymbol(localpart) : XMLSymbols.EMPTY_STRING;
   prefix =
       (prefix != null && prefix.length() > 0)
           ? fSymbolTable.addSymbol(prefix)
           : XMLSymbols.EMPTY_STRING;
   String raw = localpart;
   if (prefix != XMLSymbols.EMPTY_STRING) {
     fStringBuffer.clear();
     fStringBuffer.append(prefix);
     fStringBuffer.append(':');
     fStringBuffer.append(localpart);
     raw = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
   }
   toFill.setValues(prefix, localpart, raw, uri);
 }
 public String getURI(String prefix) {
   if (fNamespaceContext != null) {
     String uri = fNamespaceContext.getNamespaceURI(prefix);
     if (uri != null && !XMLConstants.NULL_NS_URI.equals(uri)) {
       return (fSymbolTable != null) ? fSymbolTable.addSymbol(uri) : uri.intern();
     }
   }
   return null;
 }
Exemplo n.º 4
0
 public void startPrefixMapping(String prefix, String uri) throws SAXException {
   String prefixSymbol;
   String uriSymbol;
   if (!fStringsInternalized) {
     prefixSymbol = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING;
     uriSymbol = (uri != null && uri.length() > 0) ? fSymbolTable.addSymbol(uri) : null;
   } else {
     prefixSymbol = (prefix != null) ? prefix : XMLSymbols.EMPTY_STRING;
     uriSymbol = (uri != null && uri.length() > 0) ? uri : null;
   }
   if (fNeedPushNSContext) {
     fNeedPushNSContext = false;
     fNamespaceContext.pushContext();
   }
   fNamespaceContext.declarePrefix(prefixSymbol, uriSymbol);
   if (fContentHandler != null) {
     fContentHandler.startPrefixMapping(prefix, uri);
   }
 }
 public String getPrefix(String uri) {
   if (fNamespaceContext != null) {
     if (uri == null) {
       uri = XMLConstants.NULL_NS_URI;
     }
     String prefix = fNamespaceContext.getPrefix(uri);
     if (prefix == null) {
       prefix = XMLConstants.DEFAULT_NS_PREFIX;
     }
     return (fSymbolTable != null) ? fSymbolTable.addSymbol(prefix) : prefix.intern();
   }
   return null;
 }
Exemplo n.º 6
0
 /** Fills in a QName object. */
 private void fillQName(QName toFill, String uri, String localpart, String raw) {
   if (!fStringsInternalized) {
     uri = (uri != null && uri.length() > 0) ? fSymbolTable.addSymbol(uri) : null;
     localpart = (localpart != null) ? fSymbolTable.addSymbol(localpart) : XMLSymbols.EMPTY_STRING;
     raw = (raw != null) ? fSymbolTable.addSymbol(raw) : XMLSymbols.EMPTY_STRING;
   } else {
     if (uri != null && uri.length() == 0) {
       uri = null;
     }
     if (localpart == null) {
       localpart = XMLSymbols.EMPTY_STRING;
     }
     if (raw == null) {
       raw = XMLSymbols.EMPTY_STRING;
     }
   }
   String prefix = XMLSymbols.EMPTY_STRING;
   int prefixIdx = raw.indexOf(':');
   if (prefixIdx != -1) {
     prefix = fSymbolTable.addSymbol(raw.substring(0, prefixIdx));
   }
   toFill.setValues(prefix, localpart, raw, uri);
 }
Exemplo n.º 7
0
    /** Scans the XPointer Expression */
    private boolean scanExpr(
        SymbolTable symbolTable, Tokens tokens, String data, int currentOffset, int endOffset)
        throws XNIException {

      int ch;
      int openParen = 0;
      int closeParen = 0;
      int nameOffset, dataOffset;
      boolean isQName = false;
      String name = null;
      String prefix = null;
      String schemeData = null;
      StringBuffer schemeDataBuff = new StringBuffer();

      while (true) {

        if (currentOffset == endOffset) {
          break;
        }
        ch = data.charAt(currentOffset);

        //
        while (ch == ' ' || ch == 0x0A || ch == 0x09 || ch == 0x0D) {
          if (++currentOffset == endOffset) {
            break;
          }
          ch = data.charAt(currentOffset);
        }
        if (currentOffset == endOffset) {
          break;
        }

        //
        // [1]    Pointer      ::=    Shorthand | SchemeBased
        // [2]    Shorthand    ::=    NCName
        // [3]    SchemeBased  ::=    PointerPart (S? PointerPart)*
        // [4]    PointerPart  ::=    SchemeName '(' SchemeData ')'
        // [5]    SchemeName   ::=    QName
        // [6]    SchemeData   ::=    EscapedData*
        // [7]    EscapedData  ::=    NormalChar | '^(' | '^)' | '^^' | '(' SchemeData ')'
        // [8]    NormalChar   ::=    UnicodeChar - [()^]
        // [9]    UnicodeChar  ::=    [#x0-#x10FFFF]
        // [?]    QName        ::=    (NCName ':')? NCName
        // [?]    NCName       ::=    (Letter | '_') (NCNameChar)*
        // [?]    NCNameChar   ::=    Letter | Digit | '.' | '-' | '_'  (ascii subset of
        // 'NCNameChar')
        // [?]    Letter       ::=    [A-Za-z]                              (ascii subset of
        // 'Letter')
        // [?]    Digit        ::=    [0-9]                                  (ascii subset of
        // 'Digit')
        //
        byte chartype = (ch >= 0x80) ? CHARTYPE_NONASCII : fASCIICharMap[ch];

        switch (chartype) {
          case CHARTYPE_OPEN_PAREN: // '('
            addToken(tokens, Tokens.XPTRTOKEN_OPEN_PAREN);
            openParen++;
            ++currentOffset;
            break;

          case CHARTYPE_CLOSE_PAREN: // ')'
            addToken(tokens, Tokens.XPTRTOKEN_CLOSE_PAREN);
            closeParen++;
            ++currentOffset;
            break;

          case CHARTYPE_CARRET:
          case CHARTYPE_COLON:
          case CHARTYPE_DIGIT:
          case CHARTYPE_EQUAL:
          case CHARTYPE_LETTER:
          case CHARTYPE_MINUS:
          case CHARTYPE_NONASCII:
          case CHARTYPE_OTHER:
          case CHARTYPE_PERIOD:
          case CHARTYPE_SLASH:
          case CHARTYPE_UNDERSCORE:
          case CHARTYPE_WHITESPACE:
            // Scanning SchemeName | Shorthand
            if (openParen == 0) {
              nameOffset = currentOffset;
              currentOffset = scanNCName(data, endOffset, currentOffset);

              if (currentOffset == nameOffset) {
                reportError("InvalidShortHandPointer", new Object[] {data});
                return false;
              }

              if (currentOffset < endOffset) {
                ch = data.charAt(currentOffset);
              } else {
                ch = -1;
              }

              name = symbolTable.addSymbol(data.substring(nameOffset, currentOffset));
              prefix = XMLSymbols.EMPTY_STRING;

              // The name is a QName => a SchemeName
              if (ch == ':') {
                if (++currentOffset == endOffset) {
                  return false;
                }

                ch = data.charAt(currentOffset);
                prefix = name;
                nameOffset = currentOffset;
                currentOffset = scanNCName(data, endOffset, currentOffset);

                if (currentOffset == nameOffset) {
                  return false;
                }

                if (currentOffset < endOffset) {
                  ch = data.charAt(currentOffset);
                } else {
                  ch = -1;
                }

                isQName = true;
                name = symbolTable.addSymbol(data.substring(nameOffset, currentOffset));
              }

              // REVISIT:
              if (currentOffset != endOffset) {
                addToken(tokens, Tokens.XPTRTOKEN_SCHEMENAME);
                tokens.addToken(prefix);
                tokens.addToken(name);
                isQName = false;
              } else if (currentOffset == endOffset) {
                // NCName => Shorthand
                addToken(tokens, Tokens.XPTRTOKEN_SHORTHAND);
                tokens.addToken(name);
                isQName = false;
              }

              // reset open/close paren for the next pointer part
              closeParen = 0;

              break;

            } else if (openParen > 0 && closeParen == 0 && name != null) {
              // Scanning SchemeData
              dataOffset = currentOffset;
              currentOffset = scanData(data, schemeDataBuff, endOffset, currentOffset);

              if (currentOffset == dataOffset) {
                reportError("InvalidSchemeDataInXPointer", new Object[] {data});
                return false;
              }

              if (currentOffset < endOffset) {
                ch = data.charAt(currentOffset);
              } else {
                ch = -1;
              }

              schemeData = symbolTable.addSymbol(schemeDataBuff.toString());
              addToken(tokens, Tokens.XPTRTOKEN_SCHEMEDATA);
              tokens.addToken(schemeData);

              // reset open/close paren for the next pointer part
              openParen = 0;
              schemeDataBuff.delete(0, schemeDataBuff.length());

            } else {
              // ex. schemeName()
              // Should we throw an exception with a more suitable message instead??
              return false;
            }
        }
      } // end while
      return true;
    }