Esempio n. 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()));
    }
  }
  /**
   * Overwritten to cope with additional deegree CSW specific attributes (used in the "outputSchema"
   * parameter element).
   *
   * @see org.deegree.owscommon.OWSCommonCapabilitiesDocument#getParameter(org.w3c.dom.Element)
   */
  protected OWSDomainType getOWSDomainType(String operation, Element parameterElement)
      throws XMLParsingException {
    // "name"-attribute
    String parameterName = XMLTools.getRequiredAttrValue("name", null, parameterElement);

    if ("GetRecords".equals(operation) && "outputSchema".equals(parameterName)) {
      // "ows:Value"-elements
      NodeList valueNodes = parameterElement.getElementsByTagNameNS(OWSNS.toString(), "Value");
      CatalogueOutputSchemaValue[] values = new CatalogueOutputSchemaValue[valueNodes.getLength()];
      for (int i = 0; i < valueNodes.getLength(); i++) {
        String value = XMLTools.getStringValue(valueNodes.item(i));
        String input = XMLTools.getRequiredAttrValue("input", DEEGREECSW, valueNodes.item(i));
        String output = XMLTools.getRequiredAttrValue("output", DEEGREECSW, valueNodes.item(i));
        if (value == null || value.equals("")) {
          throw new XMLParsingException("Missing or empty node '" + value + "'.");
        }
        values[i] = new CatalogueOutputSchemaValue(value, input, output);
      }
      return new CatalogueOutputSchemaParameter(parameterName, values, null);
    } else if ("GetRecords".equals(operation) && "typeName".equals(parameterName)) {
      NodeList valueNodes = parameterElement.getElementsByTagNameNS(OWSNS.toString(), "Value");
      CatalogueTypeNameSchemaValue[] values =
          new CatalogueTypeNameSchemaValue[valueNodes.getLength()];
      for (int i = 0; i < valueNodes.getLength(); i++) {
        String value = XMLTools.getStringValue(valueNodes.item(i));
        String schema = XMLTools.getRequiredAttrValue("schema", DEEGREECSW, valueNodes.item(i));
        values[i] = new CatalogueTypeNameSchemaValue(value, schema);
      }
      return new CatalogueTypeNameSchemaParameter(parameterName, values, null);
    } else {
      return super.getOWSDomainType(operation, parameterElement);
    }
  }
Esempio n. 3
0
  /**
   * Returns or creates (if it does not exist) the UnsignedPropertiesType DOM object.
   *
   * @return
   * @throws DSSException
   */
  protected void ensureUnsignedProperties() throws DSSException {

    final NodeList qualifyingPropertiesNodeList =
        currentSignatureDom.getElementsByTagNameNS(XAdESNamespaces.XAdES, "QualifyingProperties");
    if (qualifyingPropertiesNodeList.getLength() != 1) {

      throw new DSSException(
          "The signature does not contain QualifyingProperties element (or contains more than one)! Extension is not possible.");
    }

    qualifyingPropertiesDom = (Element) qualifyingPropertiesNodeList.item(0);

    final NodeList unsignedPropertiesNodeList =
        currentSignatureDom.getElementsByTagNameNS(XAdESNamespaces.XAdES, "UnsignedProperties");
    final int length = unsignedPropertiesNodeList.getLength();
    if (length == 1) {

      unsignedPropertiesDom = (Element) qualifyingPropertiesNodeList.item(0);
    } else if (length == 0) {

      unsignedPropertiesDom =
          DSSXMLUtils.addElement(
              documentDom,
              qualifyingPropertiesDom,
              XAdESNamespaces.XAdES,
              "xades:UnsignedProperties");
    } else {

      throw new DSSException(
          "The signature contains more then one UnsignedProperties element! Extension is not possible.");
    }
  }
