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

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

Introduction

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

Prototype

public String attributeValue(String name);

Source Link

Usage

From source file:com.liferay.portlet.social.util.SocialConfigurationUtil.java

License:Open Source License

private static void _readActivityContribution(Element activityElement,
        SocialActivityDefinition activityDefinition) {

    Element contributionValueElement = activityElement.element("contribution-value");
    Element contributionLimitElement = activityElement.element("contribution-limit");

    if ((contributionValueElement == null) && (contributionLimitElement == null)) {

        return;// w  ww.j  av  a2  s .co m
    }

    SocialActivityCounterDefinition activityCounterDefinition = new SocialActivityCounterDefinition();

    activityCounterDefinition.setName(SocialActivityCounterConstants.NAME_CONTRIBUTION);
    activityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_CREATOR);

    int increment = 0;

    if (contributionValueElement != null) {
        increment = GetterUtil.getInteger(contributionValueElement.getText());
    }

    activityCounterDefinition.setIncrement(increment);

    if (contributionLimitElement != null) {
        String limitEnabled = contributionLimitElement.attributeValue("enabled");

        if (Validator.isNotNull(limitEnabled)) {
            activityCounterDefinition.setLimitEnabled(GetterUtil.getBoolean(limitEnabled));
        }

        String limitPeriod = contributionLimitElement.attributeValue("period");

        if (Validator.isNotNull(limitPeriod)) {
            activityCounterDefinition.setLimitPeriod(limitPeriod);
        }

        int limitValue = GetterUtil.getInteger(contributionLimitElement.getText());

        activityCounterDefinition.setLimitValue(limitValue);
    }

    activityDefinition.addCounter(activityCounterDefinition);

    SocialActivityCounterDefinition popularityActivityCounterDefinition = new SocialActivityCounterDefinition();

    popularityActivityCounterDefinition.setName(SocialActivityCounterConstants.NAME_POPULARITY);
    popularityActivityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_ASSET);
    popularityActivityCounterDefinition.setIncrement(activityCounterDefinition.getIncrement());
    popularityActivityCounterDefinition.setLimitEnabled(activityCounterDefinition.isLimitEnabled());
    popularityActivityCounterDefinition.setLimitPeriod(activityCounterDefinition.getLimitPeriod());
    popularityActivityCounterDefinition.setLimitValue(activityCounterDefinition.getLimitValue());

    activityDefinition.addCounter(popularityActivityCounterDefinition);
}

From source file:com.liferay.portlet.social.util.SocialConfigurationUtil.java

License:Open Source License

private static void _readActivityParticipation(Element activityElement,
        SocialActivityDefinition activityDefinition) {

    Element participationValueElement = activityElement.element("participation-value");
    Element participationLimitElement = activityElement.element("participation-limit");

    if ((participationValueElement == null) && (participationLimitElement == null)) {

        return;//w w  w  .  j  a v a 2s.com
    }

    SocialActivityCounterDefinition activityCounterDefinition = new SocialActivityCounterDefinition();

    activityCounterDefinition.setName(SocialActivityCounterConstants.NAME_PARTICIPATION);
    activityCounterDefinition.setOwnerType(SocialActivityCounterConstants.TYPE_ACTOR);

    int increment = 0;

    if (participationValueElement != null) {
        increment = GetterUtil.getInteger(participationValueElement.getText());
    }

    activityCounterDefinition.setIncrement(increment);

    if (participationLimitElement != null) {
        String limitEnabled = participationLimitElement.attributeValue("enabled");

        if (Validator.isNotNull(limitEnabled)) {
            activityCounterDefinition.setLimitEnabled(GetterUtil.getBoolean(limitEnabled));
        }

        String limitPeriod = participationLimitElement.attributeValue("period");

        if (Validator.isNotNull(limitPeriod)) {
            activityCounterDefinition.setLimitPeriod(limitPeriod);
        }

        int limitValue = GetterUtil.getInteger(participationLimitElement.getText());

        activityCounterDefinition.setLimitValue(limitValue);
    }

    activityDefinition.addCounter(activityCounterDefinition);
}

From source file:com.liferay.portlet.wiki.lar.WikiDisplayPortletDataHandlerImpl.java

License:Open Source License

