Example usage for com.liferay.portal.kernel.util StringUtil shorten

List of usage examples for com.liferay.portal.kernel.util StringUtil shorten

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringUtil shorten.

Prototype

public static String shorten(String s, String suffix) 

Source Link

Document

Returns a string representing the original string appended with the specified suffix and then shortened to 20 characters.

Usage

From source file:br.com.prodevelopment.lapidarios.loja.service.impl.LojaLocalServiceImpl.java

License:Open Source License

public void updateAsset(long userId, Loja loja, long[] assetCategoryIds, String[] assetTagNames,
        long[] assetLinkEntryIds) throws PortalException, SystemException {

    boolean visible = true;

    String summary = HtmlUtil.extractText(StringUtil.shorten(loja.getNomeFantasia(), 500));

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, loja.getGroupId(), loja.getCreateDate(),
            loja.getModifiedDate(), Loja.class.getName(), loja.getLojaId(), loja.getUuid(), 0, assetCategoryIds,
            assetTagNames, visible, null, null, null, ContentTypes.TEXT_HTML, loja.getNomeFantasia(),
            loja.getNomeFantasia(), summary, null, null, 0, 0, null, false);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);
}

From source file:ca.efendi.datafeeds.service.impl.CJProductLocalServiceImpl.java

License:Open Source License

@Override
@Indexable(type = IndexableType.REINDEX)
public CJProduct refresh(final FtpSubscription subscription, final CJProduct newCJProduct)
        throws PortalException {

    final Date now = new Date();

    CJProduct cjProduct;//w w w. j ava  2 s. c o  m

    try {
        cjProduct = cjProductPersistence.findByPROGRAM_CATALOG_SKU(newCJProduct.getProgramName(),
                newCJProduct.getCatalogName(), newCJProduct.getSku());
    } catch (final NoSuchCJProductException e) {

        final long productId = counterLocalService.increment(CJProduct.class.getName());

        cjProduct = cjProductPersistence.create(productId);

        resourceLocalService.addModelResources(subscription.getCompanyId(), subscription.getGroupId(),
                subscription.getUserId(), CJProduct.class.getName(), productId, new String[] { "VIEW" },
                new String[] { "VIEW" });

        cjProduct.setUuid(PortalUUIDUtil.generate());
        cjProduct.setGroupId(subscription.getGroupId());
        cjProduct.setCompanyId(subscription.getCompanyId());
        cjProduct.setUserId(subscription.getUserId());
        cjProduct.setUserName(subscription.getUserName());

        cjProduct.setProgramName(newCJProduct.getProgramName());
        cjProduct.setCatalogName(newCJProduct.getCatalogName());
        cjProduct.setSku(newCJProduct.getSku());

        // TODO: is it already implemented by Liferay?
        //cjProduct.setCreateDate(now);

    }

    cjProduct.setProgramUrl(newCJProduct.getProgramUrl());
    cjProduct.setLastUpdated(newCJProduct.getLastUpdated());
    cjProduct.setName(newCJProduct.getName());
    cjProduct.setKeywords(newCJProduct.getKeywords());
    cjProduct.setDescription(newCJProduct.getDescription());
    cjProduct.setManufacturer(newCJProduct.getManufacturer());
    cjProduct.setManufacturerId(newCJProduct.getManufacturerId());
    cjProduct.setCurrency(newCJProduct.getCurrency());
    cjProduct.setPrice(newCJProduct.getPrice());
    cjProduct.setBuyUrl(newCJProduct.getBuyUrl());
    cjProduct.setImpressionUrl(newCJProduct.getImpressionUrl());
    cjProduct.setImageUrl(newCJProduct.getImageUrl());
    cjProduct.setInStock(newCJProduct.getInStock());

    // TODO: is it already implemented by Liferay?
    //cjProduct.setModifiedDate(now);

    //cjProduct.setCompanyId(COMPANY_ID);
    //cjProduct.setGroupId(GROUP_ID);
    //cjProduct.setUserId(USER_ID);

    Date current = new Date();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, 1);
    Date expire = cal.getTime();

    /* assetEntryLocalService.updateEntry(
        cjProduct.getUserId(), cjProduct.getGroupId(), CJProduct.class.getName(),
        cjProduct.getProductId(),
        new long[]{}, //serviceContext.getAssetCategoryIds(),
        new String[]{"shopping"}); //serviceContext.getAssetTagNames());
            
     assetEntryLocalService.updateEntry(
        CJProduct.class.getName(),
        cjProduct.getProductId(),
        current,
        expire,
        true,
        true);
    */

    String summary = HtmlUtil.extractText(StringUtil.shorten(cjProduct.getDescription(), 500));

    long[] assetCategoryIds = null;
    String[] assetTagNames = null;
    boolean visible = true;
    Double priority = null;

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(cjProduct.getUserId(), cjProduct.getGroupId(),
            cjProduct.getCreateDate(), cjProduct.getModifiedDate(), CJProduct.class.getName(),
            cjProduct.getProductId(), cjProduct.getUuid(), 0, assetCategoryIds, assetTagNames, true, visible,
            current, expire, current, expire, ContentTypes.TEXT_HTML, cjProduct.getName(),
            cjProduct.getDescription(), summary, cjProduct.getBuyUrl(), null, 0, 0, priority);

    long[] assetLinkEntryIds = null;

    assetLinkLocalService.updateLinks(cjProduct.getUserId(), assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);

    Indexer<CJProduct> indexer = IndexerRegistryUtil.nullSafeGetIndexer(CJProduct.class);

    indexer.reindex(cjProduct);

    return cjProductPersistence.update(cjProduct);

}

