Java Code Examples for org.w3c.dom.Element#getTextContent()

The following examples show how to use org.w3c.dom.Element#getTextContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSAActionAssertingHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(SOAPMessageContext context) {
    // only inbound messages are of use
    if ((Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
        return true;
    }
    try {
        Element elm = DOMUtils.getFirstElement(context.getMessage().getSOAPHeader());
        while (elm != null) {
            if ("Action".equals(elm.getLocalName()) && elm.getNamespaceURI().contains("addressing")) {
                if (!elm.getTextContent().equals(action)) {
                    throw new RuntimeException("The event sink should have received "
                            + "WSA-Action: " + action + " but received: "
                            + elm.getTextContent());
                }
                return true;
            }
            elm = DOMUtils.getNextElement(elm);
        }
    } catch (SOAPException e) {
        throw new RuntimeException(e);
    }
    throw new RuntimeException("The event sink should have received a WSA-Action associated with"
            + "the notification");
}
 
Example 2
Source File: SAMLTokenFactory.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public SAMLToken createSamlToken(Element assertion, Credential credential) {
   NodeList authenticationStatements = assertion.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "AuthenticationStatement");

   for(int i = 0; i < authenticationStatements.getLength(); ++i) {
      Element authenticationStatement = (Element)authenticationStatements.item(i);
      NodeList confirmationMethodsNodeList = authenticationStatement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "ConfirmationMethod");

      for(int j = 0; j < confirmationMethodsNodeList.getLength(); ++j) {
         Element confirmationMethodEl = (Element)confirmationMethodsNodeList.item(j);
         String confirmationMethod = confirmationMethodEl.getTextContent();
         LOG.debug("ConfirmationMethod " + confirmationMethod + " found.");
         if ("urn:oasis:names:tc:SAML:1.0:cm:holder-of-key".equals(confirmationMethod)) {
            return new SAMLHolderOfKeyToken(assertion, credential);
         }

         if ("urn:oasis:names:tc:SAML:1.0:cm:sender-vouches".equals(confirmationMethod)) {
            return new SAMLSenderVouchesCredential(assertion, credential);
         }

         LOG.debug("Unsupported configurtionMethod [" + confirmationMethod + "]");
      }
   }

   LOG.debug("Unable to determine confirmationMethod.");
   return new SAMLHolderOfKeyToken(assertion, credential);
}
 
Example 3
Source File: OVFHelper.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
private OVFDiskController getController(Element controllerItem) {
    OVFDiskController dc = new OVFDiskController();
    NodeList child = controllerItem.getChildNodes();
    for (int l = 0; l < child.getLength(); l++) {
        if (child.item(l) instanceof Element) {
            Element el = (Element)child.item(l);
            if ("rasd:ElementName".equals(el.getNodeName())) {
                dc._name = el.getTextContent();
            }
            if ("rasd:ResourceSubType".equals(el.getNodeName())) {
                dc._subType = el.getTextContent();
            }
        }
    }
    return dc;
}
 