@Override
protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId,
        PortletPreferences portletPreferences, String data) throws Exception {

    portletDataContext.importPermissions("com.liferay.portlet.wiki", portletDataContext.getSourceGroupId(),
            portletDataContext.getScopeGroupId());

    if (Validator.isNull(data)) {
        return null;
    }/*  w w w. j  av a  2  s .  c  o  m*/

    Document document = SAXReaderUtil.read(data);

    Element rootElement = document.getRootElement();

    Element nodesElement = rootElement.element("nodes");

    for (Element nodeElement : nodesElement.elements("node")) {
        String path = nodeElement.attributeValue("path");

        if (!portletDataContext.isPathNotProcessed(path)) {
            continue;
        }

        WikiNode node = (WikiNode) portletDataContext.getZipEntryAsObject(path);

        WikiPortletDataHandlerImpl.importNode(portletDataContext, node);
    }

    Element pagesElement = rootElement.element("pages");

    JournalPortletDataHandlerImpl.importReferencedData(portletDataContext, pagesElement);

    for (Element pageElement : pagesElement.elements("page")) {
        String path = pageElement.attributeValue("path");

        if (!portletDataContext.isPathNotProcessed(path)) {
            continue;
        }

        WikiPage page = (WikiPage) portletDataContext.getZipEntryAsObject(path);

        WikiPortletDataHandlerImpl.importPage(portletDataContext, pageElement, page);
    }

    Map<Long, Long> nodePKs = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class);

    for (long nodeId : nodePKs.values()) {
        WikiCacheUtil.clearCache(nodeId);
    }

    long nodeId = GetterUtil.getLong(portletPreferences.getValue("nodeId", StringPool.BLANK));

    if (nodeId > 0) {
        nodeId = MapUtil.getLong(nodePKs, nodeId, nodeId);

        portletPreferences.setValue("nodeId", String.valueOf(nodeId));
    }

    return portletPreferences;
}

From source file:com.liferay.portlet.wiki.lar.WikiPortletDataHandlerImpl.java

License:Open Source License

public static void importPage(PortletDataContext portletDataContext, Element pageElement, WikiPage page)
        throws Exception {

    long userId = portletDataContext.getUserId(page.getUserUuid());

    Map<Long, Long> nodePKs = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class);

    long nodeId = MapUtil.getLong(nodePKs, page.getNodeId(), page.getNodeId());

    String content = JournalPortletDataHandlerImpl.importReferencedContent(portletDataContext, pageElement,
            page.getContent());//from  ww  w .  j  a  v a2  s. co m

    page.setContent(content);

    ServiceContext serviceContext = portletDataContext.createServiceContext(pageElement, page, _NAMESPACE);

    if (page.getStatus() != WorkflowConstants.STATUS_APPROVED) {
        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
    }

    WikiPage importedPage = null;

    WikiPage existingPage = WikiPageUtil.fetchByUUID_G(page.getUuid(), portletDataContext.getScopeGroupId());

    if (existingPage == null) {
        try {
            existingPage = WikiPageLocalServiceUtil.getPage(nodeId, page.getTitle());
        } catch (NoSuchPageException nspe) {
        }
    }

    if (existingPage == null) {
        serviceContext.setUuid(page.getUuid());

        importedPage = WikiPageLocalServiceUtil.addPage(userId, nodeId, page.getTitle(), page.getVersion(),
                page.getContent(), page.getSummary(), page.isMinorEdit(), page.getFormat(), page.getHead(),
                page.getParentTitle(), page.getRedirectTitle(), serviceContext);
    } else {
        importedPage = WikiPageLocalServiceUtil.updatePage(userId, nodeId, existingPage.getTitle(), 0,
                page.getContent(), page.getSummary(), page.isMinorEdit(), page.getFormat(),
                page.getParentTitle(), page.getRedirectTitle(), serviceContext);
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "attachments") && page.isHead()) {

        for (Element attachmentElement : pageElement.elements("attachment")) {

            String name = attachmentElement.attributeValue("name");
            String binPath = attachmentElement.attributeValue("bin-path");

            InputStream inputStream = null;

            try {
                inputStream = portletDataContext.getZipEntryAsInputStream(binPath);

                WikiPageLocalServiceUtil.addPageAttachment(importedPage.getCompanyId(),
                        importedPage.getAttachmentsDir(), importedPage.getModifiedDate(), name, inputStream);
            } finally {
                StreamUtil.cleanUp(inputStream);
            }
        }
    }

    portletDataContext.importClassedModel(page, importedPage, _NAMESPACE);
}

From source file:com.liferay.portlet.wiki.lar.WikiPortletDataHandlerImpl.java

License:Open Source License

