Beispiel #1
0
 private boolean compareNames(Node a, Node b) {
   if (a.getLocalName() != null || b.getLocalName() != null) {
     return safeEquals(a.getNamespaceURI(), b.getNamespaceURI())
         && safeEquals(a.getLocalName(), b.getLocalName());
   }
   return safeEquals(a.getNodeName(), b.getNodeName());
 }
  /**
   * This method determins if a node in the DOM Tree <code>(iNode)</code> is the node we are looking
   * for. This is done by comparing the node's local name and namespace with a given node name
   * <code>(iNodeName)</code> and namespace <code>(iNamespace)</code>.
   *
   * @param iNode The Node we are trying to determine if it is the correct node
   * @param iNodeName The name of the node we are looking for.
   * @param iNamespace The namespace of the node we are looking for.
   * @return A boolean value indicating whether or not this is the correct node we are looking for
   */
  public static boolean isAppropriateElement(Node iNode, String iNodeName, String iNamespace) {
    Logger.getLogger("org.adl.util.debug.samplerte")
        .entering("DOMTreeUtility", "isAppropriateElement()");
    Logger.getLogger("org.adl.util.debug.samplerte")
        .finest("Input Parent Node: " + iNode.getLocalName());
    Logger.getLogger("org.adl.util.debug.samplerte")
        .finest("Input Node being searched for: " + iNodeName);
    Logger.getLogger("org.adl.util.debug.samplerte")
        .finest("Input Namespace of node being searched for: " + iNamespace);

    boolean result = false;

    if (iNode.getNodeType() == Node.ATTRIBUTE_NODE) {
      if (iNode.getNamespaceURI() == null) {
        // Attribute has been passed in and its namepsace is null, get the
        // attributes parent's namespace
        String parentsNamespace = ((Attr) iNode).getOwnerElement().getNamespaceURI();
        if ((iNode.getLocalName().equals(iNodeName)) && (parentsNamespace.equals(iNamespace))) {
          result = true;
        }
      } else {
        if ((iNode.getLocalName().equals(iNodeName))
            && (iNode.getNamespaceURI().equals(iNamespace))) {
          result = true;
        }
      }
    } else if ((iNode.getLocalName().equals(iNodeName))
        && (iNode.getNamespaceURI().equals(iNamespace))) {
      result = true;
    }

    return result;
  }
Beispiel #3
0
  static boolean isOrganizationName(Node node) {
    // Must be an Element
    if (!(node instanceof Element)) {
      return false;
    }

    /*
     * Representation of an owner name in metadata and in the old schema for
     * members.xml is as an md:OrganizationName.
     */
    if ("urn:oasis:names:tc:SAML:2.0:metadata".equals(node.getNamespaceURI())
        && "OrganizationName".equals(node.getLocalName())) {
      return true;
    }

    /*
     * Representation of an owner name in the new schema for
     * members.xml is as a members:Name.
     */
    if ("http://ukfederation.org.uk/2007/01/members".equals(node.getNamespaceURI())
        && "Name".equals(node.getLocalName())) {
      return true;
    }

    // Otherwise...
    return false;
  }
  protected Element readActionRequestElement(
      Element bodyElement, ActionRequestMessage message, ActionInvocation actionInvocation) {
    NodeList bodyChildren = bodyElement.getChildNodes();

    log.fine(
        "Looking for action request element matching namespace:" + message.getActionNamespace());

    for (int i = 0; i < bodyChildren.getLength(); i++) {
      Node bodyChild = bodyChildren.item(i);

      if (bodyChild.getNodeType() != Node.ELEMENT_NODE) continue;

      String unprefixedName = getUnprefixedNodeName(bodyChild);
      if (unprefixedName.equals(actionInvocation.getAction().getName())) {
        if (bodyChild.getNamespaceURI() == null
            || !bodyChild.getNamespaceURI().equals(message.getActionNamespace()))
          throw new UnsupportedDataException(
              "Illegal or missing namespace on action request element: " + bodyChild);
        log.fine("Reading action request element: " + unprefixedName);
        return (Element) bodyChild;
      }
    }
    throw new UnsupportedDataException(
        "Could not read action request element matching namespace: "
            + message.getActionNamespace());
  }
 private void process(Source source) throws Exception {
   Node node = getDOM(source);
   node = node.getFirstChild();
   assertEquals("HelloResponse", node.getLocalName());
   System.out.println("Node Localname=" + node.getLocalName());
   assertEquals("urn:test:types", node.getNamespaceURI());
   System.out.println("Node NS URI=" + node.getNamespaceURI());
 }
  private void doElementNamespaceValidation(Node received, Node source) {
    // validate element namespace
    if (log.isDebugEnabled()) {
      log.debug("Validating namespace for element: " + received.getLocalName());
    }

    if (received.getNamespaceURI() != null) {
      Assert.isTrue(
          source.getNamespaceURI() != null,
          ValidationUtils.buildValueMismatchErrorMessage(
              "Element namespace not equal for element '" + received.getLocalName() + "'",
              null,
              received.getNamespaceURI()));

      Assert.isTrue(
          received.getNamespaceURI().equals(source.getNamespaceURI()),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Element namespace not equal for element '" + received.getLocalName() + "'",
              source.getNamespaceURI(),
              received.getNamespaceURI()));
    } else {
      Assert.isTrue(
          source.getNamespaceURI() == null,
          ValidationUtils.buildValueMismatchErrorMessage(
              "Element namespace not equal for element '" + received.getLocalName() + "'",
              source.getNamespaceURI(),
              null));
    }
  }