Esempio n. 4
0
 private boolean checkElement(List<Element> els, String name, String localTypeName) {
   for (Element e : els) {
     if (name.equals(e.getAttribute("name"))) {
       String type = e.getAttribute("type");
       if (!StringUtils.isEmpty(type)) {
         if (checkTypeName(e, type, localTypeName)) {
           return true;
         }
       } else if ("books".equals(name) || "thebook2s".equals(name)) {
         boolean thebooks2 = "thebook2s".equals(name);
         Element ctElement =
             (Element)
                 e.getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD, "complexType").item(0);
         Element seqElement =
             (Element)
                 ctElement
                     .getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD, "sequence")
                     .item(0);
         Element xsElement =
             (Element)
                 seqElement
                     .getElementsByTagNameNS(Constants.URI_2001_SCHEMA_XSD, "element")
                     .item(0);
         String ref = xsElement.getAttribute("ref");
         if (checkTypeName(e, ref, thebooks2 ? "thebook2" : "thebook")) {
           return true;
         }
       }
     }
   }
   return false;
 }
 private boolean hasDestinationIndicationSaml2Response(Element responseElement) {
   if (null != responseElement.getAttributeNode("Destination")) {
     return true;
   }
   NodeList assertionNodeList =
       responseElement.getElementsByTagNameNS(
           "urn:oasis:names:tc:SAML:2.0:assertion", "Assertion");
   if (0 == assertionNodeList.getLength()) {
     return false;
   }
   Element assertionElement = (Element) assertionNodeList.item(0);
   NodeList audienceNodeList =
       assertionElement.getElementsByTagNameNS(
           "urn:oasis:names:tc:SAML:2.0:assertion", "Audience");
   if (0 != audienceNodeList.getLength()) {
     return true;
   }
   NodeList subjectConfirmationDataNodeList =
       assertionElement.getElementsByTagNameNS(
           "urn:oasis:names:tc:SAML:2.0:assertion", "SubjectConfirmationData");
   if (0 == subjectConfirmationDataNodeList.getLength()) {
     return false;
   }
   Element subjectConfirmationDataElement = (Element) subjectConfirmationDataNodeList.item(0);
   if (null != subjectConfirmationDataElement.getAttributeNode("Recipient")) {
     return true;
   }
   if (null != subjectConfirmationDataElement.getAttributeNode("Address")) {
     return true;
   }
   return false;
 }
  public boolean hasValidityIntervalIndication(ConversationID id) {
    Document document = getSAMLDocument(id);
    if (null == document) {
      return false;
    }

    NodeList saml1AssertionNodeList =
        document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion");
    if (0 != saml1AssertionNodeList.getLength()) {
      Element assertionElement = (Element) saml1AssertionNodeList.item(0);
      NodeList conditionsNodeList =
          assertionElement.getElementsByTagNameNS(
              "urn:oasis:names:tc:SAML:1.0:assertion", "Conditions");
      if (0 != conditionsNodeList.getLength()) {
        Element conditionsElement = (Element) conditionsNodeList.item(0);
        if (null != conditionsElement.getAttributeNode("NotBefore")
            && null != conditionsElement.getAttributeNode("NotOnOrAfter")) {
          return true;
        }
      }
    }

    NodeList saml2AssertionNodeList =
        document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion");
    if (0 != saml2AssertionNodeList.getLength()) {
      Element assertionElement = (Element) saml2AssertionNodeList.item(0);
      NodeList conditionsNodeList =
          assertionElement.getElementsByTagNameNS(
              "urn:oasis:names:tc:SAML:2.0:assertion", "Conditions");
      if (0 != conditionsNodeList.getLength()) {
        Element conditionsElement = (Element) conditionsNodeList.item(0);
        if (null != conditionsElement.getAttributeNode("NotBefore")
            && null != conditionsElement.getAttributeNode("NotOnOrAfter")) {
          return true;
        }
      }
    }

    NodeList saml2AuthnRequestNodeList =
        document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest");
    if (0 != saml2AuthnRequestNodeList.getLength()) {
      Element authnRequestElement = (Element) saml2AuthnRequestNodeList.item(0);
      NodeList conditionsNodeList =
          authnRequestElement.getElementsByTagNameNS(
              "urn:oasis:names:tc:SAML:2.0:assertion", "Conditions");
      if (0 != conditionsNodeList.getLength()) {
        Element conditionsElement = (Element) conditionsNodeList.item(0);
        if (null != conditionsElement.getAttributeNode("NotBefore")
            && null != conditionsElement.getAttributeNode("NotOnOrAfter")) {
          return true;
        }
      }
    }

    return false;
  }
