コード例 #1
0
  /**
   * Method that not only gets currently available text from the reader, but also checks that its
   * consistenly accessible using different (basic) StAX methods.
   */
  protected static String getAndVerifyText(XMLStreamReader sr) throws XMLStreamException {
    /* 05-Apr-2006, TSa: Although getText() is available for DTD
     *   and ENTITY_REFERENCE, getTextXxx() are not. Thus, can not
     *   do more checks for those types.
     */
    int type = sr.getEventType();
    if (type == ENTITY_REFERENCE || type == DTD) {
      return sr.getText();
    }

    int expLen = sr.getTextLength();
    /* Hmmh. It's only ok to return empty text for DTD event... well,
     * maybe also for CDATA, since empty CDATA blocks are legal?
     */
    /* !!! 01-Sep-2004, TSa:
     *  note: theoretically, in coalescing mode, it could be possible
     *  to have empty CDATA section(s) get converted to CHARACTERS,
     *  which would be empty... may need to enhance this to check that
     *  mode is not coalescing? Or something
     */
    if (type == CHARACTERS) {
      assertTrue("Stream reader should never return empty Strings.", (expLen > 0));
    }
    String text = sr.getText();
    assertNotNull("getText() should never return null.", text);
    assertEquals(
        "Expected text length of " + expLen + ", got " + text.length(), expLen, text.length());
    char[] textChars = sr.getTextCharacters();
    int start = sr.getTextStart();
    String text2 = new String(textChars, start, expLen);
    assertEquals(text, text2);
    return text;
  }
コード例 #2
0
  /**
   * Parse the <re> elements
   *
   * @return a list of tokens from the dictionary's entry
   * @throws javax.xml.stream.XMLStreamException
   */
  EntryToken procRegexp() throws XMLStreamException {

    reader.next();
    StringBuffer re = new StringBuffer();
    int start = reader.getTextStart();
    int length = reader.getTextLength();
    while (reader.isCharacters()) {
      start = reader.getTextStart();
      length = reader.getTextLength();
      re.append(reader.getTextCharacters(), start, length);
      reader.next();
    }
    EntryToken et = new EntryToken();
    et.setRegexp(re.toString());
    return et;
  }
コード例 #3
0
 public int getTextStart() {
   if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
     throw new IllegalStateException();
   } else {
     return parent.getTextStart();
   }
 }
コード例 #4
0
 private void handleCharacters() throws XMLStreamException {
   try {
     saxHandler.characters(
         staxStreamReader.getTextCharacters(),
         staxStreamReader.getTextStart(),
         staxStreamReader.getTextLength());
   } catch (SAXException e) {
     throw new XMLStreamException2(e);
   }
 }
コード例 #5
0
 /**
  * Parse the <alphabet> elements
  *
  * @throws javax.xml.stream.XMLStreamException
  */
 private void procAlphabet() throws XMLStreamException {
   reader.next();
   if (reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
     if (reader.getEventType() == XMLStreamConstants.CHARACTERS) {
       int start = reader.getTextStart();
       int length = reader.getTextLength();
       letters = new String(reader.getTextCharacters(), start, length);
     } else {
       throw new RuntimeException(
           "Error (" + reader.getLocation().getLineNumber() + "): Missing alphabet symbols.");
     }
   }
   //      if (letters.length()==0) {
   //        System.err.println("Note: A bug in C library libxml makes an empty
   // <alphabet></alphabet> read a newline letters. This is not the case in Java, so the .bin files
   // will differ in length.");
   //      }
   /*
    * if (reader.hasNext()) {
    * reader.next();
    * if (reader.getEventType() == XMLStreamConstants.CHARACTERS) {
    * int start = reader.getTextStart();
    * int length = reader.getTextLength();
    * letters = new String(reader.getTextCharacters(),
    * start,
    * length);
    * } else {
    * throw new RuntimeException("Error (" + reader.getLocation().getLineNumber() +
    * "): not good event type for alphabet symbols.");
    * }
    * } else {
    * throw new RuntimeException("Error (" + reader.getLocation().getLineNumber() +
    * "): Missing alphabet symbols.");
    * }
    */
 }
コード例 #6
0
 public int getTextStart() {
   return streamReader.getTextStart();
 }
