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.layout.internal.exportimport.data.handler.StagedLayoutSetStagedModelDataHandler.java

License:Open Source License

protected void exportLayouts(PortletDataContext portletDataContext, StagedLayoutSet stagedLayoutSet) {

    // Force to always export layout deletions

    portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(Layout.class));

    // Force to always have a layout group element

    portletDataContext.getExportDataGroupElement(Layout.class);

    long[] layoutIds = portletDataContext.getLayoutIds();
    List<StagedModel> stagedModels = _stagedLayoutSetStagedModelRepository
            .fetchChildrenStagedModels(portletDataContext, stagedLayoutSet);

    for (StagedModel stagedModel : stagedModels) {
        Layout layout = (Layout) stagedModel;

        if (!ArrayUtil.contains(layoutIds, layout.getLayoutId())) {
            Element layoutElement = portletDataContext.getExportDataElement(layout);

            layoutElement.addAttribute(Constants.ACTION, Constants.SKIP);

            continue;
        }//from   w ww. ja v  a 2s .c  o  m

        try {
            if (!LayoutStagingUtil.prepareLayoutStagingHandler(portletDataContext, layout)) {

                continue;
            }

            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedLayoutSet, layout,
                    PortletDataContext.REFERENCE_TYPE_CHILD);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to export layout " + layout.getName(), e);
            }
        }
    }
}

From source file:com.liferay.layout.internal.exportimport.data.handler.StagedLayoutSetStagedModelDataHandler.java

License:Open Source License

protected void exportLogo(PortletDataContext portletDataContext, StagedLayoutSet stagedLayoutSet) {

    boolean logo = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.LOGO);

    if (!logo) {//  ww w .jav  a  2 s  . co m
        stagedLayoutSet.setLogoId(0);

        return;
    }

    long layoutSetBranchId = MapUtil.getLong(portletDataContext.getParameterMap(), "layoutSetBranchId");

    LayoutSetBranch layoutSetBranch = _layoutSetBranchLocalService.fetchLayoutSetBranch(layoutSetBranchId);

    Image image = null;

    if (layoutSetBranch != null) {
        try {
            image = _imageLocalService.getImage(layoutSetBranch.getLogoId());
        } catch (PortalException pe) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to get logo for layout set branch " + layoutSetBranch.getLayoutSetBranchId(),
                        pe);
            }
        }
    } else {
        try {
            image = _imageLocalService.getImage(stagedLayoutSet.getLogoId());
        } catch (PortalException pe) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to get logo for layout set " + stagedLayoutSet.getLayoutSetId(), pe);
            }
        }
    }

    if ((image != null) && (image.getTextObj() != null)) {
        String logoPath = ExportImportPathUtil.getRootPath(portletDataContext);

        logoPath += "/logo";

        Element rootElement = portletDataContext.getExportDataRootElement();

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

        headerElement.addAttribute("logo-path", logoPath);

        portletDataContext.addZipEntry(logoPath, image.getTextObj());
    }
}

From source file:com.liferay.layout.prototype.internal.exportimport.data.handler.LayoutPrototypePortletDataHandler.java

License:Open Source License

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

    portletDataContext.addPortalPermissions();

    Element rootElement = addExportDataRootElement(portletDataContext);

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

    ActionableDynamicQuery actionableDynamicQuery = _layoutPrototypeLocalService
            .getExportActionableDynamicQuery(portletDataContext);

    actionableDynamicQuery.performActions();

    return getExportDataRootElementString(rootElement);
}

From source file:com.liferay.layout.set.prototype.internal.exportimport.data.handler.LayoutSetPrototypePortletDataHandler.java

License:Open Source License

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

    portletDataContext.addPortalPermissions();

    Element rootElement = addExportDataRootElement(portletDataContext);

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

    ActionableDynamicQuery actionableDynamicQuery = layoutSetPrototypeLocalService
            .getExportActionableDynamicQuery(portletDataContext);

    actionableDynamicQuery.performActions();

    return getExportDataRootElementString(rootElement);
}

From source file:com.liferay.lms.service.impl.LearningActivityLocalServiceImpl.java

License:Open Source License