Beispiel #7
0
  private static Element[] getChildElements(Element parent) {
    ArrayList<Element> a = new ArrayList<Element>();
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node item = children.item(i);
      if (!(item instanceof Element)) continue;

      if (JAXWSBindingsConstants.NS_JAXWS_BINDINGS.equals(item.getNamespaceURI())
          || JAXWSBindingsConstants.NS_JAXB_BINDINGS.equals(item.getNamespaceURI()))
        a.add((Element) item);
    }
    return a.toArray(new Element[a.size()]);
  }
Beispiel #8
0
 private boolean compareAttributes(Node a, Node b) {
   NamedNodeMap nnma = a.getAttributes(), nnmb = b.getAttributes();
   if (getAttrCount(nnma) != getAttrCount(nnmb)) return false;
   for (int i = 0; i < nnma.getLength(); i++) {
     Node ta = nnma.item(i);
     if (Namespaces.XMLNS_NS.equals(ta.getNamespaceURI())) continue;
     Node tb =
         ta.getLocalName() == null
             ? nnmb.getNamedItem(ta.getNodeName())
             : nnmb.getNamedItemNS(ta.getNamespaceURI(), ta.getLocalName());
     if (tb == null || !safeEquals(ta.getNodeValue(), tb.getNodeValue())) return false;
   }
   return true;
 }
Beispiel #9
0
 private boolean isGlobalBinding(Node bindings) {
   if (bindings.getNamespaceURI() == null) {
     errorReceiver.warning(
         forest.locatorTable.getStartLocation((Element) bindings),
         WsdlMessages.INVALID_CUSTOMIZATION_NAMESPACE(bindings.getLocalName()));
     return false;
   }
   return (bindings.getNamespaceURI().equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS)
       && (bindings.getLocalName().equals("package")
           || bindings.getLocalName().equals("enableAsyncMapping")
           || bindings.getLocalName().equals("enableAdditionalSOAPHeaderMapping")
           || bindings.getLocalName().equals("enableWrapperStyle")
           || bindings.getLocalName().equals("enableMIMEContent")));
 }
Beispiel #10
0
 private Namespace getNodeNamespace() {
   String uri = dom.getNamespaceURI();
   String prefix = dom.getPrefix();
   if (uri == null) uri = "";
   if (prefix == null) prefix = "";
   return Namespace.create(prefix, uri);
 }
