示例#1
1
  /**
   * Identifies WSDL documents from the {@link DOMForest}. Also identifies the root wsdl document.
   */
  private void identifyRootWsdls() {
    for (String location : rootDocuments) {
      Document doc = get(location);
      if (doc != null) {
        Element definition = doc.getDocumentElement();
        if (definition == null
            || definition.getLocalName() == null
            || definition.getNamespaceURI() == null) continue;
        if (definition.getNamespaceURI().equals(WSDLConstants.NS_WSDL)
            && definition.getLocalName().equals("definitions")) {
          rootWsdls.add(location);
          // set the root wsdl at this point. Root wsdl is one which has wsdl:service in it
          NodeList nl = definition.getElementsByTagNameNS(WSDLConstants.NS_WSDL, "service");

          // TODO:what if there are more than one wsdl with wsdl:service element. Probably such
          // cases
          // are rare and we will take any one of them, this logic should still work
          if (nl.getLength() > 0) rootWSDL = location;
        }
      }
    }
    // no wsdl with wsdl:service found, throw error
    if (rootWSDL == null) {
      StringBuilder strbuf = new StringBuilder();
      for (String str : rootWsdls) {
        strbuf.append(str);
        strbuf.append('\n');
      }
      errorReceiver.error(null, WsdlMessages.FAILED_NOSERVICE(strbuf.toString()));
    }
  }
  @Test
  public void testNamespaceFilter() throws Exception {
    // try to filter on an existing namespace
    Document dom =
        getAsDOM(
            BASEPATH + "?request=GetCapabilities&service=WCS&acceptversions=1.1.1&namespace=wcs");
    Element e = dom.getDocumentElement();
    assertEquals("Capabilities", e.getLocalName());
    XpathEngine xpath = XMLUnit.newXpathEngine();
    assertTrue(
        xpath
                .getMatchingNodes("//wcs:CoverageSummary/ows:Title[starts-with(., wcs)]", dom)
                .getLength()
            > 0);
    assertEquals(
        0,
        xpath
            .getMatchingNodes("//wcs:CoverageSummary/ows:Title[not(starts-with(., wcs))]", dom)
            .getLength());

    // now filter on a missing one
    dom =
        getAsDOM(
            BASEPATH
                + "?request=GetCapabilities&service=WCS&acceptversions=1.1.1&namespace=NoThere");
    e = dom.getDocumentElement();
    assertEquals("Capabilities", e.getLocalName());
    assertEquals(0, xpath.getMatchingNodes("//wcs:CoverageSummary", dom).getLength());
  }
  private void writeElement(OutputNode thisNode, Element anyElement) throws Exception {
    thisNode.setName(anyElement.getLocalName());
    thisNode.getAttributes().remove("class");
    if (!getCurrentNamespace(thisNode).equals(anyElement.getNamespaceURI().toString())) {
      thisNode.setAttribute("xmlns", anyElement.getNamespaceURI().toString());
      thisNode.setReference(anyElement.getNamespaceURI().toString());
    }
    NodeList childList = anyElement.getChildNodes();
    boolean childElements = false;
    for (int i = 0; i < childList.getLength(); i++) {
      Node n = childList.item(i);
      if (n instanceof Attr) {
        thisNode.setAttribute(n.getNodeName(), n.getNodeValue());
      }
      if (n instanceof Element) {
        childElements = true;
        Element e = (Element) n;
        writeElement(thisNode.getChild(e.getLocalName()), e);
      }
    }
    if (anyElement.getNodeValue() != null) {
      thisNode.setValue(anyElement.getNodeValue());
    }

    // added to work with harmony ElementImpl... getNodeValue doesn't seem to work!!!
    if (!childElements && anyElement.getTextContent() != null) {
      thisNode.setValue(anyElement.getTextContent());
    }
  }
示例#4
0
  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();
    }
  }