@SuppressWarnings("rawtypes")
public void saveHashMapToXMLExtraContent(long actId, HashMap<String, String> map)
        throws SystemException, PortalException {
    try {//w w w .  j  a  v  a  2  s.com
        LearningActivity activity = learningActivityPersistence.fetchByPrimaryKey(actId);

        if (activity != null && !map.isEmpty()) {

            //Element resultadosXML=SAXReaderUtil.createElement("p2p");
            Element resultadosXML = SAXReaderUtil.createElement(getNameLearningActivity(activity.getTypeId()));
            Document resultadosXMLDoc = SAXReaderUtil.createDocument(resultadosXML);

            Iterator it = map.entrySet().iterator();

            while (it.hasNext()) {
                Map.Entry e = (Map.Entry) it.next();
                Element eleXML = SAXReaderUtil.createElement(String.valueOf(e.getKey()));
                if (e.getKey().equals("document")) {
                    eleXML.addAttribute("id", String.valueOf(e.getValue()));
                } else {
                    eleXML.addText(String.valueOf(e.getValue()));
                }
                resultadosXML.add(eleXML);
            }
            activity.setExtracontent(resultadosXMLDoc.formattedString());
            learningActivityPersistence.update(activity, true);
        }

    } catch (Exception e) {
    }
}

From source file:com.liferay.message.boards.internal.exportimport.data.handler.MBMessageStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, MBMessage message) throws Exception {

    if (message.isDiscussion()) {
        MBDiscussion discussion = _mbDiscussionLocalService.getDiscussion(message.getClassName(),
                message.getClassPK());/*from w ww  . jav a2s .  com*/

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, message, discussion,
                PortletDataContext.REFERENCE_TYPE_PARENT);

        // Ratings that belong to discussion messages cannot be exported
        // automatically because of the special class name and class PK pair

        List<RatingsEntry> ratingsEntries = _ratingsEntryLocalService.getEntries(MBDiscussion.class.getName(),
                message.getMessageId());

        for (RatingsEntry ratingsEntry : ratingsEntries) {
            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, message, ratingsEntry,
                    PortletDataContext.REFERENCE_TYPE_WEAK);
        }
    } else if (message.getCategoryId() != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, message,
                message.getCategory(), PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    if (!message.isRoot()) {
        MBMessage parentMessage = _mbMessageLocalService.getMessage(message.getParentMessageId());

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, message, parentMessage,
                PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    message.setPriority(message.getPriority());

    MBThread thread = message.getThread();

    Element messageElement = portletDataContext.getExportDataElement(message);

    messageElement.addAttribute("question", String.valueOf(thread.isQuestion()));
    messageElement.addAttribute("threadUuid", thread.getUuid());

    boolean hasAttachmentsFileEntries = false;

    if (message.getAttachmentsFileEntriesCount() > 0) {
        hasAttachmentsFileEntries = true;
    }

    messageElement.addAttribute("hasAttachmentsFileEntries", String.valueOf(hasAttachmentsFileEntries));

    if (hasAttachmentsFileEntries) {
        for (FileEntry fileEntry : message.getAttachmentsFileEntries()) {
            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, message, fileEntry,
                    PortletDataContext.REFERENCE_TYPE_WEAK);
        }

        long folderId = message.getAttachmentsFolderId();

        if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
            message.setAttachmentsFolderId(folderId);
        }
    }

    portletDataContext.addClassedModel(messageElement, ExportImportPathUtil.getModelPath(message), message);
}

From source file:com.liferay.message.boards.internal.exportimport.data.handler.MBThreadFlagStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, MBThreadFlag threadFlag)
        throws Exception {

    MBThread thread = _mbThreadLocalService.getThread(threadFlag.getThreadId());

    MBMessage rootMessage = _mbMessageLocalService.getMessage(thread.getRootMessageId());

    if ((rootMessage.getStatus() != WorkflowConstants.STATUS_APPROVED)
            || (rootMessage.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

        return;/*from   w  w  w .java 2 s . c  o  m*/
    }

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, rootMessage);

    Element threadFlagElement = portletDataContext.getExportDataElement(threadFlag);

    threadFlagElement.addAttribute("root-message-id", String.valueOf(rootMessage.getMessageId()));

    portletDataContext.addClassedModel(threadFlagElement, ExportImportPathUtil.getModelPath(threadFlag),
            threadFlag);
}