Example 4
Source File: StaxClaimsValidator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean handleSAML2Assertion(
    org.opensaml.saml.saml2.core.Assertion assertion
) throws WSSecurityException {
    List<org.opensaml.saml.saml2.core.AttributeStatement> attributeStatements =
        assertion.getAttributeStatements();
    if (attributeStatements == null || attributeStatements.isEmpty()) {
        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
    }

    for (org.opensaml.saml.saml2.core.AttributeStatement statement : attributeStatements) {
        List<org.opensaml.saml.saml2.core.Attribute> attributes = statement.getAttributes();
        for (org.opensaml.saml.saml2.core.Attribute attribute : attributes) {
            if (!attribute.getName().startsWith(ClaimTypes.URI_BASE.toString())) {
                continue;
            }

            for (XMLObject attributeValue : attribute.getAttributeValues()) {
                Element attributeValueElement = attributeValue.getDOM();
                String text = attributeValueElement.getTextContent();
                if (!"admin-user".equals(text)) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
Example 5
Source File: ParameterEqualsCondition.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public ParameterEqualsCondition(Element element) {
	NodeList children = element.getChildNodes();
	for (int i = 0; i < children.getLength(); i++) {
		Node child = children.item(i);
		if (child instanceof Element) {
			Element childElem = (Element) child;
			if (childElem.getTagName().equals("parameter")) {
				parameterKey = childElem.getTextContent();
			} else if (childElem.getTagName().equals("value")) {
				parameterValue = childElem.getTextContent();
			}
		}
	}
}
 
Example 6
Source File: ClaimsManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected List<ProcessedClaim> parseClaimsInAssertion(org.opensaml.saml.saml2.core.Assertion assertion) {
    List<org.opensaml.saml.saml2.core.AttributeStatement> attributeStatements =
        assertion.getAttributeStatements();
    if (attributeStatements == null || attributeStatements.isEmpty()) {
        if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest("No attribute statements found");
        }
        return Collections.emptyList();
    }

    List<ProcessedClaim> collection = new ArrayList<>();

    for (org.opensaml.saml.saml2.core.AttributeStatement statement : attributeStatements) {
        if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest("parsing statement: " + statement.getElementQName());
        }
        List<org.opensaml.saml.saml2.core.Attribute> attributes = statement.getAttributes();
        for (org.opensaml.saml.saml2.core.Attribute attribute : attributes) {
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.finest("parsing attribute: " + attribute.getName());
            }
            ProcessedClaim c = new ProcessedClaim();
            c.setClaimType(URI.create(attribute.getName()));
            c.setIssuer(assertion.getIssuer().getNameQualifier());
            for (XMLObject attributeValue : attribute.getAttributeValues()) {
                Element attributeValueElement = attributeValue.getDOM();
                String value = attributeValueElement.getTextContent();
                if (LOG.isLoggable(Level.FINEST)) {
                    LOG.finest(" [" + value + "]");
                }
                c.addValue(value);
            }
            collection.add(c);
        }
    }
    return collection;

}
 
Example 7
Source File: CustomTxtTraceDefinition.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static InputLine extractInputLine(Element inputLineElement) {
    InputLine inputLine = new InputLine();
    NodeList nodeList = inputLineElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        String nodeName = node.getNodeName();
        if (nodeName.equals(CARDINALITY_ELEMENT)) {
            Element cardinalityElement = (Element) node;
            try {
                int min = Integer.parseInt(cardinalityElement.getAttribute(MIN_ATTRIBUTE));
                int max = Integer.parseInt(cardinalityElement.getAttribute(MAX_ATTRIBUTE));
                inputLine.cardinality = new Cardinality(min, max);
            } catch (NumberFormatException e) {
                return null;
            }
        } else if (nodeName.equals(REGEX_ELEMENT)) {
            Element regexElement = (Element) node;
            inputLine.regex = regexElement.getTextContent();
        } else if (nodeName.equals(EVENT_TYPE_ELEMENT)) {
            Element eventTypeElement = (Element) node;
            inputLine.eventType = eventTypeElement.getTextContent();
        } else if (nodeName.equals(INPUT_DATA_ELEMENT)) {
            Element inputDataElement = (Element) node;
            InputData inputData = new InputData();
            Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
            inputData.tag = checkNotNull(entry.getKey());
            inputData.name = checkNotNull(entry.getValue());
            inputData.action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
            inputData.format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
            inputLine.addColumn(inputData);
        } else if (nodeName.equals(INPUT_LINE_ELEMENT)) {
            Element childInputLineElement = (Element) node;
            InputLine childInputLine = extractInputLine(childInputLineElement);
            if (childInputLine != null) {
                inputLine.addChild(childInputLine);
            }
        }
    }
    return inputLine;
}
 
Example 8
Source File: ReplaceParameterRule.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public ReplaceParameterRule(String operatorTypeName, Element element) throws XMLException {
	super(operatorTypeName, element);
	NodeList children = element.getChildNodes();
	for (int i = 0; i < children.getLength(); i++) {
		Node child = children.item(i);
		if (child instanceof Element) {
			Element childElem = (Element) child;
			if (childElem.getTagName().equals("oldparameter")) {
				oldAttributeName = childElem.getTextContent();
			} else if (childElem.getTagName().equals("newparameter")) {
				newAttributeName = childElem.getTextContent();
			}
		}
	}
}
 
