Пример #1
0
 private void compareStartElement(XMLStreamReader orig, XMLStreamReader actual) throws Exception {
   Assert.assertEquals("Start element is not matched", orig.getName(), actual.getName());
   int origAttrCount = orig.getAttributeCount();
   int actualAttrCount = actual.getAttributeCount();
   for (int i = 0; i < origAttrCount; i++) {
     QName origAttrName = orig.getAttributeName(i);
     if ((origAttrName.getLocalPart().equals("location"))
         || (origAttrName.getLocalPart().equals("schemaLocation"))) {
       // skip this atribute
       origAttrCount--;
     } else {
       Assert.assertEquals(
           "Attribute " + origAttrName + " not found or value not matching",
           orig.getAttributeValue(origAttrName.getNamespaceURI(), origAttrName.getLocalPart()),
           actual.getAttributeValue(origAttrName.getNamespaceURI(), origAttrName.getLocalPart()));
     }
   }
   for (int i = 0; i < actualAttrCount; i++) {
     QName actualAttrName = actual.getAttributeName(i);
     if ((actualAttrName.getLocalPart().equals("location"))
         || (actualAttrName.getLocalPart().equals("schemaLocation"))) {
       // skip this atribute
       actualAttrCount--;
     }
   }
   Assert.assertEquals(
       "Attribute count is not matched for element " + orig.getName(),
       origAttrCount,
       actualAttrCount);
 }
Пример #2
0
  private List<SecurityHistoryNode> parseHistoryNodes(final XMLStreamReader reader) {
    List<SecurityHistoryNode> list = new ArrayList<>();

    assert reader.getAttributeCount() == 3;

    // number of history nodes to parse
    int count = Integer.parseInt(reader.getAttributeValue(2));

    logger.log(Level.FINEST, "Parsing {0} SecurityHistoryNodes", count);

    Map<String, String> elementMap = new HashMap<>();

    QName parsingElement = null;

    try {
      while (reader.hasNext() && list.size() < count) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            if (reader.getAttributeCount() > 0
                && reader.getAttributeValue(0).equals("SecurityHistoryNode")) { // start of hNode

              parsingElement = reader.getName();
            } else {
              String element = reader.getLocalName();
              elementMap.put(element, reader.getElementText());
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getName().equals(parsingElement)) {
              // build the security history node;
              SecurityHistoryNode hNode = new SecurityHistoryNode();

              hNode.setDate(decodeDate(elementMap.get("date")));
              hNode.setHigh(new BigDecimal(elementMap.get("high")));
              hNode.setLow(new BigDecimal(elementMap.get("low")));
              hNode.setPrice(new BigDecimal(elementMap.get("price")));
              hNode.setVolume(Long.parseLong(elementMap.get("volume")));

              elementMap.clear();

              list.add(hNode);
            }
            break;
          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, e.toString(), e);
    }

    return list;
  }
