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.google.apps.connector.GGroupManagerImpl.java

License:Open Source License

@Override
public void updateDescription(String emailAddress, String description) throws GoogleAppsException {

    Document document = getDocument(getGroupURL(emailAddress));

    if (hasError(document)) {
        if (_log.isInfoEnabled()) {
            _log.info(getErrorMessage(document));
        }/*from   w  w w  .  j  a  va  2 s  .  c o  m*/

        return;
    }

    Element atomEntryElement = document.getRootElement();

    List<Element> appsPropertyElements = atomEntryElement.elements(getAppsQName("property"));

    for (Element appsPropertyElement : appsPropertyElements) {
        String name = appsPropertyElement.attributeValue("name");

        if (name.equals("description")) {
            Attribute valueAttribute = appsPropertyElement.attribute("value");

            valueAttribute.setValue(description);
        }
    }

    submitUpdate(getGroupURL(emailAddress), document);
}

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

License:Open Source License

protected GGroup getGGroup(Element atomEntryElement) {
    GGroup gGroup = new GGroup();

    List<Element> appsPropertyElements = atomEntryElement.elements(getAppsQName("property"));

    for (Element appsPropertyElement : appsPropertyElements) {
        String name = appsPropertyElement.attributeValue("name");
        String value = appsPropertyElement.attributeValue("value");

        if (name.equals("description")) {
            gGroup.setDescription(value);
        } else if (name.equals("emailPermission")) {
            gGroup.setEmailPermission(value);
        } else if (name.equals("groupId")) {
            gGroup.setEmailAddress(value);
        } else if (name.equals("groupName")) {
            gGroup.setName(value);// w  w w.  j av a 2 s.  c  o  m
        } else if (name.equals("permissionPreset")) {
            gGroup.setPermissionPreset(value);
        }
    }

    return gGroup;
}

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

License:Open Source License

protected GGroupMember getGGroupMember(Element atomEntryElement) throws GoogleAppsException {

    GGroupMember gGroupMember = new GGroupMember();

    List<Element> appsPropertyElements = atomEntryElement.elements(getAppsQName("property"));

    for (Element appsPropertyElement : appsPropertyElements) {
        String name = appsPropertyElement.attributeValue("name");
        String value = appsPropertyElement.attributeValue("value");

        if (name.equals("directMember")) {
            gGroupMember.setDirect(GetterUtil.getBoolean(value));
        } else if (name.equals("memberId")) {
            gGroupMember.setEmailAddress(value);
        } else if (name.equals("memberType")) {
            gGroupMember.setType(value);
        }/*ww w . j ava 2  s.c  o  m*/
    }

    String type = gGroupMember.getType();

    if (type.equals("Group")) {
        GGroup gGroup = getGGroup(gGroupMember.getEmailAddress());

        gGroupMember.setGGroup(gGroup);
    } else if (type.equals("User")) {
        GUserManager gUserManager = googleApps.getGUserManager();

        GUser gUser = gUserManager.getGUser(gGroupMember.getEmailAddress());

        gGroupMember.setGUser(gUser);
    }

    return gGroupMember;
}

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

License:Open Source License

protected GGroupOwner getGGroupOwner(Element atomEntryElement) throws GoogleAppsException {

    GGroupOwner gGroupOwner = new GGroupOwner();

    List<Element> appsPropertyElements = atomEntryElement.elements(getAppsQName("property"));

    for (Element appsPropertyElement : appsPropertyElements) {
        String name = appsPropertyElement.attributeValue("name");
        String value = appsPropertyElement.attributeValue("value");

        if (name.equals("email")) {
            gGroupOwner.setEmailAddress(value);
        } else if (name.equals("type")) {
            gGroupOwner.setType(value);/*from w w w  .  j  av  a 2 s  . c  om*/
        }
    }

    String type = gGroupOwner.getType();

    if (type.equals("Group")) {
        GGroup gGroup = getGGroup(gGroupOwner.getEmailAddress());

        gGroupOwner.setGGroup(gGroup);
    } else if (type.equals("User")) {
        GUserManager gUserManager = googleApps.getGUserManager();

        GUser gUser = gUserManager.getGUser(gGroupOwner.getEmailAddress());

        gGroupOwner.setGUser(gUser);
    }

    return gGroupOwner;
}

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

License:Open Source License

protected GNickname getGNickname(Element atomEntryElement) {
    GNickname gNickname = new GNickname();

    Element appsLoginElement = atomEntryElement.element(getAppsQName("login"));
    Element appsNicknameElement = atomEntryElement.element(getAppsQName("nickname"));

    String nickname = appsNicknameElement.attributeValue("name");

    gNickname.setNickname(nickname);/*ww w  . j  a  v  a 2  s . c  om*/

    long userId = GetterUtil.getLong(appsLoginElement.attributeValue("userName"));

    gNickname.setUserId(userId);

    return gNickname;
}

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

