Example usage for com.liferay.portal.kernel.xml Element addAttribute

List of usage examples for com.liferay.portal.kernel.xml Element addAttribute

Introduction

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

Prototype

public Element addAttribute(String name, String value);

Source Link

Usage

From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java

License:Open Source License

protected Element doAddReferenceElement(ClassedModel referrerClassedModel, Element element,
        ClassedModel classedModel, String className, String binPath, String referenceType, boolean missing) {

    Element referenceElement = null;

    if (missing) {
        Element referencesElement = _missingReferencesElement;

        referenceElement = referencesElement.addElement("missing-reference");
    } else {/*from   w  w  w  .j  a  va  2s  .c o  m*/
        Element referencesElement = element.element("references");

        if (referencesElement == null) {
            referencesElement = element.addElement("references");
        }

        referenceElement = referencesElement.addElement("reference");
    }

    referenceElement.addAttribute("class-name", className);

    referenceElement.addAttribute("class-pk", String.valueOf(classedModel.getPrimaryKeyObj()));

    populateClassNameAttribute(classedModel, referenceElement);

    if (missing) {
        if (classedModel instanceof StagedModel) {
            referenceElement.addAttribute("display-name",
                    StagedModelDataHandlerUtil.getDisplayName((StagedModel) classedModel));
        } else {
            referenceElement.addAttribute("display-name", String.valueOf(classedModel.getPrimaryKeyObj()));
        }
    }

    if (classedModel instanceof StagedGroupedModel) {
        StagedGroupedModel stagedGroupedModel = (StagedGroupedModel) classedModel;

        referenceElement.addAttribute("group-id", String.valueOf(stagedGroupedModel.getGroupId()));

        try {
            Group group = GroupLocalServiceUtil.getGroup(stagedGroupedModel.getGroupId());

            long liveGroupId = group.getLiveGroupId();

            if (group.isStagedRemotely()) {
                liveGroupId = group.getRemoteLiveGroupId();
            }

            if (liveGroupId == GroupConstants.DEFAULT_LIVE_GROUP_ID) {
                liveGroupId = group.getGroupId();
            }

            referenceElement.addAttribute("live-group-id", String.valueOf(liveGroupId));

            if (group.isLayout()) {
                try {
                    Layout scopeLayout = LayoutLocalServiceUtil.getLayout(group.getClassPK());

                    referenceElement.addAttribute("scope-layout-uuid", scopeLayout.getUuid());
                } catch (NoSuchLayoutException nsle) {
                    if (_log.isWarnEnabled()) {
                        _log.warn("Unable to find layout " + group.getClassPK(), nsle);
                    }
                }
            }
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to find group " + stagedGroupedModel.getGroupId());
            }
        }
    }

    if (Validator.isNotNull(binPath)) {
        referenceElement.addAttribute("path", binPath);
    }

    referenceElement.addAttribute("type", referenceType);

    if (missing) {
        referenceElement.addAttribute("referrer-class-name",
                ExportImportClassedModelUtil.getClassName(referrerClassedModel));

        if (referrerClassedModel instanceof PortletModel) {
            Portlet portlet = (Portlet) referrerClassedModel;

            referenceElement.addAttribute("referrer-display-name", portlet.getRootPortletId());
        } else if (referrerClassedModel instanceof StagedModel) {
            StagedModel referrerStagedModel = (StagedModel) referrerClassedModel;

            referenceElement.addAttribute("referrer-display-name",
                    StagedModelDataHandlerUtil.getDisplayName(referrerStagedModel));
        }
    }

    if (classedModel instanceof StagedModel) {
        StagedModel stagedModel = (StagedModel) classedModel;

        referenceElement.addAttribute("uuid", stagedModel.getUuid());
        referenceElement.addAttribute("company-id", String.valueOf(stagedModel.getCompanyId()));

        Map<String, String> referenceAttributes = StagedModelDataHandlerUtil.getReferenceAttributes(this,
                stagedModel);

        for (Map.Entry<String, String> referenceAttribute : referenceAttributes.entrySet()) {

            referenceElement.addAttribute(referenceAttribute.getKey(), referenceAttribute.getValue());
        }
    }

    return referenceElement;
}

From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java

License:Open Source License

protected void populateClassNameAttribute(ClassedModel classedModel, Element element) {

    String attachedClassName = null;

    if (classedModel instanceof AttachedModel) {
        AttachedModel attachedModel = (AttachedModel) classedModel;

        attachedClassName = attachedModel.getClassName();
    } else if (BeanUtil.hasProperty(classedModel, "className")) {
        attachedClassName = BeanPropertiesUtil.getStringSilent(classedModel, "className");
    }/* w  w  w  . j ava  2  s. c o  m*/

    if (Validator.isNotNull(attachedClassName)) {
        element.addAttribute("attached-class-name", attachedClassName);
    }
}

From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java

License:Open Source License