Пример #3
0
 private static Properties getAttributes(XMLStreamReader reader) {
   Properties props = new Properties();
   if (reader.getAttributeCount() > 0) {
     for (int i = 0; i < reader.getAttributeCount(); i++) {
       String attrName = reader.getAttributeLocalName(i);
       String attrValue = reader.getAttributeValue(i);
       props.setProperty(attrName, attrValue);
     }
   }
   return props;
 }
  public static FilterMappingMetaData parse(XMLStreamReader reader) throws XMLStreamException {
    FilterMappingMetaData filterMapping = new FilterMappingMetaData();

    // Handle attributes
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      final String value = reader.getAttributeValue(i);
      if (reader.getAttributeNamespace(i) != null) {
        continue;
      }
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case ID:
          {
            filterMapping.setId(value);
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case FILTER_NAME:
          filterMapping.setFilterName(getElementText(reader));
          break;
        case URL_PATTERN:
          List<String> urlPatterns = filterMapping.getUrlPatterns();
          if (urlPatterns == null) {
            urlPatterns = new ArrayList<String>();
            filterMapping.setUrlPatterns(urlPatterns);
          }
          urlPatterns.add(getElementText(reader));
          break;
        case SERVLET_NAME:
          List<String> servletNames = filterMapping.getServletNames();
          if (servletNames == null) {
            servletNames = new ArrayList<String>();
            filterMapping.setServletNames(servletNames);
          }
          servletNames.add(getElementText(reader));
          break;
        case DISPATCHER:
          List<DispatcherType> dispatchers = filterMapping.getDispatchers();
          if (dispatchers == null) {
            dispatchers = new ArrayList<DispatcherType>();
            filterMapping.setDispatchers(dispatchers);
          }
          dispatchers.add(DispatcherType.valueOf(getElementText(reader)));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return filterMapping;
  }
Пример #5
0
  /**
   * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE StAXevent.
   *
   * @return the StAX attributes converted to an org.xml.sax.Attributes
   */
  private Attributes getAttributes() {
    AttributesImpl attrs = new AttributesImpl();

    int eventType = staxStreamReader.getEventType();
    if (eventType != XMLStreamConstants.ATTRIBUTE
        && eventType != XMLStreamConstants.START_ELEMENT) {
      throw new InternalError("getAttributes() attempting to process: " + eventType);
    }

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) {
      String uri = staxStreamReader.getAttributeNamespace(i);
      if (uri == null) uri = "";
      String localName = staxStreamReader.getAttributeLocalName(i);
      String prefix = staxStreamReader.getAttributePrefix(i);
      String qName;
      if (prefix == null || prefix.length() == 0) qName = localName;
      else qName = prefix + ':' + localName;
      String type = staxStreamReader.getAttributeType(i);
      String value = staxStreamReader.getAttributeValue(i);

      attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
  }
Пример #6
0
  static String getNextElement(
      XMLStreamReader reader, String name, Map<String, String> attributes, boolean getElementText)
      throws XMLStreamException {
    if (!reader.hasNext()) {
      throw new XMLStreamException("Expected more elements", reader.getLocation());
    }
    int type = reader.next();
    while (reader.hasNext() && type != START_ELEMENT) {
      type = reader.next();
    }
    if (reader.getEventType() != START_ELEMENT) {
      throw new XMLStreamException("No <" + name + "> found");
    }
    if (!reader.getLocalName().equals("" + name + "")) {
      throw new XMLStreamException("<" + name + "> expected", reader.getLocation());
    }

    if (attributes != null) {
      for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attr = reader.getAttributeLocalName(i);
        if (!attributes.containsKey(attr)) {
          throw new XMLStreamException("Unexpected attribute " + attr, reader.getLocation());
        }
        attributes.put(attr, reader.getAttributeValue(i));
      }
    }

    return getElementText ? reader.getElementText() : null;
  }
Пример #7
0
  private static void readCorner(ModalityInfoData data, CornerDisplay corner, XMLStreamReader xmler)
      throws XMLStreamException {

    TagView[] disElements = data.getCornerInfo(corner).getInfos();

    boolean state = true;
    int index = -1;
    String format = null;
    while (xmler.hasNext() && state) {
      switch (xmler.next()) {
        case XMLStreamConstants.CHARACTERS:
          if (index > 0 && index <= 7) {
            disElements[index - 1] = getTag(xmler.getText(), format);
            index = -1; // Reset current index and format
            format = null;
          }
          break;
        case XMLStreamConstants.START_ELEMENT:
          if ("p".equals(xmler.getName().getLocalPart())
              && xmler.getAttributeCount() >= 1) { // $NON-NLS-1$
            index = TagUtil.getIntegerTagAttribute(xmler, "index", -1); // $NON-NLS-1$
            format = xmler.getAttributeValue(null, "format"); // $NON-NLS-1$
          }
          break;
        case XMLStreamConstants.END_ELEMENT:
          if ("corner".equals(xmler.getName().getLocalPart())) { // $NON-NLS-1$
            state = false;
          }
          break;
        default:
          break;
      }
    }
  }
Пример #8
0
 private static void readModality(ModalityInfoData data, XMLStreamReader xmler)
     throws XMLStreamException {
   boolean state = true;
   while (xmler.hasNext() && state) {
     switch (xmler.next()) {
       case XMLStreamConstants.START_ELEMENT:
         if ("corner".equals(xmler.getName().getLocalPart())
             && xmler.getAttributeCount() >= 1) { // $NON-NLS-1$
           String name = xmler.getAttributeValue(null, "name"); // $NON-NLS-1$
           CornerDisplay corner = getCornerDisplay(name);
           if (corner != null) {
             readCorner(data, corner, xmler);
           }
         }
         break;
       case XMLStreamConstants.END_ELEMENT:
         if ("modality".equals(xmler.getName().getLocalPart())) { // $NON-NLS-1$
           state = false;
         }
         break;
       default:
         break;
     }
   }
 }
