Search in sources :

Example 1 with ResourceURL

use of javax.portlet.ResourceURL in project index-checker by jorgediaz-lr.

the class IndexCheckerPortlet method doView.

public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
    PortletConfig portletConfig = (PortletConfig) renderRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    renderRequest.setAttribute("updateMessage", getUpdateMessage(portletConfig));
    List<String> outputList = IndexCheckerOutput.generateCSVOutput(portletConfig, renderRequest);
    String portletId = portletConfig.getPortletName();
    String outputContent = OutputUtils.listStringToString(outputList);
    FileEntry exportCsvFileEntry = OutputUtils.addPortletOutputFileEntry(portletId, PortalUtil.getUserId(renderRequest), outputContent);
    if (exportCsvFileEntry != null) {
        ResourceURL exportCsvResourceURL = renderResponse.createResourceURL();
        exportCsvResourceURL.setResourceID(exportCsvFileEntry.getTitle());
        renderRequest.setAttribute("exportCsvResourceURL", exportCsvResourceURL.toString());
    }
    try {
        List<Long> siteGroupIds = getSiteGroupIds();
        renderRequest.setAttribute("groupIdList", siteGroupIds);
        List<String> groupDescriptionList = getSiteGroupDescriptions(siteGroupIds, renderRequest.getLocale());
        renderRequest.setAttribute("groupDescriptionList", groupDescriptionList);
    } catch (Exception e) {
        throw new PortletException(e);
    }
    try {
        renderRequest.setAttribute("modelList", getModelList());
    } catch (SystemException se) {
        throw new PortletException(se);
    }
    long filterModifiedDate = ParamUtil.getLong(renderRequest, "filterModifiedDate");
    renderRequest.setAttribute("filterModifiedDate", filterModifiedDate);
    super.doView(renderRequest, renderResponse);
}
Also used : SystemException(com.liferay.portal.kernel.exception.SystemException) PortletException(javax.portlet.PortletException) PortletConfig(javax.portlet.PortletConfig) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) ResourceURL(javax.portlet.ResourceURL) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) PortletException(javax.portlet.PortletException)

Example 2 with ResourceURL

use of javax.portlet.ResourceURL in project liferay-faces-bridge-impl by liferay.

the class EncodeActionURLResourceTests method encodeActionURLPortletResourceTest.

