List of usage examples for org.w3c.dom Document createElement
public Element createElement(String tagName) throws DOMException;
From source file:com.connexta.arbitro.utils.PolicyUtils.java
public static Element createRequestElement(RequestElementDTO requestElementDTO, Document doc) throws PolicyBuilderException { Element requestElement = doc.createElement(PolicyConstants.Request.REQUEST_ELEMENT); requestElement.setAttribute("xmlns", PolicyConstants.Request.REQ_RES_CONTEXT_XACML3); requestElement.setAttribute(PolicyConstants.Request.RETURN_POLICY_LIST, Boolean.toString(requestElementDTO.isReturnPolicyIdList())); requestElement.setAttribute(PolicyConstants.Request.COMBINED_DECISION, Boolean.toString(requestElementDTO.isCombinedDecision())); List<AttributesElementDTO> attributesElementDTOs = requestElementDTO.getAttributesElementDTOs(); if (attributesElementDTOs != null && attributesElementDTOs.size() > 0) { for (AttributesElementDTO dto : attributesElementDTOs) { requestElement.appendChild(createAttributesElement(dto, doc)); }/*from w w w .ja v a2s .co m*/ } return requestElement; }
From source file:com.photon.phresco.impl.WindowsApplicationProcessor.java
private static void updateContent(Document doc, List<ArtifactGroup> artifactGroups, List<Node> itemGroup, String elementName) {/*from w ww . ja va 2 s .c o m*/ for (Node node : itemGroup) { NodeList childNodes = node.getChildNodes(); for (int j = 0; j < childNodes.getLength(); j++) { Node item = childNodes.item(j); if (item.getNodeName().equals(elementName)) { Node parentNode = item.getParentNode(); for (ArtifactGroup artifactGroup : artifactGroups) { if (artifactGroup.getType().name().equals(Type.FEATURE.name())) { Element content = doc.createElement(elementName); if (elementName.equalsIgnoreCase(REFERENCE)) { content.setAttribute(INCLUDE, artifactGroup.getName() + DLL); Element hintPath = doc.createElement(HINTPATH); hintPath.setTextContent( DOUBLE_DOT + COMMON + File.separator + artifactGroup.getName() + DLL); content.appendChild(hintPath); } else { content.setAttribute(INCLUDE, artifactGroup.getName() + DLL); } parentNode.appendChild(content); } } break; } } } }
From source file:com.connexta.arbitro.utils.PolicyUtils.java
/** * This creates XML representation of target element using TargetElementDTO object * * @param targetElementDTO TargetElementDTO * @param doc Document//from w w w . ja v a 2 s . c o m * @return DOM element * @throws PolicyBuilderException throws */ public static Element createTargetElement(TargetElementDTO targetElementDTO, Document doc) throws PolicyBuilderException { Element targetElement = doc.createElement(PolicyConstants.TARGET_ELEMENT); List<AnyOfElementDTO> anyOfElementDTOs = targetElementDTO.getAnyOfElementDTOs(); for (AnyOfElementDTO anyOfElementDTO : anyOfElementDTOs) { Element anyOfElement = doc.createElement(PolicyConstants.ANY_OF_ELEMENT); List<AllOfElementDTO> allOfElementDTOs = anyOfElementDTO.getAllOfElementDTOs(); for (AllOfElementDTO allOfElementDTO : allOfElementDTOs) { Element allOfElement = doc.createElement(PolicyConstants.ALL_OF_ELEMENT); List<MatchElementDTO> matchElementDTOs = allOfElementDTO.getMatchElementDTOs(); for (MatchElementDTO matchElementDTO : matchElementDTOs) { Element matchElement = createMatchElement(matchElementDTO, doc); allOfElement.appendChild(matchElement); } anyOfElement.appendChild(allOfElement); } targetElement.appendChild(anyOfElement); } return targetElement; }
From source file:de.mpg.escidoc.services.common.util.Util.java
public static Node querySSRNId(String conePersonUrl) { DocumentBuilder documentBuilder; HttpClient client = new HttpClient(); try {//from w w w. j a v a 2 s . co m documentBuilder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element element = document.createElement("cone"); document.appendChild(element); GetMethod detailMethod = new GetMethod(conePersonUrl + "?format=rdf"); ProxyHelper.setProxy(client, conePersonUrl); client.executeMethod(detailMethod); if (detailMethod.getStatusCode() == 200) { Document details = documentBuilder.parse(detailMethod.getResponseBodyAsStream()); element.appendChild(document.importNode(details.getFirstChild(), true)); return document; } else { logger.error("Error querying CoNE: Status " + detailMethod.getStatusCode() + "\n" + detailMethod.getResponseBodyAsString()); return null; } } catch (Exception e) { logger.error("Error querying CoNE service. This is normal during unit tests. " + "Otherwise it should be clarified if any measures have to be taken."); return null; } }
From source file:de.mpg.escidoc.services.common.util.Util.java
public static Node getSize(String url) { DocumentBuilder documentBuilder; HttpClient httpClient = new HttpClient(); HeadMethod headMethod = new HeadMethod(url); try {//www .j av a 2s .c o m logger.info("Getting size of " + url); ProxyHelper.executeMethod(httpClient, headMethod); if (headMethod.getStatusCode() != 200) { logger.warn("Wrong status code " + headMethod.getStatusCode() + " at " + url); } documentBuilder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element element = document.createElement("size"); document.appendChild(element); Header header = headMethod.getResponseHeader("Content-Length"); if (header != null) { element.setTextContent(header.getValue()); return document; } else { element.setTextContent("0"); return document; } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.connexta.arbitro.utils.PolicyUtils.java
/** * This creates XML representation of condition element using ConditionElementDT0 object * * @param conditionElementDT0 ConditionElementDT0 * @param doc Document//from w ww .j a v a 2s .c om * @return DOM element * @throws PolicyBuilderException throws */ public static Element createConditionElement(ConditionElementDT0 conditionElementDT0, Document doc) throws PolicyBuilderException { Element conditionElement = doc.createElement(PolicyConstants.CONDITION_ELEMENT); if (conditionElementDT0.getApplyElement() != null) { conditionElement.appendChild(createApplyElement(conditionElementDT0.getApplyElement(), doc)); } else if (conditionElementDT0.getAttributeValueElementDTO() != null) { Element attributeValueElement = createAttributeValueElement( conditionElementDT0.getAttributeValueElementDTO(), doc); conditionElement.appendChild(attributeValueElement); } else if (conditionElementDT0.getAttributeDesignator() != null) { AttributeDesignatorDTO attributeDesignatorDTO = conditionElementDT0.getAttributeDesignator(); conditionElement.appendChild(createAttributeDesignatorElement(attributeDesignatorDTO, doc)); } else if (conditionElementDT0.getFunctionFunctionId() != null) { Element functionElement = doc.createElement(PolicyConstants.FUNCTION_ELEMENT); functionElement.setAttribute(PolicyConstants.FUNCTION_ID, conditionElementDT0.getFunctionFunctionId()); conditionElement.appendChild(functionElement); } else if (conditionElementDT0.getVariableId() != null) { Element variableReferenceElement = doc.createElement(PolicyConstants.VARIABLE_REFERENCE); variableReferenceElement.setAttribute(PolicyConstants.VARIABLE_ID, conditionElementDT0.getVariableId()); conditionElement.appendChild(variableReferenceElement); } return conditionElement; }
From source file:com.netspective.sparx.form.DialogContext.java
static public void exportParamToXml(Element parent, String name, String[] values) { Document doc = parent.getOwnerDocument(); Element fieldElem = doc.createElement("request-param"); fieldElem.setAttribute("name", name); if (values != null && values.length > 1) { fieldElem.setAttribute("value-type", "strings"); Element valuesElem = doc.createElement("values"); for (int i = 0; i < values.length; i++) { Element valueElem = doc.createElement("value"); valueElem.appendChild(doc.createTextNode(values[i])); valuesElem.appendChild(valueElem); }/*from ww w.java2 s . c o m*/ fieldElem.appendChild(valuesElem); parent.appendChild(fieldElem); } else if (values != null) { fieldElem.setAttribute("value-type", "string"); Element valueElem = doc.createElement("value"); valueElem.appendChild(doc.createTextNode(values[0])); fieldElem.appendChild(valueElem); parent.appendChild(fieldElem); } }
From source file:de.mpg.escidoc.services.common.util.Util.java
/** * Queries CoNE service and returns the result as DOM node. * The returned XML has the following structure: * <cone>//from w w w . ja va 2s .c o m * <author> * <familyname>Buxtehude-Mlln</familyname> * <givenname>Heribert</givenname> * <prefix>von und zu</prefix> * <title>Knig</title> * </author> * <author> * <familyname>Mller</familyname> * <givenname>Peter</givenname> * </author> * </authors> * * @param Single instituteId for an institute without departments or list of Ids. Every department has his own Id. * @return */ public static Node queryReportPersonCone(String model, String query) { DocumentBuilder documentBuilder; String queryUrl; List<String> childIds = new ArrayList<String>(); // get the childOUs if any in the query if (query.contains(" ")) { String[] result = query.split("\\s+"); for (String s : result) { childIds.add(s); } } try { documentBuilder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element element = document.createElement("cone"); document.appendChild(element); queryUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model + "/query?format=jquery&escidoc:position/dc:identifier=\"" + query + "\"&n=0"; HttpClient client = new HttpClient(); if (childIds.size() > 0) { // execute a method for every child ou for (String childId : childIds) { queryUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model + "/query?format=jquery&escidoc:position/dc:identifier=\"" + childId + "\"&n=0"; executeGetMethod(client, queryUrl, documentBuilder, document, element); } } else { // there are no child ous, methid is called once executeGetMethod(client, queryUrl, documentBuilder, document, element); } return document; } catch (Exception e) { logger.error("Error querying CoNE service. This is normal during unit tests. " + "Otherwise it should be clarified if any measures have to be taken."); return null; } }
From source file:com.meltmedia.cadmium.core.util.WarUtils.java
/** * Adds dispatchers for each item in the vargs parameter names to a * filter mapping element of a web.xml file. * @param doc The xml DOM document to create the new xml elements with. * @param filterMapping The filter mapping element to append to from a web.xml document. * @param names The names of the dispatchers to add. *//*from w ww .j av a2 s . co m*/ public static void addDispatchers(Document doc, Element filterMapping, String... names) { if (names != null) { for (String name : names) { Element dispatcher = doc.createElement("dispatcher"); dispatcher.appendChild(doc.createTextNode(name)); filterMapping.appendChild(dispatcher); } } }
From source file:com.connexta.arbitro.utils.PolicyUtils.java
/** * This creates XML representation of apply element using ApplyElementDTO object * * @param applyElementDTO ApplyElementDTO * @param doc Document/*from ww w . ja v a2 s.c om*/ * @return DOM element * @throws PolicyBuilderException throws */ public static Element createApplyElement(ApplyElementDTO applyElementDTO, Document doc) throws PolicyBuilderException { Element applyElement = doc.createElement(PolicyConstants.APPLY_ELEMENT); if (applyElementDTO.getFunctionId() != null && applyElementDTO.getFunctionId().trim().length() > 0) { applyElement.setAttribute(PolicyConstants.FUNCTION_ID, applyElementDTO.getFunctionId()); } if (applyElementDTO.getFunctionFunctionId() != null && applyElementDTO.getFunctionFunctionId().trim().length() > 0) { FunctionElementDTO functionElementDTO = new FunctionElementDTO(); functionElementDTO.setFunctionId(applyElementDTO.getFunctionFunctionId()); Element functionElement = createFunctionElement(functionElementDTO, doc); applyElement.appendChild(functionElement); } List<ApplyElementDTO> applyElementDTOs = applyElementDTO.getApplyElements(); if (applyElementDTOs != null && applyElementDTOs.size() > 0) { for (ApplyElementDTO elementDTO : applyElementDTOs) { Element subApplyElement = createApplyElement(elementDTO, doc); applyElement.appendChild(subApplyElement); } } List<AttributeValueElementDTO> attributeValueElementDTOs = applyElementDTO.getAttributeValueElementDTOs(); if (attributeValueElementDTOs != null && attributeValueElementDTOs.size() > 0) { for (AttributeValueElementDTO attributeValueElementDTO : attributeValueElementDTOs) { Element attributeValueElement = createAttributeValueElement(attributeValueElementDTO, doc); applyElement.appendChild(attributeValueElement); } } List<AttributeDesignatorDTO> attributeDesignatorDTOs = applyElementDTO.getAttributeDesignators(); if (attributeDesignatorDTOs != null && attributeDesignatorDTOs.size() > 0) { for (AttributeDesignatorDTO attributeDesignatorDTO : attributeDesignatorDTOs) { Element attributeDesignatorElement = createAttributeDesignatorElement(attributeDesignatorDTO, doc); applyElement.appendChild(attributeDesignatorElement); } } List<AttributeSelectorDTO> attributeSelectorDTOs = applyElementDTO.getAttributeSelectors(); if (attributeSelectorDTOs != null && attributeSelectorDTOs.size() > 0) { for (AttributeSelectorDTO attributeSelectorDTO : attributeSelectorDTOs) { Element attributeSelectorElement = createAttributeSelectorElement(attributeSelectorDTO, doc); applyElement.appendChild(attributeSelectorElement); } } return applyElement; }