ikrs.io.fileio.htaccess
Class HypertextAccessFile

java.lang.Object
  extended by ikrs.io.fileio.htaccess.HypertextAccessFile

public class HypertextAccessFile
extends java.lang.Object

This is a simple class for reading htaccess files.


Constructor Summary
protected HypertextAccessFile()
          This class cannot be instantiated directly; it's only meant for reading files.
 
Method Summary
 java.util.Map<java.lang.String,java.lang.String> getAddedCharsets()
          This method returns the file that was set by the "AddCharset" directive(s).
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getAddedHandlers()
          This method returns the file that was set by the "AddHandler" directive(s).
 java.util.Map<java.lang.String,java.lang.String> getAddedTypes()
          This method returns the file that was set by the "AddType" directive(s).
 java.io.File getAuthGroupFile()
          This method returns the file that was set by the "AuthGroupFile" directive (or null if not set).
 java.lang.String getAuthName()
          This method returns the value from the "AuthName" directive or null if not set.
 java.lang.String getAuthType()
          This method returns the value from the "AuthType" directive or null if not set.
 java.io.File getAuthUserFile()
          This method returns the file that was set by the "AuthUserFile" directive (or null if not set).
 java.lang.String getDefaultCharset()
          This method returns the charset that was set by the "AddDefaultCharset" directive (or null if not set).
 java.util.List<java.lang.String> getDirectoryIndexList()
          This method returns the file names that were set by the "DirectoryUndex" directive(s).
 java.util.Map<java.lang.Integer,java.lang.String> getErrorDocumentMap()
          This method returns the status code/error document map defined by all "ErrorDocument" directive(s).
 java.util.Map<java.lang.String,java.lang.Boolean> getOptions()
          This method returns the file that was set by the "Option" directive(s).
 java.util.List<java.lang.String> getRequiredGroups()
          This method returns the file that was set by the "Require Group" directive(s).
 java.util.List<java.lang.String> getRequiredUsers()
          This method returns the file that was set by the "Require User" directive(s).
 java.lang.String getSetHandler()
          This method returns the name that was set by the "SetHandler" directive(s).
 java.io.File getSourceFile()
          This method returns the source file the htaccess configuration was read from.
static void main(java.lang.String[] argv)
          For testing only.
 void merge(HypertextAccessFile mergeFrom)
          This method merges all non-empty settings from the passed hypertext access file.
static HypertextAccessFile read(java.io.File file, boolean strictMode)
          Reads the htaccess configuration from the given file.
static HypertextAccessFile read(java.io.InputStream in, boolean strictMode)
          Reads the htaccess configuration from the given inputstream.
