com.izforge.izpack.installer
Class WebRepositoryAccessor

java.lang.Object
  extended by com.izforge.izpack.installer.WebRepositoryAccessor

public class WebRepositoryAccessor
extends java.lang.Object

This class enumerates the availabe packs at the web repository. Parses the config files - install.xml, packsinfo.xml, langpacks and is used to override the static configuration in the installer jar.

Version:
$Revision: 1.1 $
Author:
Vladimir Ralev

Field Summary
private  java.lang.String baseUrl
          Base repository URL
private static int BUFFER_SIZE
          Files being downloaded in the buffer, 1MB max
private static java.lang.String installFilename
          Files to be looked for at the repository base url
private  java.lang.String installXmlString
          install.xml
private  java.lang.String installXmlUrl
          URL to remote install.xml
private static boolean NO
          Constant for checking attributes.
private  java.util.ArrayList<PackInfo> packs
          list of PackInfo entries
private  java.lang.String packsInfo
          packsinfo.xml contains nbytes, pack name and pack id
private static java.lang.String packsinfoFilename
           
private static boolean YES
          Constant for checking attributes.
 
Constructor Summary
WebRepositoryAccessor(java.lang.String urlbase)
          Create a new WebRepositoryAccessor.
 
Method Summary
static java.lang.String getCachedUrl(java.lang.String url, java.lang.String tempFolder)
          First download the jar file.
 java.util.ArrayList<PackInfo> getOnlinePacks()
          Get the list of the packs from the remore install.xml
protected  java.util.ArrayList<PackInfo> loadPacksList(XMLElement data)
           
protected  void parseError(java.lang.String message)
          Create parse error with consistent messages.
protected  void parseError(XMLElement parent, java.lang.String message)
          Create parse error with consistent messages.
protected  void parseError(XMLElement parent, java.lang.String message, java.lang.Throwable cause)
          Create a chained parse error with consistent messages.
private  java.util.ArrayList<PackInfo> parsePacks()
          Parse install.xml and return the list of packs
private  void parsePacksInfo()
          Parse packsinfo.xml, fill the nbytes field, which is not available at runtime otherwise.
protected  void parseWarn(XMLElement parent, java.lang.String message)
          Create a parse warning with consistent messages.
private  void readConfig()
          Reads the install.xml into confgiString
private  void readPacksInfo()
          Reads packsinfo.xml
protected  java.lang.String requireAttribute(XMLElement element, java.lang.String attribute)
          Call getAttribute on an element, producing a meaningful error message if not present, or empty.
protected  XMLElement requireChildNamed(XMLElement parent, java.lang.String name)
          Call getFirstChildNamed on the parent, producing a meaningful error message on failure.
protected  java.lang.String requireContent(XMLElement element)
          Call getContent on an element, producing a meaningful error message if not present, or empty.
protected  int requireIntAttribute(XMLElement element, java.lang.String attribute)
          Get a required attribute of an element, ensuring it is an integer.
protected  java.net.URL requireURLContent(XMLElement element)
          Call getContent on an element, producing a meaningful error message if not present, or empty, or a valid URL.
protected  boolean requireYesNoAttribute(XMLElement element, java.lang.String attribute)
          Call getAttribute on an element, producing a meaningful error message if not present, or one of "yes" or "no".
private  java.lang.String stringFromURL(java.lang.String url)
          Returns the contents of a file at url as a string (must be a text file)
protected  boolean validateYesNoAttribute(XMLElement element, java.lang.String attribute, boolean defaultValue)
          Call getAttribute on an element, producing a meaningful warning if not "yes" or "no".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

installXmlUrl

private java.lang.String installXmlUrl
URL to remote install.xml


baseUrl

private java.lang.String baseUrl
Base repository URL


installXmlString

private java.lang.String installXmlString
install.xml


packsInfo

private java.lang.String packsInfo
packsinfo.xml contains nbytes, pack name and pack id


packs

private java.util.ArrayList<PackInfo> packs
list of PackInfo entries


YES

private static boolean YES
Constant for checking attributes.


NO

private static boolean NO
Constant for checking attributes.


installFilename

private static final java.lang.String installFilename
Files to be looked for at the repository base url

See Also:
Constant Field Values

packsinfoFilename

private static final java.lang.String packsinfoFilename
See Also:
Constant Field Values

BUFFER_SIZE

private static final int BUFFER_SIZE
Files being downloaded in the buffer, 1MB max

See Also:
Constant Field Values
Constructor Detail

WebRepositoryAccessor

public WebRepositoryAccessor(java.lang.String urlbase)
Create a new WebRepositoryAccessor.

Parameters:
urlbase -
Method Detail

getOnlinePacks

