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.maven.plugins.compatibility.WSDDBuilder.java

License:Open Source License

public void build() throws Exception {
    if (!FileUtil.exists(_serverConfigFileName)) {
        ClassLoader classLoader = getClass().getClassLoader();

        String serverConfigContent = StringUtil.read(classLoader,
                "com/liferay/portal/tools/dependencies/server-config.wsdd");

        FileUtil.write(_serverConfigFileName, serverConfigContent);
    }//  ww  w.  ja va2  s  .  c  om

    Document document = SAXReaderUtil.read(new File(_fileName), true);

    Element rootElement = document.getRootElement();

    String packagePath = rootElement.attributeValue("package-path");

    Element portletElement = rootElement.element("portlet");
    Element namespaceElement = rootElement.element("namespace");

    if (portletElement != null) {
        _portletShortName = portletElement.attributeValue("short-name");
    } else {
        _portletShortName = namespaceElement.getText();
    }

    _outputPath += StringUtil.replace(packagePath, ".", "/") + "/service/http";

    _packagePath = packagePath;

    List<Element> entityElements = rootElement.elements("entity");

    for (Element entityElement : entityElements) {
        String entityName = entityElement.attributeValue("name");

        boolean remoteService = GetterUtil.getBoolean(entityElement.attributeValue("remote-service"), true);

        if (remoteService) {
            _createServiceWSDD(entityName);

            WSDDMerger.merge(_outputPath + "/" + entityName + "Service_deploy.wsdd", _serverConfigFileName);
        }
    }
}

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

License:Open Source License

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

    if (!message.isRoot()) {
        StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, message, MBMessage.class,
                message.getParentMessageId());
    }//from  w  ww.jav  a2s.  c  o  m

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

    Map<Long, Long> categoryIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBCategory.class);

    long parentCategoryId = MapUtil.getLong(categoryIds, message.getCategoryId(), message.getCategoryId());

    Map<Long, Long> threadIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBThread.class);

    long threadId = MapUtil.getLong(threadIds, message.getThreadId(), 0);

    Element messageElement = portletDataContext.getImportDataStagedModelElement(message);

    if (threadId == 0) {
        String threadUuid = messageElement.attributeValue("threadUuid");

        MBThread thread = _mbThreadLocalService.fetchMBThreadByUuidAndGroupId(threadUuid,
                portletDataContext.getScopeGroupId());

        if (thread != null) {
            threadId = thread.getThreadId();
        }
    }

    Map<Long, Long> messageIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBMessage.class);

    long parentMessageId = MapUtil.getLong(messageIds, message.getParentMessageId(),
            message.getParentMessageId());

    List<ObjectValuePair<String, InputStream>> inputStreamOVPs = getAttachments(portletDataContext,
            messageElement, message);

    try {
        ServiceContext serviceContext = portletDataContext.createServiceContext(message);

        MBMessage importedMessage = null;

        if (portletDataContext.isDataStrategyMirror()) {
            MBMessage existingMessage = fetchStagedModelByUuidAndGroupId(message.getUuid(),
                    portletDataContext.getScopeGroupId());

            if (existingMessage == null) {
                serviceContext.setUuid(message.getUuid());

                if (message.isDiscussion()) {
                    importedMessage = addDiscussionMessage(portletDataContext, userId, threadId,
                            parentMessageId, message, serviceContext);
                } else {
                    importedMessage = _mbMessageLocalService.addMessage(userId, message.getUserName(),
                            portletDataContext.getScopeGroupId(), parentCategoryId, threadId, parentMessageId,
                            message.getSubject(), message.getBody(), message.getFormat(), inputStreamOVPs,
                            message.getAnonymous(), message.getPriority(), message.getAllowPingbacks(),
                            serviceContext);
                }
            } else {
                if (!message.isRoot() && message.isDiscussion()) {
                    MBDiscussion discussion = _mbDiscussionLocalService.getThreadDiscussion(threadId);

                    importedMessage = _mbMessageLocalService.updateDiscussionMessage(userId,
                            existingMessage.getMessageId(), discussion.getClassName(), discussion.getClassPK(),
                            message.getSubject(), message.getBody(), serviceContext);
                } else {
                    importedMessage = _mbMessageLocalService.updateMessage(userId,
                            existingMessage.getMessageId(), message.getSubject(), message.getBody(),
                            inputStreamOVPs, new ArrayList<String>(), message.getPriority(),
                            message.getAllowPingbacks(), serviceContext);
                }
            }
        } else {
            if (message.isDiscussion()) {
                importedMessage = addDiscussionMessage(portletDataContext, userId, threadId, parentMessageId,
                        message, serviceContext);
            } else {
                importedMessage = _mbMessageLocalService.addMessage(userId, message.getUserName(),
                        portletDataContext.getScopeGroupId(), parentCategoryId, threadId, parentMessageId,
                        message.getSubject(), message.getBody(), message.getFormat(), inputStreamOVPs,
                        message.getAnonymous(), message.getPriority(), message.getAllowPingbacks(),
                        serviceContext);
            }
        }

        importedMessage = _updateAnswer(message, importedMessage);

        if (importedMessage.isRoot() && !importedMessage.isDiscussion()) {
            _mbThreadLocalService.updateQuestion(importedMessage.getThreadId(),
                    GetterUtil.getBoolean(messageElement.attributeValue("question")));
        }

        if (message.isDiscussion()) {
            Map<Long, Long> discussionIds = (Map<Long, Long>) portletDataContext
                    .getNewPrimaryKeysMap(MBDiscussion.class);

            discussionIds.put(message.getMessageId(), importedMessage.getMessageId());
        }

        threadIds.put(message.getThreadId(), importedMessage.getThreadId());

        // Keep thread UUID

        MBThread thread = importedMessage.getThread();

        thread.setUuid(messageElement.attributeValue("threadUuid"));

        _mbThreadLocalService.updateMBThread(thread);

        portletDataContext.importClassedModel(message, importedMessage);
    } finally {
        for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {

            InputStream inputStream = inputStreamOVP.getValue();

            StreamUtil.cleanUp(inputStream);
        }
    }
}

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