示例#5
0
  public static boolean matchesTagNS(Element e, String tag, String nsURI) {
    try {
      return e.getLocalName().equals(tag) && e.getNamespaceURI().equals(nsURI);
    } catch (NullPointerException npe) {

      // localname not null since parsing would fail before here
      throw new WSDLParseException("null.namespace.found", e.getLocalName());
    }
  }
示例#6
0
  protected void start(Element element, XSDElementDeclaration declaration) throws SAXException {
    String uri = element.getNamespaceURI();
    String local = element.getLocalName();

    String qName = element.getLocalName();

    NamespaceSupport namespaces = this.namespaces;

    // declaration == null -> gml3 envelope encoding test failing
    // declaration.getSchema() == null -> wfs 2.0 feature collection encoding test failing
    if (namespaceAware
        && (declaration == null
            || declaration.isGlobal()
            || declaration.getSchema() == null
            || declaration.getSchema().getElementFormDefault() == XSDForm.QUALIFIED_LITERAL)) {
      uri = (uri != null) ? uri : namespaces.getURI("");
      qName = namespaces.getPrefix(uri) + ":" + qName;
    } else {
      uri = "";
    }

    DOMAttributes atts = new DOMAttributes(element.getAttributes(), namespaces);
    serializer.startElement(uri, local, qName, atts);

    // write out any text
    for (int i = 0; i < element.getChildNodes().getLength(); i++) {
      Node node = (Node) element.getChildNodes().item(i);

      if (node instanceof Text) {
        char[] ch = ((Text) node).getData().toCharArray();
        serializer.characters(ch, 0, ch.length);
      }
    }

    // write out any child elements
    for (int i = 0; i < element.getChildNodes().getLength(); i++) {
      Node node = (Node) element.getChildNodes().item(i);

      if (node instanceof Element) {
        Element child = (Element) node;
        start(
            child,
            Schemas.getChildElementDeclaration(
                declaration, new QName(child.getNamespaceURI(), child.getNodeName())));
        end(child);
      }
    }

    // push a new context for children, declaring the default prefix to be the one of this
    // element
    this.namespaces.pushContext();

    if (uri != null) {
      this.namespaces.declarePrefix("", uri);
    }
  }
示例#7
0
  protected void end(Element element) throws SAXException {
    // push off last context
    namespaces.popContext();

    String uri = element.getNamespaceURI();
    String local = element.getLocalName();

    String qName = element.getLocalName();

    if ((element.getPrefix() != null) && !"".equals(element.getPrefix())) {
      qName = element.getPrefix() + ":" + qName;
    }

    serializer.endElement(uri, local, qName);
  }
  private boolean isAIMAnnotation(XmlObject file) {
    Document document = file.getDocument();
    Element documentElement = document.getDocumentElement();

    System.out.println(
        "isAim:" + documentElement.getLocalName() + "," + documentElement.getNamespaceURI());

    return documentElement.getLocalName().equals("ImageAnnotation")
        && (documentElement
                .getNamespaceURI()
                .equals("gme://caCORE.caCORE/3.2/edu.northwestern.radiology.AIM")
            || documentElement
                .getNamespaceURI()
                .equals("gme://caCORE/3.2/edu.northwestern.radiology.AIM"));
  }