Beispiel #11
0
 public static void copyAttributes(SOAPElement target, Element source) {
   // easy way out: no attributes
   if (!source.hasAttributes()) return;
   final boolean traceEnabled = log.isTraceEnabled();
   // traverse attributes
   NamedNodeMap attributes = source.getAttributes();
   for (int i = 0, n = attributes.getLength(); i < n; i++) {
     Node attribute = attributes.item(i);
     String namespaceURI = attribute.getNamespaceURI();
     // isn't the attribute a namespace declaration?
     if (!BpelConstants.NS_XMLNS.equals(namespaceURI)) {
       String name = attribute.getNodeName();
       String value = attribute.getNodeValue();
       if (namespaceURI == null) {
         /*
          * use the DOM level 1 method as some SAAJ implementations complain
          * when presented a null namespace URI
          */
         target.setAttribute(name, value);
       } else {
         target.setAttributeNS(namespaceURI, name, value);
       }
       if (traceEnabled) log.trace("set attribute: " + name);
     }
   }
 }
  /**
   * Creates the <a href="http://wiki.mindmakers.org/projects:BML:main">Behavior Markup Language</a>
   * string for Avatar.
   *
   * @param utterance the utterance to speak <code>null</code>
   * @param ssml SSML with BML annotations
   * @return created XML string
   * @throws XMLStreamException if the stream could not be created.
   */
  private String createBML(final String utterance, final SsmlDocument ssml)
      throws XMLStreamException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final XMLOutputFactory factory = XMLOutputFactory.newInstance();
    final XMLStreamWriter writer = factory.createXMLStreamWriter(out, ENCODING);
    writer.writeStartDocument(ENCODING, "1.0");
    writer.writeStartElement("bml");
    writer.writeAttribute("id", "bml1");
    writer.writeNamespace("ns1", BML_NAMESPACE_URI);
    if (ssml != null) {
      final Speak speak = ssml.getSpeak();
      final NodeList children = speak.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        final Node child = children.item(i);
        final String namespace = child.getNamespaceURI();
        if (namespace != null) {
          writeBMLNode(writer, child, utterance);
        }
      }
    }

    writer.writeEndElement();
    writer.writeEndDocument();
    writer.flush();
    // lastGestureEndTime = 0;
    writer.close();
    try {
      String output = out.toString(ENCODING);
      return output;
    } catch (UnsupportedEncodingException e) {
      LOGGER.warn(e.getMessage(), e);
      return out.toString();
    }
  }
Beispiel #13
0
 public static void updateGmlIDs(final Node node, final String gmlID, String oldGmlID) {
   // check this node's attributes
   if (node != null) {
     final String nodeNamespace = node.getNamespaceURI();
     final NamedNodeMap attributes = node.getAttributes();
     if (attributes != null) {
       for (int i = 0, len = attributes.getLength(); i < len; i++) {
         final Attr attr = (Attr) attributes.item(i);
         if (attr.getLocalName().equals(GmlConstants.AN_ID)) {
           if (checkAttributeForGmlId(attr, nodeNamespace)) {
             if (oldGmlID == null) {
               oldGmlID = attr.getValue();
               attr.setValue((gmlID));
             } else {
               String helperString = attr.getValue();
               helperString = helperString.replace(oldGmlID, gmlID);
               attr.setValue(helperString);
             }
           }
         }
       }
       // recurse this node's children
       final NodeList children = node.getChildNodes();
       if (children != null) {
         for (int i = 0, len = children.getLength(); i < len; i++) {
           updateGmlIDs(children.item(i), gmlID, oldGmlID);
         }
       }
     }
   }
 }
Beispiel #14
0
  /**
   * Runs an XPath expression on this node.
   *
   * @param env
   * @param expression
   * @return array of results
   * @throws XPathExpressionException
   */
  public Value xpath(Env env, String expression) {
    try {
      XPath xpath = XPathFactory.newInstance().newXPath();

      InputSource is = new InputSource(asXML(env).toInputStream());
      NodeList nodes = (NodeList) xpath.evaluate(expression, is, XPathConstants.NODESET);

      int nodeLength = nodes.getLength();

      if (nodeLength == 0) return NullValue.NULL;

      // There are matching nodes
      ArrayValue result = new ArrayValueImpl();
      for (int i = 0; i < nodeLength; i++) {
        Node node = nodes.item(i);

        boolean isPrefix = node.getPrefix() != null;

        SimpleXMLElement xml =
            buildNode(env, _cls, null, nodes.item(i), node.getNamespaceURI(), isPrefix);

        result.put(wrapJava(env, _cls, xml));
      }

      return result;
    } catch (XPathExpressionException e) {
      env.warning(e);
      log.log(Level.FINE, e.getMessage());

      return NullValue.NULL;
    }
  }