Example 9
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml1.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml1.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml1.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml1.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml1.core.Attribute attribute : attributes) {
                
                if (attribute.getAttributeName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 10
Source File: BooleanParameter.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void loadValueFromXML(Element xmlElement) {
  String rangeString = xmlElement.getTextContent();
  if (rangeString.length() == 0)
    return;
  this.value = Boolean.valueOf(rangeString);
}
 
Example 11
Source File: DocumentMetadataHandle.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
private void receiveMetadataValuesImpl(Document document) {
  DocumentMetadataValues metadataValues = getMetadataValues();
  metadataValues.clear();

  if (document == null)
    return;

  NodeList valuesIn = document.getElementsByTagNameNS(REST_API_NS, "metadata-values");
  int valuesInLength = valuesIn.getLength();
  for (int i = 0; i < valuesInLength; i++) {
    String key = null;
    String value = null;

    NodeList children = valuesIn.item(i).getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
      Node node = children.item(j);
      if (node.getNodeType() != Node.ELEMENT_NODE)
        continue;
      Element element = (Element) node;

      if ("metadata-value".equals(element.getLocalName())) {
        key = element.getAttribute("key");
        value = element.getTextContent();
      } else if (logger.isWarnEnabled())
        logger.warn("Skipping unknown value element", element.getTagName());
      if (key == null || value == null) {
        if (logger.isWarnEnabled())
          logger.warn("Could not parse value");
        continue;
      }

      metadataValues.put(key, value);
    }
  }
}
 
Example 12
Source File: ToggleParameterSetParameter.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void loadValueFromXML(@Nonnull Element xmlElement) {
  String stringValue = xmlElement.getTextContent();
  for (HashMap.Entry<String, ParameterSet> entry : toggleValues.entrySet()) {
    if (entry.getKey().toString().equals(stringValue)) {
      setValue(entry.getKey());
      break;
    }
  }
}
 
Example 13
Source File: AbstractIdRoleAttribute.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Returns qualified role names based on IDs in the XML. Each returned
 * qualified Role contains a single ID.
 * 
 * @see org.kuali.rice.kew.rule.RoleAttribute#getQualifiedRoleNames(java.lang.String,
 *      org.kuali.rice.kew.routeheader.DocumentContent)
 */
public List<String> getQualifiedRoleNames(String roleName,
		DocumentContent documentContent) {
	try {
		readConfiguration();
		String elementName = (String) getParamMap().get(XML_ELEMENT_LABEL);
		List<String> qualifiedRoleNames = new ArrayList<String>();
		XPath xPath = XPathHelper.newXPath();
		NodeList idNodes = (NodeList) xPath.evaluate("//"
				+ getAttributeElementName() + "/" + elementName,
				documentContent.getDocument(), XPathConstants.NODESET);
           List<String> qualifiedRoleIds = new ArrayList<String>();  //used only for groupTogether parsing
           for (int index = 0; index < idNodes.getLength(); index++) {
			Element idElement = (Element) idNodes.item(index);
			String id = idElement.getTextContent();
               if(isGroupTogetherRole()) {
                   qualifiedRoleIds.add(id);
               } else {
		    	qualifiedRoleNames.add(id);
		    }
           }
           if(isGroupTogetherRole()){
               qualifiedRoleNames.add(StringUtils.join(qualifiedRoleIds, STRING_ID_SEPERATOR));
           }
		return qualifiedRoleNames;
	} catch (XPathExpressionException e) {
		throw new WorkflowRuntimeException(
				"Failed to evaulate XPath expression to find ids.", e);
	}
}
 
