示例#1
0
  /**
   * Parse the
   *
   * <p>elements
   *
   * @return a list of tokens from the dictionary's entry
   * @throws javax.xml.stream.XMLStreamException
   */
  EntryToken procTransduction() throws XMLStreamException {
    ArrayList<Integer> lhs = new ArrayList<Integer>();
    ArrayList<Integer> rhs = new ArrayList<Integer>();
    skipUntil("", COMPILER_LEFT_ELEM);
    reader.next();
    String name = "";
    while (true) {
      if (reader.isEndElement() && reader.getLocalName().equals(COMPILER_LEFT_ELEM)) {
        break;
      }
      if (reader.isStartElement()) {
        name = reader.getLocalName();
        readString(lhs, name);
        reader.next();
      } else if (reader.isCharacters()) {
        readString(lhs, "");
        reader.next();
      } else if (reader.isEndElement()) {
        reader.next();
      } else {
        throw new RuntimeException(
            "Error ("
                + reader.getLocation().getLineNumber()
                + ","
                + reader.getLocation().getColumnNumber()
                + "): unexpected type of event.");
      }
    }
    skipUntil(name, COMPILER_RIGHT_ELEM);
    reader.next();
    while (true) {
      if (reader.isEndElement() && reader.getLocalName().equals(COMPILER_RIGHT_ELEM)) {
        break;
      }
      if (reader.isStartElement()) {
        name = reader.getLocalName();
        readString(rhs, name);
        reader.next();
      } else if (reader.isCharacters()) {
        readString(rhs, "");
        reader.next();
      } else if (reader.isEndElement()) {
        reader.next();
      } else {
        throw new RuntimeException(
            "Error ("
                + reader.getLocation().getLineNumber()
                + ","
                + reader.getLocation().getColumnNumber()
                + "): unexpected type of event.");
      }
    }

    skipUntil(name, COMPILER_PAIR_ELEM);
    EntryToken e = new EntryToken();
    e.setSingleTransduction(lhs, rhs);
    return e;
  }
示例#2
0
  private void testOutboundJAXBMessageToOutput(Databinding db) throws Exception {
    JavaCallInfo jci = db.createJavaCallInfo(findMethod(sei, "header"), args);
    {
      MessageContext mc = db.serializeRequest(jci);
      ;
      int count = 0;
      for (Header h : ((Packet) mc).getInternalMessage().getHeaders().asList()) {
        //                System.out.println("~~~ header " + h);
        XMLStreamReader hr = h.readHeader();
        while (hr.hasNext()) {
          int i = hr.next();
          if (hr.isCharacters()) {
            assertEquals(
                org.jvnet.staxex.Base64Data.class, ((XMLStreamReaderEx) hr).getPCDATA().getClass());
            Base64Data b64 = (Base64Data) ((XMLStreamReaderEx) hr).getPCDATA();
            //                        System.out.println("~~~~~~~~~~~~~~~ header " +
            // b64.getDataHandler());
            //
            // assertEquals(org.jvnet.staxex.Base64Data.class,((XMLStreamReaderEx)xr).getPCDATA().getClass());
            count++;
          }
        }
      }
      XMLStreamReader xr = ((Packet) mc).getInternalMessage().readPayload();
      while (xr.hasNext()) {
        int i = xr.next();
        if (xr.isCharacters()) {
          assertEquals(
              org.jvnet.staxex.Base64Data.class, ((XMLStreamReaderEx) xr).getPCDATA().getClass());
          Base64Data b64 = (Base64Data) ((XMLStreamReaderEx) xr).getPCDATA();
          //                    System.out.println("----------------- b64 " + b64.getDataHandler());
          //
          // assertEquals(org.jvnet.staxex.Base64Data.class,((XMLStreamReaderEx)xr).getPCDATA().getClass());
          count++;
        }
      }
      //            for (Attachment a : ((Packet)mc).getMessage().getAttachments()) count++;
      assertEquals(4, count);
    }
    {
      MessageContext mc = db.serializeRequest(jci);
      //            mc.writeTo(System.out);
    }
    //        System.out.println("\r\n----------------- saaj");
    //        {
    //            MessageContext mc = db.serializeRequest(jci);
    //            mc.getAsSOAPMessage().writeTo(System.out);
    //        }

  }