示例#9
0
  private static String compareElements(String path, Element e1, Element e2) {
    if (!e1.getNamespaceURI().equals(e2.getNamespaceURI()))
      return "Namespaces differ at "
          + path
          + ": "
          + e1.getNamespaceURI()
          + "/"
          + e2.getNamespaceURI();
    if (!e1.getLocalName().equals(e2.getLocalName()))
      return "Names differ at " + path + ": " + e1.getLocalName() + "/" + e2.getLocalName();
    path = path + "/" + e1.getLocalName();
    String s = compareAttributes(path, e1.getAttributes(), e2.getAttributes());
    if (!Utilities.noString(s)) return s;
    s = compareAttributes(path, e2.getAttributes(), e1.getAttributes());
    if (!Utilities.noString(s)) return s;

    Node c1 = e1.getFirstChild();
    Node c2 = e2.getFirstChild();
    c1 = skipBlankText(c1);
    c2 = skipBlankText(c2);
    while (c1 != null && c2 != null) {
      if (c1.getNodeType() != c2.getNodeType())
        return "node type mismatch in children of "
            + path
            + ": "
            + Integer.toString(e1.getNodeType())
            + "/"
            + Integer.toString(e2.getNodeType());
      if (c1.getNodeType() == Node.TEXT_NODE) {
        if (!normalise(c1.getTextContent()).equals(normalise(c2.getTextContent())))
          return "Text differs at "
              + path
              + ": "
              + normalise(c1.getTextContent())
              + "/"
              + normalise(c2.getTextContent());
      } else if (c1.getNodeType() == Node.ELEMENT_NODE) {
        s = compareElements(path, (Element) c1, (Element) c2);
        if (!Utilities.noString(s)) return s;
      }

      c1 = skipBlankText(c1.getNextSibling());
      c2 = skipBlankText(c2.getNextSibling());
    }
    if (c1 != null) return "node mismatch - more nodes in source in children of " + path;
    if (c2 != null) return "node mismatch - more nodes in target in children of " + path;
    return null;
  }
示例#10
0
  /**
   * Constructor that uses DOM Element
   *
   * @param element the DOM representation of security token.
   * @throws com.sun.identity.wss.security.SecurityException
   */
  public FAMSecurityToken(Element element) throws SecurityException {
    if (element == null) {
      throw new SecurityException(WSSUtils.bundle.getString("nullInput"));
    }

    String localName = element.getLocalName();
    if (!"FAMToken".equals(localName)) {
      throw new SecurityException(WSSUtils.bundle.getString("invalidElement"));
    }

    NodeList nl = element.getChildNodes();
    int length = nl.getLength();
    if (length == 0) {
      throw new SecurityException(WSSUtils.bundle.getString("invalidElement"));
    }

    for (int i = 0; i < length; i++) {
      Node child = (Node) nl.item(i);
      if (child.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }

      String childName = child.getLocalName();
      if (childName.equals("TokenValue")) {
        tokenID = XMLUtils.getElementValue((Element) child);
      } else if (childName.equals("AppTokenValue")) {
        appTokenID = XMLUtils.getElementValue((Element) child);
      } else if (childName.equals("TokenType")) {
        tokenType = XMLUtils.getElementValue((Element) child);
      }
    }
  }
 /**
  * Constructor creates <code>SPProvidedNameIdentifier</code> object from Document Element.
  *
  * @param spProvidedNameIdentifierElement the Document Element.
  * @throws FSMsgException on errors.
  */
 public SPProvidedNameIdentifier(Element spProvidedNameIdentifierElement) throws FSMsgException {
   Element elt = (Element) spProvidedNameIdentifierElement;
   String eltName = elt.getLocalName();
   if (eltName == null) {
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("SPProvidedNameIdentifier(Element): " + "local name missing");
     }
     throw new FSMsgException("nullInput", null);
   }
   if (!(eltName.equals("SPProvidedNameIdentifier"))) {
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("SPProvidedNameIdentifier(Element: " + "invalid root element");
     }
     throw new FSMsgException("invalidElement", null);
   }
   String read = elt.getAttribute("NameQualifier");
   if (read != null) {
     setNameQualifier(read);
   }
   read = elt.getAttribute("Format");
   if (read != null) {
     setFormat(read);
   }
   read = XMLUtils.getElementValue(elt);
   if ((read == null) || (read.length() == 0)) {
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("SPProvidedNameIdentifier(Element:  " + "null input specified");
     }
     throw new FSMsgException("nullInput", null);
   } else {
     setName(read);
   }
 }
示例#12
0
  protected final void assertName(final QName expected, final Element element) {
    String localName = element.getLocalName();
    String ns = element.getNamespaceURI();

    assertEquals(expected.getNamespaceURI(), ns);
    assertEquals(expected.getLocalPart(), localName);
  }