Beispiel #15
0
 public static void copyNamespaces(final Element target, Element source) {
   // easy way out: no attributes
   if (!source.hasAttributes()) return;
   final boolean traceEnabled = log.isTraceEnabled();
   // traverse attributes to discover namespace declarations
   NamedNodeMap attributes = source.getAttributes();
   for (int i = 0, n = attributes.getLength(); i < n; i++) {
     Node attribute = attributes.item(i);
     // is attribute a namespace declaration?
     if (!BpelConstants.NS_XMLNS.equals(attribute.getNamespaceURI())) continue;
     // namespace declaration format xmlns:prefix="namespaceURI" |
     // xmlns="defaultNamespaceURI"
     String namespaceURI = attribute.getNodeValue();
     String prefix = attribute.getLocalName();
     // default namespace declaration?
     if ("xmlns".equals(prefix)) {
       // BPEL-195: prevent addition matching visible declaration at target
       if ("".equals(getPrefix(namespaceURI, target))) continue;
       addNamespaceDeclaration(target, namespaceURI);
       if (traceEnabled) log.trace("added default namespace declaration: " + namespaceURI);
     } else {
       // BPEL-195: prevent addition matching visible declaration at target
       if (prefix.equals(getPrefix(namespaceURI, target))) continue;
       addNamespaceDeclaration(target, namespaceURI, prefix);
       if (traceEnabled) log.trace("added namespace declaration: " + prefix + "->" + namespaceURI);
     }
   }
 }
  @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();
    }
  }
Beispiel #17
0
 static boolean evaluate(Node node, String namespaceURI) {
   String nodeNamespaceURI = node.getNamespaceURI();
   return node.getNodeType() == Node.ELEMENT_NODE
       && (namespaceURI != null
           ? namespaceURI.equals(nodeNamespaceURI)
           : nodeNamespaceURI == null || nodeNamespaceURI.length() == 0);
 }
Beispiel #18
0
 private void doGet(HttpServletResponse response, XcapResourceImpl resource) throws IOException {
   response.setContentType(resource.getMimeType());
   if (resource.isAllDocument()) {
     response.getOutputStream().write(resource.getDocument().getBytes());
   } else {
     XmlResource selectedResource = resource.getSelectedResource();
     switch (resource.getNodeType()) {
       case ATTRIBUTE:
         response
             .getOutputStream()
             .write(((Attr) selectedResource.getDom()).getValue().getBytes());
         break;
       case ELEMENT:
         response.getOutputStream().write(selectedResource.getBytes());
         break;
       case NAMESPACE:
         Node node = selectedResource.getDom();
         String prefix = "<" + node.getNodeName() + " ";
         response.getOutputStream().write(prefix.getBytes());
         response.getOutputStream().write(node.getNamespaceURI().getBytes());
         response.getOutputStream().write("/>".getBytes());
         break;
       default:
         break;
     }
   }
 }
Beispiel #19
0
  /**
   * Recurse through a node and its children and make all gml:ids unique
   *
   * @param node The node to examine
   */
  public static void makeGmlIdsUnique(final Node node, final Map<String, Integer> foundIds) {
    // check this node's attributes
    final NamedNodeMap attributes = node.getAttributes();
    final String nodeNamespace = node.getNamespaceURI();
    if (attributes != null) {
      for (int i = 0, len = attributes.getLength(); i < len; i++) {
        final Attr attr = (Attr) attributes.item(i);
        if (attr.getLocalName().equals(GmlConstants.AN_ID)) {
          if (checkAttributeForGmlId(attr, nodeNamespace)) {
            final String gmlId = attr.getValue();
            if (foundIds.containsKey(gmlId)) {
              /*
               * id has already been found, suffix this one with
               * the found count for this id
               */
              attr.setValue(gmlId + foundIds.get(gmlId));
              // increment the found count for this id
              foundIds.put(gmlId, foundIds.get(gmlId) + 1);
            } else {
              // id is new, add it to the foundIds map
              foundIds.put(gmlId, 1);
            }
          }
        }
      }
    }

    // recurse this node's children
    final NodeList children = node.getChildNodes();
    if (children != null) {
      for (int i = 0, len = children.getLength(); i < len; i++) {
        makeGmlIdsUnique(children.item(i), foundIds);
      }
    }
  }
