Exemplo n.º 1
0
 private static List<RefArtifact> parseListeners(final XMLStreamReader reader)
     throws XMLStreamException {
   final List<RefArtifact> listeners = new ArrayList<RefArtifact>();
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         if (element == XmlElement.LISTENER) {
           listeners.add(parseRefArtifact(reader, element));
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         if (element == XmlElement.LISTENERS) {
           return listeners;
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
Exemplo n.º 2
0
 private static RefArtifact parseRefArtifact(
     final XMLStreamReader reader, final XmlElement artifactElementType)
     throws XMLStreamException {
   final RefArtifact refArtifact =
       new RefArtifact(getAttributeValue(reader, XmlAttribute.REF, true));
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         if (element == XmlElement.PROPERTIES) {
           refArtifact.setProperties(parseProperties(reader));
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         if (element == artifactElementType) {
           return refArtifact;
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
Exemplo n.º 3
0
 private static Properties parseProperties(final XMLStreamReader reader)
     throws XMLStreamException {
   final Properties properties = new Properties();
   properties.setPartition(getAttributeValue(reader, XmlAttribute.PARTITION, false));
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         if (element == XmlElement.PROPERTY) {
           properties.add(
               getAttributeValue(reader, XmlAttribute.NAME, true),
               getAttributeValue(reader, XmlAttribute.VALUE, false));
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         if (element == XmlElement.PROPERTIES) {
           return properties;
         } else if (element != XmlElement.PROPERTY) {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
Exemplo n.º 4
0
  public static void main(String[] args) throws Exception {

    XMLInputFactory xif = XMLInputFactory.newFactory();
    StreamSource xml = new StreamSource("src/main/resources/PClientCreate_001_Request.xml");
    XMLStreamReader xsr = xif.createXMLStreamReader(xml);
    xsr.nextTag();

    /* System.out.println(xsr.getElementText()); */

    int event = 0;
    // here we advance to next tag untill we find node called "kitchen"
    for (event = xsr.next(); event != XMLStreamReader.END_DOCUMENT; event = xsr.next()) {

      if (event == XMLStreamReader.START_ELEMENT) {
        System.out.println(xsr.getLocalName());
        if (xsr.getLocalName() == "s2465") {
          break;
        }
      }
    }

    JAXBContext jc = JAXBContext.newInstance(S2465.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();

    JAXBElement<S2465> jb = unmarshaller.unmarshal(xsr, S2465.class);
    xsr.close();

    S2465 s2465 = jb.getValue();
    System.out.println(s2465.getLgivname());
    System.out.println(s2465.getLsurname());
  }
Exemplo n.º 5
0
 private final void expectTag(String expElem, XMLStreamReader sr) throws XMLStreamException {
   if (!expElem.equals(sr.getLocalName())) {
     throw new XMLStreamException(
         "Unexpected element <" + sr.getLocalName() + ">: expecting <" + expElem + ">",
         sr.getLocation());
   }
 }
  /** Deserializes the object from XML */
  public DataReported parseReported(XMLStreamReader in) throws IOException, XMLStreamException {
    DataReported reported = new DataReported();

    ArrayList<DataField> fieldList = new ArrayList<DataField>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        reported.setFieldList(fieldList);

        return reported;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) {
        fieldList.add(parseField(in));
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "reported");

    return reported;
  }
Exemplo n.º 7
0
  public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {

    String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
    while (xtr.hasNext()) {
      xtr.next();
      if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) {
        GraphicInfo graphicInfo = new GraphicInfo();
        graphicInfo.x = Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue();
        graphicInfo.y = Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue();
        FlowElement flowElement = model.getMainProcess().getFlowElement(id);
        if (flowElement instanceof Event) {
          graphicInfo.width = 30;
          graphicInfo.height = 30;
        } else {
          graphicInfo.width =
              Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)).intValue();
          graphicInfo.height =
              Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)).intValue();
        }

        model.addGraphicInfo(id, graphicInfo);
        break;
      } else if (xtr.isEndElement() && ELEMENT_DI_SHAPE.equalsIgnoreCase(xtr.getLocalName())) {
        break;
      }
    }
  }
Exemplo n.º 8
0
  public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {

    String id = xtr.getAttributeValue(null, ATTRIBUTE_DI_BPMNELEMENT);
    GraphicInfo graphicInfo = new GraphicInfo();
    BpmnXMLUtil.addXMLLocation(graphicInfo, xtr);
    while (xtr.hasNext()) {
      xtr.next();
      if (xtr.isStartElement() && ELEMENT_DI_BOUNDS.equalsIgnoreCase(xtr.getLocalName())) {
        graphicInfo.setX(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_X)).intValue());
        graphicInfo.setY(Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_Y)).intValue());
        graphicInfo.setWidth(
            Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_WIDTH)).intValue());
        graphicInfo.setHeight(
            Double.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_DI_HEIGHT)).intValue());

        String strIsExpanded = xtr.getAttributeValue(null, ATTRIBUTE_DI_IS_EXPANDED);
        if ("true".equalsIgnoreCase(strIsExpanded)) {
          graphicInfo.setExpanded(true);
        }

        model.addGraphicInfo(id, graphicInfo);
        break;
      } else if (xtr.isEndElement() && ELEMENT_DI_SHAPE.equalsIgnoreCase(xtr.getLocalName())) {
        break;
      }
    }
  }
