org.apache.cocoon.portal.transformation
Class LinkTransformer

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.xml.AbstractXMLProducer
          extended by org.apache.cocoon.xml.AbstractXMLPipe
              extended by org.apache.cocoon.transformation.AbstractTransformer
                  extended by org.apache.cocoon.portal.transformation.LinkTransformer
All Implemented Interfaces:
Poolable, Recyclable, Component, LogEnabled, Serviceable, SitemapModelComponent, Transformer, XMLPipe, XMLProducer, XMLConsumer, ContentHandler, LexicalHandler

public class LinkTransformer
extends AbstractTransformer
implements Serviceable

This Transformer deals with tags containing links to external applications that need to be converted so that not the external application will be called directly but the request gets routed via the cocoon portal (either via proxy transformer or proxy reader). The link transformer therefore cooperates with the event link transformer. Tags that include a link for which a link event needs to be generated will be converted to <eventlink> elements. Examples:

 <img src="images/logo.jpg"> will be converted to use the proxy reader:
 <img src="proxy-images/logo.jpg&cocoon-portal-copletid=xxx&cocoon-portal-portalname=yyy
 
<form action="/submitted.jsp"> will be converted to be processed by the event link transformer <eventlink action="/submitted.jsp" attribute="action" element="form">

Version:
CVS $Id: LinkTransformer.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Gernot Koller, Friedrich Klenner

Field Summary
protected  String copletIdParamString
          Used for appending a request parameter containing the coplet id
protected  CopletInstanceData copletInstanceData
          The coplet instance data
protected  String documentBase
          The html document base uri
protected  Stack elementStack
          Used to store elements' name between startTransformingElement and endTransformingElement.
protected  boolean ignoreTargetSelf
          Handle target self as no target?
protected  ServiceManager manager
          The avalon service manager
static String NAMESPACE_PREFIX
          Namespace prefix usef vor NewEventLinkTransformer-Namespace
protected  String portalNameParamString
          Used for appending a request parameter containing the portal name
protected  String prefix
          The prefix
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.transformation.Transformer
ROLE
 
Constructor Summary
LinkTransformer()
           
 
Method Summary
protected  String buildUrlString(String uri, boolean applyPrefixAndPortalParams)
          Retrieves and stores any session token, appends proxy reader prefix and parameters if necessary
 void endDocument()
          Receive notification of the end of a document.
 void endElement(String uri, String name, String raw)
          Receive notification of the end of an element.
 void handleTag(String attributeName, String uri, String elementName, String raw, Attributes attributes, boolean eventLink, boolean direct)
          The handleTag method is responsible for preparing tags so that they can either be conveted to link events by the event link transformer or that the proxy reader is called directly.
protected  Attributes modifyLinkAttribute(String attribute, String remoteURI, Attributes attributes)
          Replaces the link of given attribute whith the new uri.
 void recycle()
          Recycle this component.
 void service(ServiceManager manager)
           
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
          Set the SourceResolver, objectModel Map, the source and sitemap Parameters used to process the request.
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(String uri, String name, String raw, Attributes attributes)
          Receive notification of the beginning of an element.
protected  void startEventLinkElement(String element, String attribute, Attributes attributes)
          Replaces the given element with an eventlink element adding the attribute and element attribute within the SAX stream.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
characters, comment, endCDATA, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDTD, startEntity, startPrefixMapping
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Field Detail

NAMESPACE_PREFIX

public static final String NAMESPACE_PREFIX
Namespace prefix usef vor NewEventLinkTransformer-Namespace

See Also:
Constant Field Values

copletIdParamString

protected String copletIdParamString
Used for appending a request parameter containing the coplet id


portalNameParamString

protected String portalNameParamString
Used for appending a request parameter containing the portal name


copletInstanceData

protected CopletInstanceData copletInstanceData
The coplet instance data


documentBase

protected String documentBase
The html document base uri


elementStack

protected Stack elementStack
Used to store elements' name between startTransformingElement and endTransformingElement.


manager

protected ServiceManager manager
The avalon service manager


prefix

protected String prefix
The prefix


