public void testSendRequest_rpc_nil() throws Exception {
    String requestText =
        "<env:Envelope xmlns:env='"
            + SOAPConstants.URI_NS_SOAP_ENVELOPE
            + "'>"
            + "<env:Body>"
            + "<tns:op xmlns:tns='"
            + BpelConstants.NS_EXAMPLES
            + "' xmlns:xsi='"
            + BpelConstants.NS_XML_SCHEMA_INSTANCE
            + "'>"
            + "  <simplePart xsi:nil='true'>wazabi</simplePart>"
            + "  <complexPart xsi:nil='1'>"
            + "    <b on='true'>true</b>"
            + "    <c name='venus'/>"
            + "    <d amount='20'/>"
            + "    <e>30</e>"
            + "  </complexPart>"
            + "</tns:op>"
            + "</env:Body>"
            + "</env:Envelope>";

    SOAPMessage soapMessage =
        MessageFactory.newInstance()
            .createMessage(null, new ByteArrayInputStream(requestText.getBytes()));

    Connection connection = integrationControl.getJmsConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
      SoapHandler soapHandler = createRpcHandler();
      soapHandler.sendRequest(soapMessage, session, jbpmContext);

      PartnerLinkEntry entry =
          integrationControl.getPartnerLinkEntry(Q_RPC_PORT_TYPE, Q_SERVICE, RPC_PORT);
      MessageConsumer consumer = session.createConsumer(entry.getDestination());
      ObjectMessage message = (ObjectMessage) consumer.receiveNoWait();
      Map requestParts = (Map) message.getObject();

      // simple part
      Element simplePart = (Element) requestParts.get("simplePart");
      assertTrue(
          DatatypeUtil.toBoolean(
              simplePart.getAttributeNS(
                  BpelConstants.NS_XML_SCHEMA_INSTANCE, BpelConstants.ATTR_NIL)));
      assertFalse(simplePart.hasChildNodes());

      // complex part
      Element complexPart = (Element) requestParts.get("complexPart");
      assertTrue(
          DatatypeUtil.toBoolean(
              complexPart.getAttributeNS(
                  BpelConstants.NS_XML_SCHEMA_INSTANCE, BpelConstants.ATTR_NIL)));
      assertFalse(complexPart.hasChildNodes());
    } finally {
      session.close();
    }
  }
    void parsePhase() {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      // Now use the factory to create a DOM parser (a.k.a. a DocumentBuilder)
      DocumentBuilder parser;
      try {
        parser = factory.newDocumentBuilder();
        // Parse the file and build a Document tree to represent its content
        Document document =
            parser.parse(new StringBufferInputStream("<root>" + conf.get("phases") + "</root>"));
        // Ask the document for a list of all phases
        NodeList rows = document.getElementsByTagName(AnalysisProcessorConfiguration.phase);
        int phasenumber = rows.getLength();
        for (int i = 0; i < phasenumber; i++) {
          Node phase = rows.item(i);
          NodeList fields = phase.getChildNodes();
          String phasename = null;
          String stacks = null;
          String funcs = null;
          List<String> functionlist = new ArrayList<String>();
          for (int j = 0; j < fields.getLength(); j++) {
            Node fieldNode = fields.item(j);
            if (!(fieldNode instanceof Element)) continue;
            Element field = (Element) fieldNode;
            if ("phasename".equals(field.getTagName()) && field.hasChildNodes())
              phasename = ((org.w3c.dom.Text) field.getFirstChild()).getData().trim();
            else if ("stack".equals(field.getTagName()) && field.hasChildNodes())
              stacks = ((org.w3c.dom.Text) field.getFirstChild()).getData();
            else if ("functions".equals(field.getTagName()) && field.hasChildNodes())
              funcs = ((org.w3c.dom.Text) field.getFirstChild()).getData();
          }
          if (stacks != null && stacks.length() != 0) stacks = stacks.replace(" ", "");
          else stacks = "";
          phasealias.put(stacks, phasename);

          if (funcs == null) {
            continue;
          }
          for (String func : funcs.split(SEPERATOR_COMMA)) {
            functionlist.add(func);
          }
          this.phases.put(stacks, functionlist);
        }
      } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        log.warn(e);
        e.printStackTrace();
      } catch (SAXException e) {
        // TODO Auto-generated catch block
        log.warn(e);
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        log.warn(e);
        e.printStackTrace();
      }
    }