@Override
protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId,
        PortletPreferences portletPreferences, String data) throws Exception {

    portletDataContext.importPermissions("com.liferay.portlet.wiki", portletDataContext.getSourceGroupId(),
            portletDataContext.getScopeGroupId());

    Document document = SAXReaderUtil.read(data);

    Element rootElement = document.getRootElement();

    Element nodesElement = rootElement.element("nodes");

    for (Element nodeElement : nodesElement.elements("node")) {
        String path = nodeElement.attributeValue("path");

        if (!portletDataContext.isPathNotProcessed(path)) {
            continue;
        }/*from www  .j a v a  2 s.  c om*/

        WikiNode node = (WikiNode) portletDataContext.getZipEntryAsObject(path);

        importNode(portletDataContext, node);
    }

    Element pagesElement = rootElement.element("pages");

    JournalPortletDataHandlerImpl.importReferencedData(portletDataContext, pagesElement);

    for (Element pageElement : pagesElement.elements("page")) {
        String path = pageElement.attributeValue("path");

        if (!portletDataContext.isPathNotProcessed(path)) {
            continue;
        }

        WikiPage page = (WikiPage) portletDataContext.getZipEntryAsObject(path);

        importPage(portletDataContext, pageElement, page);
    }

    Map<Long, Long> nodePKs = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class);

    for (long nodeId : nodePKs.values()) {
        WikiCacheUtil.clearCache(nodeId);
    }

    return null;
}

From source file:com.liferay.randombibleverse.util.RBVUtil.java

License:Open Source License

private RBVUtil() {
    Document document = null;//w w w . j  av a 2  s  .c  o m

    try {
        ClassLoader classLoader = getClass().getClassLoader();

        URL url = classLoader
                .getResource("com/liferay/randombibleverse/dependencies/" + "random_bible_verse.xml");

        document = SAXReaderUtil.read(url);
    } catch (Exception e) {
        _log.error(e, e);
    }

    _bibles = new LinkedHashMap<String, Bible>();
    _verses = new ArrayList<String>();

    Element rootElement = document.getRootElement();

    Element biblesElement = rootElement.element("bibles");

    List<Element> bibleElements = biblesElement.elements("bible");

    for (Element bibleElement : bibleElements) {
        _bibles.put(bibleElement.attributeValue("language"), new Bible(bibleElement.attributeValue("language"),
                bibleElement.attributeValue("language-name"), bibleElement.attributeValue("version-id")));
    }

    _bibles = Collections.unmodifiableMap(_bibles);

    Element versesElement = rootElement.element("verses");

    List<Element> verseElements = versesElement.elements("verse");

    for (Element verseElement : verseElements) {
        _verses.add(verseElement.attributeValue("location"));
    }

    _verses = Collections.unmodifiableList(_verses);
}

From source file:com.liferay.site.internal.exportimport.data.handler.StagedGroupStagedModelDataHandler.java

License:Open Source License

@Override
public boolean validateReference(PortletDataContext portletDataContext, Element referenceElement) {

    Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

    long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id"));

    if ((groupId == 0) || groupIds.containsKey(groupId)) {
        return true;
    }//from  w  w  w.  j  a  va2s. com

    Group existingGroup = _stagedGroupStagedModelRepository.fetchExistingGroup(portletDataContext,
            referenceElement);

    if (existingGroup == null) {
        return false;
    }

    groupIds.put(groupId, existingGroup.getGroupId());

    return true;
}

From source file:com.liferay.site.internal.exportimport.data.handler.StagedGroupStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportMissingReference(PortletDataContext portletDataContext, Element referenceElement) {

    Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

    long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id"));

    if ((groupId == 0) || groupIds.containsKey(groupId)) {
        return;/* www .j a  v a  2s .co m*/
    }

    Group existingGroup = _stagedGroupStagedModelRepository.fetchExistingGroup(portletDataContext,
            referenceElement);

    groupIds.put(groupId, existingGroup.getGroupId());
}

From source file:com.liferay.site.internal.exportimport.data.handler.StagedGroupStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, StagedGroup stagedGroup)
        throws Exception {

    Element rootElement = portletDataContext.getImportDataRootElement();

    Element sitePortletsElement = rootElement.element("site-portlets");

    List<Element> sitePortletElements = sitePortletsElement.elements();

    // Initialize progress bar

    if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
        List<String> portletIds = new ArrayList<>();

        for (Element portletElement : sitePortletElements) {
            String portletId = portletElement.attributeValue("portlet-id");

            Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId);

            if (!portlet.isActive() || portlet.isUndeployedPortlet()) {
                continue;
            }//from  ww w . j  a v a2  s. c o  m

            portletIds.add(portletId);
        }

        _portletDataHandlerStatusMessageSender.sendStatusMessage("layout", ArrayUtil.toStringArray(portletIds),
                portletDataContext.getManifestSummary());
    }

    // Import services

    Element siteServicesElement = rootElement.element("site-services");

    List<Element> siteServiceElements = siteServicesElement.elements("service");

    if (_log.isDebugEnabled() && !siteServiceElements.isEmpty()) {
        _log.debug("Importing services");
    }

    importSiteServices(portletDataContext, siteServiceElements);

    // Import layout set

    Element layoutSetElement = portletDataContext.getImportDataGroupElement(StagedLayoutSet.class);

    for (Element groupElement : layoutSetElement.elements()) {
        StagedModelDataHandlerUtil.importStagedModel(portletDataContext, groupElement);
    }

    // Import site data portlets

    if (_log.isDebugEnabled() && !sitePortletElements.isEmpty()) {
        _log.debug("Importing portlets");
    }

    importSitePortlets(portletDataContext, sitePortletElements);
}