ignoreTargetSelf

protected boolean ignoreTargetSelf
Handle target self as no target?

Constructor Detail

LinkTransformer

public LinkTransformer()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws ProcessingException,
                  SAXException,
                  IOException
Description copied from interface: SitemapModelComponent
Set the SourceResolver, objectModel Map, the source and sitemap Parameters used to process the request.

Specified by:
setup in interface SitemapModelComponent
Throws:
ProcessingException
SAXException
IOException
See Also:
SitemapModelComponent.setup(SourceResolver, Map, String, Parameters)

recycle

public void recycle()
Recycle this component. All instance variables are set to null.

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractXMLProducer

startDocument

public void startDocument()
                   throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the beginning of a document.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class AbstractXMLPipe
Throws:
SAXException
See Also:
ContentHandler.startDocument()

endDocument

public void endDocument()
                 throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the end of a document.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class AbstractXMLPipe
Throws:
SAXException
See Also:
ContentHandler.endDocument()

startElement

public void startElement(String uri,
                         String name,
                         String raw,
                         Attributes attributes)
                  throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the beginning of an element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
name - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
attributes - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException
See Also:
ContentHandler.startElement(String, String, String, Attributes)

endElement

public void endElement(String uri,
                       String name,
                       String raw)
                throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the end of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
name - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
Throws:
SAXException
See Also:
ContentHandler.endElement(String, String, String)

handleTag

public void handleTag(String attributeName,
                      String uri,
                      String elementName,
                      String raw,
                      Attributes attributes,
                      boolean eventLink,
                      boolean direct)
               throws SAXException
The handleTag method is responsible for preparing tags so that they can either be conveted to link events by the event link transformer or that the proxy reader is called directly. Tags with absolute links (starting with "http://", "ftp://", etc.) will not be touched. Tags which contain a target attribute will be modified to call the uri directly (no proxy reader or proxy transformer involved). Tags (like <a href="uri"&ht; or <form action="uri">, etc.) that require a link event will be converted to <eventlink> elements, so that the event link transformer can create the necessary link event and the proxy transformer will be used. Tags (like <img src="uri">) that shoud call the proxy reader will be converted to do so. Examples:

 <a href="http://www.somewhere.com"> will not be converted because of absolute url
 
<img src="images/logo.jpg"> will be converted to use the proxy reader: <img src="proxy-images/logo.jpg&cocoon-portal-copletid=xxx&cocoon-portal-portalname=yyy
<form action="/submitted.jsp"> will be converted to use proxy transformer: <eventlink action="/submitted.jsp" attribute="action" element="form">

Parameters:
attributeName - Name oft the attribute containing the link to be converted
uri - Namespace URI
elementName - Name of the element (tag)
raw - Raw name of the element (including namespace prefix)
attributes - Attributes of the element
eventLink - True signals that the tag sould be converted to an event link tag.
direct - True signals that the uri should point directly to the external resource (no proxys)
Throws:
SAXException - if an invalid URL was detected.

modifyLinkAttribute

protected Attributes modifyLinkAttribute(String attribute,
                                         String remoteURI,
                                         Attributes attributes)
Replaces the link of given attribute whith the new uri.

Parameters:
attribute - Name of the attribute containing the link
remoteURI - The new uri
attributes - List of attributes
Returns:
The modified List of attributes

startEventLinkElement

protected void startEventLinkElement(String element,
                                     String attribute,
                                     Attributes attributes)
                              throws SAXException
Replaces the given element with an eventlink element adding the attribute and element attribute within the SAX stream.

Parameters:
element - Original name of the element
attribute - Name of the attribute containing the link
attributes - Original list of attributes
Throws:
SAXException

buildUrlString

protected String buildUrlString(String uri,
                                boolean applyPrefixAndPortalParams)
Retrieves and stores any session token, appends proxy reader prefix and parameters if necessary

Parameters:
uri - the url to be converted
applyPrefixAndPortalParams - true signals that the url should be converted to call the proxy-reader
Returns:
the converted uri FIXME: anchors (#) should be treated right!


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.