You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by dl...@apache.org on 2005/08/29 21:12:51 UTC
cvs commit: ws-wsrp4j/sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/provider/driver PortletRegistrationFilterImpl.java URLComposerImpl.java
dlouzan 2005/08/29 12:12:51
Added: sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/provider/driver
PortletRegistrationFilterImpl.java
URLComposerImpl.java
Log:
Initial commit.
Revision Changes Path
1.1 ws-wsrp4j/sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/provider/driver/PortletRegistrationFilterImpl.java
Index: PortletRegistrationFilterImpl.java
===================================================================
/*
* Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wsrp4j.commons.producer.provider.driver;
import java.util.Iterator;
import java.util.HashMap;
import org.apache.wsrp4j.commons.producer.provider.interfaces.
PortletRegistrationFilter;
import org.apache.wsrp4j.commons.producer.provider.interfaces.
PortletRegistrationFilterWriter;
import org.apache.wsrp4j.commons.persistence.PersistentDataObject;
import org.apache.wsrp4j.commons.persistence.ServerPersistentFactory;
import org.apache.wsrp4j.commons.persistence.PersistentHandler;
import org.apache.wsrp4j.commons.persistence.driver.PersistentAccess;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
/**
* This class implements the interfaces PortletRegistrationFilter and
* PortletRegistrationFilterWriter.
*
* @author <a href="mailto:stefan.behl@de.ibm.com">Stefan Behl</a>
* @author <a href="mailto:Ralf.Altrichter@de.ibm.com">Ralf Altrichter</a>
* @version $Id: PortletRegistrationFilterImpl.java,v 1.1 2005/08/29 19:12:51 dlouzan Exp $
*/
public class PortletRegistrationFilterImpl
implements PortletRegistrationFilter, PortletRegistrationFilterWriter {
// a filter
private static PortletRegistrationFilterImpl filter;
// persistence support
private PersistentDataObject persistentDataObject;
// persistence support
private PersistentHandler persistentHandler;
// collects ConsumerPortletRegistration objects. RegistrationHandle
// is the key
private static HashMap consumerPortletRegistrationMap = new HashMap();
// for logging and exception support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
/**
* @return PortletRegistrationFilterWriter
*/
public static PortletRegistrationFilterWriter createWriter() {
if(filter == null) {
filter = new PortletRegistrationFilterImpl();
}
return filter;
}
/**
* @return PortletRegistrationFilter
*/
public static PortletRegistrationFilter createReader() {
if(filter == null) {
filter = new PortletRegistrationFilterImpl();
}
return filter;
}
/**
* Private constructor
*/
private PortletRegistrationFilterImpl() {
String MN = "Constructor";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
try {
ServerPersistentFactory persistentFactory =
PersistentAccess.getServerPersistentFactory();
persistentHandler = persistentFactory.getPersistentHandler();
persistentDataObject =
persistentFactory.getConsumerPortletRegistrationList();
restore();
} catch (WSRPException e) {
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"PortletRegistrationFilter: restore() failed!");
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Returns all portlet handles of portlets, a certain consumer (identified
* by regHandle) can utilize. Returns null if there are no entries for the
* provided regHandle.
*
* @param regHandle String representing the registration handle of a
* consumer
*
* @return Iterator of portlet handles
*/
public Iterator getAvailable(String regHandle) {
String MN = "getAvailable";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
Iterator iter = null;
if(consumerPortletRegistrationMap.containsKey(regHandle)) {
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"RegistrationHandle " + regHandle + " found in Map.");
}
ConsumerPortletRegistrationImpl cpr =
(ConsumerPortletRegistrationImpl)
consumerPortletRegistrationMap.get(regHandle);
iter = cpr.getPortletHandles().iterator();
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return iter;
}
/**
* Indicates whether a certain consumer is allowed to utilize the portlet
* identified by portletHandle or not. Returns false if there is no entry
* for the provided handles.
*
* @param regHandle String representing the registration handle of a
* consumer
* @param portletHandle String representing the portlet handle of an
* portlet
*
* @return boolean indicating whether the consumer corresponding to
* regHandle is allowed to use the portlet identified by portletHandle
*/
public boolean isAvailable(String regHandle, String portletHandle) {
String MN = "isAvailable";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
boolean retVal = false;
if(consumerPortletRegistrationMap.containsKey(regHandle)) {
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"RegistrationHandle " + regHandle + "found in Map.");
}
ConsumerPortletRegistrationImpl cpr =
(ConsumerPortletRegistrationImpl)
consumerPortletRegistrationMap.get(regHandle);
if(cpr.containsPortletHandle(portletHandle)) {
retVal = true;
if (logger.isLogging(Logger.TRACE_MEDIUM)) {
logger.text(Logger.TRACE_MEDIUM, MN,
"PortletHandle " + portletHandle +
"found for registration.");
}
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return retVal;
}
/**
* Makes a certain portlet (identified by portletHandle) available to a
* consumer (identified by regHandle). If there is no portlet in the
* portlet pool that corresponds to portletHandle, the method performs
* nothing.
*
* @param regHandle String representing the registration handle of a
* consumer
* @param portletHandle String representing the portlet handle of a consumer
*/
public void makeAvailable(String regHandle, String portletHandle)
throws WSRPException {
String MN = "makeAvailable";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
ConsumerPortletRegistrationImpl cpr = null;
if(!consumerPortletRegistrationMap.containsKey(regHandle)) {
cpr = new ConsumerPortletRegistrationImpl();
cpr.setRegistrationHandle(regHandle);
consumerPortletRegistrationMap.put(regHandle,cpr);
} else {
cpr = (ConsumerPortletRegistrationImpl)
consumerPortletRegistrationMap.get(regHandle);
}
// add the current portlet handle to the registration
cpr.addPortletHandle(portletHandle);
// make object persistent
persistentDataObject.clear();
persistentDataObject.addObject(cpr);
persistentDataObject.getPersistentInformation().setGroupID(regHandle);
store(persistentDataObject);
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Makes several portlets (identified by portletHandles) available to
* a certain consumer (identified by regHandle). For portlet handles that do
* not correspond to portlets kept within the portlet pool, the method makes
* no availability-entry.
*
* @param regHandle String representing the registration handle of a
* consumer
* @param portletHandles Iterator containing some portlet handles of
* portlets
*
* @throws WSRPException
*/
public void makeAvailable(String regHandle, Iterator portletHandles)
throws WSRPException {
String MN = "makeAvailable";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
while(portletHandles.hasNext()) {
makeAvailable(regHandle,(String)portletHandles.next());
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Removes an entire entry for a certain consumer (identified by regHandle).
* If there are no entries for the provided regHandle, the method performs
* nothing. The method is useful when a consumer deregisters.
*
* @param regHandle String representing the registration handle of a consumer
*/
public void remove(String regHandle) {
String MN = "remove";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if(consumerPortletRegistrationMap.containsKey(regHandle)) {
ConsumerPortletRegistrationImpl cpr =
(ConsumerPortletRegistrationImpl)
consumerPortletRegistrationMap.get(regHandle);
// delete object from persistent store
persistentDataObject.clear();
persistentDataObject.addObject(cpr);
persistentDataObject.getPersistentInformation().
setGroupID(regHandle);
consumerPortletRegistrationMap.remove(regHandle);
delete(persistentDataObject);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Abrogates the availability of a certain portlet (identified by
* portletHandle) regarding a certain consumer (identified by regHandle).
* If there is no entry for the provided regHandle and portletHandle,
* the method performs nothing.
*
* @param regHandle String representing the registration handle of a
* consumer
* @param portletHandle String representing the portlet handle of a consumer
*/
public void remove(String regHandle, String portletHandle)
throws WSRPException {
String MN = "remove";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if(consumerPortletRegistrationMap.containsKey(regHandle)) {
ConsumerPortletRegistrationImpl cpr =
(ConsumerPortletRegistrationImpl)
consumerPortletRegistrationMap.get(regHandle);
cpr.deletePortletHandle(portletHandle);
persistentDataObject.clear();
persistentDataObject.addObject(cpr);
persistentDataObject.getPersistentInformation().
setGroupID(regHandle);
// Is the registration list empty? No more Portlets are assigned?
if(cpr.isEmpty()) {
// delete the registration list
consumerPortletRegistrationMap.remove(regHandle);
delete(persistentDataObject);
} else {
// update the registration list
store(persistentDataObject);
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Abrogates the availability of several portlets (identified by
* portletHandles) regarding a certain consumer (identified by regHandle).
* For portlet handles that do not correspond to portlets kept within the
* portlet pool, the method performs nothing.
*
* @param regHandle String representing the registration handle of a
* consumer
* @param portletHandles Iterator containing some portlet handles of
* portlets
*/
public void remove(String regHandle, Iterator portletHandles)
throws WSRPException {
String MN = "remove";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if(portletHandles != null) {
while(portletHandles.hasNext()) {
remove(regHandle,(String) portletHandles.next());
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Delete the ConsumerPortletRegistration object from persistent store
*
* @param persistentDataObject
*/
private void delete(PersistentDataObject persistentDataObject) {
String MN = "delete";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
persistentHandler.delete(persistentDataObject);
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Store the ConsumerPortletRegistration object to persistent store
*
* @param persistentDataObject
* @throws WSRPException
*/
private void store(PersistentDataObject persistentDataObject)
throws WSRPException {
String MN = "store";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
persistentHandler.store(persistentDataObject);
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
/**
* Restores ConsumerPortletRegistration objects from the persistent store.
*
* @throws WSRPException
*/
private void restore() throws WSRPException {
String MN = "restore";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
consumerPortletRegistrationMap.clear();
persistentDataObject =
persistentHandler.restoreMultiple(persistentDataObject);
Iterator iterator = persistentDataObject.getObjects();
while (iterator.hasNext()) {
ConsumerPortletRegistrationImpl cpr =
(ConsumerPortletRegistrationImpl) iterator.next();
consumerPortletRegistrationMap.put(
cpr.getRegistrationHandle(), cpr);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/provider/driver/URLComposerImpl.java
Index: URLComposerImpl.java
===================================================================
/*
* Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wsrp4j.commons.producer.provider.driver;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import oasis.names.tc.wsrp.v1.types.PortletContext;
import oasis.names.tc.wsrp.v1.types.RuntimeContext;
import oasis.names.tc.wsrp.v1.types.Templates;
import oasis.names.tc.wsrp.v1.types.UserContext;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.producer.provider.interfaces.Provider;
import org.apache.wsrp4j.commons.producer.provider.interfaces.URLComposer;
import org.apache.wsrp4j.commons.util.Constants;
/**
* <p>This class implements the URLComposer interface providing methods to g
* enerate URLs or namespace tokens.</p>
* <p>There are two kinds of methods:
* <ul>
* <li>Methods defining URLs or tokens to be rewritten by the consumer.</li>
* <li>Methods defining complete URLs or namespaced tokens according to the
* templates delivered by the Consumer.</li></p>
*
* @author <a href="mailto:stefan.behl@de.ibm.com">Stefan Behl</a>
* @version $Id: URLComposerImpl.java,v 1.1 2005/08/29 19:12:51 dlouzan Exp $
*/
public class URLComposerImpl implements URLComposer {
// for logging and exception support
private Logger logger =
LogManager.getLogManager().getLogger(this.getClass());
private URLComposerImpl() {
// private
}
public static URLComposerImpl getInstance(Provider provider) {
URLComposerImpl urlComposer = new URLComposerImpl();
return urlComposer;
}
// methods generating rewrite urls
/**
* creates a rewrite blocking-action-url
*
* @param portletMode
* @param navigationalState
* @param interactionState
* @param windowState
* @param secureURL
* @param runtimeContext
* @param portletContext
* @param userContext
*
* @return URL as String
*/
public String createBlockingActionURL(
String portletMode,
String navigationalState,
String interactionState,
String windowState,
boolean secureURL,
RuntimeContext runtimeContext,
PortletContext portletContext,
UserContext userContext) {
String MN = "createBlockingActionURL";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
// check if valid templates are provided
if (runtimeContext != null) {
Templates templates = runtimeContext.getTemplates();
if (templates != null) {
String template = null;
if (secureURL) {
template = templates.getSecureBlockingActionTemplate();
if (template == null)
template = templates.getSecureDefaultTemplate();
} else {
template = templates.getBlockingActionTemplate();
if (template == null)
template = templates.getDefaultTemplate();
}
try {
if (template != null) {
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return this.createBlockingActionURLByTemplate(
template,
portletMode,
navigationalState,
interactionState,
windowState,
portletContext==null ? null :
portletContext.getPortletHandle(),
userContext==null ? null :
userContext.getUserContextKey(),
runtimeContext.getPortletInstanceKey(),
runtimeContext.getSessionID());
}
} catch (WSRPException e) {
// TODO: pass exception to consumer
}
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return createRewriteURL(
Constants.URL_TYPE_BLOCKINGACTION,
portletMode,
navigationalState,
interactionState,
windowState,
null,
null,
null,
java.lang.String.valueOf(secureURL));
}
/**
* creates a rewrite render-url
*/
public String createRenderURL(
String portletMode,
String navigationalState,
String windowState,
boolean secureURL,
RuntimeContext runtimeContext,
PortletContext portletContext,
UserContext userContext) {
String MN = "createRenderURL";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
// check if valid templates are provided
if (runtimeContext != null) {
Templates templates = runtimeContext.getTemplates();
if (templates != null) {
String template = null;
if (secureURL) {
template = templates.getSecureRenderTemplate();
if (template == null)
template = templates.getDefaultTemplate();
} else {
template = templates.getRenderTemplate();
if (template == null)
template = templates.getDefaultTemplate();
}
try {
if (template != null) {
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return this.createRenderURLByTemplate(
template,
portletMode,
navigationalState,
windowState,
portletContext==null ? null :
portletContext.getPortletHandle(),
userContext==null ? null :
userContext.getUserContextKey(),
runtimeContext.getPortletInstanceKey(),
runtimeContext.getSessionID());
}
} catch (WSRPException e) {
// TODO: pass exception to consumer
}
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return createRewriteURL(
Constants.URL_TYPE_RENDER,
portletMode,
navigationalState,
null,
windowState,
null,
null,
null,
java.lang.String.valueOf(secureURL));
}
/**
* creates a rewrite resource-url
*/
public String createResourceURL(
String url,
boolean rewriteResource,
boolean secureURL,
RuntimeContext runtimeContext,
PortletContext portletContext,
UserContext userContext) {
String MN = "createResourceURL";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
// check if valid templates are provided
if (runtimeContext != null) {
Templates templates = runtimeContext.getTemplates();
if (templates != null) {
String template = null;
if (secureURL) {
template = templates.getSecureResourceTemplate();
if (template == null)
template = templates.getDefaultTemplate();
} else {
template = templates.getResourceTemplate();
if (template == null)
template = templates.getDefaultTemplate();
}
try {
if (template != null) {
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return this.createResourceURLByTemplate(
template,
url,
rewriteResource,
portletContext==null ? null :
portletContext.getPortletHandle(),
userContext==null ? null :
userContext.getUserContextKey(),
runtimeContext.getPortletInstanceKey(),
runtimeContext.getSessionID());
}
} catch (WSRPException e) {
// TODO: pass exception to consumer
}
}
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return createRewriteURL(
Constants.URL_TYPE_RESOURCE,
null,
null,
null,
null,
url,
java.lang.String.valueOf(rewriteResource),
null,
java.lang.String.valueOf(secureURL));
}
/**
* creates a namespaced token
*/
public String createNamespacedToken(String token,
RuntimeContext runtimeContext) {
String MN = "createNamespacedToken";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
String nsToken = null;
// first get the prefix
// this is either the prefix passed in the RuntimeContext
if (runtimeContext != null) {
nsToken = runtimeContext.getNamespacePrefix();
}
// no namespace prefix obtained?
// then need to put in the rewrite NS wsrp_rewrite_
if (nsToken == null) {
nsToken = Constants.REWRITE_START + Constants.NAMESPACE_START;
}
// append the token
// if token is null, simply return the namespace
if (token != null) {
nsToken = nsToken.concat(token);
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return nsToken;
}
private String createRewriteURL(
String urlType,
String portletMode,
String navigationalState,
String interactionState,
String windowState,
String url,
String rewriteResource,
String token,
String secureURL) {
String MN = "createRewriteURL()";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(
Logger.TRACE_HIGH,
MN,
new Object[] {
urlType,
portletMode,
navigationalState,
interactionState,
windowState,
url,
rewriteResource,
token,
secureURL });
}
StringBuffer resultURL = new StringBuffer();
resultURL.append(Constants.REWRITE_START);
resultURL.append(Constants.PARAMS_START);
// urlType must be first (required)
if (urlType != null) {
resultURL.append(appendNameValuePair(Constants.URL_TYPE, urlType));
} else {
//TODO: Error
}
// portletMode
if (portletMode != null && portletMode.length() > 0) {
resultURL.append(Constants.NEXT_PARAM_AMP);
resultURL.append(appendNameValuePair(
Constants.PORTLET_MODE, portletMode));
}
// navigationalState
if (navigationalState != null && navigationalState.length() > 0) {
resultURL.append(Constants.NEXT_PARAM_AMP);
resultURL.append(appendNameValuePair(
Constants.NAVIGATIONAL_STATE, navigationalState));
}
// interactionState
if (interactionState != null && interactionState.length() > 0) {
resultURL.append(Constants.NEXT_PARAM_AMP);
resultURL.append(appendNameValuePair(
Constants.INTERACTION_STATE, interactionState));
}
// windowState
if (windowState != null && windowState.length() > 0) {
resultURL.append(Constants.NEXT_PARAM_AMP);
resultURL.append(appendNameValuePair(
Constants.WINDOW_STATE, windowState));
}
// url
if (url != null && url.length() > 0) {
resultURL.append(Constants.NEXT_PARAM_AMP);
try {
resultURL.append(appendNameValuePair(
Constants.URL, URLEncoder.encode(url, "utf-8")));
} catch (UnsupportedEncodingException uee) {
// this should never happen
resultURL.append(appendNameValuePair(Constants.URL, url));
}
}
// rewriteResource
if (rewriteResource != null && rewriteResource.length() > 0) {
resultURL.append(Constants.NEXT_PARAM_AMP);
resultURL.append(appendNameValuePair(
Constants.REWRITE_RESOURCE, rewriteResource));
}
// secureURL
if (secureURL != null && secureURL.length() > 0) {
resultURL.append(Constants.NEXT_PARAM_AMP);
resultURL.append(appendNameValuePair(
Constants.SECURE_URL, secureURL));
}
resultURL.append(Constants.REWRITE_END);
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
String result = resultURL.toString();
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN, result);
}
return result;
}
private String createNameValuePair(String name, String value) {
StringBuffer pair = new StringBuffer(name);
pair.append(Constants.EQUALS);
pair.append(value);
return pair.toString();
}
private String appendNameValuePair(String name, String value) {
return createNameValuePair(name, value);
}
// methods generating urls by template processing
private String createBlockingActionURLByTemplate(
String blockingActionTemplate,
String portletMode,
String navigationalState,
String interactionState,
String windowState,
String portletHandle,
String userContextKey,
String portletInstanceKey,
String sessionID)
throws WSRPException {
return processTemplate(
blockingActionTemplate,
Constants.URL_TYPE_BLOCKINGACTION,
portletMode,
navigationalState,
interactionState,
windowState,
null,
null,
portletHandle,
userContextKey,
portletInstanceKey,
sessionID);
}
private String createRenderURLByTemplate(
String renderTemplate,
String portletMode,
String navigationalState,
String windowState,
String portletHandle,
String userContextKey,
String portletInstanceKey,
String sessionID)
throws WSRPException {
return processTemplate(
renderTemplate,
Constants.URL_TYPE_RENDER,
portletMode,
navigationalState,
null,
windowState,
null,
null,
portletHandle,
userContextKey,
portletInstanceKey,
sessionID);
}
private String createResourceURLByTemplate(
String resourceTemplate,
String url,
boolean rewriteResource,
String portletHandle,
String userContextKey,
String portletInstanceKey,
String sessionID)
throws WSRPException {
return processTemplate(
resourceTemplate,
Constants.URL_TYPE_RESOURCE,
null,
null,
null,
null,
url,
java.lang.String.valueOf(rewriteResource),
portletHandle,
userContextKey,
portletInstanceKey,
sessionID);
}
private String processTemplate(
String template,
String urlType,
String portletMode,
String navigationalState,
String interactionState,
String windowState,
String url,
String rewriteResource,
String portletHandle,
String userContextKey,
String portletInstanceKey,
String sessionID)
throws WSRPException {
String MN = "processTemplate";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
String replaceToken = "";
// Any template containing "{" or "}" will be processed.
while ((template.indexOf(Constants.REPLACE_START) != -1) |
(template.indexOf(Constants.REPLACE_END) != -1)) {
StringBuffer templateBuffer = new StringBuffer(template);
// get positions of next left and right brackets
int left_br = template.indexOf(Constants.REPLACE_START);
int right_br = template.indexOf(Constants.REPLACE_END) + 1;
// check if bracketing is correct
if ((left_br > right_br) | (left_br == -1) | (right_br == -1)) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.SYNTAX_ERROR_IN_TEMPLATE);
}
// get replaceToken without curly brackets enclosing it
replaceToken = templateBuffer.substring(left_br + 1, right_br - 1);
// urlType
if (replaceToken.equalsIgnoreCase(Constants.URL_TYPE)) {
if (urlType == null) {
urlType = "";
}
templateBuffer.replace(left_br, right_br, urlType);
}
// portletMode
else if (replaceToken.equalsIgnoreCase(Constants.PORTLET_MODE)) {
if (portletMode == null) {
portletMode = "";
}
templateBuffer.replace(left_br, right_br, portletMode);
}
// navigationalState
else if (replaceToken.equalsIgnoreCase(
Constants.NAVIGATIONAL_STATE)) {
if (navigationalState == null) {
navigationalState = "";
}
templateBuffer.replace(left_br, right_br, navigationalState);
}
// interactionState
else if (replaceToken.equalsIgnoreCase(
Constants.INTERACTION_STATE)) {
if (interactionState == null) {
interactionState = "";
}
templateBuffer.replace(left_br, right_br, interactionState);
}
// windowState
else if (replaceToken.equalsIgnoreCase(Constants.WINDOW_STATE)) {
if (windowState == null) {
windowState = "";
}
templateBuffer.replace(left_br, right_br, windowState);
}
// url
else if (replaceToken.equalsIgnoreCase(Constants.URL)) {
if (url == null) {
url = "";
}
templateBuffer.replace(left_br, right_br, url);
}
// rewriteResource
else if (replaceToken.equalsIgnoreCase(
Constants.REWRITE_RESOURCE)) {
if (rewriteResource == null) {
rewriteResource = "";
}
templateBuffer.replace(left_br, right_br, rewriteResource);
}
/*
// secureURL
else if (replaceToken.equalsIgnoreCase(
Constants.SECURE_URL))
{
if (secureURL == null)
{
secureURL = "";
}
templateBuffer.replace(left_br, right_br,
secureURL);
}
// token
else if (replaceToken.equalsIgnoreCase(Constants.TOKEN))
{
if (token == null)
{
token = "";
}
templateBuffer.replace(left_br, right_br, token);
}
*/
// portletHandle
else if (replaceToken.equalsIgnoreCase(Constants.PORTLET_HANDLE)) {
if (portletHandle == null) {
portletHandle = "";
}
templateBuffer.replace(left_br, right_br, portletHandle);
}
// userContextKey
else if (replaceToken.equalsIgnoreCase(
Constants.USER_CONTEXT_KEY)) {
if (userContextKey == null) {
userContextKey = "";
}
templateBuffer.replace(left_br, right_br, userContextKey);
}
// portletInstanceKey
else if (replaceToken.equalsIgnoreCase(
Constants.PORTLET_INSTANCE_KEY)) {
if (portletInstanceKey == null) {
portletInstanceKey = "";
}
templateBuffer.replace(left_br, right_br, portletInstanceKey);
}
// sessionID
else if (replaceToken.equalsIgnoreCase(Constants.SESSION_ID)) {
if (sessionID == null) {
sessionID = "";
}
templateBuffer.replace(left_br, right_br, sessionID);
}
// unknown
else {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.UNKNOWN_TOKEN_IN_TEMPLATE);
}
// update template
template = templateBuffer.toString();
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return template;
}
}