Exemple #3
0
 void updateProperties() {
   Config config = MCPatcherUtils.config;
   Element mods = config.getMods();
   if (mods == null) {
     return;
   }
   HashMap<String, Element> oldElements = new HashMap<String, Element>();
   while (mods.hasChildNodes()) {
     Node node = mods.getFirstChild();
     if (node instanceof Element) {
       Element element = (Element) node;
       String name = config.getText(element, Config.TAG_NAME);
       if (name != null) {
         oldElements.put(name, element);
       }
     }
     mods.removeChild(node);
   }
   for (Mod mod : modsByIndex) {
     if (mod.internal) {
       continue;
     }
     Element element = oldElements.get(mod.getName());
     if (element == null) {
       defaultModElement(mod);
     } else {
       config.setText(
           element, Config.TAG_ENABLED, Boolean.toString(mod.isEnabled() && mod.okToApply()));
       updateModElement(mod, element);
       mods.appendChild(element);
       oldElements.remove(mod.getName());
     }
   }
 }
Exemple #4
0
 private void updateModElement(Mod mod, Element element) {
   Config config = MCPatcherUtils.config;
   if (mod instanceof ExternalMod) {
     ExternalMod extmod = (ExternalMod) mod;
     config.setText(element, Config.TAG_TYPE, Config.VAL_EXTERNAL_ZIP);
     config.setText(element, Config.TAG_PATH, extmod.zipFile.getName());
     Element files = config.getElement(element, Config.TAG_FILES);
     while (files.hasChildNodes()) {
       files.removeChild(files.getFirstChild());
     }
     for (Map.Entry<String, String> entry : extmod.fileMap.entrySet()) {
       Element fileElem = config.xml.createElement(Config.TAG_FILE);
       Element pathElem = config.xml.createElement(Config.TAG_FROM);
       pathElem.appendChild(config.xml.createTextNode(entry.getValue()));
       fileElem.appendChild(pathElem);
       pathElem = config.xml.createElement(Config.TAG_TO);
       pathElem.appendChild(config.xml.createTextNode(entry.getKey()));
       fileElem.appendChild(pathElem);
       files.appendChild(fileElem);
     }
   } else if (mod.customJar == null) {
     config.setText(element, Config.TAG_TYPE, Config.VAL_BUILTIN);
   } else {
     config.setText(element, Config.TAG_TYPE, Config.VAL_EXTERNAL_JAR);
     config.setText(element, Config.TAG_PATH, mod.customJar.getPath());
     config.setText(element, Config.TAG_CLASS, mod.getClass().getCanonicalName());
   }
 }
Exemple #5
0
 /**
  * Prints the given element.
  *
  * @param element the element to print
  */
 public void print(Element element) {
   // Ensure extra whitespace is not emitted next to a Text node,
   // as that will result in a situation where the restored text data is not the
   // same as the saved text data.
   boolean hasChildren = element.hasChildNodes();
   startTag(element, hasChildren);
   if (hasChildren) {
     tab++;
     boolean prevWasText = false;
     NodeList children = element.getChildNodes();
     for (int i = 0; i < children.getLength(); i++) {
       Node node = children.item(i);
       if (node instanceof Element) {
         if (!prevWasText) {
           println();
           printTabulation();
         }
         print((Element) children.item(i));
         prevWasText = false;
       } else if (node instanceof Text) {
         print(getEscaped(node.getNodeValue()));
         prevWasText = true;
       }
     }
     tab--;
     if (!prevWasText) {
       println();
       printTabulation();
     }
     endTag(element);
   }
 }