Exemplo n.º 9
0
  private static PartitionPlan parsePartitionPlan(final XMLStreamReader reader)
      throws XMLStreamException {
    final PartitionPlan partitionPlan = new PartitionPlan();
    partitionPlan.setThreads(getAttributeValue(reader, XmlAttribute.THREADS, false));
    partitionPlan.setPartitions(getAttributeValue(reader, XmlAttribute.PARTITIONS, false));

    while (reader.hasNext()) {
      final int eventType = reader.next();
      if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
        continue;
      }
      final XmlElement element = XmlElement.forName(reader.getLocalName());
      switch (eventType) {
        case START_ELEMENT:
          if (element == XmlElement.PROPERTIES) {
            partitionPlan.addProperties(parseProperties(reader));
          } else {
            throw BatchLogger.LOGGER.unexpectedXmlElement(
                reader.getLocalName(), reader.getLocation());
          }
          break;
        case END_ELEMENT:
          if (element == XmlElement.PLAN) {
            return partitionPlan;
          } else {
            throw BatchLogger.LOGGER.unexpectedXmlElement(
                reader.getLocalName(), reader.getLocation());
          }
      }
    }
    throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
  }
Exemplo n.º 10
0
  /** parse the text into a named list... */
  private NamedList<Object> processResponse(XMLStreamReader parser) {
    try {
      NamedList<Object> response = null;
      for (int event = parser.next();
          event != XMLStreamConstants.END_DOCUMENT;
          event = parser.next()) {
        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            if (response != null) {
              throw new Exception("already read the response!");
            }

            // only top-level element is "response
            String name = parser.getLocalName();
            if (name.equals("response") || name.equals("result")) {
              response = readNamedList(parser);
            } else if (name.equals("solr")) {
              return new SimpleOrderedMap<Object>();
            } else {
              throw new Exception(
                  "really needs to be response or result.  " + "not:" + parser.getLocalName());
            }
            break;
        }
      }
      return response;
    } catch (Exception ex) {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "parsing error", ex);
    } finally {
      try {
        parser.close();
      } catch (Exception ex) {
      }
    }
  }
Exemplo n.º 11
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;
  }
  public void writePayloadTo(XMLStreamWriter writer) throws XMLStreamException {
    if (payloadLocalName == null) {
      return;
    } // no body
    assert unconsumed();
    XMLStreamReaderToXMLStreamWriter conv = new XMLStreamReaderToXMLStreamWriter();
    while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
      String name = reader.getLocalName();
      String nsUri = reader.getNamespaceURI();

      // after previous conv.bridge() call the cursor will be at
      // END_ELEMENT. Check if its not soapenv:Body then move to next
      // ELEMENT
      if (reader.getEventType() == XMLStreamConstants.END_ELEMENT) {
        if (!name.equals("Body") || !nsUri.equals(soapVersion.nsUri)) {
          XMLStreamReaderUtil.nextElementContent(reader);
          if (reader.getEventType() == XMLStreamConstants.END_DOCUMENT) {
            break;
          }
          name = reader.getLocalName();
          nsUri = reader.getNamespaceURI();
        }
      }
      if (name.equals("Body") && nsUri.equals(soapVersion.nsUri)
          || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT)) {
        break;
      }
      conv.bridge(reader, writer);
    }
    reader.close();
    XMLStreamReaderFactory.recycle(reader);
  }