Пример #9
0
 private static void readModalities(XMLStreamReader xmler) throws XMLStreamException {
   while (xmler.hasNext()) {
     switch (xmler.next()) {
       case XMLStreamConstants.START_ELEMENT:
         String key = xmler.getName().getLocalPart();
         if ("modality".equals(key) && xmler.getAttributeCount() >= 1) { // $NON-NLS-1$
           String name = xmler.getAttributeValue(null, "name"); // $NON-NLS-1$
           Modality m = getModdality(name);
           if (m != null) {
             try {
               String extend = xmler.getAttributeValue(null, "extend"); // $NON-NLS-1$
               ModalityInfoData data = new ModalityInfoData(m, getModdality(extend));
               readModality(data, xmler);
               MODALITY_VIEW_MAP.put(m, data);
             } catch (Exception e) {
               LOGGER.error(
                   "Modality {} cannot be read from attributes-view.xml", //$NON-NLS-1$
                   name,
                   e);
             }
           }
         }
         break;
       default:
         break;
     }
   }
 }
  /**
   * Reads the "version" attribute of ejb-jar element and returns the corresponding {@link
   * org.jboss.metadata.ejb.spec.EjbJarVersion}.
   *
   * <p>Returns null, if either the "version" attribute is not specified or if the value of the
   * "version" attribute doesn't belong to the known values from {@link
   * org.jboss.metadata.ejb.spec.EjbJarVersion}.
   *
   * @param reader
   * @return
   * @throws XMLStreamException
   */
  protected static EjbJarVersion readVersionAttribute(XMLStreamReader reader)
      throws XMLStreamException {
    EjbJarVersion ejbJarVersion = null;

    // Look at the version attribute
    String versionString = null;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      if (attributeHasNamespace(reader, i)) {
        continue;
      }
      final EjbJarAttribute ejbJarVersionAttribute =
          EjbJarAttribute.forName(reader.getAttributeLocalName(i));
      if (ejbJarVersionAttribute == EjbJarAttribute.VERSION) {
        versionString = reader.getAttributeValue(i);
      }
    }
    if ("1.1".equals(versionString)) {
      ejbJarVersion = EjbJarVersion.EJB_1_1;
    } else if ("2.0".equals(versionString)) {
      ejbJarVersion = EjbJarVersion.EJB_2_0;
    } else if ("2.1".equals(versionString)) {
      ejbJarVersion = EjbJarVersion.EJB_2_1;
    } else if ("3.0".equals(versionString)) {
      ejbJarVersion = EjbJarVersion.EJB_3_0;
    } else if ("3.1".equals(versionString)) {
      ejbJarVersion = EjbJarVersion.EJB_3_1;
    }

    return ejbJarVersion;
  }
Пример #11
0
  private static String[] parseAccountSecurities(final XMLStreamReader reader) {

    assert reader.getAttributeCount() == 2;

    ArrayList<String> securities = new ArrayList<>();

    /* still at start of security array.  Need to know when end is reached */
    QName parsingElement = reader.getName();

    try {
      parse:
      while (reader.hasNext()) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            securities.add(reader.getElementText());
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getName().equals(parsingElement)) {
              logger.finest("Found the end of the Account Securities");
              break parse;
            }
            break;
          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, e.toString(), e);
    }

    return securities.toArray(new String[securities.size()]);
  }
Пример #12
0
  /**
   * Method processAttributes.
   *
   * @param node
   */
  protected void processAttributes(OMElement node) {
    int attribCount = parser.getAttributeCount();
    for (int i = 0; i < attribCount; i++) {
      String uri = parser.getAttributeNamespace(i);
      String prefix = parser.getAttributePrefix(i);

      OMNamespace namespace = null;
      if (uri != null && uri.length() > 0) {

        // prefix being null means this elements has a default namespace or it has inherited
        // a default namespace from its parent
        namespace = node.findNamespace(uri, prefix);
        if (namespace == null) {
          if (prefix == null || "".equals(prefix)) {
            prefix = OMSerializerUtil.getNextNSPrefix();
          }
          namespace = node.declareNamespace(uri, prefix);
        }
      }

      // todo if the attributes are supposed to namespace qualified all the time
      // todo then this should throw an exception here

      OMAttribute attr =
          node.addAttribute(
              parser.getAttributeLocalName(i), parser.getAttributeValue(i), namespace);
      attr.setAttributeType(parser.getAttributeType(i));
    }
  }