Exemple #6
0
 /**
  * Child Node List 를 얻어 온다.
  *
  * @param element parent Element
  * @return child Node List;
  */
 public NodeList getChildNodes(Element element) {
   NodeList nodeList = null;
   if (element.hasChildNodes()) {
     nodeList = element.getChildNodes();
   }
   return nodeList;
 }
 public void leave(Element element) {
   String name = element.getTagName();
   if (element.hasChildNodes()) {
     if (needIndentInClosing(element)) {
       indentation.pop();
       buffer.append(indentation.peek());
     } else if (asBuilder) {
       indentation.pop();
     }
     buffer.append("</" + name + ">");
     if (needBreakInClosing()) {
       buffer.append("\n");
     }
     return;
   }
   // no child, but HTML might need a closing tag.
   if (asHtml || noEmpty) {
     if (!isEmpty(name) && noEmpty) {
       buffer.append("</" + name + ">");
     }
   }
   if (needBreakInClosing()) {
     indentation.pop();
     buffer.append("\n");
   }
 }
  private void encodeElements(String encoding, Element element, boolean applyBase64) {
    if (element.hasChildNodes()) {

      NodeList childNodes = element.getChildNodes();

      for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeType() == node.ELEMENT_NODE) {
          this.encodeElements(encoding, (Element) node, applyBase64);
        } else if (node.getNodeType() == node.TEXT_NODE) {
          if (applyBase64) {
            try {
              byte[] bytes = base64.decode(node.getNodeValue());
              String decodedString = new String(bytes, encoding);
              node.setNodeValue(decodedString);
            } catch (Exception exp) {
            }
          } else {
            try {
              byte[] bytes = node.getNodeValue().getBytes(encoding);
              String decodedString = new String(bytes);
              node.setNodeValue(decodedString);
            } catch (Exception epx) {
            }
          }
        }
      }
    }
  }
  @Override
  public void relink_namespace(ThreadContext context) {
    Element e = (Element) node;

    e.getOwnerDocument().renameNode(e, e.lookupNamespaceURI(e.getPrefix()), e.getNodeName());

    if (e.hasAttributes()) {
      NamedNodeMap attrs = e.getAttributes();

      for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        String nsUri = "";
        String prefix = attr.getPrefix();
        String nodeName = attr.getNodeName();
        if ("xml".equals(prefix)) {
          nsUri = "http://www.w3.org/XML/1998/namespace";
        } else if ("xmlns".equals(prefix) || nodeName.equals("xmlns")) {
          nsUri = "http://www.w3.org/2000/xmlns/";
        } else {
          nsUri = attr.lookupNamespaceURI(nodeName);
        }

        e.getOwnerDocument().renameNode(attr, nsUri, nodeName);
      }
    }

    if (e.hasChildNodes()) {
      ((XmlNodeSet) children(context)).relink_namespace(context);
    }
  }
  public Document nextTableRow(String atts) {

    // peek at current cell - stay with it IF
    //  + it's the first cell in the row
    //  + the current cursor points at the first child (a block)
    //  + the block pointed by cursor is empty
    Element cell = peek("table-cell", "nextTableRow() is not applicable outside enclosing table");
    if (cell.getPreviousSibling() == null
        && cursor == cell.getFirstChild()
        && !cursor.hasChildNodes()) {
      attributes((Element) cell.getParentNode(), atts);
      return this;
    }

    // pop to table
    pop("table", "nextTableRow() is not applicable outside enclosing table");
    Element table = cursor;

    // last child is already table-body?
    if (table.getLastChild().getNodeName().equals("table-body")) {
      cursor = (Element) table.getLastChild();
    } else {
      push("table-body");
    }

    // add row
    push("table-row", atts);

    // add cell
    push("table-cell", "border=" + table.getAttribute("border"));
    push("block");

    // done
    return this;
  }
  /* (non-Javadoc)
   * @see org.eclipse.jst.pagedesigner.converter.AbstractTagConverter#doConvertRefresh()
   */
  protected Element doConvertRefresh() {
    Element hostEle = getHostElement();

    Element labelEle = createElement(IHTMLConstants.TAG_LABEL);

    JSFConverterUtil.copyAllAttributes(hostEle, labelEle, null);

    // If the "styleClass" attribute is present,
    // render its value as the value of the "class" attribute.
    JSFConverterUtil.copyAttribute(
        hostEle, IJSFConstants.ATTR_STYLECLASS, labelEle, IHTMLConstants.ATTR_CLASS);
    labelEle.removeAttribute(IJSFConstants.ATTR_STYLECLASS);

    //        String value = getValue(hostEle);
    //        Text	textNode = createText(value);
    //        labelEle.appendChild(textNode);

    int index = 0;
    Node child = hostEle.getFirstChild();
    if (hostEle.hasChildNodes()) {
      for (; child != null; child = child.getNextSibling()) {
        if (!shouldIgnore(child)) {
          if (child instanceof Element && JSFDOMUtil.isUIParameter((Element) child)) {
            // skip
          } else {
            addChild(child, new ConvertPosition(labelEle, index++));
          }
        }
      }
    } else {
      labelEle.appendChild(createText(getDefaultValue()));
    }

    return labelEle;
  }
 public static void copyChildNodes(SOAPElement target, Element source) throws SOAPException {
   // easy way out: no child nodes
   if (!source.hasChildNodes()) return;
   final boolean traceEnabled = log.isTraceEnabled();
   // traverse child nodes
   for (Node child = source.getFirstChild(); child != null; child = child.getNextSibling()) {
     switch (child.getNodeType()) {
       case Node.ELEMENT_NODE:
         {
           copyChildElement(target, (Element) child);
           break;
         }
       case Node.TEXT_NODE:
       case Node.CDATA_SECTION_NODE:
         {
           String text = child.getNodeValue();
           // drop whitespace-only text nodes
           if (!StringUtils.isWhitespace(text)) {
             target.addTextNode(text);
             if (traceEnabled) log.trace("added text node: " + text);
           }
           break;
         }
       default:
         log.debug("discarding child node: " + child);
     }
   }
 }
  public void testSendRequest_rpc() throws Exception {
    String requestText =
        "<env:Envelope xmlns:env='"
            + SOAPConstants.URI_NS_SOAP_ENVELOPE
            + "'>"
            + "<env:Body>"
            + "<tns:op xmlns:tns='"
            + BpelConstants.NS_EXAMPLES
            + "'>"
            + "  <simplePart>wazabi</simplePart>"
            + "  <complexPart>"
            + "    <b on='true'>true</b>"
            + "    <c name='venus'/>"
            + "    <d amount='20'/>"
            + "    <e>30</e>"
            + "  </complexPart>"
            + "</tns:op>"
            + "</env:Body>"
            + "</env:Envelope>";
    SOAPMessage soapMessage =
        MessageFactory.newInstance()
            .createMessage(null, new ByteArrayInputStream(requestText.getBytes()));

    Connection connection = integrationControl.getJmsConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
      SoapHandler soapHandler = createRpcHandler();
      soapHandler.sendRequest(soapMessage, session, jbpmContext);

      PartnerLinkEntry entry =
          integrationControl.getPartnerLinkEntry(Q_RPC_PORT_TYPE, Q_SERVICE, RPC_PORT);
      MessageConsumer consumer = session.createConsumer(entry.getDestination());
      ObjectMessage message = (ObjectMessage) consumer.receiveNoWait();
      Map requestParts = (Map) message.getObject();

      // simple part
      Element simplePart = (Element) requestParts.get("simplePart");
      assertEquals("simplePart", simplePart.getLocalName());
      assertNull(simplePart.getNamespaceURI());
      assertEquals("wazabi", DatatypeUtil.toString(simplePart));

      // complex part
      Element complexPart = (Element) requestParts.get("complexPart");
      assertEquals("complexPart", complexPart.getLocalName());
      assertNull(complexPart.getNamespaceURI());
      assertTrue(complexPart.hasChildNodes());

      // message properties
      assertEquals(
          rpcPartnerLinkId, message.getLongProperty(IntegrationConstants.PARTNER_LINK_ID_PROP));
      assertEquals("op", message.getStringProperty(IntegrationConstants.OPERATION_NAME_PROP));
      assertEquals("venus", message.getStringProperty("nameProperty"));
      assertEquals("30", message.getStringProperty("idProperty"));
    } finally {
      session.close();
    }
  }
 private boolean needBreakInOpening(Element element) {
   if (fragment) return false;
   if (format) return true;
   if (asBuilder
       && element.getFirstChild() != null
       && element.getFirstChild().getNodeType() == Node.ELEMENT_NODE) return true;
   if (format && element.getNextSibling() == null && element.hasChildNodes()) return true;
   return false;
 }
