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

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

Introduction

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

Prototype

String SLASH

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

Click Source Link

Usage

From source file:com.liferay.portlet.wiki.engines.HtmlEngine.java

License:Open Source License

protected Map<String, Boolean> _getOutgoingLinks(WikiPage page) throws Exception {

    if (Validator.isNull(page.getContent())) {
        return Collections.emptyMap();
    }/*  ww w.  j  a v a 2  s.c om*/

    Map<String, Boolean> links = new HashMap<String, Boolean>();

    Source source = new Source(page.getContent());

    List<StartTag> startTags = source.getAllStartTags("a");

    for (StartTag startTag : startTags) {
        String href = startTag.getAttributeValue("href");

        if (Validator.isNull(href)) {
            continue;
        }

        int pos = href.lastIndexOf(_friendlyURLMapping);

        String friendlyURL = href.substring(pos + _friendlyURLMapping.length());

        if (friendlyURL.endsWith(StringPool.SLASH)) {
            friendlyURL = friendlyURL.substring(0, friendlyURL.length() - 1);
        }

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

        if (!_router.urlToParameters(friendlyURL, routeParameters)) {
            if (_log.isWarnEnabled()) {
                _log.warn("No route could be found to match URL " + friendlyURL);
            }

            continue;
        }

        String title = routeParameters.get("title");
        String nodeName = routeParameters.get("nodeName");

        if (Validator.isNull(title) || Validator.isNull(nodeName)) {
            continue;
        }

        try {
            WikiNodeLocalServiceUtil.getNode(page.getGroupId(), nodeName);

            links.put(title.toLowerCase(), Boolean.TRUE);
        } catch (NoSuchNodeException nsne) {
            if (_log.isWarnEnabled()) {
                _log.warn(nsne.getMessage());
            }
        }
    }

    return links;
}

From source file:com.liferay.portlet.wiki.lar.WikiPortletDataHandlerImpl.java

License:Open Source License

protected static void exportPage(PortletDataContext portletDataContext, Element nodesElement,
        Element pagesElement, Element dlFileEntryTypesElement, Element dlFoldersElement,
        Element dlFileEntriesElement, Element dlFileRanksElement, WikiPage page, boolean checkDateRange)
        throws Exception {

    if (!portletDataContext.isWithinDateRange(page.getModifiedDate())) {
        return;//from   w w  w. j a va  2 s.com
    }

    String path = getPagePath(portletDataContext, page);

    // Clone this page to make sure changes to its content are never
    // persisted

    page = (WikiPage) page.clone();

    Element pageElement = (Element) pagesElement.selectSingleNode("//page[@path='".concat(path).concat("']"));

    if (portletDataContext.isPathNotProcessed(path)) {
        if (pageElement == null) {
            pageElement = pagesElement.addElement("page");
        }

        String content = JournalPortletDataHandlerImpl.exportReferencedContent(portletDataContext,
                dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement,
                pageElement, page.getContent());

        page.setContent(content);

        String imagePath = getPageImagePath(portletDataContext, page);

        pageElement.addAttribute("image-path", imagePath);

        if (portletDataContext.getBooleanParameter(_NAMESPACE, "attachments") && page.isHead()) {

            String[] attachmentsFiles = page.getAttachmentsFiles();

            for (int i = 0; i < attachmentsFiles.length; i++) {
                String attachment = attachmentsFiles[i];

                Element attachmentElement = pageElement.addElement("attachment");

                int pos = attachment.lastIndexOf(StringPool.SLASH);

                String name = attachment.substring(pos + 1);

                attachmentElement.addAttribute("name", name);

                String binPath = getPageAttachementBinPath(portletDataContext, page, i);

                attachmentElement.addAttribute("bin-path", binPath);

                byte[] bytes = DLStoreUtil.getFileAsBytes(portletDataContext.getCompanyId(),
                        CompanyConstants.SYSTEM, attachment);

                portletDataContext.addZipEntry(binPath, bytes);
            }

            page.setAttachmentsDir(page.getAttachmentsDir());
        }

        portletDataContext.addClassedModel(pageElement, path, page, _NAMESPACE);
    }

    exportNode(portletDataContext, nodesElement, page.getNodeId());
}

From source file:com.liferay.portlet.wiki.lar.WikiPortletDataHandlerImpl.java

License:Open Source License

protected static String getPageAttachementBinPath(PortletDataContext portletDataContext, WikiPage page,
        int count) {

    StringBundler sb = new StringBundler(6);

    sb.append(portletDataContext.getPortletPath(PortletKeys.WIKI));
    sb.append("/bin/");
    sb.append(page.getPageId());//from ww  w.ja v a  2  s .co  m
    sb.append(StringPool.SLASH);
    sb.append("attachement");
    sb.append(count);

    return sb.toString();
}

From source file:com.liferay.portlet.wiki.lar.WikiPortletDataHandlerImpl.java

License:Open Source License