示例#13
0
  public static Element[] filterChildElements(Element parent, String ns, String lname) {
    /*
    way too noisy
            if (LOGGER.isDebugEnabled()) {
                StringBuilder buf = new StringBuilder(100);
                buf.append("XmlaUtil.filterChildElements: ");
                buf.append(" ns=\"");
                buf.append(ns);
                buf.append("\", lname=\"");
                buf.append(lname);
                buf.append("\"");
                LOGGER.debug(buf.toString());
            }
    */

    List<Element> elems = new ArrayList<Element>();
    NodeList nlst = parent.getChildNodes();
    for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) {
      Node n = nlst.item(i);
      if (n instanceof Element) {
        Element e = (Element) n;
        if ((ns == null || ns.equals(e.getNamespaceURI()))
            && (lname == null || lname.equals(e.getLocalName()))) {
          elems.add(e);
        }
      }
    }
    return elems.toArray(new Element[elems.size()]);
  }
示例#14
0
  /** Moves JAXWS customizations under their respective target nodes. */
  private void move(Element bindings, Map<Element, Node> targetNodes) {
    Node target = targetNodes.get(bindings);
    if (target == null)
      // this must be the result of an error on the external binding.
      // recover from the error by ignoring this node
      return;

    Element[] children = DOMUtils.getChildElements(bindings);

    for (Element item : children) {
      if ("bindings".equals(item.getLocalName())) {
        // process child <jaxws:bindings> recursively
        move(item, targetNodes);
      } else if (isGlobalBinding(item)) {
        target = targetNodes.get(item);
        moveUnder(item, (Element) target);
      } else {
        if (!(target instanceof Element)) {
          return; // abort
        }
        // move this node under the target
        moveUnder(item, (Element) target);
      }
    }
  }
示例#15
0
 @Override
 public final Element put(final Element parentElement, final Object value) {
   Element newElement = document.createElementNS(XMLNS_ITEM, parentElement.getLocalName());
   if (value == null) {
     newElement.setAttribute("isNull", "yes");
     return newElement;
   }
   Map<String, Object> attributes = XmlHelper.extractAttributes(value);
   for (String key : attributes.keySet()) {
     try {
       newElement.setAttribute(key, attributes.get(key).toString());
     } catch (Exception e) {
       // XXX: ignore exceptions silenty
     }
   }
   Map<String, Collection<?>> collections = XmlHelper.extractCollections(value);
   for (String key : collections.keySet()) {
     try {
       Element container = document.createElementNS(XMLNS_DATA, key);
       newElement.appendChild(container);
       for (Object item : collections.get(key)) {
         put(container, item);
       }
     } catch (Exception e) {
       // XXX: ignore exceptions silenty
     }
   }
   newElement.appendChild(document.createTextNode(value.toString()));
   parentElement.appendChild(newElement);
   return newElement;
 }
  public static AdhocQueryType getAdhocQuery(Subscribe nhinSubscribe) {
    AdhocQueryType adhocQuery = null;
    List<Object> any = nhinSubscribe.getAny();

    for (Object anyItem : any) {
      LOG.debug(
          "SubscribeTransformHelper.getAdhocQuery - type of any in list: "
              + anyItem.getClass().getName());
      if (anyItem instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType) {
        LOG.debug("Any item was oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType");
        adhocQuery = (AdhocQueryType) anyItem;
      } else if (anyItem instanceof JAXBElement) {
        LOG.debug("Any item was JAXBElement");
        if (((JAXBElement) anyItem).getValue() instanceof AdhocQueryType) {
          LOG.debug("Any item - JAXBElement value was AdhocQueryType");
          adhocQuery = (AdhocQueryType) ((JAXBElement) anyItem).getValue();
        }
      } else if (anyItem instanceof Element) {
        LOG.debug("Any item was Element");
        Element element = (Element) anyItem;
        LOG.debug(
            "SubscribeTransformHelper.getAdhocQuery - element name of any in list: "
                + element.getLocalName());
        adhocQuery = unmarshalAdhocQuery(element);
      } else {
        LOG.debug("Any type did not fit any expected value");
      }
    }
    return adhocQuery;
  }
 /**
  * Creates a <code>DOMPGPData</code> from an element.
  *
  * @param pdElem a PGPData element
  */
 public DOMPGPData(Element pdElem) throws MarshalException {
   // get all children nodes
   byte[] keyId = null;
   byte[] keyPacket = null;
   NodeList nl = pdElem.getChildNodes();
   int length = nl.getLength();
   List other = new ArrayList(length);
   for (int x = 0; x < length; x++) {
     Node n = nl.item(x);
     if (n.getNodeType() == Node.ELEMENT_NODE) {
       Element childElem = (Element) n;
       String localName = childElem.getLocalName();
       try {
         if (localName.equals("PGPKeyID")) {
           keyId = Base64.decode(childElem);
         } else if (localName.equals("PGPKeyPacket")) {
           keyPacket = Base64.decode(childElem);
         } else {
           other.add(new javax.xml.crypto.dom.DOMStructure(childElem));
         }
       } catch (Base64DecodingException bde) {
         throw new MarshalException(bde);
       }
     }
   }
   this.keyId = keyId;
   this.keyPacket = keyPacket;
   this.externalElements = Collections.unmodifiableList(other);
 }
