Example usage for org.w3c.dom Element setTextContent

List of usage examples for org.w3c.dom Element setTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element setTextContent.

Prototype

public void setTextContent(String textContent) throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:com.seer.datacruncher.factories.streams.SchemaStreamsEXI.java

@Override
public byte[] getDownloadableStreams() {
    if (maxVertical == 0)
        return null;
    StringBuffer result = new StringBuffer();
    result.append("<_root_>\n");
    for (int i = 0; i < maxVertical; i++) {
        Document doc = getNewDomDocument();
        Element xmlNode = doc.createElement(root.getName() + i);
        xmlNode.setTextContent(getNodeText(root.getPath("."), i, linkedFieldsPaths));
        doc.appendChild(xmlNode);//from  w w w .j  av a 2 s . co  m
        recursiveListChilds(doc, xmlNode, root, i, linkedFieldsPaths);
        result.append(DomToOtherFormat.convertDomToXml(doc)).append("\n");
    }
    result.append("</_root_>");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        EXI.encodeXmlToEXI(new ByteArrayInputStream(result.toString().getBytes("UTF-8")), baos);
    } catch (UnsupportedEncodingException e) {
        log.error("UnsupportedEncodingException", e);
    } catch (SAXException e) {
        log.error("SAXException", e);
    } catch (EXIException e) {
        log.error("EXIException", e);
    } catch (IOException e) {
        log.error("IOException", e);
    }
    return baos.toByteArray();
}

From source file:fr.aliasource.webmail.quota.ActionGetQuotaAction.java