Exemplo n.º 13
0
  protected Relation parseRelation() throws XMLStreamException {
    RelationData rd = new RelationData();
    readCommon(rd);
    Relation r = new Relation(rd.getId(), rd.getVersion());
    r.setVisible(rd.isVisible());
    r.load(rd);
    externalIdMap.put(rd.getPrimitiveId(), r);

    Collection<RelationMemberData> members = new ArrayList<RelationMemberData>();
    while (true) {
      int event = parser.next();
      if (event == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("member")) {
          members.add(parseRelationMember(r));
        } else if (parser.getLocalName().equals("tag")) {
          parseTag(r);
        } else {
          parseUnknown();
        }
      } else if (event == XMLStreamConstants.END_ELEMENT) {
        break;
      }
    }
    if (r.isDeleted() && members.size() > 0) {
      System.out.println(tr("Deleted relation {0} contains members", r.getUniqueId()));
      members = new ArrayList<RelationMemberData>();
    }
    relations.put(rd.getUniqueId(), members);
    return r;
  }
Exemplo n.º 14
0
 public ArrayList<XMLInput> getJointInputs(XMLStreamReader parser) throws XMLStreamException {
   ArrayList<XMLInput> inputs = new ArrayList<XMLInput>();
   for (int event = parser.next();
       event != XMLStreamConstants.END_DOCUMENT;
       event = parser.next()) {
     switch (event) {
       case XMLStreamConstants.START_ELEMENT:
         {
           String localName = parser.getLocalName();
           if (localName.equals("input")) {
             XMLInput input = new XMLInput();
             input.parse(parser);
             inputs.add(input);
           } else {
             JAGTLog.exception("Unsupported XMLJoint Start tag: ", parser.getLocalName());
           }
         }
       case XMLStreamConstants.END_ELEMENT:
         {
           if (parser.getLocalName().equals("joints")) {
             return inputs;
           }
           break;
         }
     }
   }
   return (null);
 }
Exemplo n.º 15
0
  Pair<Stroke, Continuation<Stroke>> parseStroke(XMLStreamReader in) throws XMLStreamException {
    in.require(START_ELEMENT, null, "Stroke");

    Stroke base = new Stroke();
    Continuation<Stroke> contn = null;

    while (!(in.isEndElement() && in.getLocalName().equals("Stroke"))) {
      in.nextTag();

      if (in.getLocalName().endsWith("Parameter")) {
        contn = parseParameter(contn, in, base);
      } else if (in.getLocalName().equals("GraphicFill")) {
        contn = parseGraphicFill(contn, in, base);
      } else if (in.getLocalName().equals("GraphicStroke")) {
        contn = parseGraphicStroke(contn, in, base);
      } else if (in.isStartElement()) {
        LOG.error("Found unknown element '{}', skipping.", in.getLocalName());
        skipElement(in);
      }
    }

    in.require(END_ELEMENT, null, "Stroke");

    return new Pair<Stroke, Continuation<Stroke>>(base, contn);
  }
Exemplo n.º 16
0
  private Collection<Object> processFile(
      Mode mode,
      Set<String> xmlRootElements,
      Map<String, Class<?>> entityClasses,
      XMLStreamReader xmlStreamReader,
      Collection<Object> batch)
      throws Exception {
    do {
      xmlStreamReader.nextTag();
    } while (xmlRootElements.contains(xmlStreamReader.getLocalName()));

    do {
      final Class<?> entityClass = entityClasses.get(xmlStreamReader.getLocalName());
      try {
        final Object entity = extractEntity(xmlStreamReader, entityClass);
        batch.add(entity);

        if (batch.size() == batchSize) {
          batch = processBatch(mode, batch);
        }
      } catch (Throwable e) {
        LOGGER.error("{} Error", mode, e);
      }
    } while (xmlStreamReader.isStartElement() && xmlStreamReader.hasNext());

    return batch;
  }