From source file:ca.efendi.datafeeds.web.asset.CJProductAssetRenderer.java

License:Apache License

@Override
public String getSummary(final PortletRequest portletRequest, final PortletResponse portletResponse) {

    int abstractLength = AssetUtil.ASSET_ENTRY_ABSTRACT_LENGTH;

    if (portletRequest != null) {
        abstractLength = GetterUtil.getInteger(portletRequest.getAttribute(WebKeys.ASSET_ENTRY_ABSTRACT_LENGTH),
                AssetUtil.ASSET_ENTRY_ABSTRACT_LENGTH);
    }/*from w  ww  .j  a v  a  2 s  .  c  o  m*/

    String summary = _entry.getDescription();

    if (Validator.isNull(summary)) {
        summary = HtmlUtil.stripHtml(StringUtil.shorten(_entry.getName(), abstractLength));
    }

    return summary;
}

From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java

License:Open Source License

@Override
public void updateAsset(long userId, Contact contact, long[] assetCategoryIds, String[] assetTagNames,
        long[] assetLinkEntryIds, Double priority) throws PortalException {

    // TODO/*w w w.ja  va2  s. c om*/
    boolean visible = true;
    // boolean visible = false;
    // if (contact.isApproved()) {
    // visible = true;
    // publishDate = contact.getCreateDate();
    // }

    Date publishDate = contact.getCreateDate();

    // TODO
    String description = "TODO: contact description";
    String summary = HtmlUtil.extractText(StringUtil.shorten(contact.getCard(), 500));

    String className = Contact.class.getName();
    long classPK = contact.getContactId();

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, contact.getGroupId(),
            contact.getCreateDate(), contact.getModifiedDate(), className, classPK, contact.getUuid(), 0,
            assetCategoryIds, assetTagNames, true, visible, null, null, publishDate, null,
            ContentTypes.TEXT_HTML,
            // contact.getName(),
            "TODO: contact.getName()", description, summary, null, null, 0, 0, priority);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);

    // assetEntryLocalService.updateVisible(Contact.class.getName(),
    // classPK, visible);

}

From source file:ch.inofix.referencemanager.service.impl.BibliographyLocalServiceImpl.java

License:Open Source License

public void updateAsset(long userId, Bibliography bibliography, long[] assetCategoryIds, String[] assetTagNames,
        long[] assetLinkEntryIds, Double priority) throws PortalException {

    boolean visible = false;

    Date publishDate = null;//  w  ww .j a v a 2 s. co  m

    if (bibliography.isApproved()) {
        visible = true;
        publishDate = bibliography.getCreateDate();
    }

    String summary = HtmlUtil.extractText(StringUtil.shorten(bibliography.getTitle(), 500));

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, bibliography.getGroupId(),
            bibliography.getCreateDate(), bibliography.getModifiedDate(), Bibliography.class.getName(),
            bibliography.getBibliographyId(), bibliography.getUuid(), 0, assetCategoryIds, assetTagNames, true,
            visible, null, null, publishDate, null, ContentTypes.TEXT_HTML, bibliography.getTitle(),
            bibliography.getTitle(), summary, null, null, 0, 0, priority);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);
}

From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java

License:Open Source License

public void updateAsset(long userId, Reference reference, long[] assetCategoryIds, String[] assetTagNames,
        long[] assetLinkEntryIds, Double priority) throws PortalException {

    boolean visible = false;

    Date publishDate = null;/* w  w  w. java2s . co m*/

    if (reference.isApproved()) {
        visible = true;

        publishDate = reference.getCreateDate();
    }

    String summary = HtmlUtil.extractText(StringUtil.shorten(reference.getCitation(), 500));

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, reference.getGroupId(),
            reference.getCreateDate(), reference.getModifiedDate(), Reference.class.getName(),
            reference.getReferenceId(), reference.getUuid(), 0, assetCategoryIds, assetTagNames, true, visible,
            null, null, publishDate, null, ContentTypes.TEXT_HTML, reference.getTitle(),
            reference.getCitation(), summary, null, null, 0, 0, priority);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);
}