Esempio n. 7
0
 /**
  * Get an child element from the parent element given its {@link QName}
  *
  * <p>First an attempt to get the element based on its namespace is made, failing which an element
  * with the localpart ignoring any namespace is returned.
  *
  * @param doc
  * @param elementQName
  * @return
  */
 public static Element getChildElement(Element doc, QName elementQName) {
   NodeList nl =
       doc.getElementsByTagNameNS(elementQName.getNamespaceURI(), elementQName.getLocalPart());
   if (nl.getLength() == 0) {
     nl = doc.getElementsByTagNameNS("*", elementQName.getLocalPart());
     if (nl.getLength() == 0)
       nl = doc.getElementsByTagName(elementQName.getPrefix() + ":" + elementQName.getLocalPart());
     if (nl.getLength() == 0) return null;
   }
   return (Element) nl.item(0);
 }
  public List getDecryptedAttributes(ConversationID id, String hexKey) throws Exception {
    List samlAttributes = new ArrayList();

    /*
     * We create a new DOM tree as XMLCipher will change the tree.
     */
    String encodedSamlMessage = getEncodedSAMLMessage(id);
    String decodedSamlMessage = getDecodedSAMLMessage(encodedSamlMessage);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(decodedSamlMessage.getBytes());
    Document document = this.builder.parse(inputStream);

    byte[] keyBytes = Hex.decode(hexKey);
    SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES");
    XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.AES_128);
    xmlCipher.init(XMLCipher.DECRYPT_MODE, secretKeySpec);

    NodeList encryptedAttributeNodeList =
        document.getElementsByTagNameNS(
            "urn:oasis:names:tc:SAML:2.0:assertion", "EncryptedAttribute");
    for (int encryptedAttributeIdx = 0;
        encryptedAttributeIdx < encryptedAttributeNodeList.getLength();
        encryptedAttributeIdx++) {
      Element encryptedAttributeElement =
          (Element) encryptedAttributeNodeList.item(encryptedAttributeIdx);
      NodeList encryptedDataNodeList =
          encryptedAttributeElement.getElementsByTagNameNS(
              "http://www.w3.org/2001/04/xmlenc#", "EncryptedData");
      if (1 != encryptedDataNodeList.getLength()) {
        continue;
      }
      Element encryptedDataElement = (Element) encryptedDataNodeList.item(0);
      xmlCipher.doFinal(document, encryptedDataElement);
      NodeList attributeNodeList =
          encryptedAttributeElement.getElementsByTagNameNS(
              "urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");
      if (1 != attributeNodeList.getLength()) {
        continue;
      }
      Element attributeElement = (Element) attributeNodeList.item(0);
      String attributeName = attributeElement.getAttribute("Name");
      NodeList attributeValueNodeList =
          attributeElement.getElementsByTagNameNS(
              "urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue");
      if (0 == attributeValueNodeList.getLength()) {
        continue;
      }
      Element attributeValueElement = (Element) attributeValueNodeList.item(0);
      String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue();
      NamedValue attribute = new NamedValue(attributeName, attributeValue);
      samlAttributes.add(attribute);
    }

    return samlAttributes;
  }
Esempio n. 9
0
 /**
  * Constructer that parses the XML dom tree and extracts useful attributes.
  *
  * @param el Root element of the tree within the SOAP body.
  */
 public UDDIException(Element el, boolean createDispositionReport) {
   if (isValidElement(el)) {
     // Extract useful attributes
     NodeList nl;
     Element tmp;
     nl = el.getElementsByTagName("faultcode");
     if (nl.getLength() == 0) { // Handle possible DOM level 2 response
       nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "faultcode");
     }
     if (nl != null && nl.getLength() > 0) {
       tmp = (Element) nl.item(0);
       faultCode = getText(tmp);
     }
     nl = el.getElementsByTagName("faultstring");
     if (nl.getLength() == 0) { // Handle possible DOM level 2 response
       nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "faultstring");
     }
     if (nl != null && nl.getLength() > 0) {
       tmp = (Element) nl.item(0);
       faultString = getText(tmp);
     }
     nl = el.getElementsByTagName("faultactor");
     if (nl.getLength() == 0) { // Handle possible DOM level 2 response
       nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "faultactor");
     }
     if (nl != null && nl.getLength() > 0) {
       tmp = (Element) nl.item(0);
       faultActor = getText(tmp);
     }
     nl = el.getElementsByTagName("detail");
     if (nl.getLength() == 0) { // Handle possible DOM level 2 response
       nl = el.getElementsByTagNameNS(UDDIElement.SOAPNS, "detail");
     }
     // Try to create a disposition report
     if (nl != null && nl.getLength() > 0) {
       tmp = (Element) nl.item(0);
       detailElement = tmp;
       if (createDispositionReport) {
         try {
           nl = el.getElementsByTagName(DispositionReport.UDDI_TAG);
           if (nl != null && nl.getLength() > 0) {
             tmp = (Element) nl.item(0);
             dispositionReport = new DispositionReport(tmp);
           }
         } catch (UDDIException e) {
           // Ignore exception, we're handling it already
         }
       }
     }
   }
 }
