org.apache.cocoon.portal.transformation
Class ProxyTransformer

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.ProxyTransformer
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, LogEnabled, Parameterizable, Serviceable, SitemapModelComponent, Transformer, XMLPipe, XMLProducer, XMLConsumer, ContentHandler, LexicalHandler

public class ProxyTransformer
extends AbstractTransformer
implements Serviceable, Disposable, Parameterizable

This transformer is used to insert the XHTML data from an request to an external application at the specified element ("envelope-tag" parameter). Nesessary connection data for the external request like sessionid, cookies, documentbase, the uri, etc. will be taken from the application coplet instance data.

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

Field Summary
protected  int configuredEncoding
          The encoding (JTidy constant) if configured
static String COOKIE
           
static String COPLET_ID_PARAM
           
static String COPLETID
           
protected  CopletInstanceData copletInstanceData
          The coplet instance data
protected  String defaultEnvelopeTag
          The default value for the envelope Tag
static String DOCUMENT_BASE
           
protected  String documentBase
          The document base uri
static String ENVELOPE_TAG_PARAMETER
          Parameter for specifying the envelope tag
protected  String envelopeTag
          This tag will include the external XHMTL
protected  InputModuleHelper imHelper
          Helper for resolving input modules.
protected  String link
          The current link to the external application
static String LINK
           
protected  ServiceManager manager
          The Avalon component manager
protected  Parameters parameters
          The sitemap parameters
static String PORTAL_NAME_PARAM
           
static String PORTALNAME
           
static String PROTOCOL_HANDLER_PARAMETER
          Parameter for specifying the java protocol handler (used for https)
static String PROXY_PREFIX
           
protected  Request request
          The original request to the portal
static String SESSIONTOKEN
           
static String START_URI
           
protected  String userAgent
          The user agent identification string if confiugured
 
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
ProxyTransformer()
           
 
Method Summary
protected  boolean appendParameter(StringBuffer buffer, boolean firstparameter, boolean post, String name, String value)
           
protected  String checkForRedirect(Document doc, String documentBase)
          Analyses the XHTML response document for redirects in <meta http-equiv="refresh"> elements.
protected  String checkForRedirect(HttpURLConnection connection, String documentBase)
          Check the http status code of the http response to detect any redirects.
protected  HttpURLConnection connect(Request request, String uri, String query, boolean post)
          Establish the HttpURLConnection to the given uri.
 void dispose()
           
static CopletInstanceData getInstanceData(ServiceManager manager, Map objectModel, Parameters parameters)
          Method getInstanceData.
static CopletInstanceData getInstanceData(ServiceManager manager, String copletID, String portalName)
           
 void parameterize(Parameters parameters)
          For the proxy transformer the envelope-tag parameter can be specified.
protected  void processRequest()
          Processes the request to the external application
protected  Document readXML(HttpURLConnection connection)
          Reads the HTML document from given connection and returns a correct W3C DOM XHTML document
 void recycle()
          Recycle the producer by removing references, and resetting handlers to null (empty) implementations.
static String resolveURI(String uri, String documentBase)
          Resolve the possibly relative uri to an absolue uri based on given document base.
 void service(ServiceManager manager)
           
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
          Set the SourceResolver, objectModel Map, the source and sitemap Parameters used to process the request.
 void startElement(String uri, String name, String raw, Attributes attributes)
          Receive notification of the beginning of an element.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
characters, comment, endCDATA, endDocument, endDTD, endElement, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDocument, 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, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, 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

ENVELOPE_TAG_PARAMETER

public static final String ENVELOPE_TAG_PARAMETER
Parameter for specifying the envelope tag

See Also:
Constant Field Values

PORTALNAME

public static final String PORTALNAME
See Also:
Constant Field Values

COPLETID

public static final String COPLETID
See Also:
Constant Field Values

PROXY_PREFIX

public static final String PROXY_PREFIX
See Also:
Constant Field Values

COPLET_ID_PARAM

public static final String COPLET_ID_PARAM
See Also:
Constant Field Values

PORTAL_NAME_PARAM

public static final String PORTAL_NAME_PARAM
See Also:
Constant Field Values

SESSIONTOKEN

public static final String SESSIONTOKEN
See Also:
Constant Field Values

COOKIE

public static final String COOKIE
See Also:
Constant Field Values

START_URI

public static final String START_URI
See Also:
Constant Field Values

LINK

public static final String LINK
See Also:
Constant Field Values

DOCUMENT_BASE

