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.resourcesimporter.util.ResourceImporter.java

License:Open Source License

@Override
protected void addJournalArticles(String ddmStructureKey, String ddmTemplateKey, String dirName)
        throws Exception {

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcesDir.concat(dirName));

    if (resourcePaths == null) {
        return;//from   w  w  w .  java2  s  . com
    }

    for (String resourcePath : resourcePaths) {
        if (resourcePath.endsWith(StringPool.SLASH)) {
            continue;
        }

        String name = FileUtil.getShortFileName(resourcePath);

        URL url = servletContext.getResource(resourcePath);

        URLConnection urlConnection = url.openConnection();

        addJournalArticles(ddmStructureKey, ddmTemplateKey, name, urlConnection.getInputStream());
    }
}

From source file:com.liferay.rtl.servlet.filters.ComboServletFilter.java

License:Open Source License

protected URL getResourceURL(ServletContext servletContext, String rootPath, String path) throws Exception {

    URL url = servletContext.getResource(path);

    if (url == null) {
        return null;
    }/* w ww . j a v  a 2  s  .  c o m*/

    String filePath = ServletContextUtil.getResourcePath(url);

    int pos = filePath.indexOf(rootPath.concat(StringPool.SLASH).concat(_JAVASCRIPT_DIR));

    if (pos == 0) {
        return url;
    }

    return null;
}

From source file:com.liferay.rtl.servlet.filters.dynamiccss.DynamicCSSFilter.java

License:Open Source License

protected Object getDynamicContent(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws Exception {

    String requestURI = request.getRequestURI();

    String requestPath = requestURI;

    String contextPath = request.getContextPath();

    if (!contextPath.equals(StringPool.SLASH)) {
        requestPath = requestPath.substring(contextPath.length());
    }/*  www  .j  av a2s  .  c  om*/

    URL resourceURL = _servletContext.getResource(requestPath);

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

    URLConnection urlConnection = resourceURL.openConnection();

    String cacheCommonFileName = getCacheFileName(request);

    File cacheContentTypeFile = new File(_tempDir, cacheCommonFileName + "_E_CONTENT_TYPE");
    File cacheDataFile = new File(_tempDir, cacheCommonFileName + "_E_DATA");

    if (cacheDataFile.exists() && (cacheDataFile.lastModified() >= urlConnection.getLastModified())) {

        if (cacheContentTypeFile.exists()) {
            String contentType = FileUtil.read(cacheContentTypeFile);

            response.setContentType(contentType);
        }

        return cacheDataFile;
    }

    String dynamicContent = null;

    String content = null;

    try {
        if (requestPath.endsWith(_CSS_EXTENSION)) {
            if (_log.isInfoEnabled()) {
                _log.info("Parsing SASS on CSS " + requestPath);
            }

            content = StringUtil.read(urlConnection.getInputStream());

            dynamicContent = DynamicCSSUtil.parseSass(_servletContext, request, requestPath, content);

            response.setContentType(ContentTypes.TEXT_CSS);

            FileUtil.write(cacheContentTypeFile, ContentTypes.TEXT_CSS);
        } else if (requestPath.endsWith(_JSP_EXTENSION)) {
            if (_log.isInfoEnabled()) {
                _log.info("Parsing SASS on JSP or servlet " + requestPath);
            }

            BufferCacheServletResponse bufferCacheServletResponse = new BufferCacheServletResponse(response);

            processFilter(DynamicCSSFilter.class, request, bufferCacheServletResponse, filterChain);

            bufferCacheServletResponse.finishResponse();

            content = bufferCacheServletResponse.getString();

            dynamicContent = DynamicCSSUtil.parseSass(_servletContext, request, requestPath, content);

            FileUtil.write(cacheContentTypeFile, bufferCacheServletResponse.getContentType());
        } else {
            return null;
        }
    } catch (Exception e) {
        _log.error("Unable to parse SASS on CSS " + requestPath, e);

        if (_log.isDebugEnabled()) {
            _log.debug(content);
        }

        response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);
    }

    if (dynamicContent != null) {
        FileUtil.write(cacheDataFile, dynamicContent);
    } else {
        dynamicContent = content;
    }

    return dynamicContent;
}

From source file:com.liferay.rtl.servlet.filters.dynamiccss.DynamicCSSFilter.java

License:Open Source License

protected String sterilizeQueryString(String queryString) {
    return StringUtil.replace(queryString, new String[] { StringPool.SLASH, StringPool.BACK_SLASH },
            new String[] { StringPool.UNDERLINE, StringPool.UNDERLINE });
}