Example 14
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml2.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml2.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml2.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml2.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml2.core.Attribute attribute : attributes) {
                
                if (attribute.getName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 15
Source File: PropertiesDocReader.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeDefaultMessages()
{
	Properties defaultMessages = new Properties();
	BreakIterator sentenceBreaks = BreakIterator.getSentenceInstance(Locale.US);
	for (CompiledPropertyMetadata prop : properties.getProperties())
	{
		String descriptionMessage = PropertyMetadataConstants.PROPERTY_DESCRIPTION_PREFIX + prop.getName();
		if (propertyMessages == null || !propertyMessages.containsKey(descriptionMessage))
		{
			Element docNode = propertyDocNodes.get(prop.getName());
			if (docNode != null)
			{
				String docText = docNode.getTextContent();
				sentenceBreaks.setText(docText);
				int first = sentenceBreaks.first();
				int next = sentenceBreaks.next();
				
				String firstSentence = docText.substring(first, next);
				firstSentence = PATTERN_LEADING_WHITE_SPACE.matcher(firstSentence).replaceAll("");
				firstSentence = PATTERN_TRAILING_WHITE_SPACE.matcher(firstSentence).replaceAll("");
				
				defaultMessages.setProperty(descriptionMessage, firstSentence);
			}
		}
	}
	
	if (!defaultMessages.isEmpty())
	{
		try
		{
			FileObject res = environment.getFiler().createResource(StandardLocation.CLASS_OUTPUT, 
					"", properties.getMessagesName() + PropertyMetadataConstants.MESSAGES_DEFAULTS_SUFFIX, 
					(javax.lang.model.element.Element[]) null);
			try (OutputStream out = res.openOutputStream())
			{
				//TODO lucianc preserve order
				defaultMessages.store(out, null);
			}
		}
		catch (IOException e)
		{
			throw new RuntimeException(e);
		}
	}
}
 
Example 16
Source File: CustomClaimsHandler.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims,
        ClaimsParameters parameters) {

    // Insist that a "realm" Custom Content is available in the RST with a value equal to "custom-realm"
    List<Object> customContent = parameters.getTokenRequirements().getCustomContent();
    boolean foundRealm = false;
    for (Object customContentElement : customContent) {
        Element customRealm =
            XMLUtils.findElement((Element)customContentElement, "realm", "http://cxf.apache.org/custom");
        if (customRealm != null) {
            String realmStr = customRealm.getTextContent();
            if ("custom-realm".equals(realmStr)) {
                foundRealm = true;
                break;
            }
        }
    }

    if (!foundRealm || parameters.getRealm() == null || !parameters.getRealm().equalsIgnoreCase(getRealm())) {
        LOG.fine("Realm '" + parameters.getRealm() + "' doesn't match with configured realm '" + getRealm() + "'");
        return new ProcessedClaimCollection();
    }
    if (getUserClaims() == null || parameters.getPrincipal() == null) {
        return new ProcessedClaimCollection();
    }

    if (claims == null || claims.isEmpty()) {
        LOG.fine("No claims requested");
        return new ProcessedClaimCollection();
    }

    Map<String, String> claimMap = getUserClaims().get(parameters.getPrincipal().getName());
    if (claimMap == null || claimMap.isEmpty()) {
        LOG.fine("Claims requested for principal '" + parameters.getPrincipal().getName()
                 + "' but not found");
        return new ProcessedClaimCollection();
    }
    LOG.fine("Claims found for principal '" + parameters.getPrincipal().getName() + "'");

    if (!claims.isEmpty()) {
        ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
        for (Claim requestClaim : claims) {
            String claimValue = claimMap.get(requestClaim.getClaimType().toString());
            if (claimValue != null) {
                ProcessedClaim claim = new ProcessedClaim();
                claim.setClaimType(requestClaim.getClaimType());
                claim.setIssuer("Test Issuer");
                claim.setOriginalIssuer("Original Issuer");
                claim.addValue(claimValue);
                claimCollection.add(claim);
            }
        }
        return claimCollection;
    }
    return null;

}
 
Example 17
Source File: TestUtil.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Convert a XML Element that represents a SQL ResultSet to a frequency map
 * for unordered comparisons. This map contains mapping of the XML string of a
 * row to number of occurrences of that row in the ResultSet.
 */
public static Map<String, Integer> xmlElementToFrequencyMap(
    Element resultSetElement) throws SQLException, IOException,
    TransformerException {
  NodeList rowList = resultSetElement.getChildNodes();
  Map<String, Integer> frequencyMap = new HashMap<String, Integer>();
  for (int index = 0; index < rowList.getLength(); ++index) {
    Element rowElement = (Element)rowList.item(index);
    SortedMap<ColumnNameValue, Element> rowMap = new TreeMap<ColumnNameValue, Element>();
    Map<ColumnNameValue, Integer> repeatedColumns = new HashMap<ColumnNameValue, Integer>();
    NodeList fieldList = rowElement.getChildNodes();
    while (fieldList.getLength() > 0) {
      Element fieldElement = (Element)fieldList.item(0);
      String columnName = fieldElement.getAttribute("name");
      if (columnName != null) {
        ColumnNameValue col = new ColumnNameValue(columnName, fieldElement
            .getTextContent());
        if (repeatedColumns.containsKey(col)) {
          Integer suffix = repeatedColumns.get(col);
          repeatedColumns.put(col, Integer.valueOf(suffix.intValue() + 1));
          col.colName += ("." + suffix.toString());
          rowMap.put(col, fieldElement);
        }
        else {
          repeatedColumns.put(col, Integer.valueOf(1));
          rowMap.put(col, fieldElement);
        }
      }
      rowElement.removeChild(fieldElement);
    }
    for (Map.Entry<ColumnNameValue, Element> row : rowMap.entrySet()) {
      rowElement.appendChild(row.getValue());
    }
    String rowXML = Misc.serializeXML(rowElement);
    Object numRowInstances = frequencyMap.get(rowXML);
    if (numRowInstances == null) {
      frequencyMap.put(rowXML, Integer.valueOf(1));
    }
    else {
      frequencyMap.put(rowXML, Integer.valueOf(((Integer)numRowInstances)
          .intValue() + 1));
    }
  }
  return frequencyMap;
}
 
Example 18
Source File: JettyHTTPServerEngineBeanDefinitionParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {

        String portStr = element.getAttribute("port");
        bean.addPropertyValue("port", portStr);

        String hostStr = element.getAttribute("host");
        if (hostStr != null && !"".equals(hostStr.trim())) {
            bean.addPropertyValue("host", hostStr);
        }

        String continuationsStr = element.getAttribute("continuationsEnabled");
        if (continuationsStr != null && continuationsStr.length() > 0) {
            bean.addPropertyValue("continuationsEnabled", continuationsStr);
        }

        String maxIdleTimeStr = element.getAttribute("maxIdleTime");
        if (maxIdleTimeStr != null && !"".equals(maxIdleTimeStr.trim())) {
            bean.addPropertyValue("maxIdleTime", maxIdleTimeStr);
        }

        String sendServerVersionStr = element.getAttribute("sendServerVersion");
        if (sendServerVersionStr != null && sendServerVersionStr.length() > 0) {
            bean.addPropertyValue("sendServerVersion", sendServerVersionStr);
        }

        ValueHolder busValue = ctx.getContainingBeanDefinition()
            .getConstructorArgumentValues().getArgumentValue(0, Bus.class);
        bean.addPropertyValue("bus", busValue.getValue());
        try {
            Element elem = DOMUtils.getFirstElement(element);
            while (elem != null) {
                String name = elem.getLocalName();
                if ("tlsServerParameters".equals(name)) {
                    mapTLSServerParameters(elem, bean);
                } else if ("threadingParameters".equals(name)) {
                    mapElementToJaxbPropertyFactory(elem,
                                                    bean,
                                                    "threadingParameters",
                                                    ThreadingParametersType.class,
                                                    JettyHTTPServerEngineBeanDefinitionParser.class,
                                                    "createThreadingParameters");
                } else if ("tlsServerParametersRef".equals(name)) {
                    mapElementToJaxbPropertyFactory(elem,
                                                    bean,
                                                    "tlsServerParametersRef",
                                                    TLSServerParametersIdentifiedType.class,
                                                    JettyHTTPServerEngineBeanDefinitionParser.class,
                                                    "createTLSServerParametersConfigRef");
                } else if ("threadingParametersRef".equals(name)) {
                    mapElementToJaxbPropertyFactory(elem,
                                                    bean,
                                                    "threadingParametersRef",
                                                    ThreadingParametersIdentifiedType.class,
                                                    JettyHTTPServerEngineBeanDefinitionParser.class,
                                                    "createThreadingParametersRef"
                                                    );
                } else if ("connector".equals(name)) {
                    // only deal with the one connector here
                    List<?> list =
                        ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition());
                    bean.addPropertyValue("connector", list.get(0));
                } else if ("handlers".equals(name)) {
                    List<?> handlers =
                        ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition());
                    bean.addPropertyValue("handlers", handlers);
                } else if ("sessionTimeout".equals(name) 
                    || "sessionSupport".equals(name) || "reuseAddress".equals(name)) {
                    String text = elem.getTextContent();
                    bean.addPropertyValue(name, text);
                }

                elem = org.apache.cxf.helpers.DOMUtils.getNextElement(elem);
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not process configuration.", e);
        }

        bean.setLazyInit(false);
    }
 
