org.weborganic.bastille.pageseeder
Class PSConnection

java.lang.Object
  extended by org.weborganic.bastille.pageseeder.PSConnection

public final class PSConnection
extends Object

Wraps an HTTP connection to PageSeeder.

Since:
0.6.7

Nested Class Summary
static class PSConnection.Type
          The type of connection.
 
Method Summary
 void addXMLPart(String part)
          Add a part to the request (write the contents directly to the stream).
 void addXMLPart(String part, Map<String,String> headers)
          Add a part to the request (write the contents directly to the stream).
 void closeOutput()
          Closes the output stream when writing to the connection.
 HttpURLConnection connection()
          Returns the underlying HTTP connection.
 void disconnect()
          Deprecated. There is no need to call this method; the socket will be recycled.
 String getContentType()
          Returns the content type of the underlying HTTP connection.
 int getResponseCode()
          Returns the response code of the underlying HTTP connection.
 String getResponseMessage()
          Returns the response message of the underlying HTTP connection.
 boolean process(XMLWriter xml)
          Process the specified PageSeeder connection.
 boolean process(XMLWriter xml, PSHandler handler)
          Process the specified PageSeeder connection.
 boolean process(XMLWriter xml, Templates templates)
          Process the specified PageSeeder connection.
 boolean process(XMLWriter xml, Templates templates, Map<String,String> parameters)
          Process the specified PageSeeder connection.
 PSResource resource()
          Returns the PageSeeder resource corresponding to the URL.
 PSConnection.Type type()
          Returns the type of connection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addXMLPart

public void addXMLPart(String part)
                throws IOException
Add a part to the request (write the contents directly to the stream).

Parameters:
part - The encoding to specify in the Part's header
Throws:
IOException - Should any error occur while writing the part on the output

addXMLPart

public void addXMLPart(String part,
                       Map<String,String> headers)
                throws IOException
Add a part to the request (write the contents directly to the stream).

Parameters:
part - The encoding to specify in the Part's header
headers - A list of headers added to this XML Part ('content-type' header is ignored)
Throws:
IOException - Should any error occur while writing

closeOutput

public void closeOutput()
                 throws IOException
Closes the output stream when writing to the connection.

This method does nothing if the output stream hasn't been created.

Throws:
IOException - If thrown by the close method.

getResponseCode

public int getResponseCode()
                    throws IOException
Returns the response code of the underlying HTTP connection.

Returns:
the response code of the underlying HTTP connection.
Throws:
IOException - If thrown by the underlying HTTP connection.
See Also:
HttpURLConnection.getResponseCode()

getResponseMessage

public String getResponseMessage()
                          throws IOException
Returns the response message of the underlying HTTP connection.

Returns:
the response message of the underlying HTTP connection.
Throws:
IOException - If thrown by the underlying HTTP connection.
See Also:
HttpURLConnection.getResponseMessage()

getContentType

public String getContentType()
                      throws IOException
Returns the content type of the underlying HTTP connection.

Returns:
the content type of the underlying HTTP connection.
Throws:
IOException - If thrown by the underlying HTTP connection.
See Also:
URLConnection.getContentType()

disconnect

@Deprecated
public void disconnect()
Deprecated. There is no need to call this method; the socket will be recycled.

Disconnects the underlying HTTP connection.

See Also:
HttpURLConnection.disconnect()

connection

public HttpURLConnection connection()
Returns the underlying HTTP connection.

This method can be useful to perform additional operations on the connection which are not provided by this class.

Returns:
the underlying HTTP connection.

resource

public PSResource resource()
Returns the PageSeeder resource corresponding to the URL.

Returns:
the PageSeeder resource corresponding to the URL.

type

public PSConnection.Type type()
Returns the type of connection.

Returns:
the type of connection.

process

public boolean process(XMLWriter xml)
                throws IOException
Process the specified PageSeeder connection.

If the handler is not specified, the xml writer receives a copy of the PageSeeder XML.

Parameters:
xml - the XML to copy from PageSeeder
Returns:
true if the request was processed without errors; false otherwise.
Throws:
IOException - If an error occurs when trying to write the XML.

process

public boolean process(XMLWriter xml,
                       PSHandler handler)
                throws IOException
Process the specified PageSeeder connection.

If the handler is not specified, the xml writer receives a copy of the PageSeeder XML.

Parameters:
xml - the XML to copy from PageSeeder
handler - the handler for the XML (can be used to rewrite the XML)
Returns:
true if the request was processed without errors; false otherwise.
Throws:
IOException - If an error occurs when trying to write the XML.

process

public boolean process(XMLWriter xml,
                       Templates templates)
                throws IOException
Process the specified PageSeeder connection.

Templates can be specified to transform the XML.

Parameters:
xml - The XML to copy from PageSeeder
templates - A set of templates to process the XML (optional)
Returns:
true if the request was processed without errors; false otherwise.
Throws:
IOException - If an error occurs when trying to write the XML.

process

public boolean process(XMLWriter xml,
                       Templates templates,
                       Map<String,String> parameters)
                throws IOException
Process the specified PageSeeder connection.

Templates can be specified to transform the XML.

Parameters:
xml - The XML to copy from PageSeeder
templates - A set of templates to process the XML (optional)
parameters - Parameters to send to the XSLT transformer (optional)
Returns:
true if the request was processed without errors; false otherwise.
Throws:
IOException - If an error occurs when trying to write the XML.