Beispiel #20
0
 public static void copyNamespaces(SOAPElement target, Element source) throws SOAPException {
   // easy way out: no attributes
   if (!source.hasAttributes()) return;
   final boolean traceEnabled = log.isTraceEnabled();
   // traverse attributes to discover namespace declarations
   NamedNodeMap attributes = source.getAttributes();
   for (int i = 0, n = attributes.getLength(); i < n; i++) {
     Node attribute = attributes.item(i);
     // is attribute a namespace declaration?
     if (!BpelConstants.NS_XMLNS.equals(attribute.getNamespaceURI())) continue;
     // namespace declaration format xmlns:prefix="namespaceURI" |
     // xmlns="defaultNamespaceURI"
     String namespaceURI = attribute.getNodeValue();
     String prefix = attribute.getLocalName();
     // non-default namespace declaration?
     if (!"xmlns".equals(prefix)) {
       // BPEL-195: prevent addition matching visible declaration at target
       if (namespaceURI.equals(target.getNamespaceURI(prefix))) continue;
       target.addNamespaceDeclaration(prefix, namespaceURI);
       if (traceEnabled) log.trace("added namespace declaration: " + prefix + "->" + namespaceURI);
     }
     // non-empty default namespace declaration
     else if (namespaceURI.length() > 0) {
       prefix = generatePrefix(source, DEFAULT_NAMESPACE_PREFIX);
       target.addNamespaceDeclaration(prefix, namespaceURI);
       if (traceEnabled)
         log.trace("reassigned default namespace declaration: " + prefix + "->" + namespaceURI);
     }
   }
 }
 /*
  * @see com.sun.org.apache.xml.internal.utils.PrefixResolverDefault
  */
 protected String inferNamespaceURI(String prefix) {
   Node parent = namespaceContext;
   String namespace = null;
   int type;
   while ((null != parent)
       && (null == namespace)
       && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
           || (type == Node.ENTITY_REFERENCE_NODE))) {
     if (type == Node.ELEMENT_NODE) {
       if (parent.getNodeName().indexOf(prefix + ":") == 0) {
         return parent.getNamespaceURI();
       }
       NamedNodeMap nnm = parent.getAttributes();
       for (int i = 0; i < nnm.getLength(); i++) {
         Node attr = nnm.item(i);
         String aname = attr.getNodeName();
         boolean isPrefix = aname.startsWith("xmlns:");
         if (isPrefix || aname.equals("xmlns")) {
           int index = aname.indexOf(':');
           String p = isPrefix ? aname.substring(index + 1) : "";
           if (p.equals(prefix)) {
             namespace = attr.getNodeValue();
             break;
           }
         }
       }
     }
     parent = parent.getParentNode();
   }
   return namespace;
 }
Beispiel #22
0
 private boolean isWSDLDefinition(Node target) {
   if (target == null) return false;
   String localName = target.getLocalName();
   String nsURI = target.getNamespaceURI();
   return fixNull(localName).equals("definitions")
       && fixNull(nsURI).equals("http://schemas.xmlsoap.org/wsdl/");
 }
Beispiel #23
0
 private static String getNamespaceURI(Node n) {
   String uri = n.getNamespaceURI();
   if (uri == null) {
     // FIXME: Is "No Namespace is Empty Namespace" really OK?
     uri = "";
   }
   return uri;
 }
