Example usage for com.liferay.portal.kernel.util HttpUtil getParameterMap

List of usage examples for com.liferay.portal.kernel.util HttpUtil getParameterMap

Introduction

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

Prototype

public static Map<String, String[]> getParameterMap(String queryString) 

Source Link

Usage

From source file:com.liferay.document.library.jaxrs.provider.PaginationContextProvider.java

License:Open Source License

@Override
public Pagination createContext(Message message) {
    String queryString = (String) message.getContextualProperty(Message.QUERY_STRING);

    Map<String, String[]> parameterMap = HttpUtil.getParameterMap(queryString);

    int itemsPerPage = MapUtil.getInteger(parameterMap, "per_page", DEFAULT_ITEMS_PER_PAGE);

    int page = MapUtil.getInteger(parameterMap, "page", DEFAULT_PAGE);

    return new DefaultPagination(page, itemsPerPage);
}

From source file:com.liferay.portlet.PortletBagFactory.java

License:Open Source License

protected String getContent(String fileName) throws Exception {
    String queryString = HttpUtil.getQueryString(fileName);

    if (Validator.isNull(queryString)) {
        return StringUtil.read(_classLoader, fileName);
    }// ww w  . jav  a2 s  .  c o  m

    int pos = fileName.indexOf(StringPool.QUESTION);

    String xml = StringUtil.read(_classLoader, fileName.substring(0, pos));

    Map<String, String[]> parameterMap = HttpUtil.getParameterMap(queryString);

    if (parameterMap == null) {
        return xml;
    }

    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        String name = entry.getKey();
        String[] values = entry.getValue();

        if (values.length == 0) {
            continue;
        }

        String value = values[0];

        xml = StringUtil.replace(xml, "@" + name + "@", value);
    }

    return xml;
}

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

License:Open Source License

@Override
protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws Exception {

    Set<String> modulePathsSet = new LinkedHashSet<String>();

    Enumeration<String> enu = request.getParameterNames();

    if (ServerDetector.isWebSphere()) {
        Map<String, String[]> parameterMap = HttpUtil.getParameterMap(request.getQueryString());

        enu = Collections.enumeration(parameterMap.keySet());
    }/*from  w w  w.j  a v  a 2s .  co m*/

    while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        if (_protectedParameters.contains(name)) {
            continue;
        }

        modulePathsSet.add(name);
    }

    if (modulePathsSet.size() == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Modules paths set is empty");

        return;
    }

    String[] modulePaths = modulePathsSet.toArray(new String[modulePathsSet.size()]);

    String firstModulePath = modulePaths[0];

    String extension = FileUtil.getExtension(firstModulePath);

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

    if (Validator.isNull(minifierType)) {
        minifierType = "js";

        if (StringUtil.equalsIgnoreCase(extension, _CSS_EXTENSION)) {
            minifierType = "css";
        }
    }

    if (!minifierType.equals("css") && !minifierType.equals("js")) {
        minifierType = "js";
    }

    String modulePathsString = null;

    byte[][] bytesArray = null;

    if (!PropsValues.COMBO_CHECK_TIMESTAMP) {
        modulePathsString = Arrays.toString(modulePaths);

        if (minifierType.equals("css") && DynamicCSSUtil.isRightToLeft(request)) {

            modulePathsString += ".rtl";
        }

        bytesArray = _bytesArrayPortalCache.get(modulePathsString);
    }

    if (bytesArray == null) {
        String rootPath = ServletContextUtil.getRootPath(_servletContext);

        bytesArray = new byte[modulePaths.length][];

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

            if (!validateModuleExtension(modulePath)) {
                response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);
                response.setStatus(HttpServletResponse.SC_NOT_FOUND);

                return;
            }

            byte[] bytes = new byte[0];

            if (Validator.isNotNull(modulePath)) {
                modulePath = StringUtil.replaceFirst(modulePath, PortalUtil.getPathContext(), StringPool.BLANK);

                URL url = getResourceURL(_servletContext, rootPath, modulePath);

                if (url == null) {
                    response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);
                    response.setStatus(HttpServletResponse.SC_NOT_FOUND);

                    return;
                }

                bytes = getResourceContent(request, response, url, modulePath, minifierType);
            }

            bytesArray[i] = bytes;
        }

        if ((modulePathsString != null) && !PropsValues.COMBO_CHECK_TIMESTAMP) {

            _bytesArrayPortalCache.put(modulePathsString, bytesArray);
        }
    }

    String contentType = ContentTypes.TEXT_JAVASCRIPT;

    if (StringUtil.equalsIgnoreCase(extension, _CSS_EXTENSION)) {
        contentType = ContentTypes.TEXT_CSS;
    }

    response.setContentType(contentType);

    ServletResponseUtil.write(response, bytesArray);
}

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

License:Open Source License

@Override
public InputStream getInputStream() throws IOException {
    URL url = getURL();//from  w  w  w  .ja v a 2 s.c  om

    String path = url.getPath();
    String queryString = url.getQuery();

    Map<String, String[]> parameterMap = HttpUtil.getParameterMap(queryString);

    if (!parameterMap.containsKey(OSGiConstants.WEB_CONTEXTPATH)) {
        throw new IllegalArgumentException(OSGiConstants.WEB_CONTEXTPATH + " parameter is required");
    }

    URL innerURL = new URL(path);

    File tempFile = FileUtil.createTempFile("war");

    StreamUtil.transfer(innerURL.openStream(), new FileOutputStream(tempFile));

    try {
        WebBundleProcessor webBundleProcessor = new WebBundleProcessor(tempFile, parameterMap);

        webBundleProcessor.process();

        return webBundleProcessor.getInputStream();
    } finally {
        tempFile.delete();
    }
}