示例#18
0
  /**
   * Adds <code>AttributeValue</code> to the Attribute.
   *
   * @param element An Element object representing <code>AttributeValue</code>.
   * @exception SAMLException
   */
  public void addAttributeValue(Element element) throws SAMLException {
    if (element == null) {
      if (SAMLUtilsCommon.debug.messageEnabled()) {
        SAMLUtilsCommon.debug.message("addAttributeValue: input  is null.");
      }
      throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("nullInput"));
    }

    String tag = element.getLocalName();
    if ((tag == null) || (!tag.equals("AttributeValue"))) {
      if (SAMLUtilsCommon.debug.messageEnabled()) {
        SAMLUtilsCommon.debug.message("AttributeValue: wrong input.");
      }
      throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("wrongInput"));
    }
    try {
      if (_attributeValue == null) {
        _attributeValue = new ArrayList();
      }
      if (!(_attributeValue.add(element))) {
        if (SAMLUtilsCommon.debug.messageEnabled()) {
          SAMLUtilsCommon.debug.message(
              "Attribute: failed to " + "add to the attribute value list.");
        }
        throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("addListError"));
      }
    } catch (Exception e) {
      SAMLUtilsCommon.debug.error("addAttributeValue error", e);
      throw new SAMLRequesterException("Exception in addAttributeValue" + e.getMessage());
    }
  }
示例#19
0
  public void testFindChild() {
    tempModel
        .getStructuredDocument()
        .setText(
            StructuredModelManager.getModelManager(), //
            "<dependencies>"
                + //
                "<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><tag1/></dependency>"
                + //
                "<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><tag2/></dependency>"
                + //
                "<dependency><groupId>AAA</groupId><artifactId>BBBB</artifactId><tag3/></dependency>"
                + //
                "<dependency><artifactId>BBB</artifactId><tag4/></dependency>"
                + "</dependencies>");
    Element docElement = tempModel.getDocument().getDocumentElement();

    assertNull("null parent should return null", findChild(null, "dependency"));
    assertNull("missing child should return null", findChild(docElement, "missingElement"));

    Element dep = findChild(docElement, "dependency");
    assertNotNull("Expected node found", dep);
    assertEquals("Node type", "dependency", dep.getLocalName());
    // Should return first match
    assertDependencyChild(null, "AAA", "BBB", "tag1", dep);
  }
