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.web.extender.internal.webbundle.WebBundleProcessor.java

License:Open Source License

protected void processJarDependencies(File jarFile) throws IOException {
    DependencyVisitor dependencyVisitor = new DependencyVisitor();

    ZipFile zipFile = new ZipFile(jarFile);

    Enumeration<? extends ZipEntry> en = zipFile.entries();

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

        String name = zipEntry.getName();

        if (name.endsWith(".class")) {
            InputStream inputStream = zipFile.getInputStream(zipEntry);

            processClass(dependencyVisitor, name, inputStream, _referencedPackages);
        }/*from w w w . ja  v  a2s .c  o  m*/
    }

    Set<String> jarPackages = dependencyVisitor.getGlobals().keySet();

    for (String jarPackage : jarPackages) {
        _jarProvidedPackages.add(jarPackage.replaceAll(StringPool.SLASH, StringPool.PERIOD));
    }
}

From source file:com.liferay.web.extender.internal.webbundle.WebBundleProcessor.java

License:Open Source License

protected void processLiferayPortletXML(String webContextpath) throws IOException {

    File liferayPortletXMLFile = new File(_deployedAppFolder, "WEB-INF/liferay-portlet.xml");

    if (!liferayPortletXMLFile.exists()) {
        return;/*  w ww . j ava2s  .c  om*/
    }

    String content = FileUtil.read(liferayPortletXMLFile);

    Document liferayPortletXMLDoc = null;

    try {
        liferayPortletXMLDoc = SAXReaderUtil.read(content);
    } catch (DocumentException de) {
        throw new IOException(de);
    }

    Element rootEl = liferayPortletXMLDoc.getRootElement();

    List<Element> portletElements = rootEl.elements("portlet");

    for (Element portletElement : portletElements) {
        Element previousChild = portletElement.element("virtual-path");

        if (previousChild == null) {
            previousChild = portletElement.element("icon");
        }

        if (previousChild == null) {
            previousChild = portletElement.element("portlet-name");
        }

        Element strutsPathElement = portletElement.element("struts-path");

        if (strutsPathElement == null) {
            List<Node> children = portletElement.content();

            int pos = children.indexOf(previousChild);

            strutsPathElement = SAXReaderUtil.createElement("struts-path");

            strutsPathElement.setText("osgi".concat(webContextpath));

            children.add(pos + 1, strutsPathElement);
        } else {
            String strutsPath = strutsPathElement.getTextTrim();

            if (!strutsPath.startsWith(StringPool.SLASH)) {
                strutsPath = StringPool.SLASH.concat(strutsPath);
            }

            strutsPath = "osgi".concat(webContextpath).concat(strutsPath);

            strutsPathElement.setText(strutsPath);
        }
    }

    content = DDMXMLUtil.formatXML(liferayPortletXMLDoc);

    FileUtil.write(liferayPortletXMLFile, content);
}

From source file:com.liferay.web.extender.internal.webbundle.WebBundleProcessor.java

License:Open Source License