License:Open Source License

protected List<ObjectValuePair<String, InputStream>> getAttachments(PortletDataContext portletDataContext,
        Element messageElement, MBMessage message) {

    boolean hasAttachmentsFileEntries = GetterUtil
            .getBoolean(messageElement.attributeValue("hasAttachmentsFileEntries"));

    if (!hasAttachmentsFileEntries) {
        return Collections.emptyList();
    }/*from  w w  w . j  a v a  2s  . c o m*/

    List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<>();

    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(messageElement,
            DLFileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);

    for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");

        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);

        InputStream inputStream = null;

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

        if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {

            try {
                inputStream = FileEntryUtil.getContentStream(fileEntry);
            } catch (Exception e) {
            }
        } else {
            inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
        }

        if (inputStream == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId());
            }

            continue;
        }

        ObjectValuePair<String, InputStream> inputStreamOVP = new ObjectValuePair<>(fileEntry.getTitle(),
                inputStream);

        inputStreamOVPs.add(inputStreamOVP);
    }

    if (inputStreamOVPs.isEmpty()) {
        _log.error("Could not find attachments for message " + message.getMessageId());
    }

    return inputStreamOVPs;
}

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

License:Open Source License

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

    User user = _userLocalService.fetchUserByUuidAndCompanyId(threadFlag.getUserUuid(),
            portletDataContext.getCompanyId());

    if (user == null) {
        return;/*from  w  w w.j a  v  a2s  . co m*/
    }

    Element element = portletDataContext.getImportDataStagedModelElement(threadFlag);

    long rootMessageId = GetterUtil.getLong(element.attributeValue("root-message-id"));

    String rootMessagePath = ExportImportPathUtil.getModelPath(portletDataContext, MBMessage.class.getName(),
            rootMessageId);

    MBMessage rootMessage = (MBMessage) portletDataContext.getZipEntryAsObject(element, rootMessagePath);

    StagedModelDataHandlerUtil.importStagedModel(portletDataContext, rootMessage);

    Map<Long, Long> threadIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBThread.class);

    long threadId = MapUtil.getLong(threadIds, threadFlag.getThreadId(), threadFlag.getThreadId());

    MBThread thread = _mbThreadLocalService.fetchThread(threadId);

    if (thread == null) {
        return;
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(threadFlag);

    serviceContext.setUuid(threadFlag.getUuid());

    _mbThreadFlagLocalService.addThreadFlag(user.getUserId(), thread, serviceContext);
}

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

License:Open Source License

protected void validateLayout(Element actionElement, MDRAction action) {
    String type = action.getType();

    if (!type.equals(SiteRedirectActionHandler.class.getName())) {
        return;//w w w.j av  a2s .  c o  m
    }

    String layoutUuid = actionElement.attributeValue("layout-uuid");

    if (Validator.isNull(layoutUuid)) {
        return;
    }

    UnicodeProperties typeSettingsProperties = action.getTypeSettingsProperties();

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

    boolean privateLayout = GetterUtil.getBoolean(actionElement.attributeValue("private-layout"));

    try {
        Layout layout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, groupId, privateLayout);

        typeSettingsProperties.setProperty("plid", String.valueOf(layout.getPlid()));
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            StringBundler sb = new StringBundler(5);

            sb.append("Unable to find layout with uuid ");
            sb.append(layoutUuid);
            sb.append(" in group ");
            sb.append(groupId);
            sb.append(". Site redirect may not match the target layout.");

            _log.warn(sb.toString(), e);
        }
    }
}

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