Exemple #15
0
 public static Element element(Element element) {
   if (element != null && element.hasChildNodes()) {
     for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
       if (child.getNodeType() == Node.ELEMENT_NODE) {
         return (Element) child;
       }
     }
   }
   return null;
 }
  // Canibalized from FileSystemAccess <code>Configuration.loadResource()</code>.
  private static void parseDocument(Configuration conf, Document doc) throws IOException {
    try {
      Element root = doc.getDocumentElement();
      if (!"configuration".equals(root.getTagName())) {
        throw new IOException("bad conf file: top-level element not <configuration>");
      }
      NodeList props = root.getChildNodes();
      for (int i = 0; i < props.getLength(); i++) {
        Node propNode = props.item(i);
        if (!(propNode instanceof Element)) {
          continue;
        }
        Element prop = (Element) propNode;
        if (!"property".equals(prop.getTagName())) {
          throw new IOException("bad conf file: element not <property>");
        }
        NodeList fields = prop.getChildNodes();
        String attr = null;
        String value = null;
        for (int j = 0; j < fields.getLength(); j++) {
          Node fieldNode = fields.item(j);
          if (!(fieldNode instanceof Element)) {
            continue;
          }
          Element field = (Element) fieldNode;
          if ("name".equals(field.getTagName()) && field.hasChildNodes()) {
            attr = ((Text) field.getFirstChild()).getData().trim();
          }
          if ("value".equals(field.getTagName()) && field.hasChildNodes()) {
            value = ((Text) field.getFirstChild()).getData();
          }
        }

        if (attr != null && value != null) {
          conf.set(attr, value);
        }
      }

    } catch (DOMException e) {
      throw new IOException(e);
    }
  }