protected void processPortletXML(String webContextpath) throws IOException {
    File portletXMLFile = new File(_deployedAppFolder, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD);

    if (!portletXMLFile.exists()) {
        return;//  w w w .  j a v  a  2 s .  c  o  m
    }

    String content = FileUtil.read(portletXMLFile);

    Document document = null;

    try {
        document = SAXReaderUtil.read(content);
    } catch (DocumentException de) {
        throw new IOException(de);
    }

    Element rootElement = document.getRootElement();

    List<Element> portletElements = rootElement.elements("portlet");

    for (Element portletElement : portletElements) {
        String portletName = portletElement.elementText("portlet-name");

        String invokerPortletName = "osgi".concat(webContextpath).concat(StringPool.SLASH).concat(portletName);

        XPath xPath = SAXReaderUtil.createXPath(_INVOKER_PORTLET_NAME_XPATH);

        Element invokerPortletNameEl = (Element) xPath.selectSingleNode(portletElement);

        if (invokerPortletNameEl == null) {
            Element portletClassElement = portletElement.element("portlet-class");

            List<Node> children = portletElement.content();

            int pos = children.indexOf(portletClassElement);

            QName qName = rootElement.getQName();

            Element initParamElement = SAXReaderUtil
                    .createElement(SAXReaderUtil.createQName("init-param", qName.getNamespace()));

            initParamElement.addElement("name").setText("com.liferay.portal.invokerPortletName");
            initParamElement.addElement("value").setText(invokerPortletName);

            children.add(pos + 1, initParamElement);
        } else {
            Element valueElement = invokerPortletNameEl.element("value");

            invokerPortletName = valueElement.getTextTrim();

            if (!invokerPortletName.startsWith(StringPool.SLASH)) {
                invokerPortletName = StringPool.SLASH.concat(invokerPortletName);
            }

            invokerPortletName = "osgi".concat(webContextpath).concat(invokerPortletName);

            valueElement.setText(invokerPortletName);
        }
    }

    content = DDMXMLUtil.formatXML(document);

    FileUtil.write(portletXMLFile, content);
}

From source file:com.liferay.web.extender.servlet.BundleRequestDispatcher.java

License:Open Source License

public BundleRequestDispatcher(String servletMapping, boolean extensionMapping, String requestURI,
        Servlet servlet, FilterChain filterChain) {

    _servletMapping = servletMapping;/*from  ww  w .j a  v a 2s .  co  m*/
    _extensionMapping = extensionMapping;
    _servlet = servlet;
    _filterChain = filterChain;

    ServletContext servletContext = _servlet.getServletConfig().getServletContext();

    String contextPath = servletContext.getContextPath();

    _requestURI = StringUtil.replace(requestURI, StringPool.DOUBLE_SLASH, StringPool.SLASH);

    _contextPath = contextPath;
    _pathInfo = requestURI;
    _queryString = StringPool.BLANK;
    _servletPath = StringPool.BLANK;

    if (!_extensionMapping) {
        _servletPath = _servletMapping;
    }

    int pos = -1;

    if (!StringPool.BLANK.equals(_servletPath)) {
        _requestURI.indexOf(_servletPath);
    }

    if (pos != -1) {
        _pathInfo = _requestURI.substring(pos + _servletPath.length());
    }
}

From source file:com.liferay.web.extender.servlet.BundleServletContext.java

License:Open Source License

@Override
public String getContextPath() {
    if (_contextPath == null) {
        StringBundler sb = new StringBundler(4);

        String contextPath = super.getContextPath();

        if (!contextPath.equals(StringPool.SLASH)) {
            sb.append(contextPath);/*from  w w  w.ja v  a 2  s  .  c om*/
        }

        sb.append(PortalUtil.getPathMain());
        sb.append(OSGiServlet.SERVLET_MAPPING);
        sb.append(getServletContextName());

        _contextPath = sb.toString();
    }

    return _contextPath;
}

From source file:com.liferay.web.extender.servlet.BundleServletContext.java

License:Open Source License