From source file:ch.inofix.timetracker.service.impl.TaskRecordLocalServiceImpl.java

License:Open Source License

@Override
public void updateAsset(long userId, TaskRecord taskRecord, long[] assetCategoryIds, String[] assetTagNames,
        long[] assetLinkEntryIds, Double priority) throws PortalException {

    // TODO/*from  w  ww. j  a va2 s  .c o  m*/
    boolean visible = true;
    // boolean visible = false;
    // if (taskRecord.isApproved()) {
    // visible = true;
    // publishDate = taskRecord.getCreateDate();
    // }

    Date publishDate = null;

    String summary = HtmlUtil.extractText(StringUtil.shorten(taskRecord.getWorkPackage(), 500));

    String className = TaskRecord.class.getName();
    long classPK = taskRecord.getTaskRecordId();

    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, taskRecord.getGroupId(),
            taskRecord.getCreateDate(), taskRecord.getModifiedDate(), className, classPK, taskRecord.getUuid(),
            0, assetCategoryIds, assetTagNames, true, visible, null, null, publishDate, null,
            ContentTypes.TEXT_HTML, taskRecord.getWorkPackage(), taskRecord.getWorkPackage(), summary, null,
            null, 0, 0, priority);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
            AssetLinkConstants.TYPE_RELATED);
}

From source file:com.htmsd.slayer.service.impl.ShoppingItemServiceImpl.java

License:Open Source License

private void getItemJSONArray(long groupId, JSONArray jsonArray, List<ShoppingItem> shoppingItems,
        long currencyId) {

    double currencyRate = CommonUtil.getCurrentRate(currencyId);

    for (ShoppingItem shoppingItem : shoppingItems) {
        long imageId = shoppingItem.getSmallImage();
        double total = (currencyRate == 0) ? shoppingItem.getSellingPrice()
                : shoppingItem.getSellingPrice() / currencyRate;
        double MRP = (currencyRate == 0) ? shoppingItem.getMRP() : shoppingItem.getMRP() / currencyRate;
        String shortDescription = (Validator.isNotNull(shoppingItem.getShortDescription())
                ? shoppingItem.getShortDescription()
                : StringPool.BLANK);/*from w w w.  j a v a2s.  c  o m*/

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        jsonObject.put(HConstants.ITEM_ID, shoppingItem.getItemId());
        jsonObject.put(HConstants.NAME, shoppingItem.getName());
        jsonObject.put(HConstants.DESCRIPTION, StringUtil.shorten(shoppingItem.getDescription(), 20));
        jsonObject.put(HConstants.TOTAL_PRICE, total);
        jsonObject.put("MRP", MRP);
        jsonObject.put(HConstants.IMAGE, CommonUtil.getThumbnailpath(imageId, groupId, false));
        jsonObject.put("shortDescription", StringUtil.shorten(shortDescription, 20));

        if (DateUtil.getDaysBetween(shoppingItem.getModifiedDate(), Calendar.getInstance().getTime()) >= 2) {
            jsonObject.put(HConstants.IS_NEW_ITEM, false);
        } else {
            jsonObject.put(HConstants.IS_NEW_ITEM, true);
        }

        jsonArray.put(jsonObject);
    }
}

From source file:com.inkwell.internet.slogan.search.SloganIndexer.java

License:Open Source License

public Summary getSummary(Document document, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;//w ww . j  av a  2s. c  o  m

    if (Validator.isNull(snippet)) {
        content = document.get(Field.DESCRIPTION);

        if (Validator.isNull(content)) {
            content = StringUtil.shorten(document.get(Field.CONTENT), 200);
        }
    }

    String resourcePrimKey = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("jspPage", "/admin/view_slogan.jsp");
    portletURL.setParameter("resourcePrimKey", resourcePrimKey);

    return new Summary(title, content, portletURL);

}

From source file:com.liferay.blogs.internal.util.PingbackMethodImpl.java

License:Open Source License

protected String getExcerpt() throws IOException {
    String html = HttpUtil.URLtoString(_sourceURI);

    Source source = new Source(html);

    source.fullSequentialParse();//from w w  w . j  av a  2 s . co  m

    List<Element> elements = source.getAllElements("a");

    for (Element element : elements) {
        String href = GetterUtil.getString(element.getAttributeValue("href"));

        if (href.equals(_targetURI)) {
            element = element.getParentElement();

            TextExtractor textExtractor = new TextExtractor(element);

            String body = textExtractor.toString();

            if (body.length() < PropsValues.BLOGS_LINKBACK_EXCERPT_LENGTH) {
                element = element.getParentElement();

                if (element != null) {
                    textExtractor = new TextExtractor(element);

                    body = textExtractor.toString();
                }
            }

            return StringUtil.shorten(body, PropsValues.BLOGS_LINKBACK_EXCERPT_LENGTH);
        }
    }

    return StringPool.BLANK;
}