Example 19
Source File: WebExceptionHandlerOperationsImpl.java    From gvnix with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Removes the definition of the selected Exception in the webmvc-config.xml
 * file.
 * 
 * @param exceptionName Exception Name to remove.
 */
private String removeWebMvcConfig(String exceptionName) {

    String webXmlPath = pathResolver.getIdentifier(
            LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""),
            WEB_MVC_CONFIG);
    Validate.isTrue(fileManager.exists(webXmlPath),
            WEB_MVC_CONFIG_NOT_FOUND);

    MutableFile webXmlMutableFile = null;
    Document webXml;

    try {
        webXmlMutableFile = fileManager.updateFile(webXmlPath);
        webXml = XmlUtils.getDocumentBuilder().parse(
                webXmlMutableFile.getInputStream());
    }
    catch (Exception e) {
        throw new IllegalStateException(e);
    }
    Element root = webXml.getDocumentElement();

    Element exceptionResolver = XmlUtils
            .findFirstElement(
                    RESOLVER_BEAN_MESSAGE
                            + "/property[@name='exceptionMappings']/props/prop[@key='"
                            + exceptionName + "']", root);

    Validate.isTrue(exceptionResolver != null,
            "There isn't a Handled Exception with the name:\t"
                    + exceptionName);

    // Remove Mapping
    exceptionResolver.getParentNode().removeChild(exceptionResolver);

    String exceptionViewName = exceptionResolver.getTextContent();

    Validate.isTrue(exceptionViewName != null,
            "Can't remove the view for the:\t" + exceptionName
                    + " Exception.");

    // Remove NameSpace bean.
    Element lastExceptionControlled = XmlUtils.findFirstElement(
            "/beans/view-controller[@path='/" + exceptionViewName + "']",
            root);

    lastExceptionControlled.getParentNode().removeChild(
            lastExceptionControlled);

    XmlUtils.writeXml(webXmlMutableFile.getOutputStream(), webXml);

    return exceptionViewName;
}
 