Пример #13
0
 /**
  * Returns the attributes of the element that the given {@link XMLStreamReader} points to.
  *
  * @param reader xml stream, must not be <code>null</code> and point to a {@link
  *     XMLStreamConstants#START_ELEMENT}
  * @return attributes of the element, can be empty, but never <code>null</code>
  */
 public static Map<QName, String> getAttributes(XMLStreamReader reader) {
   HashMap<QName, String> attrs = new HashMap<QName, String>();
   for (int i = 0; i < reader.getAttributeCount(); i++) {
     attrs.put(reader.getAttributeName(i), reader.getAttributeValue(i));
   }
   return attrs;
 }
Пример #14
0
 private static Element parseElement(XMLStreamReader xsr) throws XMLStreamException {
   // xsr points to a START_ELEMENT event. Create the element and read all its attributes
   // Then read all its children events
   Element element = new Element(xsr.getLocalName());
   // text that will be added to the element. Text can come in different events, so we add it here
   // and add it to the element at the end
   StringBuilder elementText = new StringBuilder();
   int attributeCount = xsr.getAttributeCount();
   for (int i = 0; i < attributeCount; i++) {
     element.putAttribute(xsr.getAttributeLocalName(i), xsr.getAttributeValue(i));
   }
   while (xsr.hasNext()) {
     xsr.next();
     if (xsr.getEventType() == XMLStreamConstants.END_ELEMENT) {
       // element is closed. Move the cursor and return it
       // check if there is some text to add before (empty text is not added, but added text is not
       // trimmed)
       // we set empty text also if the element has no children
       if (!elementText.toString().trim().isEmpty() || !element.hasChildren()) {
         element.setText(elementText.toString());
       }
       //                xsr.next();
       return element;
     } else if (xsr.getEventType() == XMLStreamConstants.CHARACTERS) {
       // an attribute of the current element
       elementText.append(xsr.getText());
     } else if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT) {
       // new element begins -> read it recursively and add it to the current element
       element.addChild(parseElement(xsr));
     }
   }
   // we reached the end of the document without the tag end -> error parsing
   throw new XMLStreamException(
       "End of the document unexpectedly reached. Element " + element.getName() + " not closed");
 }
Пример #15
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/"));
  }
Пример #16
0
 public int getAttributeCount() {
   if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) {
     throw new IllegalStateException();
   } else {
     return parent.getAttributeCount();
   }
 }
Пример #17
0
  private static void parsePath(
      final XMLStreamReader reader, final boolean include, final MultiplePathFilterBuilder builder)
      throws XMLStreamException {
    String path = null;
    final Set<Attribute> required = EnumSet.of(Attribute.PATH);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      final Attribute attribute = Attribute.of(reader.getAttributeName(i));
      required.remove(attribute);
      switch (attribute) {
        case PATH:
          path = reader.getAttributeValue(i);
          break;
        default:
          throw unexpectedContent(reader);
      }
    }
    if (!required.isEmpty()) {
      throw missingAttributes(reader.getLocation(), required);
    }

    builder.addFilter(PathFilters.match(path), include);

    // consume remainder of element
    parseNoContent(reader);
  }
 protected void processAttributes(final EjbJarMetaData ejbJarMetaData, XMLStreamReader reader)
     throws XMLStreamException {
   // Handle attributes and set them in the EjbJarMetaData
   final int count = reader.getAttributeCount();
   for (int i = 0; i < count; i++) {
     processAttribute(ejbJarMetaData, reader, i);
   }
 }
Пример #19
0
  private static void printAttributes(XMLStreamReader xmlr) {

    if (xmlr.getAttributeCount() > 0) {

      int count = xmlr.getAttributeCount();
      for (int i = 0; i < count; i++) {

        QName name = xmlr.getAttributeName(i);
        String namespace = xmlr.getAttributeNamespace(i);
        String type = xmlr.getAttributeType(i);
        String prefix = xmlr.getAttributePrefix(i);
        String value = xmlr.getAttributeValue(i);

        System.out.println(
            "\tAttribute: {" + namespace + "}:" + name.toString() + "(" + type + ")=" + value);
      }
    }
  }
 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();
 }
