Example usage for com.liferay.portal.kernel.portlet Route addImplicitParameter

List of usage examples for com.liferay.portal.kernel.portlet Route addImplicitParameter

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.portlet Route addImplicitParameter.

Prototype

public void addImplicitParameter(String name, String value);

Source Link

Document

Adds an implicit parameter to this route.

Usage

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

License:Open Source License

protected Router newFriendlyURLRouter(Portlet portlet) throws Exception {
    if (Validator.isNull(portlet.getFriendlyURLRoutes())) {
        return null;
    }//  w ww  .j a  v a 2s .  c o  m

    Router router = new RouterImpl();

    String xml = getContent(portlet.getFriendlyURLRoutes());

    Document document = SAXReaderUtil.read(xml, true);

    Element rootElement = document.getRootElement();

    for (Element routeElement : rootElement.elements("route")) {
        String pattern = routeElement.elementText("pattern");

        Route route = router.addRoute(pattern);

        for (Element generatedParameterElement : routeElement.elements("generated-parameter")) {

            String name = generatedParameterElement.attributeValue("name");
            String value = generatedParameterElement.getText();

            route.addGeneratedParameter(name, value);
        }

        for (Element ignoredParameterElement : routeElement.elements("ignored-parameter")) {

            String name = ignoredParameterElement.attributeValue("name");

            route.addIgnoredParameter(name);
        }

        for (Element implicitParameterElement : routeElement.elements("implicit-parameter")) {

            String name = implicitParameterElement.attributeValue("name");
            String value = implicitParameterElement.getText();

            route.addImplicitParameter(name, value);
        }

        for (Element overriddenParameterElement : routeElement.elements("overridden-parameter")) {

            String name = overriddenParameterElement.attributeValue("name");
            String value = overriddenParameterElement.getText();

            route.addOverriddenParameter(name, value);
        }
    }

    return router;
}

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

License:Open Source License

@Override
public void setUp() throws Exception {
    _routerImpl = new RouterImpl();

    Route route = _routerImpl.addRoute("instance/{instanceId}/{topLink}");

    route.addGeneratedParameter("p_p_id", "15_INSTANCE_{instanceId}");

    route = _routerImpl.addRoute("GET/{controller}");

    route.addImplicitParameter("action", "index");
    route.addImplicitParameter("format", "html");
    route.addImplicitParameter("method", "GET");

    route = _routerImpl.addRoute("GET/{controller}.{format}");

    route.addImplicitParameter("action", "index");
    route.addImplicitParameter("method", "GET");

    route = _routerImpl.addRoute("POST/{controller}");

    route.addImplicitParameter("action", "create");
    route.addImplicitParameter("format", "html");
    route.addImplicitParameter("method", "POST");

    route = _routerImpl.addRoute("POST/{controller}.{format}");

    route.addImplicitParameter("action", "create");
    route.addImplicitParameter("method", "POST");

    route = _routerImpl.addRoute("GET/{controller}/{id:\\d+}");

    route.addImplicitParameter("action", "view");
    route.addImplicitParameter("format", "html");
    route.addImplicitParameter("method", "GET");

    route = _routerImpl.addRoute("GET/{controller}/{id:\\d+}.{format}");

    route.addImplicitParameter("action", "view");
    route.addImplicitParameter("method", "GET");

    route = _routerImpl.addRoute("POST/{controller}/{id:\\d+}");

    route.addImplicitParameter("action", "update");
    route.addImplicitParameter("format", "html");
    route.addImplicitParameter("method", "POST");

    route = _routerImpl.addRoute("POST/{controller}/{id:\\d+}.{format}");

    route.addImplicitParameter("action", "update");
    route.addImplicitParameter("method", "POST");

    route = _routerImpl.addRoute("{method}/{controller}/{id:\\d+}/{action}");

    route.addImplicitParameter("format", "html");

    route = _routerImpl.addRoute("{method}/{controller}/{id:\\d+}/{action}.{format}");

    route = _routerImpl.addRoute("{method}/{controller}/{action}");

    route.addImplicitParameter("format", "html");

    route = _routerImpl.addRoute("{method}/{controller}/{action}.{format}");
}