[jboss-cvs] jboss-portal/core/src/main/org/jboss/portal/core/aspects/portlet ...
Julien Viet
julien at jboss.com
Tue Jul 11 19:19:29 EDT 2006
User: julien
Date: 06/07/11 19:19:29
Added: core/src/main/org/jboss/portal/core/aspects/portlet
HeaderInterceptor.java TransactionInterceptor.java
Log:
moved remaining component->portlet package classes in core module
Revision Changes Path
1.1 date: 2006/07/11 23:19:29; author: julien; state: Exp;jboss-portal/core/src/main/org/jboss/portal/core/aspects/portlet/HeaderInterceptor.java
Index: HeaderInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.core.aspects.portlet;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.core.metadata.portlet.HeaderContentMetaData;
import org.jboss.portal.core.metadata.portlet.JBossPortletMetaData;
import org.jboss.portal.portlet.container.PortletContainer;
import org.jboss.portal.portlet.container.info.ContainerPortletInfo;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.result.FragmentResult;
import org.jboss.portal.portlet.result.Result;
import java.io.StringWriter;
import java.util.Iterator;
/**
* todo : possibility to optimize the writer stuff
*
* @author <a href="mailto:mholzner at novell.com">Martin Holzner</a>
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class HeaderInterceptor extends PortletInterceptor
{
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
invocation.invokeNext();
//
Result result = invocation.getResult();
//
if (result instanceof FragmentResult)
{
RenderInvocation render = (RenderInvocation)invocation;
FragmentResult fragment = (FragmentResult)result;
/*
Properties props = fragment.getProperties();
// Is there a rewrite token and a unique id to use for the rewrite ?
String rewrite = props.getProperty(RewriteHelper.REWRITE_FLAG);
String prefix = "jbp_" + Integer.toHexString(invocation.getWindowContext().getId().hashCode()) + "_";
if (Boolean.valueOf(rewrite).booleanValue())
{
// If no namespace prefix was presented, then use the window id as the unique token
if (props.getProperty(RewriteHelper.NAMESPACE_PREFIX) != null)
{
prefix = props.getProperty(RewriteHelper.NAMESPACE_PREFIX);
}
}
// Rewrite the content only if it is a chars result
if (fragment.getType() == FragmentResult.TYPE_CHARS)
{
// Get the chars out of
StringWriter writer = fragment.getChars();
writer.flush();
String content = writer.toString();
// If there are any rewrite tokens in the content, and rewrite
// is requested (via the response props) then replace the rewrite token with a unique id
content = RewriteHelper.wsrpRewriteContent(content, prefix);
fragment.resetBuffer();
writer.write(content);
}
// If there is content that needs to be injected into the header, check if it needs rewrite as well
String headerChars = props.getProperty(RewriteHelper.HEADER_CONTENT);
if (headerChars != null)
{
headerChars = RewriteHelper.wsrpRewriteContent(headerChars, prefix);
}
*/
// Add declaratively injected header content here (get it via the component)
String headerChars = fragment.getHeader(); // Chris' modif: note that the header might to be re-written...
PortletContainer container = ((ContainerPortletInfo)render.getInfo()).getContainer();
JBossPortletMetaData portletMD = (JBossPortletMetaData)container.getJBossMetaData();
if (portletMD != null)
{
HeaderContentMetaData headerContent = portletMD.getHeaderContent();
if (headerContent != null)
{
String contextPath = container.getApplication().getContext().getContextPath();
StringWriter writer = new StringWriter(100);
if (headerChars != null)
{
writer.write(headerChars);
}
write(headerContent, writer, contextPath);
headerChars = writer.toString();
}
}
//
fragment.setHeader(headerChars);
}
}
protected void write(HeaderContentMetaData headerContent, StringWriter writer, String contextPath)
{
for (Iterator i = headerContent.getElements().iterator(); i.hasNext();)
{
HeaderContentMetaData.Element element = (HeaderContentMetaData.Element)i.next();
String elementType = element.getElementType();
//
writer.write("<");
writer.write(elementType);
//
String rel = element.getRel();
if (rel != null)
{
writer.write(" rel='");
writer.write(rel);
writer.write("'");
}
//
String src = element.getSrc();
if (src != null)
{
// adopt the context and inject a theme id param for the theme
// servlet to be able to pick up the resource from the correct theme
writer.write(" src='");
if (src.startsWith("/"))
{
writer.write(contextPath);
}
writer.write(src);
writer.write("'");
}
//
String type = element.getType();
if (type != null)
{
writer.write(" type='");
writer.write(type);
writer.write("'");
}
//
String href = element.getHref();
if (href != null)
{
// adopt the context and inject a theme id param for the theme
// servlet to be able to pick up the resource from the correct theme
writer.write(" href='");
if (href.startsWith("/"))
{
writer.write(contextPath);
}
writer.write(href);
writer.write("'");
}
//
String title = element.getTitle();
if (title != null && !"".equals(title))
{
writer.write(" title='");
writer.write(title);
writer.write("'");
}
//
String media = element.getMedia();
if (media != null && !"".equals(media))
{
writer.write(" media='");
writer.write(media);
writer.write("'");
}
//
String bodyContent = element.getBodyContent();
if (bodyContent != null && !"".equals(bodyContent))
{
writer.write(">");
writer.write(bodyContent);
writer.write("</");
writer.write(elementType);
writer.write(">");
}
else
{
writer.write(" />");
}
}
}
}
1.1 date: 2006/07/11 23:19:29; author: julien; state: Exp;jboss-portal/core/src/main/org/jboss/portal/core/aspects/portlet/TransactionInterceptor.java
Index: TransactionInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.core.aspects.portlet;
import org.jboss.portal.portlet.invocation.PortletInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.common.transaction.Transactions;
import org.jboss.portal.portlet.container.info.ContainerPortletInfo;
import org.jboss.portal.portlet.metadata.JBossPortletMetaData;
/**
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class TransactionInterceptor extends PortletInterceptor
{
protected void invoke(PortletInvocation invocation) throws Exception, InvocationException
{
// The default type is that it does not propagate
Transactions.Type txType = Transactions.TYPE_NOT_SUPPORTED;
// Override tx type if found
ContainerPortletInfo portlet = (ContainerPortletInfo)invocation.getInfo();
JBossPortletMetaData portletMD = portlet.getContainer().getJBossMetaData();
if (portletMD != null)
{
txType = portletMD.getTxType();
}
//
if (txType == Transactions.TYPE_NOT_SUPPORTED)
{
invokeNotSupported(invocation);
}
else if (txType == Transactions.TYPE_NEVER)
{
invokeNever(invocation);
}
else if (txType == Transactions.TYPE_MANDATORY)
{
invokeMandatory(invocation);
}
else if (txType == Transactions.TYPE_SUPPORTS)
{
invokeSupports(invocation);
}
else if (txType == Transactions.TYPE_REQUIRED)
{
invokeRequired(invocation);
}
else if (txType == Transactions.TYPE_REQUIRES_NEW)
{
invokeRequiresNew(invocation);
}
else
{
throw new InvocationException("Should not happen");
}
}
protected void invokeNotSupported(PortletInvocation invocation) throws Exception, InvocationException
{
invocation.invokeNext();
}
protected void invokeNever(PortletInvocation invocation) throws Exception, InvocationException
{
invocation.invokeNext();
}
protected void invokeMandatory(PortletInvocation invocation) throws Exception, InvocationException
{
invocation.invokeNext();
}
protected void invokeSupports(PortletInvocation invocation) throws Exception, InvocationException
{
invocation.invokeNext();
}
protected void invokeRequired(PortletInvocation invocation) throws Exception, InvocationException
{
invocation.invokeNext();
}
protected void invokeRequiresNew(PortletInvocation invocation) throws Exception, InvocationException
{
invocation.invokeNext();
}
}
More information about the jboss-cvs-commits
mailing list