Пример #21
0
 public static String getAttributeByLocalName(XMLStreamReader reader, String localName) {
   String result = "";
   for (int i = 0; i < reader.getAttributeCount(); i++) {
     QName attribute = reader.getAttributeName(i);
     if (attribute != null && attribute.getLocalPart().equals(localName)) {
       result = reader.getAttributeValue(i);
     }
   }
   return result;
 }
Пример #22
0
 public void parseAttributes(XMLStreamReader parser) {
   for (int i = 0; i < parser.getAttributeCount(); i++) {
     QName attr = parser.getAttributeName(i);
     if (attr.getLocalPart().equals("id")) {
       id = parser.getAttributeValue(i);
     } else if (attr.getLocalPart().equals("name")) {
       name = parser.getAttributeValue(i);
     }
   }
 }
Пример #23
0
 /*package*/ void fillAttributes(XMLStreamReader in) {
   for (int i = in.getAttributeCount() - 1; i >= 0; i--) {
     String n = in.getAttributeLocalName(i);
     if (model.attributes.containsKey(n)) {
       if (attributes == null) attributes = new HashMap<String, String>();
       attributes.put(n, in.getAttributeValue(i));
     }
   }
   if (attributes == null) attributes = Collections.emptyMap();
 }
Пример #24
0
 private static void parseProperty(XMLStreamReader reader, AdminObjectImpl anObj)
     throws XMLStreamException {
   if (reader.getAttributeCount() > 0) {
     String key = null;
     String value = null;
     for (int i = 0; i < reader.getAttributeCount(); i++) {
       String attrName = reader.getAttributeLocalName(i);
       String attrValue = reader.getAttributeValue(i);
       if (attrName.equals(Element.NAME.getLocalName())) {
         key = attrValue;
       }
       if (attrName.equals(Element.VALUE.getLocalName())) {
         value = attrValue;
       }
     }
     anObj.addProperty(key, value);
   }
   ignoreTillEnd(reader);
 }
Пример #25
0
 private void ensureIsUpdated() {
   if (updateRequired) {
     updateRequired = false;
     attC = reader.getAttributeCount();
     ensureIndexMapSize(attC);
     for (int i = 0; i < attC; i++) {
       indexToIDMap[i] =
           idResolver.getEID(reader.getAttributeNamespace(i), reader.getAttributeLocalName(i));
     }
   }
 }
Пример #26
0
  private void doParsing(XMLStreamReader parser) throws XMLStreamException {
    for (int i = 0; i < parser.getAttributeCount(); i++) {
      QName attr = parser.getAttributeName(i);
      if (attr.getLocalPart().equals("source")) {
        source = XMLIDREFUtils.parse(parser.getAttributeValue(i));
      } else {
        JAGTLog.exception(
            "Unsupported ", this.getClass().getSimpleName(), " Attr tag: ", attr.getLocalPart());
      }
    }

    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("source")) {
              XMLSource src = new XMLSource();
              src.parse(parser);
              sources.add(src);
            } else if (localName.equals("bind_shape_matrix")) {
              if (bindShapeMatrix != null) {
                JAGTLog.exception(
                    this.getClass().getSimpleName(), " too many bind_shape_matrix tags.");
              }

              bindShapeMatrix = XMLMatrixUtils.readColumnMajor(StAXHelper.parseText(parser));
              // bindShapeMatrix = XMLMatrixUtils.readRowMajor( StAXHelper.parseText( parser ) );
            } else if (localName.equals("joints")) {
              jointsInputs = getJointInputs(parser);
            } else if (localName.equals("vertex_weights")) {
              vertexWeights = new XMLVertexWeights();
              vertexWeights.parse(parser);
            } else {
              JAGTLog.exception(
                  "Unsupported ",
                  this.getClass().getSimpleName(),
                  " Start tag: ",
                  parser.getLocalName());
            }
            break;
          }
        case XMLStreamConstants.END_ELEMENT:
          {
            if (parser.getLocalName().equals("skin")) {
              return;
            }
            break;
          }
      }
    }
  }
