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

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

Introduction

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

Prototype

public String elementText(String name);

Source Link

Usage

From source file:com.liferay.journal.web.util.JournalRSSUtil.java

License:Open Source License

protected String processContent(JournalFeed feed, JournalArticle article, String languageId,
        ThemeDisplay themeDisplay, SyndEntry syndEntry, SyndContent syndContent) throws Exception {

    String content = article.getDescription(languageId);

    String contentField = feed.getContentField();

    if (contentField.equals(JournalFeedConstants.RENDERED_WEB_CONTENT)) {
        String ddmRendererTemplateKey = article.getDDMTemplateKey();

        if (Validator.isNotNull(feed.getDDMRendererTemplateKey())) {
            ddmRendererTemplateKey = feed.getDDMRendererTemplateKey();
        }/*w  w  w .  ja va 2 s .  c  om*/

        JournalArticleDisplay articleDisplay = _journalContent.getDisplay(feed.getGroupId(),
                article.getArticleId(), ddmRendererTemplateKey, null, languageId, 1, new PortletRequestModel() {

                    @Override
                    public String toXML() {
                        return _XML_REQUUEST;
                    }

                }, themeDisplay);

        if (articleDisplay != null) {
            content = articleDisplay.getContent();
        }
    } else if (!contentField.equals(JournalFeedConstants.WEB_CONTENT_DESCRIPTION)) {

        Document document = SAXReaderUtil.read(article.getContentByLocale(languageId));

        contentField = HtmlUtil.escapeXPathAttribute(contentField);

        XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-element[@name=" + contentField + "]");

        List<Node> results = xPathSelector.selectNodes(document);

        if (results.isEmpty()) {
            return content;
        }

        Element element = (Element) results.get(0);

        String elType = element.attributeValue("type");

        if (elType.equals("document_library")) {
            String url = element.elementText("dynamic-content");

            url = processURL(feed, url, themeDisplay, syndEntry);
        } else if (elType.equals("image") || elType.equals("image_gallery")) {
            String url = element.elementText("dynamic-content");

            url = processURL(feed, url, themeDisplay, syndEntry);

            content = content + "<br /><br /><img alt='' src='" + themeDisplay.getURLPortal() + url + "' />";
        } else if (elType.equals("text_box")) {
            syndContent.setType("text");

            content = element.elementText("dynamic-content");
        } else {
            content = element.elementText("dynamic-content");
        }
    }

    return content;
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected void importLayoutIconImage(PortletDataContext portletDataContext, Layout importedLayout,
        Element layoutElement) throws Exception {

    String iconImagePath = layoutElement.elementText("icon-image-path");

    byte[] iconBytes = portletDataContext.getZipEntryAsByteArray(iconImagePath);

    if (ArrayUtil.isNotEmpty(iconBytes)) {
        if (importedLayout.getIconImageId() == 0) {
            long iconImageId = _counterLocalService.increment();

            importedLayout.setIconImageId(iconImageId);
        }// w  w w.  j a  v  a2 s  .  c o  m

        _imageLocalService.updateImage(importedLayout.getIconImageId(), iconBytes);
    }
}

From source file:com.liferay.localization.servlet.LocalizationServletContextListener.java

License:Open Source License

protected void importSQL() throws Exception {
    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    InputStream inputStream = classLoader.getResourceAsStream("/resources/data/sql.xml");

    String xml = new String(FileUtil.getBytes(inputStream));

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    List<Element> batchElements = rootElement.elements("batch");

    for (Element batchElement : batchElements) {
        String testSQL = batchElement.elementText("test-sql");

        int count = getCount(testSQL);

        if (count > 0) {
            continue;
        }// w w w  .  j  av  a2 s .  c  o m

        String[] importSQLs = StringUtil.split(batchElement.elementText("import-sql"), StringPool.SEMICOLON);

        runSQL(importSQLs);
    }
}

From source file:com.liferay.notifications.hook.events.StartupAction.java

License:Open Source License

protected void addUserNotificationDefinitions(String xml, String portletId) throws Exception {

    Class<?> clazz = getClass();

    xml = JavaFieldsParser.parse(clazz.getClassLoader(), xml);

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    for (Element definitionElement : rootElement.elements("definition")) {
        String modelName = definitionElement.elementText("model-name");

        long classNameId = 0;

        if (Validator.isNotNull(modelName)) {
            classNameId = PortalUtil.getClassNameId(modelName);
        }//from ww w  .j  a v a2s. c om

        int notificationType = GetterUtil.getInteger(definitionElement.elementText("notification-type"));

        String description = GetterUtil.getString(definitionElement.elementText("description"));

        UserNotificationDefinition userNotificationDefinition = new UserNotificationDefinition(portletId,
                classNameId, notificationType, description);

        for (Element deliveryTypeElement : definitionElement.elements("delivery-type")) {

            String name = deliveryTypeElement.elementText("name");
            int type = GetterUtil.getInteger(deliveryTypeElement.elementText("type"));
            boolean defaultValue = GetterUtil.getBoolean(deliveryTypeElement.elementText("default"));
            boolean modifiable = GetterUtil.getBoolean(deliveryTypeElement.elementText("modifiable"));

            userNotificationDefinition.addUserNotificationDeliveryType(
                    new UserNotificationDeliveryType(name, type, defaultValue, modifiable));
        }

        UserNotificationManagerUtil.addUserNotificationDefinition(portletId, userNotificationDefinition);
    }
}

From source file:com.liferay.portlet.amazonrankings.util.AmazonRankingsWebCacheItem.java

License:Open Source License

protected AmazonRankings doConvert(String key) throws Exception {
    Map<String, String> parameters = new HashMap<String, String>();

    parameters.put("AWSAccessKeyId", AmazonRankingsUtil.getAmazonAccessKeyId());
    parameters.put("IdType", "ASIN");
    parameters.put("ItemId", _isbn);
    parameters.put("Operation", "ItemLookup");
    parameters.put("ResponseGroup", "Images,ItemAttributes,Offers,SalesRank");
    parameters.put("Service", "AWSECommerceService");
    parameters.put("Timestamp", AmazonRankingsUtil.getTimestamp());

    String urlWithSignature = AmazonSignedRequestsUtil.generateUrlWithSignature(parameters);

    String xml = HttpUtil.URLtoString(urlWithSignature);

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    if (rootElement == null) {
        return null;
    }/*from w ww.  ja va 2s  .c  om*/

    if (hasErrorMessage(rootElement)) {
        return null;
    }

    Element itemsElement = rootElement.element("Items");

    if (itemsElement == null) {
        return null;
    }

    Element requestElement = itemsElement.element("Request");

    if (requestElement != null) {
        Element errorsElement = requestElement.element("Errors");

        if (hasErrorMessage(errorsElement)) {
            return null;
        }
    }

    Element itemElement = itemsElement.element("Item");

    if (itemElement == null) {
        return null;
    }

    Element itemAttributesElement = itemElement.element("ItemAttributes");

    if (itemAttributesElement == null) {
        return null;
    }

    String productName = itemAttributesElement.elementText("Title");
    String catalog = StringPool.BLANK;
    String[] authors = getAuthors(itemAttributesElement);
    String releaseDateAsString = itemAttributesElement.elementText("PublicationDate");
    Date releaseDate = getReleaseDate(releaseDateAsString);
    String manufacturer = itemAttributesElement.elementText("Manufacturer");
    String smallImageURL = getImageURL(itemElement, "SmallImage");
    String mediumImageURL = getImageURL(itemElement, "MediumImage");
    String largeImageURL = getImageURL(itemElement, "LargeImage");
    double listPrice = getPrice(itemAttributesElement.element("ListPrice"));

    double ourPrice = 0;

    Element offerListingElement = getOfferListing(itemElement);

    if (offerListingElement != null) {
        ourPrice = getPrice(offerListingElement.element("Price"));
    }

    double usedPrice = 0;
    double collectiblePrice = 0;
    double thirdPartyNewPrice = 0;

    Element offerSummaryElement = itemElement.element("OfferSummary");

    if (offerSummaryElement != null) {
        usedPrice = getPrice(offerSummaryElement.element("LowestUsedPrice"));

        collectiblePrice = getPrice(offerSummaryElement.element("LowestCollectiblePrice"));

        thirdPartyNewPrice = getPrice(offerSummaryElement.element("LowestNewPrice"));
    }

    int salesRank = GetterUtil.getInteger(itemElement.elementText("SalesRank"));
    String media = StringPool.BLANK;
    String availability = getAvailability(offerListingElement);

    return new AmazonRankings(_isbn, productName, catalog, authors, releaseDate, releaseDateAsString,
            manufacturer, smallImageURL, mediumImageURL, largeImageURL, listPrice, ourPrice, usedPrice,
            collectiblePrice, thirdPartyNewPrice, salesRank, media, availability);
}

From source file:com.liferay.portlet.amazonrankings.util.AmazonRankingsWebCacheItem.java

License:Open Source License

protected String getAvailability(Element offerListingElement) {
    if (offerListingElement == null) {
        return null;
    }/*from  w  ww. java 2  s.  c  o  m*/

    Element availabilityElement = offerListingElement.element("Availability");

    return availabilityElement.elementText("Availability");
}

From source file:com.liferay.portlet.amazonrankings.util.AmazonRankingsWebCacheItem.java

License:Open Source License

protected String getImageURL(Element itemElement, String name) {
    String imageURL = null;/*from   w  ww .  ja v  a  2 s . c om*/

    Element imageElement = itemElement.element(name);

    if (imageElement != null) {
        imageURL = imageElement.elementText("URL");
    }

    return imageURL;
}

From source file:com.liferay.portlet.amazonrankings.util.AmazonRankingsWebCacheItem.java

License:Open Source License

protected double getPrice(Element priceElement) {
    if (priceElement == null) {
        return 0;
    }//from  w ww. j a va2s  .  c  o m

    return GetterUtil.getInteger(priceElement.elementText("Amount")) * 0.01;
}

From source file:com.liferay.portlet.assetpublisher.util.AssetPublisherUtil.java

License:Open Source License

public static void removeAndStoreSelection(List<String> assetEntryUuids, PortletPreferences portletPreferences)
        throws Exception {

    if (assetEntryUuids.size() == 0) {
        return;//from  w ww .  ja va2s  . co  m
    }

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls);

    Iterator<String> itr = assetEntryXmlsList.iterator();

    while (itr.hasNext()) {
        String assetEntryXml = itr.next();

        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        if (assetEntryUuids.contains(assetEntryUuid)) {
            itr.remove();
        }
    }

    portletPreferences.setValues("assetEntryXml",
            assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()]));

    portletPreferences.store();
}

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

