Example usage for com.liferay.portal.kernel.util StringPool SPACE

List of usage examples for com.liferay.portal.kernel.util StringPool SPACE

Introduction

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

Prototype

String SPACE

To view the source code for com.liferay.portal.kernel.util StringPool SPACE.

Click Source Link

Usage

From source file:com.liferay.knowledgebase.hook.upgrade.v1_1_0.UpgradeKBArticle.java

License:Open Source License

protected void updateColumn(String tableName, String columnName, String dataType, String data)
        throws Exception {

    if (tableHasColumn(tableName, columnName)) {
        return;/*from w  ww.jav  a 2  s  .  c  om*/
    }

    String dataTypeUpperCase = StringUtil.toUpperCase(dataType);

    StringBundler sb = new StringBundler(6);

    sb.append("alter table ");
    sb.append(tableName);
    sb.append(" add ");
    sb.append(columnName);
    sb.append(StringPool.SPACE);
    sb.append(dataTypeUpperCase);

    String sql = sb.toString();

    if (dataTypeUpperCase.equals("DATE") || dataType.equals("STRING")) {
        sql = sql.concat(" null");
    }

    runSQL(sql);

    sb.setIndex(0);

    sb.append("update ");
    sb.append(tableName);
    sb.append(" set ");
    sb.append(columnName);
    sb.append(" = ");
    sb.append(data);

    runSQL(sb.toString());
}

From source file:com.liferay.knowledgebase.service.impl.KBStructureLocalServiceImpl.java

License:Open Source License

protected DynamicQuery buildDynamicQuery(long groupId, String title, String content, Date startDate,
        Date endDate, boolean andOperator) {

    Junction junction = null;// w ww  .  j  av  a 2  s.co m

    if (andOperator) {
        junction = RestrictionsFactoryUtil.conjunction();
    } else {
        junction = RestrictionsFactoryUtil.disjunction();
    }

    Map<String, String> terms = new HashMap<String, String>();

    if (Validator.isNotNull(title)) {
        terms.put("title", title);
    }

    if (Validator.isNotNull(content)) {
        String escapedContent = StringEscapeUtils.escapeXml(content);

        terms.put("content", content + StringPool.SPACE + escapedContent);
    }

    for (Map.Entry<String, String> entry : terms.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

        for (String keyword : KnowledgeBaseUtil.parseKeywords(value)) {
            Criterion criterion = RestrictionsFactoryUtil.ilike(key,
                    StringUtil.quote(keyword, StringPool.PERCENT));

            disjunction.add(criterion);
        }

        junction.add(disjunction);
    }

    if ((endDate != null) && (startDate != null)) {
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

        String[] propertyNames = { "createDate", "modifiedDate" };

        for (String propertyName : propertyNames) {
            Property property = PropertyFactoryUtil.forName(propertyName);

            Conjunction conjunction = RestrictionsFactoryUtil.conjunction();

            conjunction.add(property.gt(startDate));
            conjunction.add(property.lt(endDate));

            disjunction.add(conjunction);
        }

        junction.add(disjunction);
    }

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(KBStructure.class,
            getClass().getClassLoader());

    if (groupId > 0) {
        Property property = PropertyFactoryUtil.forName("groupId");

        dynamicQuery.add(property.eq(groupId));
    }

    return dynamicQuery.add(junction);
}

From source file:com.liferay.mail.mailbox.IMAPMailbox.java

License:Open Source License

protected long getFolderId(String type) {
    Locale[] locales = LanguageUtil.getAvailableLocales();

    List<String> words = new ArrayList<String>();

    for (Locale locale : locales) {
        String translation = StringUtil.toLowerCase(LanguageUtil.get(locale, type));

        words.addAll(ListUtil.toList(translation.split(StringPool.SPACE)));
    }/*from ww w.  j a va2 s .co m*/

    List<Folder> folders = FolderLocalServiceUtil.getFolders(account.getAccountId());

    for (String word : words) {
        for (Folder folder : folders) {
            String folderName = StringUtil.toLowerCase(folder.getDisplayName());

            if (folderName.contains(word)) {
                return folder.getFolderId();
            }
        }
    }

    return 0;
}

From source file:com.liferay.mail.util.ShellHook.java

License:Open Source License

protected void execute(String cmdLine[]) {
    for (int i = 0; i < cmdLine.length; i++) {
        if (cmdLine[i].trim().length() == 0) {
            cmdLine[i] = StringPool.UNDERLINE;
        }/*from w  ww.  ja v  a  2  s. c  o m*/
    }

    try {
        Runtime rt = Runtime.getRuntime();

        Process p = rt.exec(cmdLine);

        ProcessUtil.close(p);

        int exitValue = p.exitValue();

        if (exitValue != 0) {
            StringBundler sb = new StringBundler(cmdLine.length * 2);

            for (int i = 0; i < cmdLine.length; i++) {
                sb.append(cmdLine[i]);
                sb.append(StringPool.SPACE);
            }

            throw new IllegalArgumentException(sb.toString());
        }
    } catch (Exception e) {
        _log.error(e);
    }
}

From source file:com.liferay.message.boards.parser.bbcode.internal.HtmlBBCodeTranslatorImpl.java

License:Open Source License