Exemple #17
0
  public static List<Node> contents(Element element) {
    if (element == null || !element.hasChildNodes()) {
      return Collections.emptyList();
    }

    List<Node> contents = new ArrayList<Node>();
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
      contents.add(child);
    }
    return contents;
  }
 private Node getBudgetElement(Element xmlElement) throws Exception {
   Node budgetNode = (Node) xmlElement;
   NodeList budgetAttachments =
       XPathAPI.selectNodeList(xmlElement, "//*[local-name(.) = 'BudgetAttachments']");
   if (budgetAttachments != null && budgetAttachments.getLength() > 0) {
     Element budgetAttachment = (Element) budgetAttachments.item(0);
     if (budgetAttachment.hasChildNodes()) {
       budgetNode = budgetAttachment.getFirstChild();
     }
   }
   return budgetNode;
 }
Exemple #19
0
  @Override
  public RMAImporter createRGGElement(Element element, RGG rggInstance) {
    if (element.getNodeType() != Element.ELEMENT_NODE) {
      throw new IllegalArgumentException("elements node type must be ELEMENT_NODE");
      /**
       * **************** initialize and set attributes values *************************************
       */
    }

    String var = element.getAttribute(RGG.getConfiguration().getString("VAR"));
    String colspan = element.getAttribute(RGG.getConfiguration().getString("COLUMN-SPAN"));
    String id = element.getAttribute(RGG.getConfiguration().getString("ID"));
    String othercolumns = element.getAttribute(RGG.getConfiguration().getString("OTHER-COLUMNS"));
    /**
     * ********************************************************************************************
     */
    RMAImporter rMAImporter = new RMAImporter();
    VMAImporter vMAImporter = null;
    if (StringUtils.isNotBlank(othercolumns)) {
      vMAImporter = new VMAImporter(rggInstance, StringUtils.split(othercolumns, ','));
    } else {
      vMAImporter = new VMAImporter(rggInstance, null);
    }

    if (StringUtils.isNotBlank(var)) {
      rMAImporter.setVar(var);
    }

    if (StringUtils.isNotBlank(colspan)) {
      if (StringUtils.isNumeric(colspan)) {
        vMAImporter.setColumnSpan(Integer.parseInt(colspan));
      } else if (StringUtils.equals(colspan, RGG.getConfiguration().getString("FULL-SPAN"))) {
        vMAImporter.setColumnSpan(LayoutInfo.FULL_SPAN);
      } else {
        throw new NumberFormatException(
            RGG.getConfiguration().getString("COLUMN-SPAN")
                + " seems not to be a number: "
                + colspan
                + "nor a known keyword!");
      }
    }

    if (StringUtils.isNotBlank(id)) {
      rggInstance.addObject(id, vMAImporter);
    }

    rMAImporter.setVMAImporter(vMAImporter);

    if (element.hasChildNodes()) { // it can only be <iport>
      setInputPorts(rMAImporter, element);
    }
    return rMAImporter;
  }
 protected boolean ValidateXMLDocument(Element eElement, ChannelMode mode) throws Exception {
   if (mode == ChannelMode.Partially) {
     if (eElement.hasChildNodes()) {
       PrintConsole.printErr(
           TAG
               + " must have child node. the following template may help you "
               + "\n <Channels Mode=\"Partially\"> \n \t <Add Value=\"1\" />\n\t<Add Value=\"2\" /> \n </Channels>");
       System.exit(0);
     }
   }
   return true;
 }