From source file:com.liferay.message.boards.web.exportimport.data.handler.MBPortletDataHandler.java

License:Open Source License

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

    portletDataContext.addPortletPermissions(MBPermission.RESOURCE_NAME);

    Element rootElement = addExportDataRootElement(portletDataContext);

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

    if (portletDataContext.getBooleanParameter(NAMESPACE, "categories")
            || portletDataContext.getBooleanParameter(NAMESPACE, "messages")) {

        ActionableDynamicQuery categoryActionableDynamicQuery = _mbCategoryLocalService
                .getExportActionableDynamicQuery(portletDataContext);

        categoryActionableDynamicQuery.performActions();
    }/*from ww w.  j a v  a  2  s. c  o  m*/

    if (portletDataContext.getBooleanParameter(NAMESPACE, "messages")) {
        ActionableDynamicQuery messageActionableDynamicQuery = getMessageActionableDynamicQuery(
                portletDataContext);

        messageActionableDynamicQuery.performActions();
    }

    if (portletDataContext.getBooleanParameter(NAMESPACE, "thread-flags")) {
        ActionableDynamicQuery threadFlagActionableDynamicQuery = _mbThreadFlagLocalService
                .getExportActionableDynamicQuery(portletDataContext);

        threadFlagActionableDynamicQuery.performActions();
    }

    if (portletDataContext.getBooleanParameter(NAMESPACE, "user-bans")) {
        ActionableDynamicQuery banActionableDynamicQuery = _mbBanLocalService
                .getExportActionableDynamicQuery(portletDataContext);

        banActionableDynamicQuery.performActions();
    }

    return getExportDataRootElementString(rootElement);
}

From source file:com.liferay.mobile.device.rules.internal.exportimport.data.handler.MDRActionStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, MDRAction action) throws Exception {

    MDRRuleGroupInstance ruleGroupInstance = _mdrRuleGroupInstanceLocalService
            .getRuleGroupInstance(action.getRuleGroupInstanceId());

    StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, action, ruleGroupInstance,
            PortletDataContext.REFERENCE_TYPE_PARENT);

    Element actionElement = portletDataContext.getExportDataElement(action);

    String type = action.getType();

    if (type.equals(SiteRedirectActionHandler.class.getName())) {
        UnicodeProperties typeSettingsProperties = action.getTypeSettingsProperties();

        long plid = GetterUtil.getLong(typeSettingsProperties.getProperty("plid"));

        try {/*  ww  w  . jav a  2s .c  o  m*/
            Layout layout = _layoutLocalService.getLayout(plid);

            actionElement.addAttribute("layout-uuid", layout.getUuid());
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to set the layout uuid of layout " + plid
                        + ". Site redirect may not match after import.", e);
            }
        }
    }

    portletDataContext.addClassedModel(actionElement, ExportImportPathUtil.getModelPath(action), action);
}

From source file:com.liferay.mobile.device.rules.internal.exportimport.data.handler.MDRRuleGroupInstanceStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext,
        MDRRuleGroupInstance ruleGroupInstance) throws Exception {

    MDRRuleGroup ruleGroup = _mdrRuleGroupLocalService.getRuleGroup(ruleGroupInstance.getRuleGroupId());

    StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, ruleGroupInstance, ruleGroup,
            PortletDataContext.REFERENCE_TYPE_PARENT);

    Element ruleGroupInstanceElement = portletDataContext.getExportDataElement(ruleGroupInstance);

    String className = ruleGroupInstance.getClassName();

    if (className.equals(Layout.class.getName())) {
        Layout layout = _layoutLocalService.getLayout(ruleGroupInstance.getClassPK());

        ruleGroupInstanceElement.addAttribute("layout-uuid", layout.getUuid());
    }//from  w  w w .  ja va2s  . co m

    portletDataContext.addClassedModel(ruleGroupInstanceElement,
            ExportImportPathUtil.getModelPath(ruleGroupInstance), ruleGroupInstance);
}