@Override
public RequestDispatcher getRequestDispatcher(String path) {
    String alias = path;//w w  w . jav  a 2s  .  c om

    FilterChain filterChain = getFilterChain(alias);

    if (path.startsWith(OSGiServlet.SERVLET_MAPPING) && path.endsWith(OSGiServlet.INVOKER_PATH)) {

        return new BundleRequestDispatcher(path, false, path, _portletServlet, filterChain);
    }

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

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

    if (_servletsMap.containsKey(alias)) {
        return new BundleRequestDispatcher(alias, false, path, _servletsMap.get(alias), filterChain);
    }

    String extensionMapping = FileUtil.getExtension(alias).toLowerCase();

    if (Validator.isNotNull(extensionMapping)) {
        extensionMapping = _EXTENSION_PREFIX.concat(extensionMapping);
    }

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

    while (alias.length() != 0) {
        if (_servletsMap.containsKey(alias)) {
            return new BundleRequestDispatcher(alias, false, path, _servletsMap.get(alias), filterChain);
        } else if (_servletsMap.containsKey(alias.concat(extensionMapping))) {
            return new BundleRequestDispatcher(alias.concat(extensionMapping), true, path,
                    _servletsMap.get(alias.concat(extensionMapping)), filterChain);
        }

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

    if (_servletsMap.containsKey(StringPool.SLASH.concat(extensionMapping))) {

        return new BundleRequestDispatcher(StringPool.SLASH.concat(extensionMapping), true, path,
                _servletsMap.get(StringPool.SLASH.concat(extensionMapping)), filterChain);
    }

    if (_servletsMap.containsKey(StringPool.SLASH)) {
        return new BundleRequestDispatcher(StringPool.SLASH, false, path, _servletsMap.get(StringPool.SLASH),
                filterChain);
    }

    return null;
}

From source file:com.liferay.web.extender.servlet.BundleServletContext.java

License:Open Source License

protected void validate(String name) {
    if (name == null) {
        throw new IllegalArgumentException("Name cannot be null");
    }// w  w  w .j  av a2  s.  c  om

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

From source file:com.liferay.web.extender.servlet.BundleServletContext.java

License:Open Source License

protected void validate(String filterMapping, Filter filter, HttpContext httpContext)
        throws NamespaceException {

    if (filterMapping == null) {
        throw new IllegalArgumentException("FilterMapping cannot be null");
    }//  w w  w .j  a  v a 2 s.c o m

    if (filterMapping.endsWith(StringPool.SLASH) && !filterMapping.equals(StringPool.SLASH)) {

        throw new IllegalArgumentException("Invalid filterMapping " + filterMapping);
    }

    if (filter == null) {
        throw new IllegalArgumentException("Filter must not be null");
    }

    if (_filtersMap.containsValue(filter)) {
        throw new IllegalArgumentException("Filter is already registered");
    }

    if (httpContext == null) {
        throw new IllegalArgumentException("HttpContext cannot be null");
    }
}

From source file:com.liferay.web.extender.servlet.BundleServletContext.java

License:Open Source License

protected void validate(String alias, Servlet servlet, HttpContext httpContext) throws NamespaceException {

    if (Validator.isNull(alias)) {
        throw new IllegalArgumentException("Empty aliases are not allowed");
    }/*w w  w.j a v a  2  s.  co  m*/

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

        throw new IllegalArgumentException("Alias must start with / but must not end with it");
    }

    if (_servletsMap.containsKey(alias)) {
        throw new NamespaceException("Alias " + alias + " already exists");
    }

    if (servlet == null) {
        throw new IllegalArgumentException("Servlet must not be null");
    }

    if (_servletsMap.containsValue(servlet)) {
        throw new IllegalArgumentException("Servlet is already registered");
    }

    if (httpContext == null) {
        throw new IllegalArgumentException("HttpContext cannot be null");
    }
}

From source file:com.liferay.web.extender.servlet.OSGiServlet.java

License:Open Source License

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

    String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);

    String pathInfo = request.getPathInfo();

    if (pathInfo.startsWith(SERVLET_MAPPING)) {
        pathInfo = pathInfo.substring(5);
    }/*from   w w w  .j a va 2s.  c  o m*/

    String servletContextName = pathInfo;

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

    int pos = servletContextName.indexOf(StringPool.SLASH);

    if (pos != -1) {
        pathInfo = servletContextName.substring(pos, servletContextName.length());

        servletContextName = servletContextName.substring(0, pos);
    }

    ServletContext servletContext = ServletContextPool.get(servletContextName);

    if (servletContext == null) {
        PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND,
                new IllegalArgumentException("No application mapped to this path"), request, response);

        return;
    }

    service(request, response, servletContext, portletId, pathInfo);
}