Exemple #21
0
  /**
   * This is the work horse for {@link #circumventBug2650}.
   *
   * @param node
   * @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">Namespace axis resolution
   *     is not XPath compliant </A>
   */
  private static void circumventBug2650internal(Node node) {
    Node parent = null;
    Node sibling = null;
    final String namespaceNs = Constants.NamespaceSpecNS;
    do {
      switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
          Element element = (Element) node;
          if (!element.hasChildNodes()) break;
          if (element.hasAttributes()) {
            NamedNodeMap attributes = element.getAttributes();
            int attributesLength = attributes.getLength();

            for (Node child = element.getFirstChild();
                child != null;
                child = child.getNextSibling()) {

              if (child.getNodeType() != Node.ELEMENT_NODE) {
                continue;
              }
              Element childElement = (Element) child;

              for (int i = 0; i < attributesLength; i++) {
                Attr currentAttr = (Attr) attributes.item(i);
                if (namespaceNs != currentAttr.getNamespaceURI()) continue;
                if (childElement.hasAttributeNS(namespaceNs, currentAttr.getLocalName())) {
                  continue;
                }
                childElement.setAttributeNS(
                    namespaceNs, currentAttr.getName(), currentAttr.getNodeValue());
              }
            }
          }
        case Node.ENTITY_REFERENCE_NODE:
        case Node.DOCUMENT_NODE:
          parent = node;
          sibling = node.getFirstChild();
          break;
      }
      while ((sibling == null) && (parent != null)) {
        sibling = parent.getNextSibling();
        parent = parent.getParentNode();
      }
      ;
      if (sibling == null) {
        return;
      }

      node = sibling;
      sibling = node.getNextSibling();
    } while (true);
  }
 public static Long genLongValue(Element element) throws BusinessConfigurationException {
   if (null == element || !element.hasChildNodes()) {
     return null;
   }
   String s = ((Text) (element.getFirstChild())).getData().trim();
   try {
     long l = Long.valueOf(s);
     return l;
   } catch (NumberFormatException ex) {
     throw new BusinessConfigurationException(
         "Bad conf file: " + s + " is not a valid long value for <" + element.getTagName() + ">");
   }
 }
Exemple #23
0
  public static List<Element> elements(Element element) {
    if (element == null || !element.hasChildNodes()) {
      return Collections.emptyList();
    }

    List<Element> elements = new ArrayList<Element>();
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        elements.add((Element) child);
      }
    }
    return elements;
  }
Exemple #24
0
  public static Element element(Element element, String tagName, Parse parse) {
    if (element != null && element.hasChildNodes()) {
      for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE && tagName.equals(child.getLocalName())) {
          return (Element) child;
        }
      }
    }

    if (parse != null) {
      parse.addProblem("missing element " + tagName, element);
    }
    return null;
  }