示例#20
0
  /** Removes the scripting listeners from the given element. */
  protected void removeScriptingListenersOn(Element elt) {
    String eltNS = elt.getNamespaceURI();
    String eltLN = elt.getLocalName();
    if (SVGConstants.SVG_NAMESPACE_URI.equals(eltNS)
        && SVG12Constants.SVG_HANDLER_TAG.equals(eltLN)) {
      // For this 'handler' element, remove the handler for the given
      // event type.
      AbstractElement tgt = (AbstractElement) elt.getParentNode();
      String eventType =
          elt.getAttributeNS(
              XMLConstants.XML_EVENTS_NAMESPACE_URI, XMLConstants.XML_EVENTS_EVENT_ATTRIBUTE);
      String eventNamespaceURI = XMLConstants.XML_EVENTS_NAMESPACE_URI;
      if (eventType.indexOf(':') != -1) {
        String prefix = DOMUtilities.getPrefix(eventType);
        eventType = DOMUtilities.getLocalName(eventType);
        eventNamespaceURI = ((AbstractElement) elt).lookupNamespaceURI(prefix);
      }

      EventListener listener =
          (EventListener) handlerScriptingListeners.put(eventNamespaceURI, eventType, elt, null);
      tgt.removeEventListenerNS(eventNamespaceURI, eventType, listener, false);
    }

    super.removeScriptingListenersOn(elt);
  }
  private void transferProperties(Node qualifPropsNode, Node tempNode) {
    // The QualifyingProperties node already has a child element for the current
    // type of properties.
    Element existingProps =
        DOMHelper.getFirstDescendant(
            (Element) qualifPropsNode, QualifyingProperty.XADES_XMLNS, propsElemName);
    // The new properties (Signed or Unsigned) were marshalled into the temp
    // node.
    Element newProps = DOMHelper.getFirstChildElement(tempNode);

    Element newSpecificProps = DOMHelper.getFirstChildElement(newProps);
    do {
      Element existingSpecificProps =
          DOMHelper.getFirstDescendant(
              existingProps, newSpecificProps.getNamespaceURI(), newSpecificProps.getLocalName());

      if (null == existingSpecificProps)
        // No element for these properties. Append the new element to the existing
        // properties.
        existingProps.appendChild(newSpecificProps);
      else
        // There are properties. Transfer all the new properties into the existing
        // element.
        transferChildren(newSpecificProps, existingSpecificProps);

      newSpecificProps = DOMHelper.getNextSiblingElement(newSpecificProps);

    } while (newSpecificProps != null);
  }
示例#22
0
  public void testFindChildren() {
    tempModel
        .getStructuredDocument()
        .setText(
            StructuredModelManager.getModelManager(), //
            "<dependencies>"
                + //
                "<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><tag1/></dependency>"
                + //
                "<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><tag2/></dependency>"
                + //
                "<dependency><groupId>AAA</groupId><artifactId>BBBB</artifactId><tag3/></dependency>"
                + //
                "<dependency><artifactId>BBB</artifactId><tag4/></dependency>"
                + "</dependencies>");
    Element docElement = tempModel.getDocument().getDocumentElement();

    assertTrue("null parent should return empty list", findChilds(null, "dependency").isEmpty());
    assertTrue(
        "missing child should return empty list",
        findChilds(docElement, "missingElement").isEmpty());

    List<Element> dep = findChilds(docElement, "dependency");
    assertEquals("Children found", 4, dep.size());
    for (Element d : dep) {
      assertEquals("Node type", "dependency", d.getLocalName());
    }
    // Should return first match
    assertDependencyChild("Unexpected child", "AAA", "BBB", "tag1", dep.get(0));
    assertDependencyChild("Unexpected child", "AAAB", "BBB", "tag2", dep.get(1));
    assertDependencyChild("Unexpected child", "AAA", "BBBB", "tag3", dep.get(2));
    assertDependencyChild("Unexpected child", null, "BBB", "tag4", dep.get(3));
  }
  public KeyInfo unmarshalKeyInfo(XMLStructure xmlStructure) throws MarshalException {
    if (xmlStructure == null) {
      throw new NullPointerException("xmlStructure cannot be null");
    }
    Node node = ((javax.xml.crypto.dom.DOMStructure) xmlStructure).getNode();
    node.normalize();

    Element element = null;
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
      element = ((Document) node).getDocumentElement();
    } else if (node.getNodeType() == Node.ELEMENT_NODE) {
      element = (Element) node;
    } else {
      throw new MarshalException("xmlStructure does not contain a proper Node");
    }

    // check tag
    String tag = element.getLocalName();
    if (tag == null) {
      throw new MarshalException(
          "Document implementation must " + "support DOM Level 2 and be namespace aware");
    }
    if (tag.equals("KeyInfo")) {
      return new DOMKeyInfo(element, null, getProvider());
    } else {
      throw new MarshalException("invalid KeyInfo tag: " + tag);
    }
  }