public java.util.ArrayList<PackInfo> getOnlinePacks()
Get the list of the packs from the remore install.xml

Returns:
the packs list

stringFromURL

private java.lang.String stringFromURL(java.lang.String url)
Returns the contents of a file at url as a string (must be a text file)

Parameters:
url -
Returns:
the content

readConfig

private void readConfig()
Reads the install.xml into confgiString


readPacksInfo

private void readPacksInfo()
Reads packsinfo.xml


parsePacks

private java.util.ArrayList<PackInfo> parsePacks()
Parse install.xml and return the list of packs

Returns:
the list of packs

parsePacksInfo

private void parsePacksInfo()
Parse packsinfo.xml, fill the nbytes field, which is not available at runtime otherwise.


getCachedUrl

public static java.lang.String getCachedUrl(java.lang.String url,
                                            java.lang.String tempFolder)
                                     throws java.lang.Exception
First download the jar file. The create the input stream from the downloaded file. This is because the Jar connection's openInputStream will blocks until the whole jar in order to unzip it (there is no way to see the download progress there).

Parameters:
url -
Returns:
the url
Throws:
java.lang.Exception

loadPacksList

protected java.util.ArrayList<PackInfo> loadPacksList(XMLElement data)
                                               throws CompilerException
Throws:
CompilerException

parseError

protected void parseError(java.lang.String message)
                   throws CompilerException
Create parse error with consistent messages. Includes file name. For use When parent is unknown.

Parameters:
message - Brief message explaining error
Throws:
CompilerException

parseError

protected void parseError(XMLElement parent,
                          java.lang.String message)
                   throws CompilerException
Create parse error with consistent messages. Includes file name and line # of parent. It is an error for 'parent' to be null.

Parameters:
parent - The element in which the error occured
message - Brief message explaining error
Throws:
CompilerException

parseError

protected void parseError(XMLElement parent,
                          java.lang.String message,
                          java.lang.Throwable cause)
                   throws CompilerException
Create a chained parse error with consistent messages. Includes file name and line # of parent. It is an error for 'parent' to be null.

Parameters:
parent - The element in which the error occured
message - Brief message explaining error
Throws:
CompilerException

parseWarn

protected void parseWarn(XMLElement parent,
                         java.lang.String message)
Create a parse warning with consistent messages. Includes file name and line # of parent. It is an error for 'parent' to be null.

Parameters:
parent - The element in which the warning occured
message - Warning message

requireChildNamed

protected XMLElement requireChildNamed(XMLElement parent,
                                       java.lang.String name)
                                throws CompilerException
Call getFirstChildNamed on the parent, producing a meaningful error message on failure. It is an error for 'parent' to be null.

Parameters:
parent - The element to search for a child
name - Name of the child element to get
Throws:
CompilerException

requireURLContent

protected java.net.URL requireURLContent(XMLElement element)
                                  throws CompilerException
Call getContent on an element, producing a meaningful error message if not present, or empty, or a valid URL. It is an error for 'element' to be null.

Parameters:
element - The element to get content of
Throws:
CompilerException

requireContent

protected java.lang.String requireContent(XMLElement element)
                                   throws CompilerException
Call getContent on an element, producing a meaningful error message if not present, or empty. It is an error for 'element' to be null.

Parameters:
element - The element to get content of
Throws:
CompilerException

requireAttribute

protected java.lang.String requireAttribute(XMLElement element,
                                            java.lang.String attribute)
                                     throws CompilerException
Call getAttribute on an element, producing a meaningful error message if not present, or empty. It is an error for 'element' or 'attribute' to be null.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
Throws:
CompilerException

requireIntAttribute

protected int requireIntAttribute(XMLElement element,
                                  java.lang.String attribute)
                           throws CompilerException
Get a required attribute of an element, ensuring it is an integer. A meaningful error message is generated as a CompilerException if not present or parseable as an int. It is an error for 'element' or 'attribute' to be null.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
Throws:
CompilerException

requireYesNoAttribute

protected boolean requireYesNoAttribute(XMLElement element,
                                        java.lang.String attribute)
                                 throws CompilerException
Call getAttribute on an element, producing a meaningful error message if not present, or one of "yes" or "no". It is an error for 'element' or 'attribute' to be null.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
Throws:
CompilerException

validateYesNoAttribute

protected boolean validateYesNoAttribute(XMLElement element,
                                         java.lang.String attribute,
                                         boolean defaultValue)
Call getAttribute on an element, producing a meaningful warning if not "yes" or "no". If the 'element' or 'attribute' are null, the default value is returned.

Parameters:
element - The element to get the attribute value of
attribute - The name of the attribute to get
defaultValue - Value returned if attribute not present or invalid