Esempio n. 10
0
 private Node getFederationElement(Element body, String nodeName) throws FSException {
   NodeList nl = body.getElementsByTagNameNS(IFSConstants.LIB_NAMESPACE_URI, nodeName);
   int length = nl.getLength();
   if (length == 0) {
     nl = body.getElementsByTagNameNS(IFSConstants.FF_12_XML_NS, nodeName);
     length = nl.getLength();
   }
   if (length > 1) {
     throw new FSException((String) null);
   }
   if (length != 0) {
     return (Node) nl.item(0);
   }
   return null;
 }
Esempio n. 11
0
  /**
   * Get the set of Java Projects
   *
   * @param project the compapp project
   * @param extensionNamespace
   * @param elementName
   * @param attributeName
   * @return the set of Java Projects
   */
  private static Set<String> collectCasaPortExtensionAttributes(
      JbiProject project, String extensionNamespace, String elementName, String attributeName) {

    Set<String> ret = new HashSet<String>();

    FileObject casaFO = CasaHelper.getCasaFileObject(project, true);
    if (casaFO == null) {
      return ret;
    }

    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      factory.setValidating(false);
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document casaDocument = builder.parse(casaFO.getInputStream());

      NodeList casaPorts = casaDocument.getElementsByTagName(CASA_PORT_ELEM_NAME);

      for (int i = 0; i < casaPorts.getLength(); i++) {
        Element casaPort = (Element) casaPorts.item(i);

        NodeList extElements = casaPort.getElementsByTagNameNS(extensionNamespace, elementName);
        for (int j = 0; j < extElements.getLength(); j++) {
          Element extElement = (Element) extElements.item(j);
          String attributeValue = extElement.getAttribute(attributeName);
          ret.add(attributeValue);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return ret;
  }
Esempio n. 12
0
  @SuppressWarnings("element-type-mismatch")
  public void parseWSDL() {
    // parse source grammars
    for (InputSource value : options.getWSDLs()) {
      String systemID = value.getSystemId();
      errorReceiver.pollAbort();

      Document dom;
      Element doc;

      try {
        // if there is entity resolver use it
        if (options.entityResolver != null) {
          value = options.entityResolver.resolveEntity(null, systemID);
        }
        if (value == null) {
          value = new InputSource(systemID);
        }
        dom = parse(value, true);

        doc = dom.getDocumentElement();
        if (doc == null) {
          continue;
        }
        // if its not a WSDL document, retry with MEX
        if (doc.getNamespaceURI() == null
            || !doc.getNamespaceURI().equals(WSDLConstants.NS_WSDL)
            || !doc.getLocalName().equals("definitions")) {
          throw new SAXParseException(
              WsdlMessages.INVALID_WSDL(
                  systemID,
                  com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS,
                  doc.getNodeName(),
                  locatorTable.getStartLocation(doc).getLineNumber()),
              locatorTable.getStartLocation(doc));
        }
      } catch (FileNotFoundException e) {
        errorReceiver.error(WsdlMessages.FILE_NOT_FOUND(systemID), e);
        return;
      } catch (IOException e) {
        doc = getFromMetadataResolver(systemID, e);
      } catch (SAXParseException e) {
        doc = getFromMetadataResolver(systemID, e);
      } catch (SAXException e) {
        doc = getFromMetadataResolver(systemID, e);
      }

      if (doc == null) {
        continue;
      }

      NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
      for (int i = 0; i < schemas.getLength(); i++) {
        if (!inlinedSchemaElements.contains(schemas.item(i))) {
          inlinedSchemaElements.add((Element) schemas.item(i));
        }
      }
    }
    identifyRootWsdls();
  }
    // utility method to create or get an existing use-sdk xml element under manifest.
    // this could be made more generic by adding more metadata to the enum but since there is
    // only one case so far, keep it simple.
    private static XmlElement createOrGetUseSdk(
        ActionRecorder actionRecorder, XmlDocument document) {

      Element manifest = document.getXml().getDocumentElement();
      NodeList usesSdks =
          manifest.getElementsByTagName(ManifestModel.NodeTypes.USES_SDK.toXmlName());
      if (usesSdks.getLength() == 0) {
        usesSdks =
            manifest.getElementsByTagNameNS(
                SdkConstants.ANDROID_URI, ManifestModel.NodeTypes.USES_SDK.toXmlName());
      }
      if (usesSdks.getLength() == 0) {
        // create it first.
        Element useSdk =
            manifest.getOwnerDocument().createElement(ManifestModel.NodeTypes.USES_SDK.toXmlName());
        manifest.appendChild(useSdk);
        XmlElement xmlElement = new XmlElement(useSdk, document);
        Actions.NodeRecord nodeRecord =
            new Actions.NodeRecord(
                Actions.ActionType.INJECTED,
                new Actions.ActionLocation(xmlElement.getSourceLocation(), PositionImpl.UNKNOWN),
                xmlElement.getId(),
                "use-sdk injection requested",
                NodeOperationType.STRICT);
        actionRecorder.recordNodeAction(xmlElement, nodeRecord);
        return xmlElement;
      } else {
        return new XmlElement((Element) usesSdks.item(0), document);
      }
    }
  /**
   * Convenience method to update a template bean definition from overriding XML data. If <code>
   * overrides</code> contains attribute <code>attribute</code> or a child element with name <code>
   * attribute</code>, transfer that attribute as a bean property onto <code>template</code>,
   * overwriting the default value.
   *
   * @param reference if true, the value of the attribute is to be interpreted as a runtime bean
   *     name reference; otherwise it is interpreted as a literal value
   */
  public static boolean overrideProperty(
      String attribute, BeanDefinition template, Element overrides, boolean reference) {
    Object value = null;
    if (overrides.hasAttribute(attribute)) {
      value = overrides.getAttribute(attribute);
    } else {
      NodeList children = overrides.getElementsByTagNameNS("*", attribute);
      if (children.getLength() == 1) {
        Element child = (Element) children.item(0);
        value = child.getTextContent();
      }
    }

    if (value != null) {
      if (reference) value = new RuntimeBeanReference(value.toString());

      String propName = Conventions.attributeNameToPropertyName(attribute);
      MutablePropertyValues props = template.getPropertyValues();
      props.removePropertyValue(propName);
      props.addPropertyValue(propName, value);
      return true;
    }

    return false;
  }
Esempio n. 15
0
  // private?
  public static Set<AimQuantification> parseQuantifications(
      Element rootElement,
      AimImagingObservationCharacteristic aimImagingObservationCharacteristic) {

    System.out.println(
        "aimImagingObservationCharacteristic:" + aimImagingObservationCharacteristic);

    Set<AimQuantification> results = new HashSet<AimQuantification>();

    // ns1:ImagingObservationCharacteristic
    NodeList imagingQuantifications =
        rootElement.getElementsByTagNameNS(AIM_NS, "CharacteristicQuantification");

    for (int i = 0; i < imagingQuantifications.getLength(); i++) {
      Element imagingQuantification = (Element) imagingQuantifications.item(i);

      String name = imagingQuantification.getAttribute("name");
      String value = imagingQuantification.getAttribute("value");
      String type = imagingQuantification.getAttributeNS(XSI_NS, "type");

      AimQuantification aimQuantification = new AimQuantification();
      aimQuantification.setName(name);
      aimQuantification.setValue(value);
      aimQuantification.setType(filterNameSpace(type));
      aimQuantification.setAimImagingObservationCharacteristic(aimImagingObservationCharacteristic);

      results.add(aimQuantification);
    }
    return results;
  }
  /**
   * Set a property of a resource to a value.
   *
   * @param name the property name
   * @param value the property value
   * @exception com.ibm.webdav.WebDAVException
   */
  public void setProperty(String name, Element value) throws WebDAVException {
    // load the properties
    Document propertiesDocument = resource.loadProperties();
    Element properties = propertiesDocument.getDocumentElement();
    String ns = value.getNamespaceURI();

    Element property = null;
    if (ns == null) {
      property = (Element) ((Element) properties).getElementsByTagName(value.getTagName()).item(0);
    } else {
      property = (Element) properties.getElementsByTagNameNS(ns, value.getLocalName()).item(0);
    }

    if (property != null) {
      try {
        properties.removeChild(property);
      } catch (DOMException exc) {
      }
    }

    properties.appendChild(propertiesDocument.importNode(value, true));

    // write out the properties
    resource.saveProperties(propertiesDocument);
  }
 public SPFolderCollection getSubFolders()
     throws SAXException, ParserConfigurationException, IOException, NoSuchAlgorithmException,
         KeyManagementException, ParseException {
   GetListItems.Query query = new GetListItems.Query();
   Document docQuery =
       WsContext.stringToDom(
           "<Query><Where><Eq><FieldRef Name=\"FSObjType\"/><Value Type=\"Lookup\">1</Value></Eq></Where></Query>");
   query.getContent().add(docQuery.getDocumentElement());
   GetListItems.QueryOptions queryOptions = new GetListItems.QueryOptions();
   Document doc =
       WsContext.stringToDom(
           "<QueryOptions><ViewAttributes IncludeRootFolder=\"False\" /><IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc><Folder>"
               + url
               + "</Folder></QueryOptions>");
   queryOptions.getContent().add(doc.getDocumentElement());
   SPFolderCollection foldersCollection = null;
   GetListItemsResponse.GetListItemsResult result =
       WsContext.getListsPort(new URL(webAbsluteUrl))
           .getListItems(listName, null, query, null, "0", queryOptions, webId);
   for (Object content : result.getContent()) {
     if (content instanceof Element) {
       Element rootElement = (Element) content;
       NodeList dataNodeList =
           rootElement.getElementsByTagNameNS("urn:schemas-microsoft-com:rowset", "data");
       for (int i = 0; i < dataNodeList.getLength(); i++) {
         Element dataElement = (Element) dataNodeList.item(i);
         foldersCollection = new SPFolderCollection(name, webAbsluteUrl, webId);
         foldersCollection.loadFromXml(dataElement);
       }
     }
   }
   return foldersCollection;
 }
 /**
  * This method is used to get RRFedNonFedBudget from BudgetSubAwards
  *
  * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry.
  * @return RRFedNonFedBudget corresponding to the BudgetSubAwards object.
  */
 private RRFedNonFedBudgetDocument getRRFedNonFedBudget(BudgetSubAwards budgetSubAwards) {
   RRFedNonFedBudgetDocument rrBudget = RRFedNonFedBudgetDocument.Factory.newInstance();
   String subAwdXML = budgetSubAwards.getSubAwardXmlFileData();
   Document subAwdFormsDoc;
   try {
     subAwdFormsDoc = stringToDom(subAwdXML);
   } catch (S2SException e1) {
     return rrBudget;
   }
   Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement();
   NodeList subAwdNodeList =
       subAwdFormsElement.getElementsByTagNameNS(
           RR_FED_NON_FED_BUDGET30_11_NAMESPACE_URI, LOCAL_FED_NON_FED_NAME);
   Node subAwdNode = null;
   if (subAwdNodeList != null) {
     if (subAwdNodeList.getLength() == 0) {
       return null;
     }
     subAwdNode = subAwdNodeList.item(0);
   }
   byte[] subAwdNodeBytes = null;
   try {
     subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode));
     InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes);
     rrBudget = (RRFedNonFedBudgetDocument) XmlObject.Factory.parse(bgtIS);
   } catch (S2SException e) {
     return rrBudget;
   } catch (XmlException e) {
     return rrBudget;
   } catch (IOException e) {
     return rrBudget;
   }
   return rrBudget;
 }