示例#24
0
 /**
  * Verifies if the input xmlstring can be converted to an AttributeValue Element. If so, return
  * the element value.
  */
 private String validateAndGetAttributeValue(String value) throws SAML2Exception {
   Document doc = XMLUtils.toDOMDocument(value, SAML2SDKUtils.debug);
   if (doc == null) {
     if (SAML2SDKUtils.debug.messageEnabled()) {
       SAML2SDKUtils.debug.message(
           "AttributeImpl."
               + "validateAttributeValue:"
               + " could not obtain AttributeValue element.");
     }
     throw new SAML2Exception(SAML2SDKUtils.bundle.getString("errorObtainingElement"));
   }
   Element element = doc.getDocumentElement();
   if (element == null) {
     if (SAML2SDKUtils.debug.messageEnabled()) {
       SAML2SDKUtils.debug.message("AttributeImpl." + "validateAttributeValue: Input is null.");
     }
     throw new SAML2Exception(SAML2SDKUtils.bundle.getString("nullInput"));
   }
   // Make sure this is an AttributeValue.
   String tag = element.getLocalName();
   if ((tag == null) || (!tag.equals("AttributeValue"))) {
     if (SAML2SDKUtils.debug.messageEnabled()) {
       SAML2SDKUtils.debug.message(
           "AttributeImpl." + "validateAttributeValue: not AttributeValue.");
     }
     throw new SAML2Exception(SAML2SDKUtils.bundle.getString("wrongInput"));
   }
   return XMLUtils.getChildrenValue(element);
 }
  protected void renderShowHide(
      Element elem,
      String elemVarName,
      boolean hide,
      StringBuilder code,
      JSRenderElementImpl render) {
    if (NamespaceUtil.isSVGElement(elem)) {
      // El <script> de SVG no tiene objeto style, al menos en FireFox
      // y ASV3. Da igual lo que pase en los demás (Opera, Chrome etc) no
      // tiene sentido ocultar un <script>
      String localName = elem.getLocalName();
      if (localName.equals("script")) return;

      ClientDocumentStfulDelegateWebImpl clientDoc = getClientDocumentStfulDelegateWeb();
      BrowserWeb browser = clientDoc.getBrowserWeb();
      if (browser instanceof BrowserAdobeSVG) {
        // El <foreignObject> tampoco tiene objeto style en ASV3
        // este elemento ES visual pero como no está reconocido
        // en ASV3 los elementos hijo son tratados como elementos SVG
        // desconocidos sin visualización. Por tanto evitamos que de error.
        // De hecho la propiedad "display" no funciona en ASV3 (se ignora)
        // pero al menos no da error.
        if (localName.equals("foreignObject")) return;
      }
    }

    super.renderShowHide(elem, elemVarName, hide, code, render);
  }
示例#26
0
  @Override
  protected void changeItem(UntypedItemXml item) {
    Element element = getElement(item, property);
    if (element == null) {
      throw new CliException("Cannot find element: " + property);
    }

    String namespaceURI = element.getNamespaceURI();
    String localName = element.getLocalName();

    Node parentNode = element.getParentNode();
    String parentNamespaceUri = parentNode.getNamespaceURI();
    String parentTag = parentNode.getLocalName();

    String pathKey = parentNamespaceUri + ":" + parentTag + ":" + namespaceURI + ":" + localName;

    if ("http://platformlayer.org/service/platformlayer/v1.0:platformLayerService:http://platformlayer.org/service/platformlayer/v1.0:config"
        .equals(pathKey)) {
      Element newNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "property");
      Element keyNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "key");
      keyNode.setTextContent(key);
      Element valueNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "value");
      valueNode.setTextContent(value);
      newNode.appendChild(keyNode);
      newNode.appendChild(valueNode);

      element.appendChild(newNode);
    } else {
      throw new UnsupportedOperationException();
    }
  }