Example 20
Source File: XAdESSignature.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void checkSignaturePolicy(SignaturePolicyProvider signaturePolicyProvider) {
	final Element policyIdentifier = DomUtils.getElement(signatureElement, xadesPaths.getSignaturePolicyIdentifier());
	if (policyIdentifier != null) {
		// There is a policy
		final Element policyId = DomUtils.getElement(policyIdentifier, xadesPaths.getCurrentSignaturePolicyId());
		if (policyId != null) {
			// Explicit policy
			String policyUrlString = null;
			String policyIdString = policyId.getTextContent();
			if (Utils.isStringNotEmpty(policyIdString)) {
				policyIdString = policyIdString.replaceAll("\n", "");
				policyIdString = policyIdString.trim();
				if (DSSXMLUtils.isOid(policyIdString)) {
					// urn:oid:1.2.3 --> 1.2.3
					policyIdString = DSSXMLUtils.getOidCode(policyIdString);
				} else {
					policyUrlString = policyIdString;
				}
			}
			signaturePolicy = new SignaturePolicy(policyIdString);

			final Digest digest = DSSXMLUtils.getDigestAndValue(DomUtils.getElement(policyIdentifier, xadesPaths.getCurrentSignaturePolicyDigestAlgAndValue()));
			signaturePolicy.setDigest(digest);

			final Element policyUrl = DomUtils.getElement(policyIdentifier, xadesPaths.getCurrentSignaturePolicySPURI());
			if (policyUrl != null) {
				policyUrlString = policyUrl.getTextContent().trim();
			}

			final Element policyDescription = DomUtils.getElement(policyIdentifier, xadesPaths.getCurrentSignaturePolicyDescription());
			if (policyDescription != null && Utils.isStringNotEmpty(policyDescription.getTextContent())) {
				signaturePolicy.setDescription(policyDescription.getTextContent());
			}
			Element docRefsNode = DomUtils.getElement(policyIdentifier, xadesPaths.getCurrentSignaturePolicyDocumentationReferences());
			if (docRefsNode != null) {
				signaturePolicy.setDocumentationReferences(getDocumentationReferences(docRefsNode));
			}

			signaturePolicy.setUrl(policyUrlString);
			signaturePolicy.setPolicyContent(signaturePolicyProvider.getSignaturePolicy(policyIdString, policyUrlString));
		} else {
			// Implicit policy
			final Element signaturePolicyImplied = DomUtils.getElement(policyIdentifier, xadesPaths.getCurrentSignaturePolicyImplied());
			if (signaturePolicyImplied != null) {
				signaturePolicy = new SignaturePolicy();
			}
		}
	}
}