use of javax.portlet.BaseURL in project liferay-faces-bridge-impl by liferay.
the class BridgeURITest method testXmlEscaping.
@Test
public void testXmlEscaping() throws UnsupportedEncodingException {
try {
BridgeURI bridgeURI = newBridgeURI("http://www.liferay.com/hello.world?a=1&b=2");
BaseURL nonEncodedURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
Writer stringWriter = new StringWriter();
nonEncodedURL.write(stringWriter, false);
Assert.assertTrue("http://www.liferay.com/hello.world?a=1&b=2".equals(stringWriter.toString()));
stringWriter = new StringWriter();
nonEncodedURL.write(stringWriter, true);
Assert.assertTrue("http://www.liferay.com/hello.world?a=1&b=2".equals(stringWriter.toString()));
} catch (IOException e) {
throw new AssertionError(e);
} catch (URISyntaxException e) {
throw new AssertionError(e);
}
}
use of javax.portlet.BaseURL in project liferay-faces-bridge-impl by liferay.
the class BridgeURLActionImpl method toBaseURL.
@Override
public BaseURL toBaseURL(FacesContext facesContext) throws MalformedURLException {
BaseURL baseURL;
// If this is executing during the ACTION_PHASE of the portlet lifecycle, then
PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
if (portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) {
// Since ActionResponse is not a MimeResponse, there is no way to create a RenderURL in a standard way.
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
} else // Otherwise,
{
// Otherwise, if the URI starts with a "#" character, or it's an absolute URL that is external to
// this portlet, then simply return the URI as required by the Bridge Spec.
String uri = bridgeURI.toString();
if (uri.startsWith("#") || (bridgeURI.isAbsolute() && bridgeURI.isExternal(contextPath))) {
// TCK: encodeActionURLPoundCharTest
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
} else // then return an absolute path (to the path in the URI) as required by the Bridge Spec.
if (directLink || bridgeURI.isExternal(contextPath)) {
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
baseURL = new BaseURLDirectImpl(bridgeURI, portletRequest.getScheme(), portletRequest.getServerName(), portletRequest.getServerPort());
} else // Otherwise,
{
// Determine whether or not the portlet mode is to be changed by examining the
// "javax.portlet.faces.PortletMode" parameter.
boolean modeChanged = false;
String portletMode = getParameter(Bridge.PORTLET_MODE_PARAMETER);
if ((portletMode != null) && (portletMode.length() > 0)) {
modeChanged = true;
}
// "portlet:resource".
if (bridgeURI.isPortletScheme()) {
Bridge.PortletPhase urlPortletPhase = bridgeURI.getPortletPhase();
if (urlPortletPhase == Bridge.PortletPhase.ACTION_PHASE) {
baseURL = createActionURL(facesContext, modeChanged);
} else if (urlPortletPhase == Bridge.PortletPhase.RENDER_PHASE) {
baseURL = createRenderURL(facesContext, modeChanged);
} else {
baseURL = createResourceURL(facesContext, modeChanged);
}
} else {
if (portletRequestPhase == Bridge.PortletPhase.EVENT_PHASE) {
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
} else if (bookmarkable || (redirect && (portletRequestPhase == PortletPhase.RESOURCE_PHASE))) {
baseURL = createRenderURL(facesContext, modeChanged);
} else {
baseURL = createActionURL(facesContext, modeChanged);
}
}
// render parameters from the current PortletRequest to the BaseURL.
if (selfReferencing) {
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
copyRenderParameters(portletRequest, baseURL, externalContext.encodeNamespace(""), UINamingContainer.getSeparatorChar(facesContext));
}
// PortletURL.
if (baseURL instanceof PortletURL) {
PortletURL portletURL = (PortletURL) baseURL;
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletURLHelper.setPortletMode(portletURL, portletMode, portletRequest);
// According to the Bridge Spec, the "javax.portlet.faces.PortletMode"" parameter must not be
// "carried forward to the generated reference." According to a clarification in the Portlet 3.0
// JavaDoc for BaseURL#setProperty(String,String), setting the parameter to null will remove it.
portletURL.setParameter(Bridge.PORTLET_MODE_PARAMETER, (String) null);
String windowState = getParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
PortletURLHelper.setWindowState(portletURL, windowState, portletRequest);
// According to the Bridge Spec, the "javax.portlet.faces.WindowState" parameter must not be
// "carried forward to the generated reference." According to a clarification in the Portlet 3.0
// JavaDoc for BaseURL#setProperty(String,String), setting the parameter to null will remove it.
portletURL.setParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER, (String) null);
}
// Apply the security.
String secure = getParameter(Bridge.PORTLET_SECURE_PARAMETER);
PortletURLHelper.setSecure(baseURL, secure);
// According to the Bridge Spec, the "javax.portlet.faces.Secure" parameter must not be "carried
// forward to the generated reference." According to a clarification in the Portlet 3.0 JavaDoc for
// BaseURL#setProperty(String,String), setting the parameter to null will remove it.
baseURL.setParameter(Bridge.PORTLET_SECURE_PARAMETER, (String) null);
}
}
return baseURL;
}
use of javax.portlet.BaseURL in project liferay-faces-bridge-impl by liferay.
the class BridgeURLBase method toString.
@Override
public String toString() {
String stringValue = null;
try {
// Ask the Portlet Container for a BaseURL that contains the modified parameters.
FacesContext facesContext = FacesContext.getCurrentInstance();
BaseURL baseURL = toBaseURL(facesContext);
// portlet container to create an escaped representation of the URL string.
if (bridgeURI.isEscaped()) {
StringWriter urlWriter = new StringWriter();
try {
baseURL.write(urlWriter, true);
stringValue = urlWriter.toString();
} catch (IOException e) {
logger.error(e);
stringValue = baseURL.toString();
}
} else // Otherwise, ask the portlet container to create a normal (non-escaped) string
// representation of the URL string.
{
stringValue = baseURL.toString();
}
// parameter.
if (baseURL instanceof FacesViewActionURL) {
FacesViewActionURL facesViewActionURL = (FacesViewActionURL) baseURL;
String viewId = facesViewActionURL.getViewId();
if (viewId != null) {
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
String requestMapKey = Bridge.VIEW_ID + stringValue;
requestMap.put(requestMapKey, viewId);
}
}
} catch (MalformedURLException e) {
logger.error(e);
}
return stringValue;
}
use of javax.portlet.BaseURL in project liferay-faces-bridge-impl by liferay.
the class BridgeURLPartialActionImpl method toBaseURL.
@Override
public BaseURL toBaseURL(FacesContext facesContext) throws MalformedURLException {
BaseURL baseURL = null;
String uri = bridgeURI.toString();
if (uri != null) {
if (uri.startsWith("http")) {
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
logger.debug("URL starts with http so assuming that it has already been encoded: url=[{0}]", uri);
} else {
baseURL = createResourceURL(facesContext, bridgeURI.getParameterMap());
}
} else {
logger.warn("Unable to encode PartialActionURL for url=[null]");
}
return baseURL;
}
use of javax.portlet.BaseURL in project liferay-faces-bridge-impl by liferay.
the class BridgeURLResourceImpl method toBaseURL.
@Override
public BaseURL toBaseURL(FacesContext facesContext) throws MalformedURLException {
BaseURL baseURL;
String uri = bridgeURI.toString();
// doesn't have the double-forward-slash like "http://" does, then
if (bridgeURI.isOpaque()) {
// parameters. This will be a URL that represents navigation to a different viewId.
if (bridgeURI.isPortletScheme()) {
// TCK: modeViewIDTest
// TCK: requestRenderIgnoresScopeViaCreateViewTest
// TCK: requestRenderRedisplayTest
// TCK: requestRedisplayOutOfScopeTest
// TCK: renderRedirectTest
// TCK: ignoreCurrentViewIdModeChangeTest
// TCK: exceptionThrownWhenNoDefaultViewIdTest
String portletMode = getParameter(Bridge.PORTLET_MODE_PARAMETER);
boolean modeChanged = ((portletMode != null) && (portletMode.length() > 0));
Bridge.PortletPhase urlPortletPhase = bridgeURI.getPortletPhase();
if (urlPortletPhase == Bridge.PortletPhase.ACTION_PHASE) {
baseURL = createActionURL(facesContext, modeChanged);
} else if (urlPortletPhase == Bridge.PortletPhase.RENDER_PHASE) {
baseURL = createRenderURL(facesContext, modeChanged);
} else {
baseURL = createResourceURL(facesContext, modeChanged);
}
// user clicks on the link (invokes the BaseURL).
if (selfReferencing) {
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
copyRenderParameters(portletRequest, baseURL, externalContext.encodeNamespace(""), UINamingContainer.getSeparatorChar(facesContext));
}
// PortletURL.
if (baseURL instanceof PortletURL) {
PortletURL portletURL = (PortletURL) baseURL;
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletURLHelper.setPortletMode(portletURL, portletMode, portletRequest);
String windowState = getParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
PortletURLHelper.setWindowState(portletURL, windowState, portletRequest);
}
// Apply the security.
String secure = getParameter(Bridge.PORTLET_SECURE_PARAMETER);
PortletURLHelper.setSecure(baseURL, secure);
// According to the Bridge Spec, the "javax.portlet.faces.Secure" parameter must not be "carried
// forward to the generated reference." According to a clarification in the Portlet 3.0 JavaDoc for
// BaseURL#setProperty(String,String), setting the parameter to null will remove it.
baseURL.setParameter(Bridge.PORTLET_SECURE_PARAMETER, (String) null);
} else // Otherwise, return the a BaseURL string representation (unmodified value) as required by the Bridge Spec.
{
// TCK: encodeResourceURLOpaqueTest
baseURL = new BaseURLNonEncodedImpl(bridgeURI, encoding);
}
} else // Otherwise, if the URL is a JSF2 portlet resource URL, then
if (PortletResourceUtilCompat.isPortletResourceURL(uri)) {
// FACES-63 Return the URI unmodified to prevent double-encoding of resource URLs.
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
} else // resource URL identifier, then return a ResourceURL that can retrieve the JSF2 resource.
if ((uri != null) && uri.contains("javax.faces.resource")) {
baseURL = createResourceURL(facesContext, bridgeURI.getParameterMap());
} else // of the URL that contains the context-path.
if (bridgeURI.isPathRelative()) {
// TCK: encodeResourceURLRelativeURLTest
// TCK: encodeResourceURLRelativeURLBackLinkTest
ExternalContext externalContext = facesContext.getExternalContext();
String contextPath = externalContext.getRequestContextPath();
baseURL = new BaseURLRelativeImpl(bridgeURI, contextPath);
} else // Otherwise, if the URL is external, then return an encoded BaseURL string representation of the URL.
if (bridgeURI.isExternal(contextPath)) {
// TCK: encodeResourceURLForeignExternalURLBackLinkTest
ExternalContext externalContext = facesContext.getExternalContext();
PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
baseURL = new BaseURLPortletResponseEncodedImpl(bridgeURI, portletResponse);
} else // to a different Faces view, then
if (viewLink) {
String portletMode = getParameter(Bridge.PORTLET_MODE_PARAMETER);
String windowState = getParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
boolean secure = BooleanHelper.toBoolean(getParameter(Bridge.PORTLET_SECURE_PARAMETER));
// JavaDoc comments for {@link Bridge#VIEW_LINK}.
if (getViewId() != null) {
// TCK: encodeResourceURLViewLinkTest
// TCK: encodeResourceURLViewLinkWithBackLinkTest
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletURL actionURL = createActionURL(facesContext, PortletURLHelper.EXCLUDED_PARAMETER_NAMES);
PortletURLHelper.setPortletMode(actionURL, portletMode, portletRequest);
PortletURLHelper.setWindowState(actionURL, windowState, portletRequest);
PortletURLHelper.setSecure(actionURL, secure);
// According to the Bridge Spec, the "javax.portlet.faces.Secure" parameter must not be "carried
// forward to the generated reference." According to a clarification in the Portlet 3.0 JavaDoc for
// BaseURL#setProperty(String,String), setting the parameter to null will remove it.
actionURL.setParameter(Bridge.PORTLET_SECURE_PARAMETER, (String) null);
baseURL = actionURL;
} else // Otherwise, return a PortletURL (Render URL) that contains the "_jsfBridgeNonFacesView" render parameter,
// which is a signal to the GenericFacesPortlet to dispatch to this non-Faces target when the URL is
// requested. Note that this seems to be a use-case that is contradictory with the JavaDoc for
// Brige#VIEW_LINK which claims navigation to a different view. But there are a number of tests in the TCK
// that utilize this (see below).
{
Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
if (isHeaderOrRenderOrResourcePhase(portletRequestPhase)) {
// TCK: encodeActionURLNonJSFViewRenderTest
// TCK: encodeActionURLNonJSFViewWithParamRenderTest
// TCK: encodeActionURLNonJSFViewWithModeRenderTest
// TCK: encodeActionURLNonJSFViewWithInvalidModeRenderTest
// TCK: encodeActionURLNonJSFViewWithWindowStateRenderTest
// TCK: encodeActionURLNonJSFViewWithInvalidWindowStateRenderTest
// TCK: encodeActionURLNonJSFViewResourceTest
// TCK: encodeActionURLNonJSFViewWithParamResourceTest
// TCK: encodeActionURLNonJSFViewWithModeResourceTest
// TCK: encodeActionURLNonJSFViewWithInvalidModeResourceTest
// TCK: encodeActionURLNonJSFViewWithWindowStateResourceTest
// TCK: encodeActionURLNonJSFViewWithInvalidWindowStateResourceTest
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletURL renderURL = createRenderURL(facesContext, PortletURLHelper.EXCLUDED_PARAMETER_NAMES);
renderURL.setParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER, bridgeURI.getPath());
PortletURLHelper.setPortletMode(renderURL, portletMode, portletRequest);
PortletURLHelper.setWindowState(renderURL, windowState, portletRequest);
PortletURLHelper.setSecure(renderURL, secure);
// According to the Bridge Spec, the "javax.portlet.faces.Secure" parameter must not be "carried
// forward to the generated reference." According to a clarification in the Portlet 3.0 JavaDoc for
// BaseURL#setProperty(String,String), setting the parameter to null will remove it.
renderURL.setParameter(Bridge.PORTLET_SECURE_PARAMETER, (String) null);
baseURL = renderURL;
} else {
throw new IllegalStateException("Unable to encode a URL for a non-Faces view in the " + portletRequestPhase + " of the portlet lifecycle.");
}
}
} else // Otherwise, if the URL targets a Faces viewId, then return a ResourceURL that targets the view.
if (getViewId() != null) {
// TCK: resourceAttrRetainedAfterRedisplayPPRTest
// TCK: encodeActionURLJSFViewResourceTest
// TCK: encodeActionURLWithParamResourceTest
// TCK: encodeActionURLWithModeResourceTest
// TCK: encodeActionURLWithInvalidModeResourceTest
// TCK: encodeActionURLWithWindowStateResourceTest
// TCK: encodeActionURLWithInvalidWindowStateResourceTest
// TCK: encodeURLEscapingTest
// TCK: encodeResourceURLWithModeTest
baseURL = createResourceURL(facesContext, PortletURLHelper.EXCLUDED_PARAMETER_NAMES);
} else // an appropriate ResourceURL.
if (inProtocol) {
// TCK: nonFacesResourceTest
ResourceURL resourceURL = createResourceURL(facesContext);
resourceURL.setResourceID(bridgeURI.getContextRelativePath(contextPath));
baseURL = resourceURL;
} else // Otherwise, assume that the URL is for an resource external to the portlet context like
// "/portalcontext/resources/foo.png" and return a BaseURL string representation of it.
{
// TCK: encodeResourceURLTest
// TCK: encodeResourceURLBackLinkTest
baseURL = new BaseURLBridgeURIAdapterImpl(bridgeURI);
}
return baseURL;
}
Aggregations