Esempio n. 19
0
  /** extracts XML from PDF */
  protected byte[] getXMLFromPDF(PdfReader reader) throws Exception {
    XfaForm xfaForm = reader.getAcroFields().getXfa();
    Node domDocument = xfaForm.getDomDocument();
    if (domDocument == null) return null;
    Element documentElement = ((Document) domDocument).getDocumentElement();

    Element datasetsElement =
        (Element) documentElement.getElementsByTagNameNS(XFA_NS, "datasets").item(0);
    Element dataElement = (Element) datasetsElement.getElementsByTagNameNS(XFA_NS, "data").item(0);

    Element xmlElement = (Element) dataElement.getChildNodes().item(0);

    Node budgetElement = getBudgetElement(xmlElement);

    byte[] serializedXML = XfaForm.serializeDoc(budgetElement);

    return serializedXML;
  }
Esempio n. 20
0
 /**
  * Given an element, returns its direct child with the given namespace and name, failing unless
  * there is one and only one match. Use null to indicate the empty namespace.
  */
 public static Element getElementOrThrowNS(
     Element element, String namespaceURI, String localName) {
   NodeList elements = element.getElementsByTagNameNS(namespaceURI, localName);
   if (elements.getLength() != 1) {
     throw new IllegalPropertyException(
         "Element " + element.getNodeName() + " must have exactly one " + localName + " element");
   }
   return (Element) elements.item(0);
 }
  public List<NamedValue> getSAMLAttributes(ConversationID id) {
    List<NamedValue> samlAttributes = new ArrayList<NamedValue>();

    Document document = getSAMLDocument(id);
    if (null == document) {
      return samlAttributes;
    }

    NodeList attributeNodeList =
        document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Attribute");
    for (int idx = 0; idx < attributeNodeList.getLength(); idx++) {
      Element attributeElement = (Element) attributeNodeList.item(idx);
      String attributeName = attributeElement.getAttribute("AttributeName");
      NodeList attributeValueNodeList =
          attributeElement.getElementsByTagNameNS(
              "urn:oasis:names:tc:SAML:1.0:assertion", "AttributeValue");
      if (0 == attributeValueNodeList.getLength()) {
        continue;
      }
      Element attributeValueElement = (Element) attributeValueNodeList.item(0);
      String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue();
      NamedValue attribute = new NamedValue(attributeName, attributeValue);
      samlAttributes.add(attribute);
    }

    NodeList attribute2NodeList =
        document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");
    for (int idx = 0; idx < attribute2NodeList.getLength(); idx++) {
      Element attributeElement = (Element) attribute2NodeList.item(idx);
      String attributeName = attributeElement.getAttribute("Name");
      NodeList attributeValueNodeList =
          attributeElement.getElementsByTagNameNS(
              "urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue");
      if (0 == attributeValueNodeList.getLength()) {
        continue;
      }
      Element attributeValueElement = (Element) attributeValueNodeList.item(0);
      String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue();
      NamedValue attribute = new NamedValue(attributeName, attributeValue);
      samlAttributes.add(attribute);
    }

    return samlAttributes;
  }