License:Open Source License

protected static void importEntry(PortletDataContext context, User defaultUser, Map<String, Long> userMap,
        DateFormat dateFormat, Element entryEl) throws PortalException, SystemException {

    String creator = entryEl.elementText(SAXReaderUtil.createQName("creator", _NS_DC));

    Long userId = userMap.get(creator);

    if (userId == null) {
        userId = context.getUserId(null);
    }/*from   w  w  w  .jav  a 2 s . c om*/

    String title = entryEl.elementTextTrim("title");

    if (Validator.isNull(title)) {
        title = entryEl.elementTextTrim(SAXReaderUtil.createQName("post_name", _NS_WP));
    }

    String content = entryEl.elementText(SAXReaderUtil.createQName("encoded", _NS_CONTENT));

    content = content.replaceAll("\\n", "\n<br />");

    // LPS-1425

    if (Validator.isNull(content)) {
        content = "<br />";
    }

    String dateText = entryEl.elementTextTrim(SAXReaderUtil.createQName("post_date_gmt", _NS_WP));

    Date postDate = new Date();

    try {
        postDate = dateFormat.parse(dateText);
    } catch (ParseException pe) {
        _log.warn("Parse " + dateText, pe);
    }

    Calendar cal = Calendar.getInstance();

    cal.setTime(postDate);

    int displayDateMonth = cal.get(Calendar.MONTH);
    int displayDateDay = cal.get(Calendar.DAY_OF_MONTH);
    int displayDateYear = cal.get(Calendar.YEAR);
    int displayDateHour = cal.get(Calendar.HOUR_OF_DAY);
    int displayDateMinute = cal.get(Calendar.MINUTE);

    String pingStatusText = entryEl.elementTextTrim(SAXReaderUtil.createQName("ping_status", _NS_WP));

    boolean allowPingbacks = pingStatusText.equalsIgnoreCase("open");
    boolean allowTrackbacks = allowPingbacks;

    String statusText = entryEl.elementTextTrim(SAXReaderUtil.createQName("status", _NS_WP));

    int workflowAction = WorkflowConstants.ACTION_PUBLISH;

    if (statusText.equalsIgnoreCase("draft")) {
        workflowAction = WorkflowConstants.ACTION_SAVE_DRAFT;
    }

    String[] assetTagNames = null;

    String categoryText = entryEl.elementTextTrim("category");

    if (Validator.isNotNull(categoryText)) {
        assetTagNames = new String[] { categoryText };
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setAssetTagNames(assetTagNames);
    serviceContext.setScopeGroupId(context.getGroupId());
    serviceContext.setWorkflowAction(workflowAction);

    BlogsEntry entry = null;

    try {
        entry = BlogsEntryLocalServiceUtil.addEntry(userId, title, StringPool.BLANK, content, displayDateMonth,
                displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks,
                allowTrackbacks, null, false, null, null, null, serviceContext);
    } catch (Exception e) {
        _log.error("Add entry " + title, e);

        return;
    }

    MBMessageDisplay messageDisplay = MBMessageLocalServiceUtil.getDiscussionMessageDisplay(userId,
            context.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(),
            WorkflowConstants.STATUS_APPROVED);

    Map<Long, Long> messageIdMap = new HashMap<Long, Long>();

    List<Node> commentNodes = entryEl.selectNodes("wp:comment", "wp:comment_parent/text()");

    for (Node commentNode : commentNodes) {
        Element commentEl = (Element) commentNode;

        importComment(context, defaultUser, messageDisplay, messageIdMap, entry, commentEl);
    }
}