private void _addAssetPriority(Element element, long classNameId, long classPK) {

    double assetEntryPriority = AssetEntryLocalServiceUtil.getEntryPriority(classNameId, classPK);

    element.addAttribute("asset-entry-priority", String.valueOf(assetEntryPriority));
}

From source file:com.liferay.exportimport.lar.ThemeExporter.java

License:Open Source License

protected void exportThemeSettings(PortletDataContext portletDataContext, String themeId, String colorSchemeId,
        String css) throws Exception {

    Element exportDataRootElement = portletDataContext.getExportDataRootElement();

    Element headerElement = exportDataRootElement.element("header");

    headerElement.addAttribute("theme-id", themeId);
    headerElement.addAttribute("color-scheme-id", colorSchemeId);

    Element cssElement = headerElement.addElement("css");

    cssElement.addCDATA(css);/*from  w  w  w .ja v  a 2  s . com*/
}

From source file:com.liferay.exportimport.test.PortletDataContextReferencesTest.java

License:Open Source License

@Test
public void testSameMissingReferenceMultipleTimes() throws Exception {
    Element bookmarksEntryElement = _portletDataContext.getExportDataElement(_bookmarksEntry);

    bookmarksEntryElement.addAttribute("path", ExportImportPathUtil.getModelPath(_bookmarksEntry));

    _portletDataContext.addReferenceElement(_bookmarksEntry, bookmarksEntryElement, _bookmarksFolder,
            PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
    _portletDataContext.addReferenceElement(_bookmarksEntry, bookmarksEntryElement, _bookmarksFolder,
            PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);

    Element missingReferencesElement = _portletDataContext.getMissingReferencesElement();

    List<Element> missingReferenceElements = missingReferencesElement.elements();

    Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size());

    List<Element> referencesElements = _portletDataContext.getReferenceElements(_bookmarksEntry,
            BookmarksFolder.class);

    Assert.assertEquals(referencesElements.toString(), 2, referencesElements.size());

    for (Element referenceElement : referencesElements) {
        Assert.assertTrue(GetterUtil.getBoolean(referenceElement.attributeValue("missing")));
    }/*from   ww  w  .  j  a va  2s .  c  om*/
}

From source file:com.liferay.exportimport.test.util.exportimport.data.handler.DummyFolderPortletDataHandler.java

License:Open Source License

@Override
protected String doExportData(final PortletDataContext portletDataContext, String portletId,
        PortletPreferences portletPreferences) throws Exception {

    Element rootElement = addExportDataRootElement(portletDataContext);

    if (!portletDataContext.getBooleanParameter(NAMESPACE, "entries")) {
        return getExportDataRootElementString(rootElement);
    }/* ww w.  j  a  v  a 2  s  .  c om*/

    rootElement.addAttribute("group-id", String.valueOf(portletDataContext.getScopeGroupId()));

    ActionableDynamicQuery dummyFolderActionableDynamicQuery = _dummyFolderStagedModelRepository
            .getExportActionableDynamicQuery(portletDataContext);

    dummyFolderActionableDynamicQuery.performActions();

    return getExportDataRootElementString(rootElement);
}

From source file:com.liferay.faces.portal.component.inputsearch.internal.InputSearchRenderer.java

License:Open Source License