示例#27
0
    /** Runs the script. */
    public void handleEvent(Event evt) {
      Element elt = (Element) evt.getCurrentTarget();
      // Evaluate the script
      String script = handlerElement.getTextContent();
      if (script.length() == 0) return;

      DocumentLoader dl = bridgeContext.getDocumentLoader();
      AbstractDocument d = (AbstractDocument) handlerElement.getOwnerDocument();
      int line = dl.getLineNumber(handlerElement);
      final String desc =
          Messages.formatMessage(
              HANDLER_SCRIPT_DESCRIPTION,
              new Object[] {d.getDocumentURI(), eventNamespaceURI, eventType, new Integer(line)});

      // Find the scripting language
      String lang =
          handlerElement.getAttributeNS(null, SVGConstants.SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE);
      if (lang.length() == 0) {
        Element e = elt;
        while (e != null
            && (!SVGConstants.SVG_NAMESPACE_URI.equals(e.getNamespaceURI())
                || !SVGConstants.SVG_SVG_TAG.equals(e.getLocalName()))) {
          e = SVGUtilities.getParentElement(e);
        }
        if (e == null) return;

        lang = e.getAttributeNS(null, SVGConstants.SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE);
      }

      runEventHandler(script, evt, lang, desc);
    }
 @Override
 public ServiceCreationConfiguration<TransactionManagerProvider> parseServiceCreationConfiguration(
     Element fragment) {
   String localName = fragment.getLocalName();
   if ("jta-tm".equals(localName)) {
     String transactionManagerProviderConfigurationClassName =
         fragment.getAttribute("transaction-manager-lookup-class");
     try {
       ClassLoader defaultClassLoader = ClassLoading.getDefaultClassLoader();
       Class<?> aClass =
           Class.forName(
               transactionManagerProviderConfigurationClassName, true, defaultClassLoader);
       return new LookupTransactionManagerProviderConfiguration(
           (Class<? extends TransactionManagerLookup>) aClass);
     } catch (Exception e) {
       throw new XmlConfigurationException("Error configuring XA transaction manager", e);
     }
   } else {
     throw new XmlConfigurationException(
         String.format(
             "XML configuration element <%s> in <%s> is not supported",
             fragment.getTagName(),
             (fragment.getParentNode() == null
                 ? "null"
                 : fragment.getParentNode().getLocalName())));
   }
 }
示例#29
0
  /**
   * Returns a sibling element that matches a given definition, or <tt>null</tt> if no match is
   * found.
   *
   * @param sibling the sibling DOM element to begin the search
   * @param target the node to search for
   * @return the matching element, or <tt>null</tt> if not found
   */
  public static Element findSibling(Element sibling, XmlNode target) {
    String xmlName = target.getLocalName();
    String xmlNamespace = target.getNamespace();

    Node node = sibling;
    if (node == null) {
      return null;
    }

    while ((node = node.getNextSibling()) != null) {
      if (node.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }
      Element element = (Element) node;
      if (!element.getLocalName().equals(xmlName)) {
        continue;
      }
      if (target.isNamespaceAware()) {
        String ns = element.getNamespaceURI();
        if (ns == null) {
          if (xmlNamespace != null) {
            continue;
          }
        } else {
          if (!ns.equals(xmlNamespace)) {
            continue;
          }
        }
      }
      return element;
    }
    return null;
  }
示例#30
0
 private static String getElementStringRep(Element el) {
   String result = el.getLocalName();
   if (el.getNamespaceURI() != null) {
     result = el.getNamespaceURI() + ":" + result;
   }
   return result;
 }