Exemplo n.º 17
0
  /** Extract the metadata of a file system hash */
  public FileSystemHashMetadata loadFileSystemHashMetadata() throws XMLStreamException {
    String endTag = "metadata";
    HashMap<String, String> fshMetadata = new HashMap<>();
    int type;
    String currentElement;
    boolean done = false;

    while (!done && reader.hasNext()) {
      type = reader.next();
      if (type == XMLStreamReader.START_ELEMENT) {
        currentElement = reader.getLocalName();
        type = reader.next();
        if (type == XMLStreamReader.CHARACTERS) {
          fshMetadata.put(currentElement, reader.getText());
          // Look for the end of the current element and throw an exception if it cannot be found
          do {
            type = reader.next();
          } while (type != XMLStreamReader.END_ELEMENT);
          verifyClosing(currentElement);
        } else if (type == XMLStreamReader.END_ELEMENT) {
          verifyClosing(currentElement);
        }
      } else if (type == XMLStreamReader.END_ELEMENT) {
        done = reader.getLocalName().compareTo(endTag) == 0;
      }
    }
    return new FileSystemHashMetadata(fshMetadata);
  }
Exemplo n.º 18
0
 private static ExceptionClassFilter parseExceptionClassFilter(
     final XMLStreamReader reader, final XmlElement artifactElementType)
     throws XMLStreamException {
   final ExceptionClassFilter filter = new ExceptionClassFilter();
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         switch (element) {
           case INCLUDE:
             filter.addInclude(getAttributeValue(reader, XmlAttribute.CLASS, true));
             break;
           case EXCLUDE:
             filter.addExclude(getAttributeValue(reader, XmlAttribute.CLASS, true));
             break;
           default:
             throw BatchLogger.LOGGER.unexpectedXmlElement(
                 reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         if (element == artifactElementType) {
           return filter;
         } else if (element != XmlElement.INCLUDE && element != XmlElement.EXCLUDE) {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
Exemplo n.º 19
0
 private static boolean get(
     XMLStreamReader parser, String xmlElem, String[] xmlNames, String[] strRet) {
   boolean ret = true;
   int maxElem = strRet.length;
   for (int i = 0; i < maxElem; ++i) {
     strRet[i] = "";
   }
   try {
     while (parser.hasNext()) {
       int event = parser.next();
       if (event == XMLStreamConstants.END_ELEMENT) {
         if (parser.getLocalName().equals(xmlElem)) {
           break;
         }
       }
       if (event == XMLStreamConstants.START_ELEMENT) {
         for (int i = 0; i < maxElem; ++i) {
           if (parser.getLocalName().equals(xmlNames[i])) {
             strRet[i] = parser.getElementText();
             break;
           }
         }
       }
     }
   } catch (Exception ex) {
     ret = false;
     Log.fehlerMeldung(467256394, ex);
   }
   return ret;
 }
Exemplo n.º 20
0
 private static Split parseSplit(final XMLStreamReader reader) throws XMLStreamException {
   final Split split = new Split(getAttributeValue(reader, XmlAttribute.ID, true));
   split.setAttributeNext(getAttributeValue(reader, XmlAttribute.NEXT, false));
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         if (element == XmlElement.FLOW) {
           split.addFlow(parseFlow(reader));
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         if (element == XmlElement.SPLIT) {
           return split;
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
Exemplo n.º 21
0
 /**
  * Processes elements and its sub-elements.
  *
  * @param reader XML stream reader
  * @throws XMLStreamException Thrown if problem occurred while reading XML stream.
  * @throws SQLException Thrown if problem occurred while communicating with database.
  */
 private static void processElement(final XMLStreamReader reader)
     throws XMLStreamException, SQLException {
   switch (reader.getNamespaceURI()) {
     case Namespaces.VYMENNY_FORMAT_TYPY:
       switch (reader.getLocalName()) {
         case "VymennyFormat":
           exchangeFormatConvertor.convert(reader);
           break;
         default:
           XMLUtils.processUnsupported(reader);
       }
       break;
     case Namespaces.SPECIALNI_VYMENNY_FORMAT_TYPY:
       switch (reader.getLocalName()) {
         case "SpecialniVymennyFormat":
           specialExchangeFormatConvertor.convert(reader);
           break;
         default:
           XMLUtils.processUnsupported(reader);
       }
       break;
     default:
       XMLUtils.processUnsupported(reader);
   }
 }
Exemplo n.º 22
0
  protected void parseChildElements(
      String elementName, BaseElement parentElement, XMLStreamReader xtr) {
    Map<String, BaseChildElementParser> childParsers =
        new HashMap<String, BaseChildElementParser>();
    childParsers.putAll(genericChildParserMap);
    if (childElementParsers != null) {
      childParsers.putAll(childElementParsers);
    }

    boolean readyWithChildElements = false;
    try {
      while (readyWithChildElements == false && xtr.hasNext()) {
        xtr.next();
        if (xtr.isStartElement()) {
          if (childParsers.containsKey(xtr.getLocalName())) {
            childParsers.get(xtr.getLocalName()).parseChildElement(xtr, parentElement);
          }

        } else if (xtr.isEndElement() && elementName.equalsIgnoreCase(xtr.getLocalName())) {
          readyWithChildElements = true;
        }
      }
    } catch (Exception e) {
      LOGGER.log(Level.WARNING, "Error parsing child elements for " + elementName, e);
    }
  }
Exemplo n.º 23
0
  public void testDOMSource() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();

    InputSource source = new InputSource(new StringReader(xml));
    Document doc = builder.parse(source);

    // Fails when using DOMWrappingReader
    XMLStreamReader reader = getInputFactory().createXMLStreamReader(new DOMSource(doc));

    reader.next(); // root
    assertEquals(0, reader.getAttributeCount());
    assertEquals(1, reader.getNamespaceCount());
    assertEquals("http://testnamespace/", reader.getNamespaceURI());
    assertEquals("ns2", reader.getPrefix());
    assertEquals("root", reader.getLocalName());

    reader.next(); // arg0
    reader.next(); // obj

    assertEquals("obj", reader.getLocalName());
    assertEquals(
        "ns2:mycomplextype",
        reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type"));
    assertEquals("http://testnamespace/", reader.getNamespaceURI("ns2"));
    assertEquals("http://testnamespace/", reader.getNamespaceContext().getNamespaceURI("ns2"));

    assertEquals("ns2", reader.getNamespaceContext().getPrefix("http://testnamespace/"));
  }
Exemplo n.º 24
0
  protected Way parseWay() throws XMLStreamException {
    WayData wd = new WayData();
    readCommon(wd);
    Way w = new Way(wd.getId(), wd.getVersion());
    w.setVisible(wd.isVisible());
    w.load(wd);
    externalIdMap.put(wd.getPrimitiveId(), w);

    Collection<Long> nodeIds = new ArrayList<Long>();
    while (true) {
      int event = parser.next();
      if (event == XMLStreamConstants.START_ELEMENT) {
        if (parser.getLocalName().equals("nd")) {
          nodeIds.add(parseWayNode(w));
        } else if (parser.getLocalName().equals("tag")) {
          parseTag(w);
        } else {
          parseUnknown();
        }
      } else if (event == XMLStreamConstants.END_ELEMENT) {
        break;
      }
    }
    if (w.isDeleted() && nodeIds.size() > 0) {
      System.out.println(tr("Deleted way {0} contains nodes", w.getUniqueId()));
      nodeIds = new ArrayList<Long>();
    }
    ways.put(wd.getUniqueId(), nodeIds);
    return w;
  }
Exemplo n.º 25
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;
  }
 private void processContentXml(InputStream in, String sitePath, Session session, ZipFile zip)
     throws XMLStreamException {
   Map<String, Resource> resources = new HashMap<String, Resource>();
   String currentResourceId = null;
   XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(in);
   for (int event = reader.next(); event != XMLStreamReader.END_DOCUMENT; event = reader.next()) {
     String localName = null;
     switch (event) {
       case XMLStreamReader.START_ELEMENT:
         localName = reader.getLocalName();
         if ("archive".equalsIgnoreCase(localName)) {
           final String system = reader.getAttributeValue(null, "system");
           boolean supportedVersion = false;
           for (String version : supportedVersions) {
             if (version.equalsIgnoreCase(system)) {
               supportedVersion = true;
             }
           }
           if (!supportedVersion) {
             throw new Error("Not a supported version: " + system);
           }
           break;
         }
         if ("collection".equalsIgnoreCase(localName) || "resource".equalsIgnoreCase(localName)) {
           // grab the resource's attributes
           Resource resource = new Resource();
           for (int i = 0; i < reader.getAttributeCount(); i++) {
             resource.attributes.put(
                 reader.getAttributeLocalName(i).toLowerCase(), reader.getAttributeValue(i));
           }
           currentResourceId = resource.getId();
           resources.put(currentResourceId, resource);
           break;
         }
         if ("property".equalsIgnoreCase(localName)) {
           Resource resource = resources.get(currentResourceId);
           final String name = reader.getAttributeValue(null, "name");
           String value = reader.getAttributeValue(null, "value");
           if (value != null && !"".equals(value)) {
             if (reader.getAttributeValue(null, "enc").equalsIgnoreCase("BASE64")) {
               value = new String(base64.decode(value));
             }
             resource.properties.put(name, value);
           }
           break;
         }
         break;
       case XMLStreamReader.END_ELEMENT:
         localName = reader.getLocalName();
         if ("collection".equalsIgnoreCase(localName) || "resource".equalsIgnoreCase(localName)) {
           makeResource(resources.get(currentResourceId), sitePath, session, zip);
         }
         break;
     } // end switch
   } // end for
   reader.close();
 }
Exemplo n.º 27
0
 private static Flow parseFlow(final XMLStreamReader reader) throws XMLStreamException {
   final Flow flow = new Flow(getAttributeValue(reader, XmlAttribute.ID, true));
   flow.setAttributeNext(getAttributeValue(reader, XmlAttribute.NEXT, false));
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         switch (element) {
           case DECISION:
             flow.addJobElement(parseDecision(reader));
             break;
           case FLOW:
             flow.addJobElement(parseFlow(reader));
             break;
           case SPLIT:
             flow.addJobElement(parseSplit(reader));
             break;
           case STEP:
             flow.addJobElement(parseStep(reader));
             break;
           case NEXT:
             if (flow.getAttributeNext() != null) {
               throw BatchLogger.LOGGER.cannotHaveBothNextAttributeAndElement(
                   reader.getLocation(), flow.getAttributeNext());
             }
             flow.addTransitionElement(parseNext(reader));
             break;
           case FAIL:
             flow.addTransitionElement(parseFail(reader));
             break;
           case END:
             flow.addTransitionElement(parseEnd(reader));
             break;
           case STOP:
             flow.addTransitionElement(parseStop(reader));
             break;
           default:
             throw BatchLogger.LOGGER.unexpectedXmlElement(
                 reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         switch (element) {
           case FLOW:
             return flow;
           default:
             throw BatchLogger.LOGGER.unexpectedXmlElement(
                 reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
Exemplo n.º 28
0
 private static Chunk parseChunk(final XMLStreamReader reader) throws XMLStreamException {
   final Chunk chunk = new Chunk();
   chunk.setCheckpointPolicy(getAttributeValue(reader, XmlAttribute.CHECKPOINT_POLICY, false));
   chunk.setItemCount(getAttributeValue(reader, XmlAttribute.ITEM_COUNT, false));
   chunk.setTimeLimit(getAttributeValue(reader, XmlAttribute.TIME_LIMIT, false));
   chunk.setSkipLimit(getAttributeValue(reader, XmlAttribute.SKIP_LIMIT, false));
   chunk.setRetryLimit(getAttributeValue(reader, XmlAttribute.RETRY_LIMIT, false));
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         switch (element) {
           case READER:
             chunk.setReader(parseRefArtifact(reader, XmlElement.READER));
             break;
           case PROCESSOR:
             chunk.setProcessor(parseRefArtifact(reader, XmlElement.PROCESSOR));
             break;
           case WRITER:
             chunk.setWriter(parseRefArtifact(reader, XmlElement.WRITER));
             break;
           case CHECKPOINT_ALGORITHM:
             chunk.setCheckpointAlgorithm(
                 parseRefArtifact(reader, XmlElement.CHECKPOINT_ALGORITHM));
             break;
           case SKIPPABLE_EXCEPTION_CLASSES:
             chunk.setSkippableExceptionClasses(
                 parseExceptionClassFilter(reader, XmlElement.SKIPPABLE_EXCEPTION_CLASSES));
             break;
           case RETRYABLE_EXCEPTION_CLASSES:
             chunk.setRetryableExceptionClasses(
                 parseExceptionClassFilter(reader, XmlElement.RETRYABLE_EXCEPTION_CLASSES));
             break;
           case NO_ROLLBACK_EXCEPTION_CLASSES:
             chunk.setNoRollbackExceptionClasses(
                 parseExceptionClassFilter(reader, XmlElement.NO_ROLLBACK_EXCEPTION_CLASSES));
             break;
           default:
             throw BatchLogger.LOGGER.unexpectedXmlElement(
                 reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         if (element == XmlElement.CHUNK) {
           return chunk;
         } else {
           throw BatchLogger.LOGGER.unexpectedXmlElement(
               reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
  public void writePayloadTo(
      ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment)
      throws SAXException {
    assert unconsumed();
    try {
      if (payloadLocalName == null) {
        return;
      } // no body

      XMLStreamReaderToContentHandler conv =
          new XMLStreamReaderToContentHandler(reader, contentHandler, true, fragment);

      while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
        String name = reader.getLocalName();
        String nsUri = reader.getNamespaceURI();

        // after previous conv.bridge() call the cursor will be at
        // END_ELEMENT. Check if its not soapenv:Body then move to next
        // ELEMENT
        if (reader.getEventType() == XMLStreamConstants.END_ELEMENT) {
          if (!name.equals("Body") || !nsUri.equals(soapVersion.nsUri)) {
            XMLStreamReaderUtil.nextElementContent(reader);
            if (reader.getEventType() == XMLStreamConstants.END_DOCUMENT) {
              break;
            }
            name = reader.getLocalName();
            nsUri = reader.getNamespaceURI();
          }
        }
        if (name.equals("Body") && nsUri.equals(soapVersion.nsUri)
            || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT)) {
          break;
        }

        conv.bridge();
      }
      reader.close();
      XMLStreamReaderFactory.recycle(reader);
    } catch (XMLStreamException e) {
      Location loc = e.getLocation();
      if (loc == null) {
        loc = DummyLocation.INSTANCE;
      }

      SAXParseException x =
          new SAXParseException(
              e.getMessage(),
              loc.getPublicId(),
              loc.getSystemId(),
              loc.getLineNumber(),
              loc.getColumnNumber(),
              e);
      errorHandler.error(x);
    }
  }
Exemplo n.º 30
0
  /**
   * Parse recovery tag
   *
   * @param reader reader
   * @return the parsed recovery object
   * @throws XMLStreamException in case of error
   * @throws ParserException in case of error
   * @throws ValidateException in case of error
   */
  protected Recovery parseRecovery(XMLStreamReader reader)
      throws XMLStreamException, ParserException, ValidateException {

    Boolean noRecovery = null;
    Credential security = null;
    Extension plugin = null;

    for (Recovery.Attribute attribute : Recovery.Attribute.values()) {
      switch (attribute) {
        case NO_RECOVERY:
          {
            noRecovery = attributeAsBoolean(reader, attribute.getLocalName(), Boolean.FALSE);
            break;
          }
        default:
          break;
      }
    }

    while (reader.hasNext()) {
      switch (reader.nextTag()) {
        case END_ELEMENT:
          {
            if (XaDataSource.Tag.forName(reader.getLocalName()) == XaDataSource.Tag.RECOVERY) {
              return new Recovery(security, plugin, noRecovery);
            } else {
              if (Recovery.Tag.forName(reader.getLocalName()) == Recovery.Tag.UNKNOWN) {
                throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
              }
            }
            break;
          }
        case START_ELEMENT:
          {
            Recovery.Tag tag = Recovery.Tag.forName(reader.getLocalName());
            switch (tag) {
              case RECOVER_CREDENTIAL:
                {
                  security = parseCredential(reader);
                  break;
                }
              case RECOVER_PLUGIN:
                {
                  plugin = parseExtension(reader, tag.getLocalName());
                  break;
                }
              default:
                throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
          }
      }
    }
    throw new ParserException(bundle.unexpectedEndOfDocument());
  }