From source file:com.liferay.site.internal.exportimport.data.handler.StagedGroupStagedModelDataHandler.java

License:Open Source License

protected void importSitePortlets(PortletDataContext portletDataContext, List<Element> sitePortletElements)
        throws Exception {

    Map<Long, Layout> layouts = (Map<Long, Layout>) portletDataContext
            .getNewPrimaryKeysMap(Layout.class + ".layout");

    Map<String, String[]> parameterMap = portletDataContext.getParameterMap();

    boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    LayoutCache layoutCache = new LayoutCache();

    for (Element portletElement : sitePortletElements) {
        String portletPath = portletElement.attributeValue("path");
        String portletId = portletElement.attributeValue("portlet-id");
        long layoutId = GetterUtil.getLong(portletElement.attributeValue("layout-id"));
        long oldPlid = GetterUtil.getLong(portletElement.attributeValue("old-plid"));

        Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId);

        if (!portlet.isActive() || portlet.isUndeployedPortlet()) {
            continue;
        }/*from   w  w w.  j  ava2 s  .  c  om*/

        Layout layout = layouts.get(layoutId);

        long plid = LayoutConstants.DEFAULT_PLID;

        if (layout != null) {
            if (SitesUtil.isLayoutModifiedSinceLastMerge(layout)) {
                continue;
            }

            plid = layout.getPlid();
        }

        portletDataContext.setPlid(plid);
        portletDataContext.setOldPlid(oldPlid);
        portletDataContext.setPortletId(portletId);

        if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
            _portletDataHandlerStatusMessageSender.sendStatusMessage("portlet", portletId,
                    portletDataContext.getManifestSummary());
        }

        Document portletDocument = SAXReaderUtil.read(portletDataContext.getZipEntryAsString(portletPath));

        portletElement = portletDocument.getRootElement();

        // The order of the import is important. You must always import the
        // portlet preferences first, then the portlet data, then the
        // portlet permissions. The import of the portlet data assumes that
        // portlet preferences already exist.

        _exportImportHelper.setPortletScope(portletDataContext, portletElement);

        long portletPreferencesGroupId = portletDataContext.getGroupId();

        Element portletDataElement = portletElement.element("portlet-data");

        Map<String, Boolean> importPortletControlsMap = _exportImportHelper.getImportPortletControlsMap(
                portletDataContext.getCompanyId(), portletId, portletDataContext.getParameterMap(),
                portletDataElement, portletDataContext.getManifestSummary());

        if (layout != null) {
            portletPreferencesGroupId = layout.getGroupId();
        }

        try {
            _exportImportLifecycleManager.fireExportImportLifecycleEvent(EVENT_PORTLET_IMPORT_STARTED,
                    getProcessFlag(), portletDataContext.getExportImportProcessId(),
                    _portletDataContextFactory.clonePortletDataContext(portletDataContext));

            // Portlet preferences

            _portletImportController.importPortletPreferences(portletDataContext,
                    portletDataContext.getCompanyId(), portletPreferencesGroupId, layout, portletElement, false,
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));

            // Portlet data

            if (importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA)) {

                _portletImportController.importPortletData(portletDataContext, portletDataElement);
            }

            _exportImportLifecycleManager.fireExportImportLifecycleEvent(EVENT_PORTLET_IMPORT_SUCCEEDED,
                    getProcessFlag(), portletDataContext.getExportImportProcessId(),
                    _portletDataContextFactory.clonePortletDataContext(portletDataContext));
        } catch (Throwable t) {
            _exportImportLifecycleManager.fireExportImportLifecycleEvent(EVENT_PORTLET_IMPORT_FAILED,
                    getProcessFlag(), portletDataContext.getExportImportProcessId(),
                    _portletDataContextFactory.clonePortletDataContext(portletDataContext), t);

            throw t;
        } finally {
            _portletImportController.resetPortletScope(portletDataContext, portletPreferencesGroupId);
        }

        // Portlet permissions

        if (permissions) {
            _permissionImporter.importPortletPermissions(layoutCache, portletDataContext.getCompanyId(),
                    portletDataContext.getGroupId(), serviceContext.getUserId(), layout, portletElement,
                    portletId);
        }

        // Archived setups

        _portletImportController.importPortletPreferences(portletDataContext, portletDataContext.getCompanyId(),
                portletDataContext.getGroupId(), null, portletElement, false,
                importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
                importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
                importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
                importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));
    }
}