gate.util.ant.packager
Class GappModel

java.lang.Object
  extended by gate.util.ant.packager.GappModel

public class GappModel
extends Object


Field Summary
private  org.jdom.Document gappDocument
           
private  URL gappFileURL
          The URL at which this GAPP file is saved.
private  URL gateHomeURL
          The URL against which to resolve $gatehome$ relative paths.
private  Map<URL,List<org.jdom.Element>> pluginRelpathsMap
          Map whose keys are the resolved URLs of plugins referred to by relative paths in the GAPP file and whose values are the JDOM Elements of the <urlString> elements concerned.
private static org.jdom.xpath.XPath relativePluginPathElementsXPath
          XPath selecting all urlStrings that contain $relpath$ or $gatehome$ in the <urlList> section of the file.
private static org.jdom.xpath.XPath relativeResourcePathElementsXPath
          XPath selecting all urlStrings that contain $relpath$ or $gatehome$ in the <application> section of the file.
private  Map<URL,List<org.jdom.Element>> resourceRelpathsMap
          Map whose keys are the resolved URLs of resource files other than plugin directories referred to by relative paths in the GAPP file and whose values are the JDOM Elements of the <urlString> elements concerned.
 
Constructor Summary
GappModel(URL gappFileURL)
           
GappModel(URL gappFileURL, URL gateHomeURL)
          Create a GappModel for a GAPP file.
 
Method Summary
private  void buildRelpathsMap(List<org.jdom.Element> relpathElements, Map<URL,List<org.jdom.Element>> relpathsMap)
           
 void finish()
          Finish up processing of the gapp file ready for writing.
 org.jdom.Document getGappDocument()
          Get the JDOM Document representing this GAPP file.
 URL getGappFileURL()
          Get the URL at which the GAPP file resides.
 Set<URL> getPluginURLs()
          Get the plugin URLs that are referenced by relative paths in this GAPP file.
 Set<URL> getResourceURLs()
          Get the resource URLs that are referenced by relative paths in this GAPP file.
 void setGappFileURL(URL gappFileURL)
          Set the URL at which the GAPP file resides.
 void updatePathForURL(URL originalURL, URL newURL, boolean makeRelative)
          Update the modelled content of the GAPP file to replace any relative paths referring to originalURL with those pointing to newURL.
 void write()
          Write out the (possibly modified) GAPP file to its new location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gappDocument

private org.jdom.Document gappDocument

gappFileURL

private URL gappFileURL
The URL at which this GAPP file is saved.


gateHomeURL

private URL gateHomeURL
The URL against which to resolve $gatehome$ relative paths.


pluginRelpathsMap

private Map<URL,List<org.jdom.Element>> pluginRelpathsMap
Map whose keys are the resolved URLs of plugins referred to by relative paths in the GAPP file and whose values are the JDOM Elements of the <urlString> elements concerned.


resourceRelpathsMap

private Map<URL,List<org.jdom.Element>> resourceRelpathsMap
Map whose keys are the resolved URLs of resource files other than plugin directories referred to by relative paths in the GAPP file and whose values are the JDOM Elements of the <urlString> elements concerned.


relativeResourcePathElementsXPath

private static org.jdom.xpath.XPath relativeResourcePathElementsXPath
XPath selecting all urlStrings that contain $relpath$ or $gatehome$ in the <application> section of the file.


relativePluginPathElementsXPath

private static org.jdom.xpath.XPath relativePluginPathElementsXPath
XPath selecting all urlStrings that contain $relpath$ or $gatehome$ in the <urlList> section of the file.

Constructor Detail

GappModel

public GappModel(URL gappFileURL)
See Also:
GappModel(URL,URL)

GappModel

public GappModel(URL gappFileURL,
                 URL gateHomeURL)
Create a GappModel for a GAPP file.

Parameters:
gappFileURL - the URL of the GAPP file to model.
gateHomeURL - the URL against which $gatehome$ relative paths should be resolved. This may be null if you are sure that the GAPP you are packaging does not contain any $gatehome$ paths. If no gateHomeURL is provided but the application does contain a $gatehome$ path, a GateRuntimeException will be thrown.
Method Detail

buildRelpathsMap

private void buildRelpathsMap(List<org.jdom.Element> relpathElements,
                              Map<URL,List<org.jdom.Element>> relpathsMap)
                       throws MalformedURLException
Throws:
MalformedURLException

getGappFileURL

public URL getGappFileURL()
Get the URL at which the GAPP file resides.

Returns:
the gappFileURL

setGappFileURL

public void setGappFileURL(URL gappFileURL)
Set the URL at which the GAPP file resides. When this GappModel is constructed this will be the URL from which the file is loaded, but this should be changed if you wish to write the updated GAPP to another location.

Parameters:
gappFileURL - the gappFileURL to set

getGappDocument

public org.jdom.Document getGappDocument()
Get the JDOM Document representing this GAPP file.

Returns:
the document

getPluginURLs

public Set<URL> getPluginURLs()
Get the plugin URLs that are referenced by relative paths in this GAPP file.

Returns:
the set of URLs.

getResourceURLs

public Set<URL> getResourceURLs()
Get the resource URLs that are referenced by relative paths in this GAPP file.

Returns:
the set of URLs.

updatePathForURL

public void updatePathForURL(URL originalURL,
                             URL newURL,
                             boolean makeRelative)
Update the modelled content of the GAPP file to replace any relative paths referring to originalURL with those pointing to newURL. If makeRelative is true, the new path will be relativized against the current gappFileURL, so you should call setGappFileURL(java.net.URL) with the URL at which the file will ultimately be saved before calling this method. If makeRelative is false the new URL will be used directly as an absolute URL (so to replace a relative path with the absolute URL to the same file you can call updatePathForURL(u, u, false)).

Parameters:
originalURL - The original URL whose references are to be replaced.
newURL - the replacement URL.
makeRelative - should we relativize the newURL before use?

finish

public void finish()
Finish up processing of the gapp file ready for writing.


write

public void write()
           throws IOException
Write out the (possibly modified) GAPP file to its new location.

Throws:
IOException - if an I/O error occurs.