com.fatwire.gst.foundation.url
Class LightweightAbstractAssembler

java.lang.Object
  extended by com.fatwire.gst.foundation.url.LightweightAbstractAssembler
All Implemented Interfaces:
com.fatwire.cs.core.uri.Assembler
Direct Known Subclasses:
WraPathAssembler, WraPathPreviewAssembler

public abstract class LightweightAbstractAssembler
extends Object
implements com.fatwire.cs.core.uri.Assembler

Lightweight abstract assembler that handles property management, provides a logger, handles encoding and decoding and query string processing. Much lighter in weight than com.fatwire.cs.core.uri.AbstractAssembler .

Since:
Sep 27, 2008
Author:
Tony Field

Field Summary
protected static org.apache.commons.logging.Log LOG
          Logger for use by sub-classes.
 
Fields inherited from interface com.fatwire.cs.core.uri.Assembler
LOG_NAME, PROP_PATH_PREFIX, PROP_URIBASE_BLOB_SERVER, PROP_URIBASE_CACHE_SERVER, PROP_URIBASE_CATALOG_MANAGER, PROP_URIBASE_CONTENT_SERVER, PROP_URIBASE_COOKIE_SERVER, PROP_URIBASE_DISPATCH_MANAGER, PROP_URIBASE_PAGE_DISPATCH_SERVER, PROP_URIBASE_SATELLITE_SERVER, PROP_URIBASE_SEED_DISPATCH_SERVER, PROP_URIBASE_SYNC_SEED_DISPATCH_SERVER, PROP_URIBASE_TREE_MANAGER
 
Constructor Summary
protected LightweightAbstractAssembler()
          Constructor.
 
Method Summary
protected  String constructQueryString(Map<String,String[]> parameters)
          Given an input map of name-value pairs, construct a query string.
protected static URI constructURI(String scheme, String authority, String path, String quotedQueryString, String fragment)
          The multi-arg java.net.URI constructors quote illegal characters.
protected  String decode(String string)
          URLDecodes a string using the encoding specified by this class.
protected  String decode(String string, String encoding)
          URLDecodes a string using the encoding specified.
protected  String encode(String string)
          URLEncodes a string using the encoding specified by this class.
protected  String[] excludeFromPackedargs(String[] origPackedargsStrings, Collection<String> toExclude)
          Given an array of query-string-like packed arguments, eliminate the specified parameters and return the packedargs parameter with the values stripped.
protected  String getProperty(String name, String dephault)
          Convenience method to get a property value set into the assembler from the configuration files.
protected  Map<String,String[]> parseQueryString(String qry)
          Parse a query string and put the parameters into a map.
 void setProperties(Properties props)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.fatwire.cs.core.uri.Assembler
assemble, disassemble
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Logger for use by sub-classes.

Constructor Detail

LightweightAbstractAssembler

protected LightweightAbstractAssembler()
Constructor. Upon object construction, support for UTF-8 encoding is tested, and the result is cached for future use in the encode() and decode() methods.

UTF-8 is the recommended URLEncoding:

Method Detail

setProperties

public void setProperties(Properties props)
Specified by:
setProperties in interface com.fatwire.cs.core.uri.Assembler

getProperty

protected String getProperty(String name,
                             String dephault)
Convenience method to get a property value set into the assembler from the configuration files.

Parameters:
name - name of property to import
dephault - default value of property - returned if the property value is not specified
Returns:
property value or dephault value

encode

protected final String encode(String string)
URLEncodes a string using the encoding specified by this class.

Parameters:
string - the string to encode
Returns:
encoded string
Throws:
IllegalStateException - if UTF-8 encoding is not supported and the platform's default encoding is not supported.

decode

protected final String decode(String string)
URLDecodes a string using the encoding specified by this class.

Parameters:
string - encoded string
Returns:
decoded string
Throws:
IllegalStateException - if UTF-8 encoding is not supported and the platform's default encoding is not supported.
IllegalArgumentException - if the string is not well-formed for decoding.

decode

protected final String decode(String string,
                              String encoding)
URLDecodes a string using the encoding specified.

Parameters:
string - encoded string
encoding - the encoding to use to decode the string. If null is specified, the decoding specified by this class shall be used.
Returns:
decoded string
Throws:
IllegalStateException - if the encoding specified is not supported, or if UTF-8 encoding is not supported and the platform's default encoding is not supported.
IllegalArgumentException - if the string is not well-formed for decoding.

constructURI

protected static final URI constructURI(String scheme,
                                        String authority,
                                        String path,
                                        String quotedQueryString,
                                        String fragment)
                                 throws URISyntaxException
The multi-arg java.net.URI constructors quote illegal characters. However, this class requires that the query string already be properly URLEncoded. As a result, we can't use the multi-arg URI constructor because all of our % symbols and the + symbol will end up getting double-encoded. So, we need to construct a full URL ourselves so we can use the single-arg URI constructor, because it does not quote anything.

There are multiple variants of combinations of these parameters to create a valid URL. Consult the URI specificaiton for what is allowed and what is not. The URI constructor will throw a URISyntaxException if required components are missing for a given combination.

Parameters:
scheme - the URI scheme (protocol)
authority - the URI authority (host:port)
path - the path for the URI (servlet context path, servlet name, pathinfo)
quotedQueryString - the query string, with illegal characters already quoted.
fragment - the fragment (anchor)
Returns:
the valid URI with proper encoding
Throws:
URISyntaxException - if there is a problem with what is passed in

parseQueryString

protected final Map<String,String[]> parseQueryString(String qry)
Parse a query string and put the parameters into a map. Input parameters will be URLDecoded prior to their addition into the resultant map.

Note that the map returned contains a String[] as the value, not a single String value This provides support for query strings with multiple values for a given parameter name.

This decoding method is smart enough to be able to interpret the _charset_ URL parameter that is often used by IE.

Parameters:
qry -
Returns:
map containing String/String[] pairs.
Throws:
IllegalArgumentException - if there are mistakes in the string that make it impossible to parse.

constructQueryString

protected final String constructQueryString(Map<String,String[]> parameters)
Given an input map of name-value pairs, construct a query string. This supports multiple values for any given parameter. Names and values are properly encoded.

Parameters:
parameters - parameters to encode and place in the query string
Returns:
the query string, or null if no values needed to be added.
See Also:
encode(String)

excludeFromPackedargs

protected final String[] excludeFromPackedargs(String[] origPackedargsStrings,
                                               Collection<String> toExclude)
Given an array of query-string-like packed arguments, eliminate the specified parameters and return the packedargs parameter with the values stripped.

Parameters:
origPackedargsStrings - array of query string-like packed args.
toExclude - list of args to remove from the packed args.
Returns:
array the same length as the original array, containing the same values, except the toExclude parameters are removed. If all params end up getting removed, the packedargs string ends up being null. The array returned is never null though.
Throws:
IllegalArgumentException - if the input args or the input list are null.


Copyright © 2010-2013 Oracle Corporation. All Rights Reserved.