Esempio n. 22
0
 private Node getSAMLElement(Element body, String nodeName) throws FSException {
   NodeList nl = body.getElementsByTagNameNS(IFSConstants.PROTOCOL_NAMESPACE_URI, nodeName);
   int length = nl.getLength();
   if (length > 1) {
     throw new FSException((String) null);
   }
   if (length != 0) {
     return (Node) nl.item(0);
   }
   return null;
 }
Esempio n. 23
0
 protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
   Element e = options.getHandlerChainConfiguration();
   if (e == null) return;
   JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
   NodeList nl = e.getElementsByTagNameNS("http://java.sun.com/xml/ns/javaee", "handler-chain");
   if (nl.getLength() > 0) {
     String fName = getHandlerConfigFileName(className);
     handlerChainAnn.param("file", fName);
     generateHandlerChainFile(e, className);
   }
 }
 protected String getContent(String source)
     throws SAXException, IOException, ParserConfigurationException, TransformerException {
   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   factory.setNamespaceAware(true);
   Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(source)));
   Element root = doc.getDocumentElement();
   Element holder =
       (Element)
           root.getElementsByTagNameNS(AbstractSubscription.WSN_URI, "NotificationMessage")
               .item(0);
   Element message =
       (Element) holder.getElementsByTagNameNS(AbstractSubscription.WSN_URI, "Message").item(0);
   Element content = null;
   for (int i = 0; i < message.getChildNodes().getLength(); i++) {
     if (message.getChildNodes().item(i) instanceof Element) {
       content = (Element) message.getChildNodes().item(i);
       break;
     }
   }
   String messageContent = content.getTextContent();
   return messageContent;
 }