@Override
public void execute(IProxy p, IParameterSource req, IResponder responder) {
    String mailBox = req.getParameter("mailBox");

    IStoreConnection store = p.getAccount().getStoreProtocol();

    QuotaInfo qi = null;//  w ww .  j  a  va 2s. c  o m
    try {
        qi = store.getQuota(mailBox);

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        store.destroy();
    }

    try {
        Document doc = DOMUtils.createDoc("http://minig.org/xsd/quotaInfo", "quotainfo");

        Element root = doc.getDocumentElement();

        Element att = DOMUtils.createElement(root, "enable");
        att.setTextContent(String.valueOf(qi.isEnable()));

        Element att1 = DOMUtils.createElement(root, "usage");
        att1.setTextContent(String.valueOf(qi.getUsage()));

        Element att2 = DOMUtils.createElement(root, "limit");
        att2.setTextContent(String.valueOf(qi.getLimit()));
        responder.sendDom(doc);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:cz.incad.kramerius.rest.api.k5.client.search.SearchResource.java

public static void changeMasterPidInDOM(Element docElem) {
    // <str name="PID">uuid:2ad31d65-50ca-11e1-916e-001b63bd97ba</str>
    Element elm = XMLUtils.findElement(docElem, new XMLUtils.ElementsFilter() {

        @Override//from   w  ww . j  a  v a2s  . c o m
        public boolean acceptElement(Element element) {
            if (element.getNodeName().equals("str")) {
                if (element.hasAttribute("name") && (element.getAttribute("name").equals("PID"))) {
                    return true;
                }
            }
            return false;
        }
    });
    if (elm != null) {
        String pid = elm.getTextContent();
        if (pid.contains("/")) {
            pid = pid.replace("/", "");
            elm.setTextContent(pid);
        }
    }
}

From source file:no.dusken.barweb.view.XListView.java

private Element createVareElement(Vare v, Document dom) {
    Element vareEle = dom.createElement("vare");
    vareEle.setTextContent(v.getName());
    return vareEle;
}

From source file:com.twinsoft.convertigo.beans.steps.SessionGetStep.java

@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
    if (StringUtils.isNotEmpty(key)) {
        Element keyElement = doc.createElement("key");
        keyElement.setTextContent(key);
        stepNode.appendChild(keyElement);

        Object value = getSequence().context.httpSession.getAttribute(key);
        if (value != null) {
            Element expressionElement = doc.createElement("expression");
            expressionElement.setTextContent(value.toString());
            stepNode.appendChild(expressionElement);
        }//  ww w.j  av  a  2  s .  c  o  m
    }
}

From source file:no.dusken.barweb.view.InvoiceView.java

private Element createPersonElement(BarPerson p, Integer owes, Document dom) {
    Element personEle = dom.createElement("person");
    personEle.setTextContent(p.getName());
    personEle.setAttribute("owes", owes.toString());
    return personEle;
}

From source file:fr.aliasource.webmail.server.proxy.client.http.setting.SaveSignatureMethod.java

protected Document getSignaturesAsXML(Map<String, String> addrs)
        throws ParserConfigurationException, FactoryConfigurationError {
    Document doc = DOMUtils.createDoc("http://obm.aliasource.fr/xsd/signature_list", "signatureList");
    Element root = doc.getDocumentElement();
    for (Entry<String, String> addr : addrs.entrySet()) {
        Element fe = DOMUtils.createElement(root, "signature");
        fe.setAttribute("email", addr.getKey());
        fe.setTextContent(addr.getValue());
    }//from   ww w  .  ja v  a  2 s.  c  o m
    return doc;
}

From source file:com.viadee.acceptancetests.roo.addon.POMWrapper.java

Element addChildToParentWithNameAndTextContent(Element parent, String tagName, String textContent) {
    Element newChild = addChildElementWithName(parent, tagName);
    newChild.setTextContent(textContent);
    return newChild;
}

From source file:com.connexta.arbitro.utils.policy.BasicPolicyHelper.java

public static Element createPolicyElement(BasicPolicyDTO basicPolicyDTO, Document doc)
        throws PolicyBuilderException {

    Element policyElement = doc.createElement(PolicyConstants.POLICY_ELEMENT);

    policyElement.setAttribute("xmlns", PolicyConstants.XACMLData.XACML3_POLICY_NAMESPACE);

    if (basicPolicyDTO.getPolicyId() != null && basicPolicyDTO.getPolicyId().trim().length() > 0) {
        policyElement.setAttribute(PolicyConstants.POLICY_ID, basicPolicyDTO.getPolicyId());
    } else {//from ww  w.j ava2 s.  c  o m
        throw new PolicyBuilderException("Policy name can not be null");
    }

    if (basicPolicyDTO.getRuleAlgorithm() != null && basicPolicyDTO.getRuleAlgorithm().trim().length() > 0) {
        policyElement.setAttribute(PolicyConstants.RULE_ALGORITHM, basicPolicyDTO.getRuleAlgorithm());
    } else {
        policyElement.setAttribute(PolicyConstants.RULE_ALGORITHM,
                PolicyConstants.RuleCombiningAlog.DENY_OVERRIDE_ID); // TODO
        log.warn("Rule combining algorithm is not defined. Use default algorithm; Deny Override");
    }

    if (basicPolicyDTO.getVersion() != null && basicPolicyDTO.getVersion().trim().length() > 0) {
        policyElement.setAttribute(PolicyConstants.POLICY_VERSION, basicPolicyDTO.getVersion());
    } else {
        // policy version is can be handled by policy registry.  therefore we can ignore it, although it
        // is a required attribute
        policyElement.setAttribute(PolicyConstants.POLICY_VERSION, "1.0");
    }

    if (basicPolicyDTO.getDescription() != null && basicPolicyDTO.getDescription().trim().length() > 0) {

        Element descriptionElement = doc.createElement(PolicyConstants.DESCRIPTION_ELEMENT);
        descriptionElement.setTextContent(basicPolicyDTO.getDescription());
        policyElement.appendChild(descriptionElement);
    }

    BasicTargetDTO basicTargetDTO = basicPolicyDTO.getTargetDTO();
    List<BasicRuleDTO> basicRuleDTOs = basicPolicyDTO.getBasicRuleDTOs();

    if (basicTargetDTO != null) {
        policyElement.appendChild(BasicPolicyHelper.createTargetElement(basicTargetDTO, doc));
    } else {
        policyElement.appendChild(doc.createElement(PolicyConstants.TARGET_ELEMENT));
    }
    if (basicRuleDTOs != null && basicRuleDTOs.size() > 0) {
        for (BasicRuleDTO basicRuleDTO : basicRuleDTOs) {
            policyElement.appendChild(BasicPolicyHelper.createRuleElement(basicRuleDTO, doc));
        }
    } else {
        BasicRuleDTO basicRuleDTO = new BasicRuleDTO();
        basicRuleDTO.setRuleId(UUID.randomUUID().toString());
        basicRuleDTO.setRuleEffect(PolicyConstants.RuleEffect.DENY);
        policyElement.appendChild(BasicPolicyHelper.createRuleElement(basicRuleDTO, doc));
    }

    return policyElement;
}

From source file:com.bstek.dorado.idesupport.robot.EntityDataTypeReflectionRobot.java

private Element createPropertyElement(Element parentElement, String propertyName, String propertyValue) {
    Element propertyElement = createPropertyElement(parentElement, propertyName);
    propertyElement.setTextContent(propertyValue);
    return propertyElement;
}