License:Open Source License

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

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

    Map<Long, Long> ruleGroupIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(MDRRuleGroup.class);

    Long ruleGroupId = MapUtil.getLong(ruleGroupIds, ruleGroupInstance.getRuleGroupId(),
            ruleGroupInstance.getRuleGroupId());

    long classPK = 0;

    Element ruleGroupInstanceElement = portletDataContext.getImportDataStagedModelElement(ruleGroupInstance);

    String layoutUuid = ruleGroupInstanceElement.attributeValue("layout-uuid");

    try {/*  w  w  w . jav  a 2s.  co  m*/
        if (Validator.isNotNull(layoutUuid)) {
            Layout layout = _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid,
                    portletDataContext.getScopeGroupId(), portletDataContext.isPrivateLayout());

            classPK = layout.getPrimaryKey();
        } else {
            LayoutSet layoutSet = _layoutSetLocalService.getLayoutSet(portletDataContext.getScopeGroupId(),
                    portletDataContext.isPrivateLayout());

            classPK = layoutSet.getLayoutSetId();
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            StringBundler sb = new StringBundler(5);

            sb.append("Layout ");
            sb.append(layoutUuid);
            sb.append(" is missing for rule group instance ");
            sb.append(ruleGroupInstance.getRuleGroupInstanceId());
            sb.append(", skipping this rule group instance.");

            _log.warn(sb.toString());
        }

        return;
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(ruleGroupInstance);

    serviceContext.setUserId(userId);

    MDRRuleGroupInstance importedRuleGroupInstance = null;

    if (portletDataContext.isDataStrategyMirror()) {
        MDRRuleGroupInstance existingMDRRuleGroupInstance = fetchStagedModelByUuidAndGroupId(
                ruleGroupInstance.getUuid(), portletDataContext.getScopeGroupId());

        if (existingMDRRuleGroupInstance == null) {
            serviceContext.setUuid(ruleGroupInstance.getUuid());

            importedRuleGroupInstance = _mdrRuleGroupInstanceLocalService.addRuleGroupInstance(
                    portletDataContext.getScopeGroupId(), ruleGroupInstance.getClassName(), classPK,
                    ruleGroupId, ruleGroupInstance.getPriority(), serviceContext);
        } else {
            importedRuleGroupInstance = _mdrRuleGroupInstanceLocalService.updateRuleGroupInstance(
                    existingMDRRuleGroupInstance.getRuleGroupInstanceId(), ruleGroupInstance.getPriority());
        }
    } else {
        importedRuleGroupInstance = _mdrRuleGroupInstanceLocalService.addRuleGroupInstance(
                portletDataContext.getScopeGroupId(), ruleGroupInstance.getClassName(), classPK, ruleGroupId,
                ruleGroupInstance.getPriority(), serviceContext);
    }

    portletDataContext.importClassedModel(ruleGroupInstance, importedRuleGroupInstance);
}

From source file:com.liferay.opensocial.admin.lar.AdminPortletDataHandlerImpl.java

License:Open Source License

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

    Document document = SAXReaderUtil.read(data);

    Element rootElement = document.getRootElement();

    Element gadgetsElement = rootElement.element("gadgets");

    for (Element gadgetElement : gadgetsElement.elements("gadget")) {
        String gadgetPath = gadgetElement.attributeValue("path");

        if (!portletDataContext.isPathNotProcessed(gadgetPath)) {
            continue;
        }/*from w  w w.j  a  v a 2 s.c o m*/

        Gadget gadget = (Gadget) portletDataContext.getZipEntryAsObject(gadgetPath);

        importGadget(portletDataContext, gadgetElement, gadget);
    }

    return null;
}

From source file:com.liferay.portlet.blogs.lar.BlogsPortletDataHandlerImpl.java

License:Open Source License

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

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

    Document document = SAXReaderUtil.read(data);

    Element rootElement = document.getRootElement();

    Element entriesElement = rootElement.element("entries");

    if (entriesElement != null) {
        JournalPortletDataHandlerImpl.importReferencedData(portletDataContext, entriesElement);
    } else {/*from w w  w . ja  v  a 2  s  . c om*/
        entriesElement = rootElement;
    }

    for (Element entryElement : entriesElement.elements("entry")) {
        String path = entryElement.attributeValue("path");

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

        BlogsEntry entry = (BlogsEntry) portletDataContext.getZipEntryAsObject(path);

        importEntry(portletDataContext, entryElement, entry);
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wordpress")) {
        WordPressImporter.importData(portletDataContext);
    }

    return null;
}