Esempio n. 25
0
  /**
   * Returns or create (if it does not exist) the SignedDataObjectProperties DOM object.
   *
   * @throws DSSException
   */
  protected void ensureSignedDataObjectProperties() throws DSSException {

    final NodeList signedDataObjectPropertiesNodeList =
        currentSignatureDom.getElementsByTagNameNS(
            XAdESNamespaces.XAdES, "SignedDataObjectProperties");
    final int length = signedDataObjectPropertiesNodeList.getLength();
    if (length == 1) {
      signedDataObjectPropertiesDom = (Element) signedDataObjectPropertiesNodeList.item(0);
    } else if (length > 1) {
      throw new DSSException(
          "The signature contains more than one SignedDataObjectProperties element! Extension is not possible.");
    }
  }
Esempio n. 26
0
  //	@Test
  public void testElementsByTagNameWithNamespace() throws Exception {
    builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);

    String xml =
        "<?xml version=\"1.0\"?>"
            + "<t:root xmlns=\"http://void.com/\" xmlns:t=\"http://t.com/\" id=\"stella\" t:type=\"police\">"
            + "<t:item id=\"a\"/>"
            + "<child id=\"1\"/>"
            + "<t:item id=\"b\"/>"
            + "<child id=\"2\"/>"
            + "</t:root>";

    // TODO: Can I utilize xmlSearchNs or xmlSearchNsByHref? the problem is it searchs a specific
    // node and recurse up.
    // I don't have such a node

    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
    Element root = doc.getDocumentElement();

    List<String> expectedList = Arrays.asList("1", "2");
    List<String> actualList = new ArrayList<String>();
    NodeList nl = root.getElementsByTagNameNS("http://void.com/", "child");
    for (int i = 0; i < nl.getLength(); i++) {
      Element elem = (Element) nl.item(i);
      actualList.add(elem.getAttribute("id"));
    }
    Assert.assertArrayEquals("elementsByTagName", expectedList.toArray(), actualList.toArray());

    expectedList = Arrays.asList("a", "b");
    actualList.clear();
    nl = root.getElementsByTagNameNS("http://t.com/", "item");
    for (int i = 0; i < nl.getLength(); i++) {
      Element elem = (Element) nl.item(i);
      actualList.add(elem.getAttribute("id"));
    }
  }
 private boolean isDigested(NodeList nodeList, Element signatureElement)
     throws XMLSignatureException, XMLSecurityException {
   NodeList referenceNodeList =
       signatureElement.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Reference");
   Document document = nodeList.item(0).getOwnerDocument();
   Manifest manifest = new Manifest(document);
   VerifyReference[] references = new VerifyReference[referenceNodeList.getLength()];
   for (int referenceIdx = 0; referenceIdx < referenceNodeList.getLength(); referenceIdx++) {
     Element referenceElement = (Element) referenceNodeList.item(referenceIdx);
     VerifyReference reference = new VerifyReference(referenceElement, manifest);
     reference.init();
     references[referenceIdx] = reference;
   }
   return isDigested(nodeList, references);
 }