protected static String getPageImagePath(PortletDataContext portletDataContext, WikiPage page)
        throws Exception {

    StringBundler sb = new StringBundler(6);

    sb.append(portletDataContext.getPortletPath(PortletKeys.WIKI));
    sb.append("/page/");
    sb.append(page.getUuid());/*from  w  ww .  j a  va  2s . c  o m*/
    sb.append(StringPool.SLASH);
    sb.append(page.getVersion());
    sb.append(StringPool.SLASH);

    return sb.toString();
}

From source file:com.liferay.portlet.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(WikiNode node, WikiPage page, ServiceContext serviceContext, boolean update)
        throws PortalException, SystemException {

    PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

    if (preferences == null) {
        long ownerId = node.getGroupId();
        int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
        long plid = PortletKeys.PREFS_PLID_SHARED;
        String portletId = PortletKeys.WIKI;
        String defaultPreferences = null;

        preferences = portletPreferencesLocalService.getPreferences(node.getCompanyId(), ownerId, ownerType,
                plid, portletId, defaultPreferences);
    }/* www  .j av a 2  s .com*/

    if (!update && WikiUtil.getEmailPageAddedEnabled(preferences)) {
    } else if (update && WikiUtil.getEmailPageUpdatedEnabled(preferences)) {
    } else {
        return;
    }

    String portalURL = serviceContext.getPortalURL();
    String layoutFullURL = serviceContext.getLayoutFullURL();

    WikiPage previousVersionPage = getPreviousVersionPage(page);

    String attachmentURLPrefix = portalURL + serviceContext.getPathMain() + "/wiki/get_page_attachment?p_l_id="
            + serviceContext.getPlid() + "&nodeId=" + page.getNodeId() + "&title="
            + HttpUtil.encodeURL(page.getTitle()) + "&fileName=";

    String pageDiffs = StringPool.BLANK;

    try {
        pageDiffs = WikiUtil.diffHtml(previousVersionPage, page, null, null, attachmentURLPrefix);
    } catch (Exception e) {
    }

    String pageContent = null;

    if (Validator.equals(page.getFormat(), "creole")) {
        pageContent = WikiUtil.convert(page, null, null, attachmentURLPrefix);
    } else {
        pageContent = page.getContent();
        pageContent = WikiUtil.processContent(pageContent);
    }

    String pageURL = StringPool.BLANK;
    String diffsURL = StringPool.BLANK;

    if (Validator.isNotNull(layoutFullURL)) {
        pageURL = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "wiki/" + node.getNodeId() + StringPool.SLASH
                + HttpUtil.encodeURL(page.getTitle());

        if (previousVersionPage != null) {
            StringBundler sb = new StringBundler(16);

            sb.append(layoutFullURL);
            sb.append("?p_p_id=");
            sb.append(PortletKeys.WIKI);
            sb.append("&p_p_state=");
            sb.append(WindowState.MAXIMIZED);
            sb.append("&struts_action=");
            sb.append(HttpUtil.encodeURL("/wiki/compare_versions"));
            sb.append("&nodeId=");
            sb.append(node.getNodeId());
            sb.append("&title=");
            sb.append(HttpUtil.encodeURL(page.getTitle()));
            sb.append("&sourceVersion=");
            sb.append(previousVersionPage.getVersion());
            sb.append("&targetVersion=");
            sb.append(page.getVersion());
            sb.append("&type=html");

            diffsURL = sb.toString();
        }
    }

    String fromName = WikiUtil.getEmailFromName(preferences, page.getCompanyId());
    String fromAddress = WikiUtil.getEmailFromAddress(preferences, page.getCompanyId());

    String subjectPrefix = null;
    String body = null;
    String signature = null;

    if (update) {
        subjectPrefix = WikiUtil.getEmailPageUpdatedSubjectPrefix(preferences);
        body = WikiUtil.getEmailPageUpdatedBody(preferences);
        signature = WikiUtil.getEmailPageUpdatedSignature(preferences);
    } else {
        subjectPrefix = WikiUtil.getEmailPageAddedSubjectPrefix(preferences);
        body = WikiUtil.getEmailPageAddedBody(preferences);
        signature = WikiUtil.getEmailPageAddedSignature(preferences);
    }

    String subject = page.getTitle();

    if (subject.indexOf(subjectPrefix) == -1) {
        subject = subjectPrefix + StringPool.SPACE + subject;
    }

    if (Validator.isNotNull(signature)) {
        body += "\n" + signature;
    }

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(page.getCompanyId());
    subscriptionSender.setContextAttributes("[$DIFFS_URL$]", diffsURL, "[$NODE_NAME$]", node.getName(),
            "[$PAGE_DATE_UPDATE$]", page.getModifiedDate(), "[$PAGE_ID$]", page.getPageId(), "[$PAGE_SUMMARY$]",
            page.getSummary(), "[$PAGE_TITLE$]", page.getTitle(), "[$PAGE_URL$]", pageURL);
    subscriptionSender.setContextAttribute("[$PAGE_CONTENT$]", pageContent, false);
    subscriptionSender.setContextAttribute("[$PAGE_DIFFS$]", replaceStyles(pageDiffs), false);
    subscriptionSender.setContextUserPrefix("PAGE");
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("wiki_page", page.getNodeId(), page.getPageId());
    subscriptionSender.setPortletId(PortletKeys.WIKI);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(node.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(page.getUserId());

    subscriptionSender.addPersistedSubscribers(WikiNode.class.getName(), node.getNodeId());
    subscriptionSender.addPersistedSubscribers(WikiPage.class.getName(), page.getResourcePrimKey());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.portlet.wiki.WikiFriendlyURLMapper.java

License:Open Source License

@Override
public String buildPath(LiferayPortletURL liferayPortletURL) {
    Map<String, String> routeParameters = new HashMap<String, String>();

    buildRouteParameters(liferayPortletURL, routeParameters);

    if (routeParameters.containsKey("title")) {
        String title = routeParameters.get("title");

        title = title.replaceAll(StringPool.SLASH, "%2F");

        routeParameters.put("title", title);
    }//  ww  w .  ja  va2 s . c o  m

    String friendlyURLPath = router.parametersToUrl(routeParameters);

    if (Validator.isNull(friendlyURLPath)) {
        return null;
    }

    addParametersIncludedInPath(liferayPortletURL, routeParameters);

    friendlyURLPath = StringPool.SLASH.concat(getMapping()).concat(friendlyURLPath);

    return friendlyURLPath;
}

From source file:com.liferay.resourcesimporter.messaging.HotDeployMessageListener.java

License:Open Source License

protected Properties getPluginPackageProperties(ServletContext servletContext) {

    Properties properties = new Properties();

    try {/* w  w  w .j  a v a  2  s . c o m*/
        String propertiesString = StringUtil
                .read(servletContext.getResourceAsStream("/WEB-INF/liferay-plugin-package.properties"));

        if (propertiesString != null) {
            String contextPath = servletContext.getRealPath(StringPool.SLASH);

            contextPath = StringUtil.replace(contextPath, StringPool.BACK_SLASH, StringPool.SLASH);

            propertiesString = propertiesString.replace("${context.path}", contextPath);

            PropertiesUtil.load(properties, propertiesString);
        }
    } catch (IOException e) {
        _log.error(e, e);
    }

    return properties;
}

From source file:com.liferay.resourcesimporter.servlet.ResourcesImporterServletContextListener.java

License:Open Source License

protected Properties getPluginPackageProperties(ServletContext servletContext) {

    Properties properties = new Properties();

    try {/*  w w w. ja  va2  s .c om*/
        String propertiesString = StringUtil
                .read(servletContext.getResourceAsStream("/WEB-INF/liferay-plugin-package.properties"));

        if (propertiesString == null) {
            return properties;
        }

        String contextPath = servletContext.getRealPath(StringPool.SLASH);

        contextPath = StringUtil.replace(contextPath, StringPool.BACK_SLASH, StringPool.SLASH);

        propertiesString = propertiesString.replace("${context.path}", contextPath);

        PropertiesUtil.load(properties, propertiesString);
    } catch (IOException ioe) {
        _log.error(ioe, ioe);
    }

    return properties;
}

From source file:com.liferay.resourcesimporter.util.FileSystemImporter.java

License:Open Source License

protected void addApplicationDisplayTemplate(String parentDirName, String dirName, long classNameId)
        throws Exception {

    File dir = new File(_resourcesDir, parentDirName + StringPool.SLASH + dirName);

    if (!dir.isDirectory() || !dir.canRead()) {
        return;/*from  w  w w  .  j  a  v  a2 s . c  o  m*/
    }

    File[] files = listFiles(dir);

    for (File file : files) {
        String script = StringUtil.read(getInputStream(file));

        if (Validator.isNull(script)) {
            continue;
        }

        addApplicationDisplayTemplate(script, file, classNameId);
    }
}

From source file:com.liferay.resourcesimporter.util.FileSystemImporter.java

License:Open Source License

protected void addDDLDisplayTemplates(String ddmStructureKey, String dirName, String fileName)
        throws Exception {

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(groupId,
            PortalUtil.getClassNameId(DDLRecordSet.class), ddmStructureKey);

    File dir = new File(_resourcesDir, dirName + StringPool.SLASH + fileName);

    if (!dir.isDirectory() || !dir.canRead()) {
        return;/* w  ww  .  jav a2s .co  m*/
    }

    File[] files = listFiles(dir);

    for (File file : files) {
        String language = getDDMTemplateLanguage(file.getName());

        String script = StringUtil.read(getInputStream(file));

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

        addDDMTemplate(groupId, ddmStructure.getStructureId(), file.getName(), language, script,
                DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, null);
    }
}