Changeset 13650


Ignore:
Timestamp:
2007-01-17T11:14:23+13:00 (15 years ago)
Author:
lh92
Message:

added a method to find where is the xml-source directory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl-documentation/shared/ExternalRef.java

    r13632 r13650  
    11import java.io.InputStream;
    22import java.io.FileInputStream;
     3import java.io.File;
    34
    45import org.w3c.dom.Document;
     
    1213
    1314public class ExternalRef{   
    14 
    15     public ExternalRef(){} 
     15    private String basePath;
     16    public ExternalRef(){       
     17    }   
    1618
    1719    public String getRef(String file, String lang, String targettype, String id){
    18        
     20        getPath();
    1921        try{
    20         String tfile = file+"_"+lang+".xml";
    21         String path = tfile;
     22            String tfile = file+"_"+lang+".xml";
     23            String path = basePath + "/xml-source/" + lang + "/" + tfile;
    2224
    23         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    24         DocumentBuilder domBuilder = factory.newDocumentBuilder();
    25         InputStream is = new FileInputStream(path);
    26         Document doc = domBuilder.parse(is);
     25            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     26      DocumentBuilder domBuilder = factory.newDocumentBuilder();
     27      InputStream is = new FileInputStream(path);
     28      Document doc = domBuilder.parse(is);
    2729
    2830        NodeList list = doc.getElementsByTagName(targettype);
     
    4244        }
    4345    }   
     46   
     47    private void getPath(){
     48        basePath = System.getProperty("user.dir");
     49       
     50        System.err.println(basePath);
     51       
     52        //find where is the manuals directory
     53        File tempfile = new File(basePath);
     54        String parentPath = tempfile.getParent();       
     55       
     56        boolean find = false;
     57        while(!find){
     58            System.err.println(parentPath);
     59            File tempfile2 = new File(parentPath+"/manuals");
     60            if(tempfile2.exists() && tempfile2.isDirectory()){
     61                basePath = parentPath+"/manuals";
     62                find = true;
     63          }
     64          else if(parentPath.endsWith("manuals")){
     65            //if the shared directory is inside the manual directory
     66                basePath = parentPath;
     67                find = true;
     68          }
     69          if(!find){
     70            tempfile = new File(parentPath);
     71            parentPath = tempfile.getParent();
     72          }
     73      }
     74    }
    4475}
Note: See TracChangeset for help on using the changeset viewer.