Example usage for com.liferay.portal.kernel.xml Document setRootElement

List of usage examples for com.liferay.portal.kernel.xml Document setRootElement

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Document setRootElement.

Prototype

public void setRootElement(Element rootElement);

Source Link

Usage

From source file:com.liferay.asset.publisher.web.upgrade.v1_0_0.UpgradePortletPreferences.java

License:Open Source License

protected void upgradeUuids(String[] assetEntryXmls) throws Exception {
    for (int i = 0; i < assetEntryXmls.length; i++) {
        String assetEntry = assetEntryXmls[i];

        Document document = _saxReader.read(assetEntry);

        Element rootElement = document.getRootElement();

        Element assetTypeElementUuid = rootElement.element("asset-entry-uuid");

        if (assetTypeElementUuid == null) {
            continue;
        }//from  w ww  . j  a v a  2  s  . c o m

        String journalArticleResourceUuid = getJournalArticleResourceUuid(
                assetTypeElementUuid.getStringValue());

        if (journalArticleResourceUuid == null) {
            continue;
        }

        rootElement.remove(assetTypeElementUuid);

        assetTypeElementUuid.setText(journalArticleResourceUuid);

        rootElement.add(assetTypeElementUuid);

        document.setRootElement(rootElement);

        assetEntryXmls[i] = document.formattedString(StringPool.BLANK);
    }
}

From source file:it.smc.calendar.sync.caldav.methods.BasePropMethodImpl.java

License:Open Source License

protected int writeResponseXML(WebDAVRequest webDAVRequest, Set<QName> props) throws Exception {

    WebDAVStorage storage = webDAVRequest.getWebDAVStorage();

    long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest());

    Document document = SAXReaderUtil.createDocument();

    Element multistatusElement = SAXReaderUtil.createElement(CalDAVProps.createQName("multistatus"));

    document.setRootElement(multistatusElement);

    Resource resource = storage.getResource(webDAVRequest);

    if (resource != null) {
        addResponse(storage, webDAVRequest, resource, props, multistatusElement, depth);

        String xml = document.formattedString(StringPool.FOUR_SPACES);

        if (_log.isDebugEnabled()) {
            _log.debug("Response XML\n" + xml);
        }//  w w  w. ja  v a  2 s  .co  m

        // Set the status prior to writing the XML

        int status = WebDAVUtil.SC_MULTI_STATUS;

        HttpServletResponse response = webDAVRequest.getHttpServletResponse();

        response.setContentType(ContentTypes.TEXT_XML_UTF8);
        response.setStatus(status);

        try {
            ServletResponseUtil.write(response, xml);

            response.flushBuffer();
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        }

        return status;
    } else {
        if (_log.isDebugEnabled()) {
            _log.debug("No resource found for " + storage.getRootPath() + webDAVRequest.getPath());
        }

        return HttpServletResponse.SC_NOT_FOUND;
    }
}