Пример #27
0
  private void parseTransaction(final XMLStreamReader reader) {

    assert reader.getAttributeCount() == 2;

    Map<String, String> elementMap = new HashMap<>();

    /* still at start of the transaction.  Need to know when end is reached */
    QName parsingElement = reader.getName();

    String transactionClass = reader.getAttributeValue(0);
    String transactionId = reader.getAttributeValue(1);

    elementMap.put(ID, transactionId);

    try {
      while (reader.hasNext()) {

        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            String element = reader.getLocalName();
            elementMap.put(element.intern(), reader.getElementText());
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getName().equals(parsingElement)) {
              logger.log(Level.FINEST, "Found the end of a Transaction: {0}", transactionId);

              try {
                Transaction transaction = generateTransaction(transactionClass, elementMap);

                if (transaction != null) {
                  Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
                  engine.addTransaction(transaction);
                  logger.finest("Transaction add complete");
                }
              } catch (Exception e) {
                logger.log(Level.SEVERE, "Error importing transaction id: {0}", transactionId);
                logger.log(Level.SEVERE, e.toString(), e);
                throw new RuntimeException(e);
              }
              return;
            }
            break;
          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, "Error importing transaction id: {0}", transactionId);
      logger.log(Level.SEVERE, e.toString(), e);
    }
  }
Пример #28
0
 /**
  * Method to get a HashMap of XML attributes and values
  *
  * @param reader an XMLStreamReader object
  * @return a HashMap of attributes
  */
 private HashMap<QName, String> getAttributes(XMLStreamReader reader) {
   HashMap<QName, String> rawAttributesMap = new HashMap<QName, String>();
   int attributeCount = reader.getAttributeCount();
   for (int i = 0; i < attributeCount; i++) {
     QName attributeQName = reader.getAttributeName(i);
     String attributeValue = reader.getAttributeValue(i);
     if (log.isTraceEnabled())
       log.trace("attributeQName: " + attributeQName + " attributeValue: " + attributeValue);
     rawAttributesMap.put(attributeQName, attributeValue);
   }
   return rawAttributesMap;
 }
Пример #29
0
  void importAccounts(final XMLStreamReader reader) {

    logger.info("Begin Account import");

    try {
      parse:
      while (reader.hasNext()) {
        int event = reader.next();

        switch (event) {
          case XMLStreamConstants.START_ELEMENT:
            if (reader.getAttributeCount() > 0) {
              if (reader.getAttributeValue(0).contains("Account")) {
                logger.finest("Found the start of an Account");
                parseAccount(reader);
              }
            }
            break;
          case XMLStreamConstants.END_ELEMENT:
            if (reader.getLocalName().equals("objects")) {
              logger.finest("Found the end of the object list and accounts");
              break parse;
            }
            break;
          default:
            break;
        }
      }
    } catch (XMLStreamException e) {
      logger.log(Level.SEVERE, e.toString(), e);
    }

    logger.info("Linking accounts");

    Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

    for (Account account : parentMap.keySet()) {
      if (account.getAccountType() != AccountType.ROOT) {
        Account parent = accountMap.get(parentMap.get(account));
        if (!account.getParent().equals(parent)) {
          if (engine.moveAccount(account, parent)) {
            logger.log(
                Level.FINEST,
                "Moving {0} to {1}",
                new Object[] {account.getName(), parent.getName()});
          }
        }
      }
    }

    logger.info("Account import complete");
  }
Пример #30
0
  public static PortComponentRef parse(XMLStreamReader reader) throws XMLStreamException {
    PortComponentRef portComponentRef = new PortComponentRef();

    // Handle attributes
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
      final String value = reader.getAttributeValue(i);
      if (reader.getAttributeNamespace(i) != null) {
        continue;
      }
      final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      switch (attribute) {
        case ID:
          {
            portComponentRef.setId(value);
            break;
          }
        default:
          throw unexpectedAttribute(reader, i);
      }
    }

    // Handle elements
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case SERVICE_ENDPOINT_INTERFACE:
          portComponentRef.setServiceEndpointInterface(getElementText(reader));
          break;
        case ENABLE_MTOM:
          portComponentRef.setEnableMtom(Boolean.valueOf(getElementText(reader)));
          break;
        case MTOM_THRESHOLD:
          portComponentRef.setMtomThreshold(Integer.valueOf(getElementText(reader)));
          break;
        case ADDRESSING:
          portComponentRef.setAddressing(AddressingParser.parse(reader));
          break;
        case RESPECT_BINDING:
          portComponentRef.setRespectBinding(RespectBindingParser.parse(reader));
          break;
        case PORT_COMPONENT_LINK:
          portComponentRef.setPortComponentLink(getElementText(reader));
          break;
        default:
          throw unexpectedElement(reader);
      }
    }

    return portComponentRef;
  }