Changeset 3735 in main


Ignore:
Timestamp:
04/21/12 00:31:47 (10 years ago)
Author:
Garth Braithwaite
Message:

java - added objects to get an XML document model map via the document service. Added the ability to lookup a file based on the resource path lookup/find.

Location:
trunk/src/main
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/main/java/org/ibisph/systemid/ClassPathSystemID.java

    r3710 r3735  
    1414   * @throws java.io.FileNotFoundException
    1515   */
    16   public ClassPathSystemID(String urlOrPathAndFilename) throws java.net.MalformedURLException, java.io.IOException {
     16  public ClassPathSystemID(String urlOrPathAndFilename) {
    1717    java.net.URL url = Thread.currentThread().getContextClassLoader().getResource(urlOrPathAndFilename);
    1818    if(null != url) this.systemID = url.toExternalForm();
  • trunk/src/main/java/org/ibisph/systemid/ResourceSystemID.java

    r3710 r3735  
    1919   * @throws java.io.FileNotFoundException
    2020   */
    21   public ResourceSystemID(String pathAndFilename) throws Exception {
     21  public ResourceSystemID(String pathAndFilename) {
    2222
    2323    // another way is to use the servlet context like:
     
    2828  } //----------------------- End of Constructor ----------------------------
    2929 
    30   public ResourceSystemID(String contextPath, String subPathAndFilename) throws Exception {
     30  public ResourceSystemID(String contextPath, String subPathAndFilename) {
    3131    this(org.ibisph.util.IOPath.concat(contextPath, subPathAndFilename));
    3232  } //----------------------- End of Constructor ----------------------------
  • trunk/src/main/java/org/ibisph/systemid/modelmap/SystemIDFromHTTPRequestParameter.java

    r3710 r3735  
    88import org.ibisph.systemid.VerifiedURLSystemID;
    99import org.ibisph.util.IOPath;
     10import org.ibisph.util.StrLib;
    1011
    1112/**
     
    3435    SystemID xmlSystemID = null;
    3536    String xmlName = request.getParameter("xmlURL");
    36     if(xmlName != null) {
     37    if(StrLib.isSomething(xmlName)) {
    3738      xmlSystemID = new VerifiedURLSystemID(xmlName);
    3839    }
     
    4041    else {
    4142      xmlName = request.getParameter("xmlFile");
    42       if(xmlName == null) xmlName = request.getParameter("xml");
     43      if(!StrLib.isSomething(xmlName)) xmlName = request.getParameter("xml");
    4344      try {
    4445        xmlSystemID = new VerifiedFileSystemID(xmlName);
  • trunk/src/main/java/org/ibisph/xml/service/FileStoredDocument.java

    r3734 r3735  
    1313import org.ibisph.util.FileLib;
    1414import org.ibisph.util.IOPath;
     15import org.ibisph.util.StrLib;
    1516
    1617/**
     
    4849  } //-------------------------- End of Method ------------------------------
    4950  public org.dom4j.Document get(String xmlPathAndFilename) throws DocumentException {
    50     return( get(new File(xmlPathAndFilename)) );
     51    String s = getVerifiedPathAndFilename(xmlPathAndFilename);
     52    File file = new File(s);
     53    return(get(file));
    5154  } //-------------------------- End of Method ------------------------------
    5255
     
    6467  public boolean load(File xmlFile, org.dom4j.Document document) throws DocumentException {
    6568    SAXReader xmlReader = new SAXReader();
    66     if((xmlFile != null) && xmlFile.exists()) {
     69    if((null != xmlFile) && xmlFile.exists()) {
    6770      document.setDocument( xmlReader.read(xmlFile) );
    6871      return(true);
     
    122125    String xmlPathAndFilename
    123126  ) throws IOException, UnsupportedEncodingException {
    124     save(document, xmlPathAndFilename, outputFormat);
     127    save(
     128      document,
     129      getVerifiedPathAndFilename(xmlPathAndFilename),
     130      this.outputFormat
     131    );
    125132  } //-------------------------- End of Method ------------------------------
    126133
     
    143150
    144151
    145   public boolean delete(String documentPathAndName) {
    146     return(FileLib.delete(documentPathAndName));
     152  public boolean delete(String xmlPathAndFilename) {
     153    return(FileLib.delete(xmlPathAndFilename));
    147154  } //-------------------------- End of Method ------------------------------
    148155
    149156
    150   public boolean exists(String documentPathAndName) {
    151     File file = new File(documentPathAndName);
    152     boolean exists = file.exists();
    153     return(exists);
     157  public boolean exists(String xmlPathAndFilename) {
     158    return(StrLib.isSomething(getVerifiedPathAndFilename(xmlPathAndFilename)));
    154159  } //-------------------------- End of Method ------------------------------
    155160
     161
     162  /**
     163   * Helper that localizes getting/searching the path and resource path for
     164   * the given file.  First checks path passed in.  If file exists then that
     165   * is verified so return.  Else check the classloader's path.  Else check
     166   * the thread's class path.  In the case of the two latter checks a URL/
     167   * system id type string is returned
     168   * @param pathAndFilename path and filename to be verified.
     169   * @return verified path and filename.  If supplied value does not exist
     170   *   then the classpath is checked.
     171   * @throws Exception
     172   */
     173  protected String getVerifiedPathAndFilename(String pathAndFilename) {
     174    File file = new File(pathAndFilename);
     175    if(file.exists()) return(pathAndFilename);
     176
     177    java.net.URL url = Thread.currentThread().getContextClassLoader().getResource(pathAndFilename);
     178    if(null != url) return(url.toExternalForm());
     179
     180    url = this.getClass().getClassLoader().getResource(pathAndFilename);
     181    if(null != url) return(url.toExternalForm());
     182
     183    return(null);
     184  } //-------------------------- End of Method ------------------------------
     185   
    156186} //============================ END OF CLASS =================================
    157187
Note: See TracChangeset for help on using the changeset viewer.