示例#3
0
  @SuppressWarnings("unchecked")
  protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
    ExtensionElement extensionElement = new ExtensionElement();
    extensionElement.setName(xtr.getLocalName());
    if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
      extensionElement.setNamespace(xtr.getNamespaceURI());
    }
    if (StringUtils.isNotEmpty(xtr.getPrefix())) {
      extensionElement.setNamespacePrefix(xtr.getPrefix());
    }

    BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes);

    boolean readyWithExtensionElement = false;
    while (readyWithExtensionElement == false && xtr.hasNext()) {
      xtr.next();
      if (xtr.isCharacters()) {
        if (StringUtils.isNotEmpty(xtr.getText().trim())) {
          extensionElement.setElementText(xtr.getText().trim());
        }
      } else if (xtr.isStartElement()) {
        ExtensionElement childExtensionElement = parseExtensionElement(xtr);
        extensionElement.addChildElement(childExtensionElement);
      } else if (xtr.isEndElement()
          && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
        readyWithExtensionElement = true;
      }
    }
    return extensionElement;
  }
示例#4
0
  /**
   * Parse the <f> elements
   *
   * @return a list of tokens from the dictionary's entry
   */
  EntryToken procFlag() throws XMLStreamException {
    ArrayList<Integer> both_sides = new ArrayList<Integer>();
    // String n = attrib(COMPILER_N_ATTR);
    // String v = attrib(COMPILER_VALUE_ATTR);
    String name = "";
    reader.next();
    while (true) {
      if (reader.isEndElement() && reader.getLocalName().equals(COMPILER_FLAG_ELEM)) {
        break;
      }
      if (reader.isStartElement()) {
        name = reader.getLocalName();
        readString(both_sides, name);
        reader.next();
      } else if (reader.isCharacters()) {
        readString(both_sides, "");
        reader.next();
      } else if (reader.isEndElement()) {
        reader.next();
      } else {
        throw new RuntimeException(
            "Error ("
                + reader.getLocation().getLineNumber()
                + ","
                + reader.getLocation().getColumnNumber()
                + "): unexpected type of event.");
      }
    }

    /*
     * while (true) {
     * reader.next();
     * int type = reader.getEventType();
     * if (type == XMLStreamConstants.END_ELEMENT || type == XMLStreamConstants.START_ELEMENT) {
     * name = reader.getLocalName();
     *
     * System.err.println("name = " + name);
     * }
     * if (name.equals(COMPILER_FLAG_ELEM)) {
     * break;
     * }
     * readString(both_sides, name);
     * }
     */
    EntryToken e = new EntryToken();

    if (direction.equals(COMPILER_RESTRICTION_LR_VAL)) {
      e.setSingleTransduction(new ArrayList<Integer>(), both_sides);
    } else {
      e.setSingleTransduction(both_sides, new ArrayList<Integer>());
    }
    return e;
  }
  public void compare(XMLStreamReader orig, XMLStreamReader actual) throws Exception {

    boolean origEnd = false;
    boolean actualEnd = false;
    while (orig.hasNext() || actual.hasNext()) {
      int origTag = orig.next();
      while (!orig.isStartElement() && !orig.isEndElement() && !orig.isCharacters()) {
        if (orig.hasNext()) {
          origTag = orig.next();
        } else {
          origEnd = true;
          break;
        }
      }
      int actualTag = actual.next();
      while (!actual.isStartElement() && !actual.isEndElement() && !actual.isCharacters()) {
        if (actual.hasNext()) {
          actualTag = actual.next();
        } else {
          actualEnd = true;
          break;
        }
      }
      if (!origEnd && !actualEnd) {
        Assert.assertEquals("XML mismatch", origTag, actualTag);
        if (orig.isStartElement()) {
          compareStartElement(orig, actual);
        } else if (orig.isEndElement()) {
          compareEndElement(orig, actual);
        } else if (orig.isCharacters()) {
          compareCharacters(orig, actual);
        }
      } else {
        break;
      }
    }
  }