Beispiel #24
0
 /**
  * Return the number of real attributes in the map. Filter out xmlns namespace attributes.
  *
  * @param nnm
  * @return
  */
 private int getAttrCount(NamedNodeMap nnm) {
   int count = 0;
   for (int i = 0; i < nnm.getLength(); i++) {
     Node n = nnm.item(i);
     if (!Namespaces.XMLNS_NS.equals(n.getNamespaceURI())) ++count;
   }
   return count;
 }
  public void compareJAXBElementObjects(JAXBElement controlObj, JAXBElement testObj) {
    assertEquals(controlObj.getName().getLocalPart(), testObj.getName().getLocalPart());
    assertEquals(controlObj.getName().getNamespaceURI(), testObj.getName().getNamespaceURI());
    assertEquals(controlObj.getDeclaredType(), testObj.getDeclaredType());

    Node controlValue = (Node) controlObj.getValue();
    Node testValue = (Node) testObj.getValue();

    assertEquals(controlValue.getNamespaceURI(), testValue.getNamespaceURI());
    assertEquals(controlValue.getLocalName(), testValue.getLocalName());

    Text controlText = (Text) controlValue.getFirstChild();
    Text testText = (Text) testValue.getFirstChild();
    assertEquals(controlText.getTextContent(), testText.getTextContent());

    assertEquals(controlValue.getChildNodes().getLength(), testValue.getChildNodes().getLength());
  }
  public QName getName() {
    Node el = getCurrentNode();

    String prefix = getPrefix();
    String ln = getLocalName();

    return new QName(el.getNamespaceURI(), ln, prefix);
  }
Beispiel #27
0
  // <foo><!--comment-->bar</foo> will put the text as a tail of the comment
  // this isn't very nice. Do we have getText too, that gets all text of foo?
  private MeiElement makeMeiElement(Node element) {
    // TODO: CDATA
    // Comments get a name #comment
    String nshref = element.getNamespaceURI();
    String nsprefix = element.getPrefix();
    MeiNamespace elns = new MeiNamespace(nshref, nsprefix);
    MeiElement e = new MeiElement(elns, element.getNodeName());
    if (element.getNodeType() == Node.COMMENT_NODE) {
      e.setValue(element.getNodeValue());
    }

    NamedNodeMap attributes = element.getAttributes();
    if (attributes != null) {
      for (int i = 0; i < attributes.getLength(); i++) {
        Node item = attributes.item(i);
        if (XML_ID_ATTRIBUTE.equals(item.getNodeName())) {
          e.setId(item.getNodeValue());
        } else {
          String attrns = item.getNamespaceURI();
          String attrpre = item.getPrefix();
          MeiNamespace atns = new MeiNamespace(attrns, attrpre);
          MeiAttribute a = new MeiAttribute(atns, item.getNodeName(), item.getNodeValue());
          e.addAttribute(a);
        }
      }
    }

    NodeList childNodes = element.getChildNodes();
    MeiElement lastElement = null;
    for (int i = 0; i < childNodes.getLength(); i++) {
      Node item = childNodes.item(i);
      if (item.getNodeType() == Node.TEXT_NODE) {
        if (lastElement == null) {
          e.setValue(item.getNodeValue());
        } else {
          lastElement.setTail(item.getNodeValue());
        }
      } else {
        MeiElement child = makeMeiElement(item);
        e.addChild(child);
        lastElement = child;
      }
    }
    return e;
  }