From source file:com.liferay.rtl.servlet.filters.dynamiccss.DynamicCSSUtil.java

License:Open Source License

public static String parseSass(ServletContext servletContext, HttpServletRequest request, String resourcePath,
        String content) throws Exception {

    if (!DynamicCSSFilter.ENABLED) {
        return content;
    }/*from w w  w .  j  a  va2s  .c  o  m*/

    // Request will only be null when called by StripFilterTest

    if (request == null) {
        return content;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Theme theme = null;

    if (themeDisplay == null) {
        theme = _getTheme(request);

        if (theme == null) {
            String currentURL = PortalUtil.getCurrentURL(request);

            if (_log.isWarnEnabled()) {
                _log.warn("No theme found for " + currentURL);
            }

            if (isRightToLeft(request) && !RTLCSSUtil.isExcludedPath(resourcePath)) {

                content = RTLCSSUtil.getRtlCss(content);
            }

            return content;
        }
    }

    String parsedContent = null;

    boolean themeCssFastLoad = _isThemeCssFastLoad(request, themeDisplay);

    URLConnection resourceURLConnection = null;

    URL resourceURL = servletContext.getResource(resourcePath);

    if (resourceURL != null) {
        resourceURLConnection = resourceURL.openConnection();
    }

    URLConnection cacheResourceURLConnection = null;

    URL cacheResourceURL = _getCacheResourceURL(servletContext, request, resourcePath);

    if (cacheResourceURL != null) {
        cacheResourceURLConnection = cacheResourceURL.openConnection();
    }

    if (themeCssFastLoad && (cacheResourceURLConnection != null) && (resourceURLConnection != null)
            && (cacheResourceURLConnection.getLastModified() == resourceURLConnection.getLastModified())) {

        parsedContent = StringUtil.read(cacheResourceURLConnection.getInputStream());
    } else {
        content = _parseStaticTokens(content);

        String queryString = request.getQueryString();

        if (!themeCssFastLoad && Validator.isNotNull(queryString)) {
            content = propagateQueryString(content, queryString);
        }

        parsedContent = _parseSass(servletContext, request, themeDisplay, theme, resourcePath, content);

        if (isRightToLeft(request) && !RTLCSSUtil.isExcludedPath(resourcePath)) {

            parsedContent = RTLCSSUtil.getRtlCss(parsedContent);

            // Append custom CSS for RTL

            URL rtlCustomResourceURL = _getRtlCustomResourceURL(servletContext, resourcePath);

            if (rtlCustomResourceURL != null) {
                URLConnection rtlCustomResourceURLConnection = rtlCustomResourceURL.openConnection();

                String rtlCustomContent = StringUtil.read(rtlCustomResourceURLConnection.getInputStream());

                String parsedRtlCustomContent = _parseSass(servletContext, request, themeDisplay, theme,
                        resourcePath, rtlCustomContent);

                parsedContent += parsedRtlCustomContent;
            }
        }
    }

    if (Validator.isNull(parsedContent)) {
        return content;
    }

    String portalContextPath = PortalUtil.getPathContext();

    String baseURL = portalContextPath;

    String contextPath = ContextPathUtil.getContextPath(servletContext);

    if (!contextPath.equals(portalContextPath)) {
        baseURL = StringPool.SLASH.concat(GetterUtil.getString(servletContext.getServletContextName()));
    }

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

    parsedContent = StringUtil.replace(parsedContent,
            new String[] { "@base_url@", "@portal_ctx@", "@theme_image_path@" },
            new String[] { baseURL, portalContextPath, _getThemeImagesPath(request, themeDisplay, theme) });

    return parsedContent;
}

From source file:com.liferay.rtl.servlet.filters.dynamiccss.DynamicCSSUtil.java

License:Open Source License

private static String _getCacheFileName(String fileName, String suffix) {
    String cacheFileName = StringUtil.replace(fileName, StringPool.BACK_SLASH, StringPool.SLASH);

    int x = cacheFileName.lastIndexOf(StringPool.SLASH);
    int y = cacheFileName.lastIndexOf(StringPool.PERIOD);

    return cacheFileName.substring(0, x + 1) + ".sass-cache/" + cacheFileName.substring(x + 1, y) + suffix
            + cacheFileName.substring(y);
}

From source file:com.liferay.rtl.tools.RtlCssBuilder.java

License:Open Source License

private String _normalizeFileName(String dirName, String fileName) {
    return StringUtil.replace(dirName + StringPool.SLASH + fileName,
            new String[] { StringPool.BACK_SLASH, StringPool.DOUBLE_SLASH },
            new String[] { StringPool.SLASH, StringPool.SLASH });
}

From source file:com.liferay.scriptingexecutor.messaging.ScriptingExecutorHotDeployMessageListener.java

License:Open Source License

protected void executeScripts(ServletContext servletContext, String language,
        String requiredDeploymentContexts) {

    InputStream inputStream = null;

    Set<String> resourcePaths = servletContext.getResourcePaths(_SCRIPTS_DIR);

    Set<String> servletContextNames = SetUtil.fromArray(StringUtil.split(requiredDeploymentContexts));

    servletContextNames.add(servletContext.getServletContextName());
    servletContextNames.add(ClassLoaderPool.getContextName(PortalClassLoaderUtil.getClassLoader()));

    for (String resourcePath : resourcePaths) {
        if (resourcePath.endsWith(StringPool.SLASH)) {
            if (_log.isInfoEnabled()) {
                _log.info("Skipping directory " + resourcePath);
            }//  w w w  .  j a v  a 2  s  .  c o m

            continue;
        }

        try {
            inputStream = servletContext.getResourceAsStream(resourcePath);

            ScriptingUtil.exec(null, new HashMap<String, Object>(), language, StringUtil.read(inputStream),
                    servletContextNames.toArray(new String[servletContextNames.size()]));
        } catch (Exception e) {
            _log.error("Unable to execute script " + resourcePath, e);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
}

From source file:com.liferay.servermanager.servlet.ServerManagerServlet.java

License:Open Source License

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {

    if (!isValidUser(request)) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        return;/*from  ww  w .  jav a  2s. c o  m*/
    }

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put(JSONKeys.ERROR, StringPool.BLANK);
    responseJSONObject.put(JSONKeys.OUTPUT, StringPool.BLANK);
    responseJSONObject.put(JSONKeys.STATUS, 0);

    try {
        Queue<String> arguments = new LinkedList<String>();

        String path = request.getPathInfo();

        path = StringUtil.toLowerCase(path);

        if (path.startsWith(StringPool.SLASH)) {
            path = path.substring(1);
        }

        String[] pathParts = StringUtil.split(path, StringPool.SLASH);

        for (String pathPart : pathParts) {
            arguments.add(pathPart);
        }

        execute(request, responseJSONObject, arguments);
    } catch (Exception e) {
        responseJSONObject.put(JSONKeys.ERROR, StackTraceUtil.getStackTrace(e));
        responseJSONObject.put(JSONKeys.STATUS, 1);
    }

    String format = ParamUtil.getString(request, "format");

    if (format.equals("raw")) {
        response.setContentType(ContentTypes.TEXT_PLAIN);

        String outputStream = responseJSONObject.getString(JSONKeys.OUTPUT);

        ServletResponseUtil.write(response, outputStream);
    } else {
        response.setContentType(ContentTypes.APPLICATION_JSON);

        ServletResponseUtil.write(response, responseJSONObject.toString());
    }
}

From source file:com.liferay.servletjspcompiler.compiler.internal.JspResourceResolver.java

License:Open Source License

protected Collection<String> handleSystemBundle(BundleWiring bundleWiring, final String path,
        final String fileRegex, int options) {

    String key = path + StringPool.SLASH + fileRegex;

    Collection<String> resources = _jspResourceCache.getResources(bundleWiring, key);

    if (resources != null) {
        return resources;
    }/*from  w  w  w .ja va2s. c o  m*/

    resources = new ArrayList<String>();

    Map<String, List<URL>> extraPackageMap = ModuleFrameworkUtilAdapter.getExtraPackageMap();

    String packageName = path.replace('/', '.');

    List<URL> urls = extraPackageMap.get(packageName);

    if ((urls == null) || !urls.isEmpty()) {
        _jspResourceCache.putResources(bundleWiring, key, resources);

        return resources;
    }

    String matcherRegex = fileRegex.replace(StringPool.STAR, "[^/]*");

    matcherRegex = matcherRegex.replace(".", "\\.");

    matcherRegex = path + "/" + matcherRegex;

    for (URL url : urls) {
        try {
            JarURLConnection jarUrlConnection = (JarURLConnection) url.openConnection();

            JarFile jarFile = jarUrlConnection.getJarFile();

            Enumeration<? extends ZipEntry> enumeration = jarFile.entries();

            while (enumeration.hasMoreElements()) {
                ZipEntry zipEntry = enumeration.nextElement();

                String name = zipEntry.getName();

                if (name.matches(matcherRegex)) {
                    resources.add(name);
                }
            }
        } catch (Exception e) {
            _log.error(e, e);
        }
    }

    _jspResourceCache.putResources(bundleWiring, key, resources);

    return resources;
}