Exemple #25
0
 /**
  * adds a tag to the existing word. Only adds the current tag and not its children
  *
  * @param tag
  */
 public void addTag(Element tag) {
   Element e = XMLParser.xmlDocument.createElement(tag.getNodeName());
   NamedNodeMap attributes = tag.getAttributes();
   for (int i = 0; i < attributes.getLength(); i++) {
     Attr attribute = (Attr) attributes.item(i);
     e.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
   }
   tags.add(e);
   if (tag.hasChildNodes()) {
     if (tag.getFirstChild().getNodeType() == Element.ELEMENT_NODE) {
       addTag((Element) tag.getFirstChild());
     }
   }
 }
  private void recordNodesInfo(Element currentElement) {
    NodeList childrenList = currentElement.getChildNodes();
    for (int i = 0; i < childrenList.getLength(); i++) {
      Node child = childrenList.item(i);
      if (child instanceof Element) {
        Element childElement = (Element) child;

        String id = childElement.getAttribute("id");
        String name = childElement.getAttribute("name");

        if (childElement.getNodeName().equals("participantSet")
            || childElement.getNodeName().equals("associationEdge")
            || childElement.getNodeName().equals("sendOrReceiveActivity")
            || childElement.getNodeName().equals("messageLink")
            || childElement.getNodeName().equals("process")) {

          nodeMapForTopology.put(id, new Object[] {childElement.getNodeName(), childElement});
        }
        // extended by Changhua Li
        // to store the process and its children
        if (childElement.getNodeName().equals("process")) {
          processIdMapForTopology.put(id, "process");
          if (childElement.hasChildNodes()) {
            NodeList childrenListOfProcess = childElement.getChildNodes();
            for (int j = 0; j < childrenListOfProcess.getLength(); j++) {
              Node childOfProcess = childrenListOfProcess.item(j);
              if (childOfProcess instanceof Element) {
                Element childElementOfProcess = (Element) childOfProcess;
                String childId = childElementOfProcess.getAttribute("childId");
                child2processMap.put(childId, name);
              }
            }
          }
        }
        // extended end

        if (childElement.getNodeName().equals("sendOrReceiveActivity")) {
          recordSendActivityOfMessageLink(childElement);
        }

        if (childElement.getNodeName().equals("messageLink")) {
          recordReceiveActivityOfMessageLink(childElement);
        }

        if (childElement.getNodeName().equals("associationEdge")) {
          recordTargetOfAssociationEdge(childElement);
        }
      }
    }
  }
  private void serialize(Element e, XmlSerializer s, int depth, String spaces) throws Exception {

    String name = e.getTagName();

    writeSpace(s, depth, spaces);

    s.startTag("", name);

    if (e.hasAttributes()) {
      NamedNodeMap nm = e.getAttributes();
      for (int i = 0; i < nm.getLength(); i++) {
        Attr attr = (Attr) nm.item(i);
        s.attribute("", attr.getName(), attr.getValue());
      }
    }

    if (e.hasChildNodes()) {

      NodeList nl = e.getChildNodes();

      int elements = 0;

      for (int i = 0; i < nl.getLength(); i++) {

        Node n = nl.item(i);

        short type = n.getNodeType();

        switch (type) {
          case Node.ELEMENT_NODE:
            serialize((Element) n, s, depth + 1, spaces);
            elements++;
            break;
          case Node.TEXT_NODE:
            s.text(text(n));
            break;
          case Node.CDATA_SECTION_NODE:
            s.cdsect(text(n));
            break;
        }
      }

      if (elements > 0) {
        writeSpace(s, depth, spaces);
      }
    }

    s.endTag("", name);
  }
Exemple #28
0
  public static List<Element> elements(Element element, Set<String> allowedTagNames) {
    if (element == null || !element.hasChildNodes()) {
      return Collections.emptyList();
    }

    List<Element> elements = new ArrayList<Element>();
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element childElement = (Element) child;
        if (allowedTagNames.contains(child.getLocalName())) {
          elements.add(childElement);
        }
      }
    }
    return elements;
  }
Exemple #29
0
  public static List<Element> elements(Element element, String tagName) {
    if (element == null || !element.hasChildNodes()) {
      return Collections.emptyList();
    }

    List<Element> elements = new ArrayList<Element>();
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element childElement = (Element) child;
        String childTagName = childElement.getLocalName();

        if (tagName.equals(childTagName)) elements.add(childElement);
      }
    }
    return elements;
  }
Exemple #30
0
  public static List<Element> elements(Element element, String namespace, String localName) {
    if (element == null || !element.hasChildNodes()) {
      return Collections.emptyList();
    }

    List<Element> elements = new ArrayList<Element>();
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
      String childNamespace = element.getNamespaceURI();
      if (child.getNodeType() == Node.ELEMENT_NODE
          && (namespace != null ? namespace.equals(childNamespace) : childNamespace == null)
          && localName.equals(element.getLocalName())) {
        elements.add((Element) child);
      }
    }
    return elements;
  }