License:Open Source License

protected GUser getGUser(Element atomEntryElement) {
    GUser gUser = new GUser();

    Element appsLoginElement = atomEntryElement.element(getAppsQName("login"));
    Element appsNameElement = atomEntryElement.element(getAppsQName("name"));

    boolean active = !GetterUtil.getBoolean(appsLoginElement.attributeValue("suspended"));

    gUser.setActive(active);/*  w  w  w . ja v a 2s  .com*/

    boolean administrator = GetterUtil.getBoolean(appsLoginElement.attributeValue("admin"));

    gUser.setAdministrator(administrator);

    boolean agreedToTermsOfUse = GetterUtil.getBoolean(appsLoginElement.attributeValue("agreedToTerms"));

    gUser.setAgreedToTermsOfUse(agreedToTermsOfUse);

    String firstName = appsNameElement.attributeValue("givenName");

    gUser.setFirstName(firstName);

    String lastName = appsNameElement.attributeValue("familyName");

    gUser.setLastName(lastName);

    long userId = GetterUtil.getLong(appsLoginElement.attributeValue("userName"));

    gUser.setUserId(userId);

    return gUser;
}

From source file:com.liferay.journal.content.web.internal.JournalContentPortletLayoutListener.java

License:Open Source License

protected String getRuntimePortletId(String xml) throws Exception {
    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    String portletName = rootElement.attributeValue("name");
    String instanceId = rootElement.attributeValue("instance");

    PortletInstance portletInstance = new PortletInstance(portletName, instanceId);

    return portletInstance.getPortletInstanceKey();
}

From source file:com.liferay.journal.exportimport.data.handler.JournalArticleStagedModelDataHandler.java

License:Open Source License

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

    validateMissingGroupReference(portletDataContext, referenceElement);

    String uuid = referenceElement.attributeValue("uuid");
    String articleResourceUuid = referenceElement.attributeValue("article-resource-uuid");

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

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

    groupId = MapUtil.getLong(groupIds, groupId);

    String articleArticleId = referenceElement.attributeValue("article-id");
    boolean preloaded = GetterUtil.getBoolean(referenceElement.attributeValue("preloaded"));

    JournalArticle existingArticle = fetchExistingArticle(uuid, articleResourceUuid, groupId, articleArticleId,
            null, 0.0, preloaded);//from  www .j  a v  a2 s. co m

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

    return true;
}

From source file:com.liferay.journal.exportimport.data.handler.JournalArticleStagedModelDataHandler.java

License:Open Source License

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

    importMissingGroupReference(portletDataContext, referenceElement);

    String uuid = referenceElement.attributeValue("uuid");
    String articleResourceUuid = referenceElement.attributeValue("article-resource-uuid");

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

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

    groupId = MapUtil.getLong(groupIds, groupId);

    String articleArticleId = referenceElement.attributeValue("article-id");
    boolean preloaded = GetterUtil.getBoolean(referenceElement.attributeValue("preloaded"));

    JournalArticle existingArticle = null;

    existingArticle = fetchExistingArticle(uuid, articleResourceUuid, groupId, articleArticleId, null, 0.0,
            preloaded);//from  www  . j  a  va  2s  .c  om

    Map<String, String> articleArticleIds = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(JournalArticle.class + ".articleId");

    articleArticleIds.put(articleArticleId, existingArticle.getArticleId());

    Map<Long, Long> articleIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(JournalArticle.class);

    long articleId = GetterUtil.getLong(referenceElement.attributeValue("class-pk"));

    articleIds.put(articleId, existingArticle.getId());
}