// Test is SingleRequest -- Render only
// Test #6.102
@BridgeTest(test = "encodeActionURLPortletResourceTest")
public String encodeActionURLPortletResourceTest(TestBean testBean) {
    testBean.setTestComplete(true);
    final String PORTLET_RENDER_TEST_STRING = "portlet:resource?_jsfBridgeViewId=/tests/singleRequestTest.xhtml&param1=value1&param2=value2";
    final String PORTLET_RENDER_TEST_STRING_XMLENCODED = "portlet:resource?_jsfBridgeViewId=/tests/singleRequestTest.xhtml&amp;param1=value1&amp;param2=value2";
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    MimeResponse response = (MimeResponse) externalContext.getResponse();
    ResourceURL portletURL = response.createResourceURL();
    portletURL.setParameter("_jsfBridgeViewId", "/tests/singleRequestTest.xhtml");
    portletURL.setParameter("param1", "value1");
    portletURL.setParameter("param2", "value2");
    StringWriter sw = new StringWriter(50);
    String portletEncoded = null;
    try {
        portletURL.write(sw, true);
        portletEncoded = sw.toString();
    } catch (Exception e) {
        portletEncoded = portletURL.toString();
    }
    // PortletContainers can return "URLs" with strict XML encoding -- as the bridge
    // encoding depends on what is past in to it -- make sure we send in a string
    // with the same encoding as compare string.
    String bridgeEncoded = null;
    if (EncodeURLTestUtil.isStrictXhtmlEncoded(portletEncoded)) {
        bridgeEncoded = externalContext.encodeActionURL(PORTLET_RENDER_TEST_STRING_XMLENCODED);
    } else {
        bridgeEncoded = externalContext.encodeActionURL(PORTLET_RENDER_TEST_STRING);
    }
    if (bridgeEncoded.equals(portletEncoded)) {
        testBean.setTestResult(true, "encodeActionURL correctly encoded a portlet resource URL as an actionURL using the portlet: syntax.");
        return Constants.TEST_SUCCESS;
    } else {
        testBean.setTestResult(false, "encodeActionURL incorrectly encoded a portlet resource URL as an actionURL using the portlet: syntax.  In encoding: " + PORTLET_RENDER_TEST_STRING + " the bridge returned: " + bridgeEncoded + " but the corresponding portletURL encoding returned: " + portletEncoded);
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) StringWriter(java.io.StringWriter) ExternalContext(javax.faces.context.ExternalContext) MimeResponse(javax.portlet.MimeResponse) ResourceURL(javax.portlet.ResourceURL) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 3 with ResourceURL

use of javax.portlet.ResourceURL in project liferay-faces-bridge-ext by liferay.

the class LiferayURLFactoryImpl method getLiferayResourceURL.

@Override
public LiferayResourceURL getLiferayResourceURL(PortletRequest portletRequest, MimeResponse mimeResponse, boolean friendlyURLMapperEnabled) {
    if (friendlyURLMapperEnabled) {
        ResourceURL resourceURL = mimeResponse.createResourceURL();
        return new LiferayResourceURLFriendlyImpl(resourceURL, mimeResponse.getNamespace(), mimeResponse.getCharacterEncoding());
    } else {
        LiferayURLGenerator liferayURLGenerator = (LiferayURLGenerator) portletRequest.getAttribute(RESOURCE_URL_GENERATOR);
        if (liferayURLGenerator == null) {
            ResourceURL resourceURL = mimeResponse.createResourceURL();
            liferayURLGenerator = new LiferayURLGeneratorResourceImpl(resourceURL.toString(), mimeResponse.getNamespace(), mimeResponse.getCharacterEncoding());
            portletRequest.setAttribute(RESOURCE_URL_GENERATOR, liferayURLGenerator);
        }
        return new LiferayResourceURLImpl(liferayURLGenerator);
    }
}
Also used : ResourceURL(javax.portlet.ResourceURL)

Example 4 with ResourceURL

use of javax.portlet.ResourceURL in project social by Meeds-io.

the class UISpacesToolBarPortlet method toJSON.

protected JSONObject toJSON(UserNode node, String navId, MimeResponse res) throws Exception {
    JSONObject json = new JSONObject();
    String nodeId = node.getId();
    json.put("label", node.getEncodedResolvedLabel());
    json.put("hasChild", node.getChildrenCount() > 0);
    json.put("isSelected", nodeId.equals(getSelectedNode().getId()));
    json.put("icon", node.getIcon());
    ResourceURL rsURL = res.createResourceURL();
    rsURL.setResourceID(res.encodeURL(getResourceIdFromNode(node, navId)));
    json.put("getNodeURL", rsURL.toString());
    json.put("actionLink", Utils.getSpaceURL(node));
    JSONArray childs = new JSONArray();
    for (UserNode child : node.getChildren()) {
        childs.put(toJSON(child, navId, res));
    }
    json.put("childs", childs);
    return json;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UserNode(org.exoplatform.portal.mop.user.UserNode) ResourceURL(javax.portlet.ResourceURL)

Example 5 with ResourceURL

use of javax.portlet.ResourceURL in project acs-community-packaging by Alfresco.

the class AlfrescoFacesPortlet method getResourceURL.

/**
 * Creates a resource URL from the given faces context.
 *
 * @param context
 *            the faces context
 * @return the resource URL
 */
public static String getResourceURL(FacesContext context, String path) {
    MimeResponse portletResponse = (MimeResponse) context.getExternalContext().getResponse();
    ResourceURL resourceURL = portletResponse.createResourceURL();
    resourceURL.setResourceID(path);
    return resourceURL.toString();
}
Also used : MimeResponse(javax.portlet.MimeResponse) ResourceURL(javax.portlet.ResourceURL)

Aggregations

ResourceURL (javax.portlet.ResourceURL)17 MimeResponse (javax.portlet.MimeResponse)6 UserNode (org.exoplatform.portal.mop.user.UserNode)5 JSONArray (org.json.JSONArray)5 JSONObject (org.json.JSONObject)5 ExternalContext (javax.faces.context.ExternalContext)3 NavigationResource (org.exoplatform.web.url.navigation.NavigationResource)3 NodeURL (org.exoplatform.web.url.navigation.NodeURL)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 MalformedURLException (java.net.MalformedURLException)2 PortletResponse (javax.portlet.PortletResponse)2 PortletURL (javax.portlet.PortletURL)2 WebuiRequestContext (org.exoplatform.webui.application.WebuiRequestContext)2 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1