protected void handleImage(StringBundler sb, Stack<String> tags, List<BBCodeItem> bbCodeItems,
        IntegerWrapper marker) {//  www . j a  va 2s .c  o  m

    sb.append("<img src=\"");

    int pos = marker.getValue();

    String src = extractData(bbCodeItems, marker, "img", BBCodeParser.TYPE_DATA, true);

    Matcher matcher = _imagePattern.matcher(src);

    if (matcher.matches()) {
        sb.append(HtmlUtil.escapeAttribute(src));
    }

    sb.append("\"");

    BBCodeItem bbCodeItem = bbCodeItems.get(pos);

    String attributes = bbCodeItem.getAttribute();

    if (Validator.isNotNull(attributes)) {
        sb.append(StringPool.SPACE);

        handleImageAttributes(sb, attributes);
    }

    sb.append(" />");

    tags.push(StringPool.BLANK);
}

From source file:com.liferay.message.boards.parser.bbcode.internal.HtmlBBCodeTranslatorImpl.java

License:Open Source License

protected void handleImageAttributes(StringBundler sb, String attributes) {
    Matcher matcher = _attributesPattern.matcher(attributes);

    while (matcher.find()) {
        String attributeName = matcher.group(1);

        if (Validator.isNotNull(attributeName)
                && _imageAttributes.contains(StringUtil.toLowerCase(attributeName))) {

            String attributeValue = matcher.group(2);

            sb.append(StringPool.SPACE);
            sb.append(attributeName);/*from ww w . ja va 2s. c  om*/
            sb.append(StringPool.EQUAL);
            sb.append(StringPool.QUOTE);
            sb.append(HtmlUtil.escapeAttribute(attributeValue));
            sb.append(StringPool.QUOTE);
        }
    }
}

From source file:com.liferay.newsletter.service.impl.NewsletterCampaignLocalServiceImpl.java

License:Open Source License

protected void sendEmail(long contactId, NewsletterCampaign campaign) throws PortalException, SystemException {

    String passwordString = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD);
    String userString = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER);
    String host = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST);
    String port = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT);

    if (passwordString.isEmpty()) {
        passwordString = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST);
    }/*  www. j  a va2  s .  c o  m*/

    if (userString.isEmpty()) {
        userString = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST);
    }

    if (host.isEmpty()) {
        host = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST);
    }

    if (port.isEmpty()) {
        port = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST);
    }

    Properties properties = new Properties();

    properties.put(NewsletterConstants.MAIL_TRANSPORT_PROTOCOL, "smtp");
    properties.put(NewsletterConstants.MAIL_SMTP_HOST, host);
    properties.put(NewsletterConstants.MAIL_SMTP_SOCKET_FACTORY_PORT, port);
    properties.put(NewsletterConstants.MAIL_SMTP_PORT, port);
    properties.put(NewsletterConstants.MAIL_SMTP_SOCKET_FACTORY_FALLBACK, "false");
    properties.put(NewsletterConstants.MAIL_SMTP_STARTTLS_ENABLE, "true");
    properties.put(NewsletterConstants.MAIL_SMTP_AUTH, "true");

    MailAuthenticator mailAuthenticator = new MailAuthenticator(userString, passwordString);

    Session session = Session.getInstance(properties, mailAuthenticator);

    String senderEmail = campaign.getSenderEmail();
    String emailSubject = campaign.getEmailSubject();

    NewsletterContent content = campaign.getContent();

    String senderName = campaign.getSenderName();

    StringBundler sb = new StringBundler(10);

    sb.append(StringPool.QUOTE);
    sb.append(senderName);
    sb.append(StringPool.QUOTE);
    sb.append(StringPool.SPACE);
    sb.append(StringPool.LESS_THAN);
    sb.append(senderEmail);
    sb.append(StringPool.GREATER_THAN);

    String from = sb.toString();

    NewsletterContact contact = newsletterContactLocalService.getContact(contactId);

    try {
        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress(from));
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(contact.getEmail()));
        message.setSentDate(new Date());
        message.setSubject(emailSubject);
        message.setContent(content.getContent(), "text/html");

        Transport.send(message);
    } catch (Exception e) {
        throw new SendEmailException(e.getMessage());
    }
}

From source file:com.liferay.polls.internal.search.PollsQuestionIndexer.java

License:Open Source License

protected String getDescriptionField(PollsQuestion pollsQuestion) {
    String[] availableLanguageIds = pollsQuestion.getAvailableLanguageIds();

    StringBundler sb = new StringBundler();

    for (String languageId : availableLanguageIds) {
        sb.append(pollsQuestion.getDescription(languageId));
        sb.append(StringPool.SPACE);
    }/*from   ww w .  ja  v a  2s. com*/

    return sb.toString();
}

From source file:com.liferay.polls.internal.search.PollsQuestionIndexer.java

License:Open Source License

protected String getTitleField(PollsQuestion pollsQuestion) {
    String[] availableLanguageIds = pollsQuestion.getAvailableLanguageIds();

    StringBundler sb = new StringBundler();

    for (String languageId : availableLanguageIds) {
        sb.append(pollsQuestion.getTitle(languageId));
        sb.append(StringPool.SPACE);
    }//from ww w  .j a v a 2 s.  co  m

    return sb.toString();
}

From source file:com.liferay.portlet.asset.service.impl.AssetTagLocalServiceImpl.java

License:Open Source License

protected void validate(String name) throws PortalException {
    if (!AssetUtil.isValidWord(name)) {
        throw new AssetTagException(StringUtil.merge(AssetUtil.INVALID_CHARACTERS, StringPool.SPACE),
                AssetTagException.INVALID_CHARACTER);
    }//from  w  ww.  ja v a  2  s  . c om
}