From source file:com.liferay.portlet.blogs.lar.BlogsPortletDataHandlerImpl.java

License:Open Source License

protected void importEntry(PortletDataContext portletDataContext, Element entryElement, BlogsEntry entry)
        throws Exception {

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

    String content = JournalPortletDataHandlerImpl.importReferencedContent(portletDataContext, entryElement,
            entry.getContent());/*from  w  w w.j  a va 2  s  .com*/

    entry.setContent(content);

    Calendar displayDateCal = CalendarFactoryUtil.getCalendar();

    displayDateCal.setTime(entry.getDisplayDate());

    int displayDateMonth = displayDateCal.get(Calendar.MONTH);
    int displayDateDay = displayDateCal.get(Calendar.DATE);
    int displayDateYear = displayDateCal.get(Calendar.YEAR);
    int displayDateHour = displayDateCal.get(Calendar.HOUR);
    int displayDateMinute = displayDateCal.get(Calendar.MINUTE);

    if (displayDateCal.get(Calendar.AM_PM) == Calendar.PM) {
        displayDateHour += 12;
    }

    boolean allowPingbacks = entry.isAllowPingbacks();
    boolean allowTrackbacks = entry.isAllowTrackbacks();
    String[] trackbacks = StringUtil.split(entry.getTrackbacks());
    int status = entry.getStatus();

    ServiceContext serviceContext = portletDataContext.createServiceContext(entryElement, entry, _NAMESPACE);

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

    String smallImageFileName = null;
    InputStream smallImageInputStream = null;

    try {
        String smallImagePath = entryElement.attributeValue("small-image-path");

        if (entry.isSmallImage() && Validator.isNotNull(smallImagePath)) {
            smallImageFileName = String.valueOf(entry.getSmallImageId()).concat(StringPool.PERIOD)
                    .concat(entry.getSmallImageType());
            smallImageInputStream = portletDataContext.getZipEntryAsInputStream(smallImagePath);
        }

        BlogsEntry importedEntry = null;

        if (portletDataContext.isDataStrategyMirror()) {
            BlogsEntry existingEntry = BlogsEntryUtil.fetchByUUID_G(entry.getUuid(),
                    portletDataContext.getScopeGroupId());

            if (existingEntry == null) {
                serviceContext.setUuid(entry.getUuid());

                importedEntry = BlogsEntryLocalServiceUtil.addEntry(userId, entry.getTitle(),
                        entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay,
                        displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks,
                        trackbacks, entry.isSmallImage(), entry.getSmallImageURL(), smallImageFileName,
                        smallImageInputStream, serviceContext);
            } else {
                importedEntry = BlogsEntryLocalServiceUtil.updateEntry(userId, existingEntry.getEntryId(),
                        entry.getTitle(), entry.getDescription(), entry.getContent(), displayDateMonth,
                        displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks,
                        allowTrackbacks, trackbacks, entry.getSmallImage(), entry.getSmallImageURL(),
                        smallImageFileName, smallImageInputStream, serviceContext);
            }
        } else {
            importedEntry = BlogsEntryLocalServiceUtil.addEntry(userId, entry.getTitle(),
                    entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay,
                    displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks,
                    trackbacks, entry.getSmallImage(), entry.getSmallImageURL(), smallImageFileName,
                    smallImageInputStream, serviceContext);
        }

        portletDataContext.importClassedModel(entry, importedEntry, _NAMESPACE);
    } finally {
        StreamUtil.cleanUp(smallImageInputStream);
    }

}

From source file:com.liferay.portlet.blogs.lar.WordPressImporter.java

License:Open Source License

protected static Map<String, Long> getWordPressUserMap(PortletDataContext context) {

    Map<String, Long> userMap = new HashMap<String, Long>();

    String path = getWordPressPath(context, _USER_MAP_FILE);

    String fileData = context.getZipEntryAsString(path);

    if (Validator.isNull(fileData)) {
        return userMap;
    }//  w  w  w. ja v a  2 s.  co m

    Document doc = null;

    try {
        doc = SAXReaderUtil.read(fileData);
    } catch (DocumentException de) {
        _log.error(de.getMessage(), de);

        return userMap;
    }

    Element root = doc.getRootElement();

    List<Element> userEls = root.elements("wordpress-user");

    for (Element userEl : userEls) {
        try {
            User user = UserUtil.findByC_EA(context.getCompanyId(), userEl.attributeValue("email-address"));

            userMap.put(userEl.getTextTrim(), user.getUserId());
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug("User for {" + context.getCompanyId() + ", " + userEl.attributeValue("email-address")
                        + "}", e);
            }
        }
    }

    return userMap;
}