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.httpservice.internal.servlet.BundleRequestDispatcher.java

License:Open Source License

public BundleRequestDispatcher(String servletMapping, boolean extensionMapping, String requestURI,
        BundleServletContext bundleServletContext, BundleFilterChain bundleFilterChain) {

    _servletMapping = servletMapping;/*  w ww.jav a2  s. c  o  m*/
    _extensionMapping = extensionMapping;
    _requestURI = StringUtil.replace(requestURI, StringPool.DOUBLE_SLASH, StringPool.SLASH);
    _bundleServletContext = bundleServletContext;
    _bundleFilterChain = bundleFilterChain;

    if (!_extensionMapping) {
        _servletPath = _servletMapping;
    } else {
        _servletPath = _requestURI;
    }

    if ((_servletPath != null) && _requestURI.startsWith(_servletPath)
            && (_requestURI.length() > _servletPath.length())) {

        _pathInfo = _requestURI.substring(_servletPath.length());

        try {
            _pathInfo = URLDecoder.decode(_pathInfo, StringPool.UTF8);
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException(uee);
        }
    }
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

public static String getServletContextName(Bundle bundle, boolean generate) {

    Dictionary<String, String> headers = bundle.getHeaders();

    String webContextPath = headers.get("Web-ContextPath");

    if (Validator.isNotNull(webContextPath)) {
        return webContextPath.substring(1);
    }/* w ww. ja  v  a2s.co  m*/

    String deploymentContext = null;

    try {
        String pluginPackageXml = HttpUtil
                .URLtoString(bundle.getResource("/WEB-INF/liferay-plugin-package.xml"));

        if (pluginPackageXml != null) {
            Document document = SAXReaderUtil.read(pluginPackageXml);

            Element rootElement = document.getRootElement();

            deploymentContext = GetterUtil.getString(rootElement.elementText("recommended-deployment-context"));
        } else {
            String pluginPackageProperties = HttpUtil
                    .URLtoString(bundle.getResource("/WEB-INF/liferay-plugin-package.properties"));

            if (pluginPackageProperties != null) {
                if (_log.isDebugEnabled()) {
                    _log.debug("Reading plugin package from " + "liferay-plugin-package.properties");
                }

                Properties properties = PropertiesUtil.load(pluginPackageProperties);

                deploymentContext = GetterUtil
                        .getString(properties.getProperty("recommended-deployment-context"), deploymentContext);
            }
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }
    }

    if (Validator.isNull(deploymentContext) && generate) {
        deploymentContext = PortalUtil.getJsSafePortletId(bundle.getSymbolicName());
    }

    if (Validator.isNotNull(deploymentContext) && deploymentContext.startsWith(StringPool.SLASH)) {

        deploymentContext = deploymentContext.substring(1);
    }

    return deploymentContext;
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

@Override
public String getContextPath() {
    if (_contextPath != null) {
        return _contextPath;
    }//from ww w  .  j  a  v a 2  s  . c  o  m

    StringBundler sb = new StringBundler(5);

    String contextPath = super.getContextPath();

    if (!contextPath.equals(StringPool.SLASH)) {
        sb.append(contextPath);
    }

    sb.append(PortalUtil.getPathContext());
    sb.append(Portal.PATH_MODULE);
    sb.append(StringPool.SLASH);
    sb.append(getServletContextName());

    _contextPath = sb.toString();

    return _contextPath;
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

@Override
public RequestDispatcher getRequestDispatcher(String path) {
    String portalContextPath = PortalUtil.getPathContext();

    String contextPath = getContextPath();

    if (Validator.isNotNull(portalContextPath) && contextPath.startsWith(portalContextPath)) {

        contextPath = contextPath.substring(portalContextPath.length());
    }/*  w  w w  . j  a va2  s.  co m*/

    if (path.startsWith(_PATH_MODULE_SLASH) && path.startsWith(contextPath)) {

        path = path.substring(contextPath.length());
    }

    if (Validator.isNull(path)) {
        path = StringPool.SLASH;
    }

    if (!isValidPath(path)) {
        return null;
    }

    BundleFilterChain bundleFilterChain = getFilterChain(path);

    if (_servletsByURLPatterns.containsKey(path)) {
        bundleFilterChain.setServlet(_servletsByURLPatterns.get(path));

        return new BundleRequestDispatcher(path, false, path, this, bundleFilterChain);
    }

    String extension = StringUtil.toLowerCase(FileUtil.getExtension(path));

    boolean extensionMapping = false;

    if (Validator.isNotNull(extension)) {
        extension = "*.".concat(extension);

        extensionMapping = true;
    }

    String alias = path.substring(0, path.lastIndexOf(StringPool.SLASH));

    while (alias.length() != 0) {
        if (_servletsByURLPatterns.containsKey(alias)) {
            bundleFilterChain.setServlet(_servletsByURLPatterns.get(alias));

            return new BundleRequestDispatcher(alias, false, path, this, bundleFilterChain);
        } else if (_servletsByURLPatterns.containsKey(alias.concat(extension))) {

            bundleFilterChain.setServlet(_servletsByURLPatterns.get(alias.concat(extension)));

            return new BundleRequestDispatcher(alias.concat(extension), true, path, this, bundleFilterChain);
        }

        alias = path.substring(0, alias.lastIndexOf(StringPool.SLASH));
    }

    if (_servletsByURLPatterns.containsKey(StringPool.SLASH.concat(extension))) {

        bundleFilterChain.setServlet(_servletsByURLPatterns.get(StringPool.SLASH.concat(extension)));

        return new BundleRequestDispatcher(StringPool.SLASH.concat(extension), extensionMapping, path, this,
                bundleFilterChain);
    }

    if (_servletsByURLPatterns.containsKey(StringPool.SLASH)) {
        bundleFilterChain.setServlet(_servletsByURLPatterns.get(StringPool.SLASH));

        return new BundleRequestDispatcher(StringPool.SLASH, false, path, this, bundleFilterChain);
    }

    return null;
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

@Override
public Set<String> getResourcePaths(String path) {
    Set<String> paths = new HashSet<String>();

    Enumeration<String> enumeration = _bundle.getEntryPaths(path);

    if (enumeration == null) {
        return Collections.emptySet();
    }//from   w w w  .j a v a  2 s . c  om

    while (enumeration.hasMoreElements()) {
        String entryPath = enumeration.nextElement();

        paths.add(StringPool.SLASH.concat(entryPath));
    }

    return paths;
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

public void open() throws DocumentException {
    Hashtable<String, Object> properties = new Hashtable<String, Object>();

    properties.put("bundle", _bundle);
    properties.put("bundle.id", _bundle.getBundleId());
    properties.put("bundle.symbolicName", _bundle.getSymbolicName());
    properties.put("bundle.version", _bundle.getVersion());
    properties.put("Web-ContextPath", StringPool.SLASH.concat(_servletContextName));

    BundleContext bundleContext = _bundle.getBundleContext();

    _serviceRegistration = bundleContext.registerService(BundleServletContext.class, this, properties);

    _httpServiceTracker = new HttpServiceTracker(bundleContext, _bundle);

    _httpServiceTracker.open();/* ww  w .ja v a2  s .c o m*/
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

public void registerResources(String alias, String name, HttpContext httpContext) throws NamespaceException {

    Map<String, String> initParameters = new Hashtable<String, String>();

    initParameters.put("alias", alias);

    if (name == null) {
        throw new IllegalArgumentException("Name is null");
    }//from  w  w w .j  ava 2  s . c  o  m

    if (name.endsWith(StringPool.SLASH) && !name.equals(StringPool.SLASH)) {
        throw new IllegalArgumentException("Invalid name " + name);
    }

    initParameters.put("name", name);

    Servlet resourceServlet = new ResourceServlet();

    try {
        registerServlet(name, alias, resourceServlet, initParameters, httpContext);

        AuthPublicPathRegistry.register(Portal.PATH_MODULE + StringPool.SLASH + _servletContextName + alias);
    } catch (ServletException se) {
        throw new IllegalArgumentException(se);
    }
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

public void unregisterServlet(String servletName) {
    Servlet servlet = _servletsByServletNames.remove(servletName);

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

    servlet.destroy();

    Set<Map.Entry<String, Servlet>> set = _servletsByURLPatterns.entrySet();

    Iterator<Map.Entry<String, Servlet>> iterator = set.iterator();

    while (iterator.hasNext()) {
        Map.Entry<String, Servlet> entry = iterator.next();

        Servlet curServlet = entry.getValue();

        if (curServlet != servlet) {
            continue;
        }

        AuthPublicPathRegistry
                .unregister(Portal.PATH_MODULE + StringPool.SLASH + _servletContextName + entry.getKey());

        iterator.remove();

        if (_log.isInfoEnabled()) {
            String urlPattern = entry.getKey();

            _log.info("Unmapped servlet " + servletName + " from " + urlPattern);
        }
    }

    if (_log.isInfoEnabled()) {
        _log.info("Unregistered servlet " + servletName);
    }
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

protected boolean isValidPath(String path) {
    if (!path.startsWith(StringPool.SLASH)) {
        path = StringPool.SLASH.concat(path);
    }//from ww  w .j a v a  2 s.  co  m

    for (String illegalPath : _ILLEGAL_PATHS) {
        if (path.startsWith(illegalPath)) {
            return false;
        }
    }

    return true;
}

From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java

License:Open Source License

protected void validateURLPattern(String urlPattern) {
    if (Validator.isNull(urlPattern)) {
        throw new IllegalArgumentException("An empty URL pattern is not allowed");
    }/*from   w w w . ja  v a  2 s.c  o  m*/

    if (!urlPattern.startsWith(StringPool.SLASH)
            || (urlPattern.endsWith(StringPool.SLASH) && !urlPattern.equals(StringPool.SLASH))) {

        throw new IllegalArgumentException("URL patterns must start with / but cannot end with it");
    }
}