Esempio n. 28
0
 private void assertEndpointReference(
     EndpointReference epr, String refPar, DocumentBuilder builder) throws IOException {
   Logger.getLogger(this.getClass()).info("epr: " + epr);
   assert (W3CEndpointReference.class.getName().equals(epr.getClass().getName()));
   Element endpointReference = DOMUtils.parse(epr.toString(), builder);
   assert ("EndpointReference".equals(endpointReference.getNodeName()));
   assert ("http://www.w3.org/2005/08/addressing".equals(endpointReference.getAttribute("xmlns")));
   NodeList addresses = endpointReference.getElementsByTagName("Address");
   assert (addresses.getLength() == 1);
   assert (("http://" + hostName + ":8081/jaxws-endpoint")
       .equals(addresses.item(0).getFirstChild().getNodeValue()));
   if (refPar != null) {
     Element refEle = DOMUtils.parse(refPar, builder);
     NodeList nodeList =
         endpointReference.getElementsByTagNameNS(refEle.getNamespaceURI(), refEle.getLocalName());
     assert (nodeList.getLength() == 1);
     assert (refEle.getTextContent().equals(nodeList.item(0).getTextContent()));
   }
 }
  protected String getWMIError(SOAPFault soapFault) {
    XPathExpression xpath =
        XmlUtils.compileXPath(
            WinRMConstants.XPATH,
            "s:Detail/f:WSManFault/f:Message/f:ProviderFault/f:ExtendedError");
    Element extendedError = XmlUtils.selectElement(xpath, soapFault);

    if (extendedError != null) {
      NodeList descriptionElements = extendedError.getElementsByTagNameNS("*", "Description");

      if (descriptionElements.getLength() != 0) {
        if (!StringUtils.isBlank(descriptionElements.item(0).getTextContent())) {
          return descriptionElements.item(0).getTextContent();
        }
      }
    }

    return null; // No Description, or it's empty
  }
 private boolean isOmitEntity(final NodeList omitConfig, String appVersion) {
   if (appVersion == null || omitConfig == null) {
     return false;
   }
   Element omitConfigNode = (Element) omitConfig.item(0);
   if (omitConfigNode != null) {
     NodeList versionNode =
         omitConfigNode.getElementsByTagNameNS(
             EntityListParser.ENTITY_LIST_XSD_NS, EntityListParser.VERSION);
     if (versionNode != null) {
       Element verisonElement = (Element) versionNode.item(0);
       String versionRegex = verisonElement.getNodeValue();
       if (isMatch(versionRegex, appVersion)) {
         return true;
       }
     }
   }
   return false;
 }