From source file:com.liferay.journal.exportimport.data.handler.JournalArticleStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, JournalArticle article)
        throws Exception {

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

    long authorId = _journalCreationStrategy.getAuthorUserId(portletDataContext, article);

    if (authorId != JournalCreationStrategy.USE_DEFAULT_USER_ID_STRATEGY) {
        userId = authorId;/* www  .  j av  a2  s .co  m*/
    }

    User user = _userLocalService.getUser(userId);

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(JournalFolder.class);

    long folderId = MapUtil.getLong(folderIds, article.getFolderId(), article.getFolderId());

    String articleId = article.getArticleId();

    boolean autoArticleId = false;

    if (Validator.isNumber(articleId)
            || (_journalArticleLocalService.fetchArticle(portletDataContext.getScopeGroupId(), articleId,
                    JournalArticleConstants.VERSION_DEFAULT) != null)) {

        autoArticleId = true;
    }

    Map<String, String> articleIds = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(JournalArticle.class + ".articleId");

    String newArticleId = articleIds.get(articleId);

    if (Validator.isNotNull(newArticleId)) {

        // A sibling of a different version was already assigned a new
        // article id

        articleId = newArticleId;
        autoArticleId = false;
    }

    String content = article.getContent();

    content = _journalArticleExportImportContentProcessor.replaceImportContentReferences(portletDataContext,
            article, content);

    article.setContent(content);

    String newContent = _journalCreationStrategy.getTransformedContent(portletDataContext, article);

    if (newContent != JournalCreationStrategy.ARTICLE_CONTENT_UNCHANGED) {
        article.setContent(newContent);
    }

    Date displayDate = article.getDisplayDate();

    int displayDateMonth = 0;
    int displayDateDay = 0;
    int displayDateYear = 0;
    int displayDateHour = 0;
    int displayDateMinute = 0;

    if (displayDate != null) {
        Calendar displayCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        displayCal.setTime(displayDate);

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

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

    Date expirationDate = article.getExpirationDate();

    int expirationDateMonth = 0;
    int expirationDateDay = 0;
    int expirationDateYear = 0;
    int expirationDateHour = 0;
    int expirationDateMinute = 0;
    boolean neverExpire = true;

    if (expirationDate != null) {
        Calendar expirationCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        expirationCal.setTime(expirationDate);

        expirationDateMonth = expirationCal.get(Calendar.MONTH);
        expirationDateDay = expirationCal.get(Calendar.DATE);
        expirationDateYear = expirationCal.get(Calendar.YEAR);
        expirationDateHour = expirationCal.get(Calendar.HOUR);
        expirationDateMinute = expirationCal.get(Calendar.MINUTE);

        neverExpire = false;

        if (expirationCal.get(Calendar.AM_PM) == Calendar.PM) {
            expirationDateHour += 12;
        }
    }

    Date reviewDate = article.getReviewDate();

    int reviewDateMonth = 0;
    int reviewDateDay = 0;
    int reviewDateYear = 0;
    int reviewDateHour = 0;
    int reviewDateMinute = 0;
    boolean neverReview = true;

    if (reviewDate != null) {
        Calendar reviewCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        reviewCal.setTime(reviewDate);

        reviewDateMonth = reviewCal.get(Calendar.MONTH);
        reviewDateDay = reviewCal.get(Calendar.DATE);
        reviewDateYear = reviewCal.get(Calendar.YEAR);
        reviewDateHour = reviewCal.get(Calendar.HOUR);
        reviewDateMinute = reviewCal.get(Calendar.MINUTE);

        neverReview = false;

        if (reviewCal.get(Calendar.AM_PM) == Calendar.PM) {
            reviewDateHour += 12;
        }
    }

    Map<String, String> ddmStructureKeys = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(DDMStructure.class + ".ddmStructureKey");

    String parentDDMStructureKey = MapUtil.getString(ddmStructureKeys, article.getDDMStructureKey(),
            article.getDDMStructureKey());

    Map<String, Long> ddmStructureIds = (Map<String, Long>) portletDataContext
            .getNewPrimaryKeysMap(DDMStructure.class);

    long ddmStructureId = 0;

    if (article.getClassNameId() != 0) {
        ddmStructureId = ddmStructureIds.get(article.getClassPK());
    }

    Map<String, String> ddmTemplateKeys = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(DDMTemplate.class + ".ddmTemplateKey");

    String parentDDMTemplateKey = MapUtil.getString(ddmTemplateKeys, article.getDDMTemplateKey(),
            article.getDDMTemplateKey());

    File smallFile = null;

    try {
        Element articleElement = portletDataContext.getImportDataStagedModelElement(article);

        if (article.isSmallImage()) {
            String smallImagePath = articleElement.attributeValue("small-image-path");

            if (Validator.isNotNull(article.getSmallImageURL())) {
                String smallImageURL = _journalArticleExportImportContentProcessor
                        .replaceImportContentReferences(portletDataContext, article,
                                article.getSmallImageURL());

                article.setSmallImageURL(smallImageURL);
            } else if (Validator.isNotNull(smallImagePath)) {
                byte[] bytes = portletDataContext.getZipEntryAsByteArray(smallImagePath);

                if (bytes != null) {
                    smallFile = FileUtil.createTempFile(article.getSmallImageType());

                    FileUtil.write(smallFile, bytes);
                }
            }
        }

        JournalArticle latestArticle = _journalArticleLocalService
                .fetchLatestArticle(article.getResourcePrimKey());

        if ((latestArticle != null) && (latestArticle.getId() == article.getId())) {

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

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

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

                InputStream inputStream = null;

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

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

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

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

                        continue;
                    }

                    TempFileEntryUtil.addTempFileEntry(portletDataContext.getScopeGroupId(), userId,
                            JournalArticleStagedModelDataHandler.class.getName(), fileEntry.getFileName(),
                            inputStream, fileEntry.getMimeType());
                } finally {
                    StreamUtil.cleanUp(inputStream);
                }
            }
        }

        String articleURL = null;

        boolean addGroupPermissions = _journalCreationStrategy.addGroupPermissions(portletDataContext, article);
        boolean addGuestPermissions = _journalCreationStrategy.addGuestPermissions(portletDataContext, article);

        ServiceContext serviceContext = portletDataContext.createServiceContext(article);

        serviceContext.setAddGroupPermissions(addGroupPermissions);
        serviceContext.setAddGuestPermissions(addGuestPermissions);

        if ((expirationDate != null) && expirationDate.before(new Date())) {
            article.setStatus(WorkflowConstants.STATUS_EXPIRED);
        }

        if ((article.getStatus() != WorkflowConstants.STATUS_APPROVED)
                && (article.getStatus() != WorkflowConstants.STATUS_SCHEDULED)) {

            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
        }

        JournalArticle importedArticle = null;

        String articleResourceUuid = articleElement.attributeValue("article-resource-uuid");

        // Used when importing LARs with journal schemas under 1.1.0

        _setLegacyValues(article);

        if (portletDataContext.isDataStrategyMirror()) {
            serviceContext.setUuid(article.getUuid());
            serviceContext.setAttribute("articleResourceUuid", articleResourceUuid);
            serviceContext.setAttribute("urlTitle", article.getUrlTitle());

            boolean preloaded = GetterUtil.getBoolean(articleElement.attributeValue("preloaded"));

            JournalArticle existingArticle = fetchExistingArticle(articleResourceUuid,
                    portletDataContext.getScopeGroupId(), articleId, newArticleId, preloaded);

            JournalArticle existingArticleVersion = null;

            if (existingArticle != null) {
                existingArticleVersion = fetchExistingArticleVersion(article.getUuid(),
                        portletDataContext.getScopeGroupId(), existingArticle.getArticleId(),
                        article.getVersion());
            }

            if ((existingArticle != null) && (existingArticleVersion == null)) {

                autoArticleId = false;
                articleId = existingArticle.getArticleId();
            }

            if (existingArticleVersion == null) {
                importedArticle = _journalArticleLocalService.addArticle(userId,
                        portletDataContext.getScopeGroupId(), folderId, article.getClassNameId(),
                        ddmStructureId, articleId, autoArticleId, article.getVersion(), article.getTitleMap(),
                        article.getDescriptionMap(), article.getContent(), parentDDMStructureKey,
                        parentDDMTemplateKey, article.getLayoutUuid(), displayDateMonth, displayDateDay,
                        displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth,
                        expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute,
                        neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
                        reviewDateMinute, neverReview, article.isIndexable(), article.isSmallImage(),
                        article.getSmallImageURL(), smallFile, null, articleURL, serviceContext);
            } else {
                importedArticle = _journalArticleLocalService.updateArticle(userId,
                        existingArticle.getGroupId(), folderId, existingArticle.getArticleId(),
                        article.getVersion(), article.getTitleMap(), article.getDescriptionMap(),
                        article.getContent(), parentDDMStructureKey, parentDDMTemplateKey,
                        article.getLayoutUuid(), displayDateMonth, displayDateDay, displayDateYear,
                        displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay,
                        expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire,
                        reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute,
                        neverReview, article.isIndexable(), article.isSmallImage(), article.getSmallImageURL(),
                        smallFile, null, articleURL, serviceContext);

                String articleUuid = article.getUuid();
                String importedArticleUuid = importedArticle.getUuid();

                if (!articleUuid.equals(importedArticleUuid)) {
                    importedArticle.setUuid(articleUuid);

                    _journalArticleLocalService.updateJournalArticle(importedArticle);
                }
            }
        } else {
            importedArticle = _journalArticleLocalService.addArticle(userId,
                    portletDataContext.getScopeGroupId(), folderId, article.getClassNameId(), ddmStructureId,
                    articleId, autoArticleId, article.getVersion(), article.getTitleMap(),
                    article.getDescriptionMap(), article.getContent(), parentDDMStructureKey,
                    parentDDMTemplateKey, article.getLayoutUuid(), displayDateMonth, displayDateDay,
                    displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay,
                    expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth,
                    reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview,
                    article.isIndexable(), article.isSmallImage(), article.getSmallImageURL(), smallFile, null,
                    articleURL, serviceContext);
        }

        portletDataContext.importClassedModel(article, importedArticle);

        if (Validator.isNull(newArticleId)) {
            articleIds.put(article.getArticleId(), importedArticle.getArticleId());
        }

        Map<Long, Long> articlePrimaryKeys = (Map<Long, Long>) portletDataContext
                .getNewPrimaryKeysMap(JournalArticle.class + ".primaryKey");

        articlePrimaryKeys.put(article.getPrimaryKey(), importedArticle.getPrimaryKey());
    } finally {
        if (smallFile != null) {
            smallFile.delete();
        }
    }
}