Java Code Examples for org.apache.axiom.om.OMElement#getChildren()

The following examples show how to use org.apache.axiom.om.OMElement#getChildren() . 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: WSXACMLMessageReceiver.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Format the sent in response as required by OpenSAML
 *
 * @param xacmlResponse : received XACML response
 * @return formatted response
 */
private String formatResponse(String xacmlResponse) throws Exception {

    xacmlResponse = xacmlResponse.replace("\n", "");
    OMElement omElemnt;

    try {
        omElemnt = org.apache.axiom.om.util.AXIOMUtil.stringToOM(xacmlResponse);
        omElemnt.setNamespace(xacmlContextNS);
        if (omElemnt.getChildren() != null) {
            Iterator childIterator = omElemnt.getChildElements();
            setXACMLNamespace(childIterator);
        }
    } catch (Exception e) {
        log.error("Error while generating the OMElement from the XACML request.", e);
        throw new Exception("Error while generating the OMElement from the XACML request.", e);
    }

    return omElemnt.toString();
}
 
Example 2
Source File: WSXACMLMessageReceiver.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Format the sent in response as required by OpenSAML
 *
 * @param xacmlResponse : received XACML response
 * @return formatted response
 */
private String formatResponse(String xacmlResponse) throws Exception {

    xacmlResponse = xacmlResponse.replace("\n", "");
    OMElement omElemnt;

    try {
        omElemnt = org.apache.axiom.om.util.AXIOMUtil.stringToOM(xacmlResponse);
        omElemnt.setNamespace(xacmlContextNS);
        if (omElemnt.getChildren() != null) {
            Iterator childIterator = omElemnt.getChildElements();
            setXACMLNamespace(childIterator);
        }
    } catch (Exception e) {
        log.error("Error while generating the OMElement from the XACML request.", e);
        throw new Exception("Error while generating the OMElement from the XACML request.", e);
    }

    return omElemnt.toString();
}
 
Example 3
Source File: ChartMetaDataHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private ArrayList<SeriesDTO> getSeries() {
    Iterator iterator = chartReportElement.getChildren();
    OMElement specificChart = (OMElement) iterator.next();

    Iterator seriesIter = specificChart.getChildren();
    ArrayList<SeriesDTO> seriesArrayList = new ArrayList<SeriesDTO>();
    while (seriesIter.hasNext()) {
        OMElement seriesElement = (OMElement) seriesIter.next();
        String seriesName = seriesElement.getAttribute(new QName(NAME)).getAttributeValue();
        SeriesDTO series = new SeriesDTO();
        series.setName(seriesName);
        setData(series, seriesElement);
        seriesArrayList.add(series);
    }

    return seriesArrayList;
}
 
Example 4
Source File: RDFExposedAsRDFSampleTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void listVehicles() throws Exception {

        HttpClientUtil httpClient = new HttpClientUtil();
        OMElement result = httpClient.get(serviceEndPoint + "_getvehicles");
        Assert.assertNotNull(result, "Response null");
        Iterator itr = result.getChildren();
        while (itr.hasNext()) {
            OMElement product = (OMElement) itr.next();
            OMElement productModel = (OMElement) product.getChildrenWithLocalName("Model").next();
            OMAttribute modelResource = (OMAttribute) productModel.getAllAttributes().next();
            Assert.assertTrue(modelResource.getAttributeValue().startsWith("http://productlines/"),
                    "Model rdf resource value is correct");
        }
    }
 
Example 5
Source File: RDFExposedAsRDFSampleTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private void listVehicles() throws Exception {

        HttpClientUtil httpClient = new HttpClientUtil();
        OMElement result = httpClient.get(serviceEndPoint + "_getvehicles");
        Assert.assertNotNull(result, "Response null");
        Iterator itr = result.getChildren();
        while (itr.hasNext()) {
            OMElement product = (OMElement) itr.next();
            OMElement productModel = (OMElement) product.getChildrenWithLocalName("Model").next();
            OMAttribute modelResource = (OMAttribute) productModel.getAllAttributes().next();
            Assert.assertEquals(modelResource.getAttributeValue().startsWith("http://productlines/"),
                    true, "Model rdf resource value is correct");
        }
    }
 
Example 6
Source File: ProvideAndRegisterDocumentSet.java    From openxds with Apache License 2.0 5 votes vote down vote up
static OMText getBinaryNode(OMElement document) {
	Iterator<OMNode> childrenIterator = document.getChildren();
	while (childrenIterator.hasNext())
	{
		OMNode container = childrenIterator.next();
		if (container instanceof OMText && StringUtils.isNotBlank(((OMText)container).getText()))
		{
			return (OMText)container;
		}
	}		
	return null;
}
 