示例#6
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;
  }
示例#7
0
 // to be changed
 private void skipBlanks() throws XMLStreamException {
   reader.next();
   while (true) {
     if (reader.isStartElement() || reader.isEndElement()) {
       return;
     } else if (reader.getEventType() == XMLStreamConstants.COMMENT) {
       reader.next();
     } else if (reader.isCharacters()) {
       if (!reader.isWhiteSpace()) {
         throw new RuntimeException(
             "Error (" + reader.getLocation().getLineNumber() + "): Invalid construction.");
       }
       reader.next();
     }
   }
 }
示例#8
0
 /**
  * Parse the <i> elements
  *
  * @return a list of tokens from the dictionary's entry
  * @throws javax.xml.stream.XMLStreamException
  */
 EntryToken procIdentity() throws XMLStreamException {
   ArrayList<Integer> both_sides = new ArrayList<Integer>();
   if (!(reader.isStartElement() && reader.isEndElement())) {
     // not an emoty node
   }
   String name = "";
   reader.next();
   while (true) {
     if (reader.isEndElement() && reader.getLocalName().equals(COMPILER_IDENTITY_ELEM)) {
       break;
     }
     if (reader.isStartElement()) {
       name = reader.getLocalName();
       readString(both_sides, name);
       reader.next();
     } else if (reader.isCharacters()) {
       readString(both_sides, "");
       reader.next();
     } else if (reader.isEndElement()) {
       reader.next();
     } else {
       throw new RuntimeException(
           "Error ("
               + reader.getLocation().getLineNumber()
               + ","
               + reader.getLocation().getColumnNumber()
               + "): unexpected type of event.");
     }
   }
   /*
    * while (true) {
    * reader.next();
    * int type = reader.getEventType();
    * if (type == XMLStreamConstants.END_ELEMENT || type == XMLStreamConstants.START_ELEMENT) {
    * name = reader.getLocalName();
    * }
    * if (name.equals(COMPILER_IDENTITY_ELEM)) {
    * break;
    * }
    * readString(both_sides, name);
    * }
    */
   EntryToken e = new EntryToken();
   e.setSingleTransduction(both_sides, both_sides);
   return e;
 }
 private void readRecord(XMLStreamReader reader) throws XMLStreamException {
   String currentKey = null;
   if (isStartElement("record")) {
     while (reader.hasNext() && !isEndElement("record")) {
       reader.next();
       if (reader.isStartElement()) {
         if (reader.getLocalName().equals("contributor_list")) {
           contributorList = readBasicRecords(reader, "person", "contributor_list");
           currentKey = null;
         } else if (reader.getLocalName().equals("tracklist")) {
           trackList = readBasicRecords(reader, "track_details", "tracklist");
           currentKey = null;
         } else {
           currentKey = reader.getLocalName();
         }
       } else if (reader.isCharacters()) {
         if (currentKey != null && !reader.getText().trim().equals("")) {
           atts.put(currentKey, reader.getText());
           currentKey = null;
         }
       }
     }
   } else throw new IllegalStateException("Reader is not at the start of a record");
 }
 public boolean isCharacters() {
   return streamReader.isCharacters();
 }
示例#11
0
 public boolean isCharacters() {
   return state != STATE_START_DOCUMENT && state != STATE_END_DOCUMENT && parent.isCharacters();
 }
示例#12
0
 @Override
 public boolean isCharacters() {
   return reader.isCharacters();
 }