static HypertextAccessFile read(java.io.LineNumberReader lnr, boolean strictMode)
          Reads the htaccess configuration from the given line number reader.
 boolean requiresValidUser()
          This method returns the flag that is set by the "Require valid-user" directive.
 java.lang.String toString()
           
 java.lang.StringBuffer toString(java.lang.StringBuffer b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HypertextAccessFile

protected HypertextAccessFile()
This class cannot be instantiated directly; it's only meant for reading files. Use the read() method instead.

Method Detail

read

public static HypertextAccessFile read(java.io.File file,
                                       boolean strictMode)
                                throws java.io.IOException,
                                       java.text.ParseException
Reads the htaccess configuration from the given file.

Parameters:
file - The input file (must be a text file in .htaccess format).
strictMode - If this mode is set to true the reader will NOT ignore any unknown/unexpected irregularities but throw a ParseException. There are even some un-handled keywords which still lack some implementation (set to false if you want to ignore them).
Throws:
java.io.IOException - If any IO errors occur.
java.text.ParseException - If the passed file cannot be parsed or is not a htaccess file.

read

public static HypertextAccessFile read(java.io.InputStream in,
                                       boolean strictMode)
                                throws java.io.IOException,
                                       java.text.ParseException
Reads the htaccess configuration from the given inputstream.

Parameters:
in - The input stream (must deliver a text file in .htaccess format).
strictMode - If this mode is set to true the reader will NOT ignore any unknown/unexpected irregularities but throw a ParseException. There are even some un-handled keywords which still lack some implementation (set to false if you want to ignore them).
Throws:
java.io.IOException - If any IO errors occur.
java.text.ParseException - If the passed data cannot be parsed or is not a htaccess file.

read

public static HypertextAccessFile read(java.io.LineNumberReader lnr,
                                       boolean strictMode)
                                throws java.io.IOException,
                                       java.text.ParseException
Reads the htaccess configuration from the given line number reader.

Parameters:
lnr - The line number reader to read the data from (must deliver a text file in .htaccess format).
strictMode - If this mode is set to true the reader will NOT ignore any unknown/unexpected irregularities but throw a ParseException. There are even some un-handled keywords which still lack some implementation (set to false if you want to ignore them).
Throws:
java.io.IOException - If any IO errors occur.
java.text.ParseException - If the passed data cannot be parsed or is not a htaccess file.

getSourceFile

public java.io.File getSourceFile()
This method returns the source file the htaccess configuration was read from.

Returns:
The source file the htaccess configuration was read from.

getAuthType

public java.lang.String getAuthType()
This method returns the value from the "AuthType" directive or null if not set.

Returns:
The value from the "AuthType" directive or null if not set.

getAuthName

public java.lang.String getAuthName()
This method returns the value from the "AuthName" directive or null if not set.

Returns:
The value from the "Authname" directive or null if not set.

getAuthUserFile

public java.io.File getAuthUserFile()
This method returns the file that was set by the "AuthUserFile" directive (or null if not set).

Returns:
The file that was set by the "AuthUserFile" directive (or null if not set).

getAuthGroupFile

public java.io.File getAuthGroupFile()
This method returns the file that was set by the "AuthGroupFile" directive (or null if not set).

Returns:
The file that was set by the "AuthGroupFile" directive (or null if not set).

getRequiredGroups

public java.util.List<java.lang.String> getRequiredGroups()
This method returns the file that was set by the "Require Group" directive(s).

Returns:
The file that was set by the "Require Group" directive(s). The returned List is never null.

getRequiredUsers

public java.util.List<java.lang.String> getRequiredUsers()
This method returns the file that was set by the "Require User" directive(s).

Returns:
The file that was set by the "Require User" directive(s). The returned List is never null.

requiresValidUser

public boolean requiresValidUser()
This method returns the flag that is set by the "Require valid-user" directive.

Returns:
The flag that is set by the "Require valid-user" directive.

getAddedTypes

public java.util.Map<java.lang.String,java.lang.String> getAddedTypes()
This method returns the file that was set by the "AddType" directive(s). The mapping is: Extension -> MIME type.

Returns:
The file that was set by the "AddType" directive(s). The returned Map is never null.

getOptions

public java.util.Map<java.lang.String,java.lang.Boolean> getOptions()
This method returns the file that was set by the "Option" directive(s). The mapping is: OptionName -> true|false

Returns:
The file that was set by the "Option" directive(s). The returned Map is never null.

getSetHandler

public java.lang.String getSetHandler()
This method returns the name that was set by the "SetHandler" directive(s). If there were more than one 'SetHandeler' directives (only allowed in non-strict mode) the last name is returned.

Returns:
The file that was set by the "SetHandler" directive(s) or null if not available.

getAddedHandlers

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getAddedHandlers()
This method returns the file that was set by the "AddHandler" directive(s). The mapping is: HandlerName -> ExtensionList

Returns:
The file that was set by the "AddHandler" directive(s). The returned List is never null.

getDefaultCharset

public java.lang.String getDefaultCharset()
This method returns the charset that was set by the "AddDefaultCharset" directive (or null if not set).

Returns:
The charset that was set by the "AddDefaultCharset" directive (or null if not set).

getAddedCharsets

public java.util.Map<java.lang.String,java.lang.String> getAddedCharsets()
This method returns the file that was set by the "AddCharset" directive(s). The mapping is: File-Extension -> Charset

Returns:
The file that was set by the "AddCharset" directive(s). The returned List is never null.

getDirectoryIndexList

public java.util.List<java.lang.String> getDirectoryIndexList()
This method returns the file names that were set by the "DirectoryUndex" directive(s).

Returns:
The file names that were set by the "DirectoryUndex" directive(s).

getErrorDocumentMap

public java.util.Map<java.lang.Integer,java.lang.String> getErrorDocumentMap()
This method returns the status code/error document map defined by all "ErrorDocument" directive(s).

Returns:
The status code/error document map defined by all "ErrorDocument" directive(s).

merge

public void merge(HypertextAccessFile mergeFrom)
           throws java.lang.NullPointerException
This method merges all non-empty settings from the passed hypertext access file. The settings will be copied from 'mergeFrom' into this object. Existing settings will be overwritten.

Parameters:
mergeFrom - The hypertext access file containing the settings to be merge into this (must not be null).
Throws:
java.lang.NullPointerException - If mergeFrom param is null.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.StringBuffer toString(java.lang.StringBuffer b)

main

public static void main(java.lang.String[] argv)
For testing only.