@Override
protected StringBuilder getMarkup(UIComponent uiComponent, StringBuilder markup) throws Exception {

    //J-//from  w  w  w . j  a va 2 s  . com
    // NOTE: The specified markup looks like the following (HTML comments added for clarity):
    //
    // <!-- Opening <div> rendered by html/taglib/ui/input_search/page.jsp -->
    // <div class="input-append">
    //
    //    <!-- Input text field rendered by html/taglib/ui/input_search/page.jsp -->
    //    <input class="search-query span9" id="...:jid42" name="..." placeholder="" type="text" value="" />
    //
    //    <!-- Search button rendered by html/taglib/ui/input_search/page.jsp -->
    //    <button class="btn" type="submit">Search</button>
    //
    //    <!-- HtmlInputText (dynamically added JSF child component) -->
    //    <input type="text" name="...:htmlInputText" />
    //
    //    <!-- HtmlCommandButton (dynamically added JSF child component) -->
    //    <input type="submit" name="...:htmlCommandButton" value="" />
    //
    // <!-- Closing </div> rendered by html/taglib/ui/input_search/page.jsp -->
    // </div>
    //J+

    // Parse the generated markup as an XML document.
    InputSearch inputSearch = cast(uiComponent);
    Document document = SAXReaderUtil.read(markup.toString());
    Element rootElement = document.getRootElement();

    // Locate the first/main input element in the XML document. This is the one that will contain contain the value
    // that will be submitted in the postback and received by the decode(FacesContext, UIComponent) method).
    String xpathInput = "//input[contains(@id, '" + uiComponent.getClientId() + "')]";
    Element mainInputElement = (Element) rootElement.selectSingleNode(xpathInput);

    if (mainInputElement != null) {

        // Copy the value attribute of the InputSearch component to the first input element in the XML document.
        mainInputElement.attribute("value").setValue((String) inputSearch.getValue());

        // Locate the dynamically added HtmlInputText and HtmlCommandButton child components.
        String xpathInputs = "//input[@type='text']";
        List<Node> inputElements = rootElement.selectNodes(xpathInputs);

        if ((inputElements != null) && (inputElements.size() == 2)) {

            // Copy each "on" attribute name/value pairs from the HtmlInputText to the first input element in
            // the XML document. This will enable all of the AjaxBehavior events like keyup/keydown to work.
            Element htmlInputTextElement = (Element) inputElements.get(1);
            Iterator<Attribute> attributeIterator = htmlInputTextElement.attributeIterator();

            while (attributeIterator.hasNext()) {
                Attribute attribute = attributeIterator.next();
                String attributeName = attribute.getName();

                if (attributeName.startsWith("on")) {
                    mainInputElement.addAttribute(attributeName, attribute.getValue());
                }
            }

            // Remove the HtmlInputText <input> from the XML document so that only one text field is rendered.
            htmlInputTextElement.getParent().remove(htmlInputTextElement);
        }
    }

    // Locate the HtmlCommandButton in the XML document.
    List<UIComponent> children = uiComponent.getChildren();
    HtmlCommandButton htmlCommandButton = (HtmlCommandButton) children.get(1);
    String htmlCommandButtonClientId = htmlCommandButton.getClientId();

    // Note that if there is an AjaxBehavior, then the rendered HtmlCommandButton can be located in the XML document
    // via the name attribute. Otherwise it can be located in the XML document via the id attribute.
    String htmlCommandButtonXPath = "//input[contains(@name,'" + htmlCommandButtonClientId
            + "') and @type='submit']";
    Element htmlCommandButtonElement = (Element) rootElement.selectSingleNode(htmlCommandButtonXPath);

    if (htmlCommandButtonElement == null) {
        htmlCommandButtonXPath = "//input[contains(@id,'" + htmlCommandButtonClientId
                + "') and @type='submit']";
        htmlCommandButtonElement = (Element) rootElement.selectSingleNode(htmlCommandButtonXPath);
    }

    if (htmlCommandButtonElement != null) {

        // Locate the <button> element in the XML document that was rendered by page.jsp
        Element buttonElement = (Element) rootElement.selectSingleNode("//button[@type='submit']");

        if (buttonElement != null) {

            // Copy attributes found on the HtmlCommandButton <input> element to the <button> element that was
            // rendered by page.jsp
            Attribute onClickAttr = htmlCommandButtonElement.attribute("onclick");

            if (onClickAttr != null) {
                buttonElement.addAttribute("onclick", onClickAttr.getValue());
            }

            Attribute nameAttr = htmlCommandButtonElement.attribute("name");

            if (nameAttr != null) {
                buttonElement.addAttribute("name", nameAttr.getValue());
            }

            Attribute idAttr = htmlCommandButtonElement.attribute("id");

            if (idAttr != null) {
                buttonElement.addAttribute("id", idAttr.getValue());
            }

            // Remove the HtmlCommandButton <input> from the XML document so that only one button is rendered.
            htmlCommandButtonElement.getParent().remove(htmlCommandButtonElement);
        }
    }

    // Returned the modified verson of the specified markup.
    return new StringBuilder(rootElement.asXML());
}

From source file:com.liferay.google.apps.connector.GHelperUtil.java

License:Open Source License

public static Element addAppsProperty(Element parentElement, String name, String value) {

    Element element = parentElement.addElement("apps:property");

    element.addAttribute("name", name);
    element.addAttribute("value", value);

    return element;
}

From source file:com.liferay.google.apps.connector.GHelperUtil.java

License:Open Source License

public static Element addAtomCategory(Element parentElement, String type) {
    Element element = parentElement.addElement("atom:category");

    element.addAttribute("scheme", "http://schemas.google.com/g/2005#kind");
    element.addAttribute("term", "http://schemas.google.com/apps/2006#" + type);

    return element;
}

From source file:com.liferay.google.apps.connector.GNicknameManagerImpl.java

License:Open Source License

@Override
public void addGNickname(long userId, String nickname) throws GoogleAppsException {

    Document document = SAXReaderUtil.createDocument();

    Element atomEntryElement = addAtomEntry(document);

    addAtomCategory(atomEntryElement, "nickname");

    Element appsLoginElement = atomEntryElement.addElement("apps:login");

    appsLoginElement.addAttribute("userName", String.valueOf(userId));

    Element appsNicknameElement = atomEntryElement.addElement("apps:nickname");

    appsNicknameElement.addAttribute("name", nickname);

    submitAdd(nicknameURL, document);//from  w  ww.  ja v a  2 s  .  c  o m
}