Example 7
Source File: AbstractXMLDoc.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
protected List<OMElement> getChildElements(OMElement parentElement, String tagName) {
	List<OMElement> elements = new ArrayList<OMElement>();
	Iterator children = parentElement.getChildren();
	while (children.hasNext()) {
		Object o = children.next();
		if (o instanceof OMElement) {
			OMElement child = (OMElement) o;
			if (tagName == null || tagName.trim().equals("") || child.getLocalName().equals(tagName)) {
				elements.add(child);
			}
		}
	}
	return elements;
}
 
Example 8
Source File: APIEndpointPasswordRegistryHandler.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called for a registry get operation
 *
 * @param requestContext - The request context
 * @return - returns the modified resource
 * @throws RegistryException
 */
public Resource get(RequestContext requestContext) throws RegistryException {
    Resource resource = requestContext.getResource();
    if (resource != null) {
        String resourceContent = RegistryUtils.decodeBytes((byte[]) resource.getContent());
        try {
            OMElement omElement = AXIOMUtil.stringToOM(resourceContent);
            Iterator mainChildIt = omElement.getChildren();
            while (mainChildIt.hasNext()) {
                Object childObj = mainChildIt.next();
                if ((childObj instanceof OMElement) && ((APIConstants.OVERVIEW_ELEMENT)
                        .equals(((OMElement) childObj).getLocalName()))) {
                    Iterator childIt = ((OMElement) childObj)
                            .getChildrenWithLocalName(APIConstants.ENDPOINT_PASSWORD_ELEMENT);
                    //There is only one ep-password, hence no iteration
                    if (childIt.hasNext()) {
                        OMElement child = (OMElement) childIt.next();
                        String actualPassword = child.getText();
                        //Store the password in a hidden property to access in the PUT method.
                        if (!actualPassword.isEmpty()) {
                            resource.setProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY, actualPassword);
                            child.setText(APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD);
                        }
                    }
                }
            }
            resource.setContent(RegistryUtils.encodeString(omElement.toString()));
            log.debug("Modified API resource content with default password before get operation");
        } catch (XMLStreamException e) {
            log.error("There was an error in reading XML Stream during API get.");
            throw new RegistryException("There was an error reading the API resource.", e);
        }
    }
    return resource;
}
 
Example 9
Source File: ChartMetaDataHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private DataDTO getData(OMElement element) {
    DataDTO data = new DataDTO();
    data.setFieldId(element.getAttributeValue(new QName(ID)));
    Iterator iterator = element.getChildren();
    data.setDsTableName(((OMElement) iterator.next()).getText());
    data.setDsColumnName(((OMElement) iterator.next()).getText());
    return data;
}
 
Example 10
Source File: APIEndpointPasswordRegistryHandler.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * This method is called for a registry put operation
 *
 * @param requestContext - The request context
 * @throws RegistryException
 */
public void put(RequestContext requestContext) throws RegistryException {
    Resource resource = requestContext.getResource();
    Object content = resource.getContent();
    String resourceContent;
    if (content instanceof String) {
        resourceContent = (String) resource.getContent();
    } else if (content instanceof byte[]) {
        resourceContent = RegistryUtils.decodeBytes((byte[]) resource.getContent());
    } else {
        log.warn("The resource content is not of expected type");
        return;
    }
    try {
        OMElement omElement = AXIOMUtil.stringToOM(resourceContent);
        Iterator mainChildIt = omElement.getChildren();
        while (mainChildIt.hasNext()) {
            Object childObj = mainChildIt.next();
            if ((childObj instanceof OMElement) && ((APIConstants.OVERVIEW_ELEMENT)
                    .equals(((OMElement) childObj).getLocalName()))) {
                Iterator childIt = ((OMElement) childObj)
                        .getChildrenWithLocalName(APIConstants.ENDPOINT_PASSWORD_ELEMENT);
                //There is only one ep-password, hence no iteration
                if (childIt.hasNext()) {
                    OMElement child = (OMElement) childIt.next();
                    String pswd = child.getText();
                    //Password has been edited on put
                    if (!"".equals(pswd) && !((APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD).equals(pswd))) {
                        resource.setProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY, pswd);
                        child.setText(pswd);
                    } else if ((APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD)
                            .equals(pswd)) { //Password not being changed
                        String actualPassword = resource
                                .getProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY);
                        child.setText(actualPassword);
                    }
                }
            }
        }
        resource.setContent(RegistryUtils.encodeString(omElement.toString()));
        requestContext.setResource(resource);
        log.debug("Modified API resource content with actual password before put operation");
    } catch (XMLStreamException e) {
        log.error("There was an error in reading XML Stream during API update.");
        throw new RegistryException("There was an error updating the API resource.", e);
    }
}
 
Example 11
Source File: ChartMetaDataHandler.java    From carbon-commons with Apache License 2.0 3 votes vote down vote up
private void setData(SeriesDTO series, OMElement seriesElement) {
    Iterator iterator = seriesElement.getChildren();

    DataDTO xData = getData((OMElement) iterator.next());
    series.setXdata(xData);

    DataDTO yData = getData((OMElement) iterator.next());
    series.setYdata(yData);

}