Beispiel #28
0
 private static String getNodeNameWithNamespace(Node node) {
   String name = node.getNodeName();
   String ns = node.getNamespaceURI();
   String prefix = (ns != null) ? node.lookupPrefix(ns) : null;
   if ((prefix != null) && !name.startsWith(prefix + ":")) {
     name = prefix + ":" + name;
   }
   return name;
 }
  /**
   * Sign a node in a document
   *
   * @param doc
   * @param nodeToBeSigned
   * @param keyPair
   * @param publicKey
   * @param digestMethod
   * @param signatureMethod
   * @param referenceURI
   * @return
   * @throws ParserConfigurationException
   * @throws XMLSignatureException
   * @throws MarshalException
   * @throws GeneralSecurityException
   */
  public static Document sign(
      Document doc,
      Node nodeToBeSigned,
      KeyPair keyPair,
      String digestMethod,
      String signatureMethod,
      String referenceURI,
      X509Certificate x509Certificate)
      throws ParserConfigurationException, GeneralSecurityException, MarshalException,
          XMLSignatureException {
    if (nodeToBeSigned == null) throw logger.nullArgumentError("Node to be signed");

    if (logger.isTraceEnabled()) {
      logger.trace("Document to be signed=" + DocumentUtil.asString(doc));
    }

    Node parentNode = nodeToBeSigned.getParentNode();

    // Let us create a new Document
    Document newDoc = DocumentUtil.createDocument();
    // Import the node
    Node signingNode = newDoc.importNode(nodeToBeSigned, true);
    newDoc.appendChild(signingNode);

    if (!referenceURI.isEmpty()) {
      propagateIDAttributeSetup(nodeToBeSigned, newDoc.getDocumentElement());
    }
    newDoc = sign(newDoc, keyPair, digestMethod, signatureMethod, referenceURI, x509Certificate);

    // if the signed element is a SAMLv2.0 assertion we need to move the signature element to the
    // position
    // specified in the schema (before the assertion subject element).
    if (nodeToBeSigned.getLocalName().equals("Assertion")
        && WSTrustConstants.SAML2_ASSERTION_NS.equals(nodeToBeSigned.getNamespaceURI())) {
      Node signatureNode =
          DocumentUtil.getElement(newDoc, new QName(WSTrustConstants.DSIG_NS, "Signature"));
      Node subjectNode =
          DocumentUtil.getElement(
              newDoc, new QName(WSTrustConstants.SAML2_ASSERTION_NS, "Subject"));
      if (signatureNode != null && subjectNode != null) {
        newDoc.getDocumentElement().removeChild(signatureNode);
        newDoc.getDocumentElement().insertBefore(signatureNode, subjectNode);
      }
    }

    // Now let us import this signed doc into the original document we got in the method call
    Node signedNode = doc.importNode(newDoc.getFirstChild(), true);

    if (!referenceURI.isEmpty()) {
      propagateIDAttributeSetup(newDoc.getDocumentElement(), (Element) signedNode);
    }

    parentNode.replaceChild(signedNode, nodeToBeSigned);
    // doc.getDocumentElement().replaceChild(signedNode, nodeToBeSigned);

    return doc;
  }
  /**
   * This method determines whether or not the current node is a SCORM Application Profile node. The
   * parent node is needed for cases where the current node is an attribute node
   *
   * @param iCurrentNode The current node being processed
   * @param iParentNode The parent of the current node being processed
   * @return Returns whether or not (true/false) the current node is a SCORM application profile
   *     node
   */
  public static boolean isSCORMAppProfileNode(Node iCurrentNode, Node iParentNode) {
    Logger.getLogger("org.adl.util.debug.samplerte")
        .entering("DOMTreeUtility", "isSCORMAppProfileNode");
    Logger.getLogger("org.adl.util.debug.samplerte")
        .finest("Input Current Node: " + iCurrentNode.getLocalName());
    Logger.getLogger("org.adl.util.debug.samplerte")
        .finest("Input Parent Node: " + iParentNode.getLocalName());

    boolean result = false;

    // If the current node is from one of the known SCORM testable
    // namespaces then return true
    String namespace = iCurrentNode.getNamespaceURI();

    if (namespace == null) {
      String parentsNamespace = iParentNode.getNamespaceURI();

      // Check the parent nodes namespace
      if ((parentsNamespace.equals(ADLCP_NAMESPACE))
          || (parentsNamespace.equals(IMSCP_NAMESPACE))
          || (parentsNamespace.equals(ADLNAV_NAMESPACE))
          || (parentsNamespace.equals(IEEE_LOM_NAMESPACE))
          || (parentsNamespace.equals(ADLSEQ_NAMESPACE))
          || (parentsNamespace.equals("http://www.w3.org/XML/1998/namespace"))
          || (parentsNamespace.equals("http://www.w3.org/2001/XMLSchema-instance"))
          || (parentsNamespace.equals("http://www.w3.org/2000/xmlns/"))
          || (parentsNamespace.equals(IMSSS_NAMESPACE))) {
        result = true;
      }
    } else if ((namespace.equals(ADLCP_NAMESPACE))
        || (namespace.equals(IMSCP_NAMESPACE))
        || (namespace.equals(IEEE_LOM_NAMESPACE))
        || (namespace.equals(ADLNAV_NAMESPACE))
        || (namespace.equals(ADLSEQ_NAMESPACE))
        || (namespace.equals("http://www.w3.org/XML/1998/namespace"))
        || (namespace.equals("http://www.w3.org/2001/XMLSchema-instance"))
        || (namespace.equals("http://www.w3.org/2000/xmlns/"))
        || (namespace.equals(IMSSS_NAMESPACE))) {
      result = true;
    }

    return result;
  }