public static final String DOCUMENT_BASE
See Also:
Constant Field Values

PROTOCOL_HANDLER_PARAMETER

public static final String PROTOCOL_HANDLER_PARAMETER
Parameter for specifying the java protocol handler (used for https)

See Also:
Constant Field Values

documentBase

protected String documentBase
The document base uri


link

protected String link
The current link to the external application


defaultEnvelopeTag

protected String defaultEnvelopeTag
The default value for the envelope Tag


envelopeTag

protected String envelopeTag
This tag will include the external XHMTL


manager

protected ServiceManager manager
The Avalon component manager


copletInstanceData

protected CopletInstanceData copletInstanceData
The coplet instance data


request

protected Request request
The original request to the portal


configuredEncoding

protected int configuredEncoding
The encoding (JTidy constant) if configured


userAgent

protected String userAgent
The user agent identification string if confiugured


parameters

protected Parameters parameters
The sitemap parameters


imHelper

protected InputModuleHelper imHelper
Helper for resolving input modules.

Constructor Detail

ProxyTransformer

public ProxyTransformer()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException
See Also:
Serviceable.service(org.apache.avalon.framework.service.ServiceManager)

dispose

public void dispose()
Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()

parameterize

public void parameterize(Parameters parameters)
For the proxy transformer the envelope-tag parameter can be specified.

Specified by:
parameterize in interface Parameterizable
See Also:
Parameterizable.parameterize(Parameters)

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters parameters)
           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()
Description copied from class: AbstractXMLProducer
Recycle the producer by removing references, and resetting handlers to null (empty) implementations.

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractXMLProducer
See Also:
Recyclable.recycle()

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)

processRequest

protected void processRequest()
                       throws SAXException
Processes the request to the external application

Throws:
SAXException

appendParameter

protected boolean appendParameter(StringBuffer buffer,
                                  boolean firstparameter,
                                  boolean post,
                                  String name,
                                  String value)
                           throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

checkForRedirect

protected String checkForRedirect(HttpURLConnection connection,
                                  String documentBase)
                           throws IOException
Check the http status code of the http response to detect any redirects.

Parameters:
connection - The HttpURLConnection
documentBase - The current documentBase (needed for relative redirects)
Returns:
the redirected URL or null if no redirects are detected.
Throws:
IOException - if exceptions occure while analysing the response

checkForRedirect

protected String checkForRedirect(Document doc,
                                  String documentBase)
                           throws MalformedURLException
Analyses the XHTML response document for redirects in <meta http-equiv="refresh"> elements.

Parameters:
doc - The W3C DOM document containing the XHTML response
documentBase - The current document base (needed for relative redirects)
Returns:
String the redirected URL or null if no redirects are detected.
Throws:
MalformedURLException - if the redirect uri is malformed.

readXML

protected Document readXML(HttpURLConnection connection)
                    throws SAXException
Reads the HTML document from given connection and returns a correct W3C DOM XHTML document

Parameters:
connection - hte HttpURLConnection to read from
Returns:
the result as valid W3C DOM XHTML document
Throws:
SAXException

connect

protected HttpURLConnection connect(Request request,
                                    String uri,
                                    String query,
                                    boolean post)
                             throws IOException
Establish the HttpURLConnection to the given uri. User-Agent, Accept-Language and Encoding headers will be copied from the original request, if no other headers are specified.

Parameters:
request - the original request
uri - the remote uri
query - the remote query string
post - true if request method was POST
Returns:
the established HttpURLConnection
Throws:
IOException - on any exception

resolveURI

public static String resolveURI(String uri,
                                String documentBase)
                         throws MalformedURLException
Resolve the possibly relative uri to an absolue uri based on given document base.

Parameters:
uri - the uri to resolve
documentBase - the current document base
Returns:
returns an absolute URI based on document base (e.g. http://mydomain.com/some/file.html)
Throws:
MalformedURLException - if uri or document base is malformed.

getInstanceData

public static CopletInstanceData getInstanceData(ServiceManager manager,
                                                 String copletID,
                                                 String portalName)
                                          throws ProcessingException
Throws:
ProcessingException

getInstanceData

public static CopletInstanceData getInstanceData(ServiceManager manager,
                                                 Map objectModel,
                                                 Parameters parameters)
                                          throws ProcessingException
Method getInstanceData.

Parameters:
manager -
objectModel -
parameters -
Returns:
CopletInstanceData
Throws:
ProcessingException


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