The portlets I have seen so far display the same content when maximized as
they do in a normal state. But one has a lot more screen real estate when
maximized. I have had occasions where I wanted to display different content
when maximized. I have done this using two methods.
1) For the FileServerPortlet (HTML) I wanted to display different content
when the portlet is maximized: So I defined a new parameter,
maximizedContent, that points to a different URL. I then re-wrote a couple
of the routines thus:
private DiskCache cache;
private PortletConfig config;
private String url;
private String maximizedUrl;
public void init() throws PortletException {
super.init();
cache = JetspeedDiskCache.getInstance();
config = getPortletConfig();
url = config.getURL();
maximizedUrl = config.getInitParameter("maximizedContent");
try {
setContent(getElement(url));
} catch (Exception ex) {
if (ex instanceof PortletException) {
throw (PortletException) ex;
} else {
throw new PortletException(ex.getMessage());
}
}
}
public ConcreteElement getContent(RunData rundata) {
ConcreteElement result = null;
if (maximizedUrl != null && !maximizedUrl.equals(url)) {
JetspeedRunData jrd = (JetspeedRunData) rundata;
if (JetspeedRunData.MAXIMIZE == jrd.getMode()) {
try {
result = getElement(maximizedUrl);
} catch(IOException ex) {
result = new ClearElement(ex.toString());
}
}
}
if (result == null) {
result = super.getContent(rundata);
}
return result;
}
private static final int CAPACITY = 1024;
private ConcreteElement getElement(String url) throws IOException {
Reader rdr = cache.getEntry(url).getReader();
StringBuffer buffer = new StringBuffer();
char[] chars = new char[CAPACITY];
int readCount = 0;
while( ( readCount = rdr.read( chars )) > 0 ) {
buffer.append( chars, 0, readCount);
}
rdr.close();
return new ClearElement(buffer.toString());
}
This gives a cool result in that an entirely different page can be displayed
when the portlet is maximized. One shortcoming is that the maximized page
is not cached.
For the RSSPortlet, I wanted to have different display options when the
portlet is maximized. I did this by adding new parameters
max_itemdisplayed, max_showdescription, max_showtitle, and
max_showtextinput, which allow for different settings of itemdisplayed,
showdescription, showtitle, and showtextinput when the portlet is maximized.
In the init() method, I added:
params.put("maximized", "false");
Then I rewrote the getContent method:
public ConcreteElement getContent(RunData data) {
CapabilityMap map = CapabilityMapFactory.getCapabilityMap(data);
String type = map.getPreferredType().toString();
ConcreteElement content = new ClearElement(INVALID_TYPE);
JetspeedRunData jrd = (JetspeedRunData) data;
boolean maximized = JetspeedRunData.MAXIMIZE == jrd.getMode();
params.put("maximized", new Boolean(maximized).toString());
String stylesheet = (String) stylesheets.get(type);
if (maximized && stylesheet != null) {
content = new ClearElement(transform(stylesheet));
} else {
content = getContent(data, map);
if (stylesheet != null && content == null) {
content = new ClearElement(transform(stylesheet));
setContent(content, map);
}
}
return content;
}
private String transform(String stylesheet) {
String result = null;
try {
result = SimpleTransform.transform
(document, stylesheet, params);
} catch (SAXException ex) {
result = ex.getLocalizedMessage();
} finally {
return result;
}
}
Of course, I also had to alter the stylesheet to use different formatting
based on the maximized parameter. Typically, I set showdescription to false
and max_showdescription to true or something like that.
As before, the shortcoming is that the maximized content is not cached.
{Note: we are using 1.4b1. If using 1.4b2, you would return a
JetspeedClearElement instead of a ClearElement.]
While all this works, I was wondering if there was a more direct approach.
1. Would it be possible to completely decouple the minimized and maximized
content into different portlets? With this approach, portlet1 automatically
invokes portlet2 when maximized and portlet2 invokes portlet1 when restored.
That way, no other code needs changing.
2. Failing that, I know it would be possible to disable the maximize
capability on portlet1, and mandate a maximized state on portlet2. I could
provide a hyperlink "more" on portlet1 that invoked portlet2 and a "return"
hyperlink on portlet2 that invokes portlet1. Unfortunately, I am still new
pretty new to Jetspeed and I have not been able to find out how to do this
in the documentation. Could someone point me in the right direction?
Thanks in advance.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]