コード例 #7
0
 public void parse(XMLStreamReader input) throws XMLStreamException, XNIException {
   if (input.hasNext()) {
     int eventType = input.getEventType();
     if (eventType != XMLStreamConstants.START_DOCUMENT
         && eventType != XMLStreamConstants.START_ELEMENT) {
       throw new XMLStreamException();
     }
     fLocationWrapper.setLocation(input.getLocation());
     fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
     boolean first = true;
     loop:
     while (input.hasNext()) {
       if (!first) {
         eventType = input.next();
       } else {
         first = false;
       }
       switch (eventType) {
         case XMLStreamConstants.START_ELEMENT:
           ++fDepth;
           fLocationWrapper.setLocation(input.getLocation());
           fNamespaceContext.setNamespaceContext(input.getNamespaceContext());
           fillQName(
               fElementQName, input.getNamespaceURI(), input.getLocalName(), input.getPrefix());
           fillXMLAttributes(input);
           fillDeclaredPrefixes(input);
           addNamespaceDeclarations();
           fNamespaceContext.pushContext();
           fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
           break;
         case XMLStreamConstants.END_ELEMENT:
           fLocationWrapper.setLocation(input.getLocation());
           fNamespaceContext.setNamespaceContext(input.getNamespaceContext());
           fillQName(
               fElementQName, input.getNamespaceURI(), input.getLocalName(), input.getPrefix());
           fillDeclaredPrefixes(input);
           fSchemaDOMParser.endElement(fElementQName, null);
           fNamespaceContext.popContext();
           --fDepth;
           if (fDepth <= 0) {
             break loop;
           }
           break;
         case XMLStreamConstants.CHARACTERS:
           fTempString.setValues(
               input.getTextCharacters(), input.getTextStart(), input.getTextLength());
           fSchemaDOMParser.characters(fTempString, null);
           break;
         case XMLStreamConstants.SPACE:
           fTempString.setValues(
               input.getTextCharacters(), input.getTextStart(), input.getTextLength());
           fSchemaDOMParser.ignorableWhitespace(fTempString, null);
           break;
         case XMLStreamConstants.CDATA:
           fSchemaDOMParser.startCDATA(null);
           fTempString.setValues(
               input.getTextCharacters(), input.getTextStart(), input.getTextLength());
           fSchemaDOMParser.characters(fTempString, null);
           fSchemaDOMParser.endCDATA(null);
           break;
         case XMLStreamConstants.PROCESSING_INSTRUCTION:
           fillProcessingInstruction(input.getPIData());
           fSchemaDOMParser.processingInstruction(input.getPITarget(), fTempString, null);
           break;
         case XMLStreamConstants.DTD:
           /* There shouldn't be a DTD in the schema */
           break;
         case XMLStreamConstants.ENTITY_REFERENCE:
           /* Not needed for schemas */
           break;
         case XMLStreamConstants.COMMENT:
           /* No point in sending comments */
           break;
         case XMLStreamConstants.START_DOCUMENT:
           ++fDepth;
           /* We automatically call startDocument before the loop */
           break;
         case XMLStreamConstants.END_DOCUMENT:
           /* We automatically call endDocument after the loop */
           break;
       }
     }
     fLocationWrapper.setLocation(null);
     fNamespaceContext.setNamespaceContext(null);
     fSchemaDOMParser.endDocument(null);
   }
 }
コード例 #8
0
  /**
   * Reads a string and puts it in a list of integers
   *
   * @param result the list of integers that contains the read string
   * @param name the name of the current node
   * @throws javax.xml.stream.XMLStreamException
   */
  private void readString(List<Integer> result, String name) throws XMLStreamException {
    if (reader.getEventType() == XMLStreamConstants.CHARACTERS) {
      int start = reader.getTextStart();
      int length = reader.getTextLength();
      String value = new String(reader.getTextCharacters(), start, length);
      for (int i = 0; i < value.length(); i++) {
        result.add((int) value.charAt(i));
      }
      // System.err.println("value = " + value);
    } else if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
      if (name.equals(COMPILER_BLANK_ELEM)) {
        requireEmptyError(name);
        result.add((int) (' '));
      } else if (name.equals(COMPILER_JOIN_ELEM)) {
        requireEmptyError(name);
        result.add((int) '+');
      } else if (name.equals(COMPILER_POSTGENERATOR_ELEM)) {
        requireEmptyError(name);
        result.add((int) '~');
      } else if (name.equals(COMPILER_GROUP_ELEM)) {
        int type = reader.getEventType();
        if (type != XMLStreamConstants.END_ELEMENT) {
          result.add((int) '#');
        }
      } else if (name.equals(COMPILER_S_ELEM)) {
        requireEmptyError(name);
        String symbol = "<" + attrib(COMPILER_N_ATTR) + ">";
        if (!alphabet.isSymbolDefined(symbol)) {
          throw new RuntimeException(
              "Error ("
                  + reader.getLocation().getLineNumber()
                  + ","
                  + reader.getLocation().getColumnNumber()
                  + "): Undefined symbol '"
                  + symbol
                  + "'.");
        }
        result.add(alphabet.cast(symbol));
      } else {
        throw new RuntimeException(
            "Error ("
                + reader.getLocation().getLineNumber()
                + "): Invalid specification of element '<"
                + name
                + ">' in this context.");
      }
    } else if (reader.getEventType() == XMLStreamConstants.END_ELEMENT) {
      if (name.equals(COMPILER_BLANK_ELEM)) {
      } else if (name.equals(COMPILER_JOIN_ELEM)) {
      } else if (name.equals(COMPILER_POSTGENERATOR_ELEM)) {
      } else if (name.equals(COMPILER_GROUP_ELEM)) {
      } else {
        throw new RuntimeException(
            "Error ("
                + reader.getLocation().getLineNumber()
                + ","
                + reader.getLocation().getColumnNumber()
                + "): unexpected event type '"
                + XMLPrint.getEventTypeString(reader.getEventType())
                + "'.");
      }
    } else {
      throw new RuntimeException(
          "Error ("
              + reader.getLocation().getLineNumber()
              + ","
              + reader.getLocation().getColumnNumber()
              + "): unexpected event type '"
              + XMLPrint.getEventTypeString(reader.getEventType())
              + "'.");
    }

    // System.err.println("result = " + result);
  }
コード例 #9
0
ファイル: CachedCxfPayload.java プロジェクト: sryll/camel
 public int getTextStart() {
   return reader.getTextStart();
 }