Update of 
/var/cvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload
In directory james.mmbase.org:/tmp/cvs-serv26542

Modified Files:
        DownloadSettings.java DownloadThread.java 
Log Message:
CMSC-945(Modify using which  download path from jsp in java files)


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload
See also: http://www.mmbase.org/jira/browse/CMSC-945


Index: DownloadSettings.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload/DownloadSettings.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- DownloadSettings.java       20 Jun 2008 06:53:21 -0000      1.4
+++ DownloadSettings.java       30 Jun 2008 10:41:44 -0000      1.5
@@ -9,6 +9,7 @@
    public final static String DOWNLOADING_LINE = "           =>";
 
    private int level;
+   private String liveUrl;
    private String tempPath;
    private String storePath;
    private String wgetPath;
@@ -17,7 +18,7 @@
    private String webappName;
 
 
-   public DownloadSettings(int level, String targetPath, String storePath, 
String wgetPath, String downloadUrl,String webappName,
+   public DownloadSettings(int level, String liveUrl , String targetPath, 
String storePath, String wgetPath, String downloadUrl,String webappName,
          ServletContext servletContext) {
       this.level = level;
       this.tempPath = targetPath;
@@ -26,6 +27,7 @@
       this.downloadUrl = downloadUrl;
       this.servletContext = servletContext;
       this.webappName = webappName; 
+      this.liveUrl = liveUrl;
    }
 
 
@@ -59,9 +61,12 @@
    }
 
 
-public String getWebappName() {
+   public String getWebappName() {
        return webappName;
-}
+   }
+   public String getLiveUrl(){
+       return liveUrl; 
+   }
 
 
 


Index: DownloadThread.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload/DownloadThread.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- DownloadThread.java 20 Jun 2008 06:53:21 -0000      1.5
+++ DownloadThread.java 30 Jun 2008 10:41:44 -0000      1.6
@@ -34,8 +34,6 @@
 import org.mmbase.bridge.Cloud;
 import org.mmbase.bridge.Node;
 
-
-
 public class DownloadThread extends Thread {
 
    private static Log log = LogFactory.getLog(DownloadThread.class);
@@ -50,17 +48,17 @@
    private Node node;
    private static ArrayList<String> redownloadfiles = new ArrayList<String>();
    private String webPath;
-   private String webappName="";
+       private String webappName = "";
    private String[] suffix;
    
-   private static final String[] EXCLUDE_FILES = new String[] { "admin", 
"data", "editors", "htmlarea", "jsp",
-         "META-INF", "mmbase", "WEB-INF", "xinha" };
+       private static final String[] EXCLUDE_FILES = new String[] { "admin",
+                       "data", "editors", "htmlarea", "jsp", "META-INF", 
"mmbase",
+                       "WEB-INF", "xinha" };
 
    private HashMap<String, ArrayList<String>> results = new HashMap<String, 
ArrayList<String>>();
 
    private static final int BUFFER = 2048;
 
-
    public DownloadThread(String url, DownloadSettings downloadSettings) {
       super("Downloading " + url);
       this.url = url;
@@ -68,7 +66,6 @@
       this.webappName = downloadSettings.getWebappName();
     }
 
-
    public void start() {
       startTime = System.currentTimeMillis();
       createNode();
@@ -76,49 +73,52 @@
    }
   
    /**Set the suffix according to the txt file*/
-   private void setupSuffix() throws IOException{
-      InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream("../config/subfix.txt");
+       private void setupSuffix() throws IOException {
+               InputStream is = Thread.currentThread().getContextClassLoader()
+                               .getResourceAsStream("../config/subfix.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        StringBuffer buffer = new StringBuffer();
        String line;
        try {
-      while (StringUtils.isNotEmpty(line=br.readLine())){
+                       while (StringUtils.isNotEmpty(line = br.readLine())) {
              buffer.append(line);
          }
        } catch (IOException e) {
          // TODO Auto-generated catch block
          log.info("Some errors happened while reading the subfix.txt");
-       }finally{
-          if(is!=null){
+               } finally {
+                       if (is != null) {
                is.close();
            }
        }
        suffix = buffer.toString().split(";");
    }
+
    public void run() {
      try {
          cleanUp();
          download();
-         File file = new File(downloadSettings.getStorePath());//get the files 
which wget last download
+                       File file = new 
File(downloadSettings.getTempPath());//get the files which wget last download
          setupSuffix();
          modifyDownloadPath();
-         findAssociatdFiles(file, new MyFilenameFilter(".css", ".js", 
".html"));
+                       findAssociatdFiles(file, new MyFilenameFilter(".css", 
".js",
+                                       ".html"));
          redownload(redownloadfiles);
+                       redownloadfiles.clear();//this will avoid to redownload 
picture in different request
          zip();
-      }
-      catch (Exception e) {
+               } catch (Exception e) {
          exception = e;
       }
       endTime = System.currentTimeMillis();
       updateNode();
    }
 
-
    private void updateNode() {
       node.setDateValue("completed", new Date(endTime));
       node.setStringValue("report", getStatus());
       if (fileName != null) {
-         node.setStringValue("filename", downloadSettings.getDownloadUrl() + 
"/" + fileName);
+                       node.setStringValue("filename", 
downloadSettings.getDownloadUrl()
+                                       + "/" + fileName);
       }
 
       if (exception != null) {
@@ -130,7 +130,6 @@
       node.commit();
    }
 
-
    private Node createNode() {
       Cloud cloud = CloudProviderFactory.getCloudProvider().getCloud();
       node = cloud.getNodeManager("staticdownload").createNode();
@@ -139,13 +138,11 @@
       return node;
    }
 
-
    private void cleanUp() {
       File f = new File(downloadSettings.getTempPath());
       deleteRecursive(f, true);
    }
 
-
    private void deleteRecursive(File f, boolean isFirst) {
       if (f.isDirectory()) {
          File files[] = f.listFiles();
@@ -158,16 +155,19 @@
       }
    }
 
-
    private void zip() throws IOException {
       fileName = "download_" + node.getNumber() + ".zip";
-      FileOutputStream dest = new 
FileOutputStream(downloadSettings.getStorePath() + "/" + fileName);
-      ZipOutputStream out = new ZipOutputStream(new 
BufferedOutputStream(dest));
+               FileOutputStream dest = new FileOutputStream(downloadSettings
+                               .getStorePath()
+                               + "/" + fileName);
+               ZipOutputStream out = new ZipOutputStream(
+                               new BufferedOutputStream(dest));
       // out.setMethod(ZipOutputStream.DEFLATED);
       // get a list of files from current directory
       File f = new File(downloadSettings.getTempPath());
       File containingDir = f.listFiles()[0];
-      zipFile(containingDir, out, containingDir.getAbsolutePath().length() + 
1);
+               zipFile(containingDir, out,
+                               containingDir.getAbsolutePath().length() + 1);
 
       String realPath = downloadSettings.getServletContext().getRealPath("/");
       File realFile = new File(realPath);
@@ -183,7 +183,6 @@
       out.close();
    }
 
-
    private void fixFile(File file) throws IOException {
       String inputData = readFile(file);
 
@@ -194,22 +193,19 @@
       }
    }
 
-
    private void writeFile(File file, String outputData) throws IOException {
       FileWriter writer = null;
       try {
          writer = new FileWriter(file);
          writer.write(outputData);
          writer.flush();
-      }
-      finally {
+               } finally {
          if (writer != null) {
             writer.close();
          }
       }
    }
 
-
    private String readFile(File file) throws IOException {
       BufferedReader reader = null;
       try {
@@ -221,15 +217,13 @@
             buffer.append(line);
          }
          return buffer.toString();
-      }
-      finally {
+               } finally {
          if (reader != null) {
             reader.close();
          }
       }
    }
 
-
    private boolean includeFile(String name) {
       for (String exclude : EXCLUDE_FILES) {
          if (name.equals(exclude)) {
@@ -239,8 +233,8 @@
       return true;
    }
 
-
-   private void zipFile(File f, ZipOutputStream out, int trimLength) throws 
IOException {
+       private void zipFile(File f, ZipOutputStream out, int trimLength)
+                       throws IOException {
       File files[] = f.listFiles();
       byte data[] = new byte[BUFFER];
 
@@ -249,14 +243,14 @@
          log.info("Adding: " + file.getName());
          if (file.isDirectory()) {
             zipFile(file, out, trimLength);
-         }
-         else {
+                       } else {
             if (file.getName().endsWith(".html")) {
                fixFile(file);
             }
             FileInputStream fi = new FileInputStream(file);
             BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
-            ZipEntry entry = new 
ZipEntry(file.getAbsolutePath().substring(trimLength));
+                               ZipEntry entry = new 
ZipEntry(file.getAbsolutePath().substring(
+                                               trimLength));
             out.putNextEntry(entry);
             int count;
             while ((count = origin.read(data, 0, BUFFER)) != -1) {
@@ -268,20 +262,22 @@
    }
    
    /** make the web address useful*/
-   private void modifyDownloadPath(){
-      if(!downloadSettings.getDownloadUrl().endsWith("/")){
-         webPath = downloadSettings.getDownloadUrl()+"/";
-      }else{
-         webPath = downloadSettings.getDownloadUrl();
+       private void modifyDownloadPath() {
+               if (!downloadSettings.getLiveUrl().endsWith("/")) {
+                       webPath = downloadSettings.getLiveUrl() + "/";
+               } else {
+                       webPath = downloadSettings.getLiveUrl();
       }
    }
+
    /**redownload the things which the before had not done*/
-   private void redownload(List<String> paths) throws IOException{
-      for(String path:paths){
+       private void redownload(List<String> paths) throws IOException {
+               for (String path : paths) {
          pubDownload(path);
       }
    }
-   private void pubDownload(String urll) throws IOException{
+
+       private void pubDownload(String urll) throws IOException {
       List<String> command = new ArrayList<String>();
          command.add(downloadSettings.getWgetPath());
          command.add(urll);
@@ -299,8 +295,7 @@
          while (stillRunning) {
             try {
                Thread.sleep(1000);
-            }
-            catch (InterruptedException e) {
+                       } catch (InterruptedException e) {
                 // nothing
             }
 
@@ -315,8 +310,7 @@
             try {
                returnCode = process.exitValue();
                stillRunning = false;
-            }
-            catch (IllegalThreadStateException e) {
+                       } catch (IllegalThreadStateException e) {
                 // nothing
             }
          }
@@ -329,15 +323,15 @@
      pubDownload(url);
    }
 
-
    private void processErrors(String text) {
 
       for (String line : text.split("\n")) {
          if (line.startsWith(DownloadSettings.DOWNLOADING_LINE)) {
-            currentFile = 
line.substring(DownloadSettings.DOWNLOADING_LINE.length() + 1);
-         }
-         else if (line.startsWith(DownloadSettings.RESPONSE_LINE)) {
-            String response = 
line.substring(DownloadSettings.RESPONSE_LINE.length() + 1);
+                               currentFile = 
line.substring(DownloadSettings.DOWNLOADING_LINE
+                                               .length() + 1);
+                       } else if 
(line.startsWith(DownloadSettings.RESPONSE_LINE)) {
+                               String response = 
line.substring(DownloadSettings.RESPONSE_LINE
+                                               .length() + 1);
 
             ArrayList<String> responseResult = results.get(response);
             if (responseResult == null) {
@@ -349,7 +343,6 @@
       }
    }
 
-
    public String getStatus() {
       StringBuffer status = new StringBuffer();
       for (String key : results.keySet()) {
@@ -369,16 +362,15 @@
       return status.toString();
    }
 
-
    private void processOutput(String output) {
       if (output != null) {
          log.info(output);
       }
    }
 
-
    private String readOutput(InputStream stream) throws IOException {
-      BufferedReader reader = new BufferedReader(new 
InputStreamReader(stream));
+               BufferedReader reader = new BufferedReader(
+                               new InputStreamReader(stream));
       StringBuffer result = new StringBuffer();
 
       while (reader.ready()) {
@@ -388,7 +380,6 @@
       return result.toString();
    }
 
-
    public final static String fixFlash(String string) {
       int startIndex = 0;
       while ((startIndex = string.indexOf("<object", startIndex)) != -1) {
@@ -408,14 +399,17 @@
          for (int count = 0; count < 2; count++) {
             swfStart[count] = string.lastIndexOf("\"", swfIndex[count]) + 1;
             swfEnd[count] = string.indexOf("\"", swfIndex[count]);
-            swfString[count] = string.substring(swfStart[count], 
swfEnd[count]);
+                               swfString[count] = 
string.substring(swfStart[count],
+                                               swfEnd[count]);
          }
 
-         boolean embedFirst = string.lastIndexOf("embed", swfIndex[0]) > 
string.lastIndexOf("param", swfIndex[0]);
+                       boolean embedFirst = string.lastIndexOf("embed", 
swfIndex[0]) > string
+                                       .lastIndexOf("param", swfIndex[0]);
          int from = (embedFirst) ? 0 : 1;
          int to = (embedFirst) ? 1 : 0;
 
-         string = string.substring(0, swfStart[to]) + swfString[from] + 
string.substring(swfEnd[to]);
+                       string = string.substring(0, swfStart[to]) + 
swfString[from]
+                                       + string.substring(swfEnd[to]);
 
          System.out.println("after >>> " + string);
          startIndex = string.indexOf("</object", startIndex);
@@ -448,23 +442,25 @@
       }
    }
   
-   private void spellPath(String targetPath,String directoryName){
+       private void spellPath(String targetPath, String directoryName) {
       String regEx1 = "\\.\\.";
       Pattern p1 = Pattern.compile(regEx1);
       Matcher m1 = p1.matcher(targetPath);
       String str1 = m1.replaceAll(directoryName);
       String path = webPath + str1;
-      if(!redownloadfiles.contains(path))
+               if (!redownloadfiles.contains(path))
          redownloadfiles.add(path);
    }
    
-   private String getUrl(){
-      return downloadSettings.getDownloadUrl();
+       private String getUrl() {
+               return downloadSettings.getLiveUrl();
    }
+
    /**Use the filter to find the associated files which last wget downloads,
     * then pick up the getTargetStringAndWriteFile() method
     * @throws IOException */
-   private void findAssociatdFiles(File file , MyFilenameFilter myfilter) 
throws IOException {
+       private void findAssociatdFiles(File file, MyFilenameFilter myfilter)
+                       throws IOException {
       String fileName = file.getAbsolutePath();
       if (!fileName.endsWith(File.separator)) {
          fileName = fileName + File.separator;
@@ -475,11 +471,13 @@
       File[] files = file.listFiles(myfilter);
       for (int i = 0; i < files.length; i++) {
          if (files[i].isFile()) {
-            for(String suf:suffix){
-               String outputData = 
this.getTargetStringAndWriteFile(files[i],suf);
-               if(outputData.length()!=0 && 
files[i].length()!=outputData.length()){
+                               for (String suf : suffix) {
+                                       String outputData = 
this.getTargetStringAndWriteFile(
+                                                       files[i], suf);
+                                       if (outputData.length() != 0
+                                                       && files[i].length() != 
outputData.length()) {
                   try {
-                     this.writeFile(files[i],outputData);
+                                                       
this.writeFile(files[i], outputData);
                   } catch (IOException e) {
                      log.info("Something wrong in writing data into files");
                   }
@@ -490,26 +488,29 @@
          }
       }
    }
+
    /**Regular expressions for judging*/
-   private String regularJudge(String regEx,String targetString){
+       private String regularJudge(String regEx, String targetString) {
       String targetPath = "";
-      if(regEx!=null&&targetString!=null){
+               if (regEx != null && targetString != null) {
          Pattern p = Pattern.compile(regEx);
          Matcher m = p.matcher(targetString);
          boolean  rs = m.find();
-         if(rs){
+                       if (rs) {
             targetPath = m.group();
          }
       }
       return targetPath;
    }
+
    /**Regular expressions for replacing*/
-   private String regularReplace(String target,String former,String newer){
+       private String regularReplace(String target, String former, String 
newer) {
       String regEx = former;
       Pattern p = Pattern.compile(regEx);
       Matcher m = p.matcher(target);
       return m.replaceAll(newer);
    }
+
    /**
     *Spell the path of downloading , modify the paths in files
     [EMAIL PROTECTED] targetStringNew : the path of pictures in former file
@@ -517,49 +518,65 @@
     [EMAIL PROTECTED] file : the current file
     [EMAIL PROTECTED] the new string in current line
     */
-   private String downloadAndModifyPath(String targetStringNew,String 
tempString,File file){
+       private String downloadAndModifyPath(String targetStringNew,
+                       String tempString, File file) {
       String downloadPath;
-      if(StringUtils.isEmpty(webappName)){
-         downloadPath = webPath+targetStringNew.substring(1);
-      }else{
-         downloadPath = 
webPath+targetStringNew.substring(webappName.length()+2);
+               if (StringUtils.isEmpty(webappName)) {
+                       downloadPath = webPath + targetStringNew.substring(1);
+               } else {
+                       downloadPath = webPath
+                                       + 
targetStringNew.substring(webappName.length() + 2);
       }
-      if(!redownloadfiles.contains(downloadPath))
+               if (!redownloadfiles.contains(downloadPath))
          redownloadfiles.add(downloadPath);
+               
       String filePath = file.getParent();
       int beginIndex = filePath.indexOf(getUrl());
-      String filePathIntercept = 
filePath.substring(beginIndex+getUrl().length());
+               String filePathIntercept = filePath.substring(beginIndex
+                               + getUrl().length());
       String[] strs = filePathIntercept.split("\\\\");
       int num = strs.length;
-      String docs ="";
-      for(int i=1;i< num;i++){
+               String docs = "";
+               for (int i = 1; i < num; i++) {
          docs += "../";
       }
-      
if(StringUtils.isEmpty(filePathIntercept)&&StringUtils.isEmpty(webappName)){
-         String targetStringNews =targetStringNew.substring(1);
-         tempString = this.regularReplace(tempString, targetStringNew, 
targetStringNews);         
-      }else 
if(StringUtils.isNotEmpty(filePathIntercept)&&StringUtils.isEmpty(webappName)){
-         tempString = this.regularReplace(tempString, targetStringNew, 
docs+targetStringNew.substring(1));
-      }else 
if(StringUtils.isEmpty(filePathIntercept)&&StringUtils.isNotEmpty(webappName)){
-         String targetStringNews 
=targetStringNew.substring(webappName.length()+2);
-         tempString = this.regularReplace(tempString, targetStringNew, 
targetStringNews);            
-      }else 
if(StringUtils.isNotEmpty(filePathIntercept)&&StringUtils.isNotEmpty(webappName)){
-         tempString = this.regularReplace(tempString, "/"+webappName+"/", 
docs);
+               if (StringUtils.isEmpty(filePathIntercept)
+                               && StringUtils.isEmpty(webappName)) {
+                       String targetStringNews = targetStringNew.substring(1);
+                       tempString = this.regularReplace(tempString, 
targetStringNew,
+                                       targetStringNews);
+               } else if (StringUtils.isNotEmpty(filePathIntercept)
+                               && StringUtils.isEmpty(webappName)) {
+                       tempString = this.regularReplace(tempString, 
targetStringNew, docs
+                                       + targetStringNew.substring(1));
+               } else if (StringUtils.isEmpty(filePathIntercept)
+                               && StringUtils.isNotEmpty(webappName)) {
+                       String targetStringNews = 
targetStringNew.substring(webappName
+                                       .length() + 2);
+                       tempString = this.regularReplace(tempString, 
targetStringNew,
+                                       targetStringNews);
+               } else if (StringUtils.isNotEmpty(filePathIntercept)
+                               && StringUtils.isNotEmpty(webappName)) {
+                       tempString = this.regularReplace(tempString,
+                                       "/" + webappName + "/", docs);
       }
       return tempString;
    }
-   private void addDownloadPath(String str,File file,String targetPath){
+
+       private void addDownloadPath(String str, File file, String targetPath) {
       String filepath = file.getAbsolutePath();
-      String url = downloadSettings.getDownloadUrl();
-      int tagStart=filepath.indexOf(url);
+               String url = downloadSettings.getLiveUrl();
+               int tagStart = filepath.indexOf(url);
       String u = filepath.substring(tagStart);
-      int tagEnd = u.indexOf("\\"+str);
-      String m = u.substring(0,tagEnd);
+               int tagEnd = u.indexOf("\\" + str);
+               String m = u.substring(0, tagEnd);
       String ss = regularReplace(m, "\\\\", "/");
       String str1 = regularReplace(targetPath, "\\.\\.", ss);
-      if(!redownloadfiles.contains(str1))
+               
+               if (!redownloadfiles.contains(str1))
          redownloadfiles.add(str1);
    }
+
    /**
     * Use regular expressions to get the paths of pictures
     * and rewrite the path into the file
@@ -567,87 +584,109 @@
     * @param suffix : the messages about suffix of pictures
     * @throws IOException 
     */
-   private String getTargetStringAndWriteFile(File file,String suffix) throws 
IOException{
+       private String getTargetStringAndWriteFile(File file, String suffix)
+                       throws IOException {
       BufferedReader reader = null;
       String outputData = "";
-         try{
+               try {
             reader = new BufferedReader(new FileReader(file));
             String tempString = null;
-               while((tempString = 
reader.readLine())!=null&&!file.getName().endsWith(".html")){
-                  String regEx = "[\\w/.-]+\\."+suffix;
-                  String targetPath = regularJudge(regEx,tempString);
-                  if(targetPath!=""){
+                       while ((tempString = reader.readLine()) != null
+                                       && !file.getName().endsWith(".html")) {
+                               String regEx = "[\\w/.-]+\\." + suffix;
+                               String targetPath = regularJudge(regEx, 
tempString);
+                               if (targetPath != "") {
                      int tagStart = -1;
-                     String fileParentPath = file.getParent()+File.separator;
-                     String directoryName ="";
-                     if(StringUtils.isNotEmpty(webappName)&&(tagStart = 
fileParentPath.indexOf(webappName))>=0&&fileParentPath.contains("js")){
-                        int tagEnd = 
fileParentPath.indexOf("\\js",tagStart+webappName.length()+1);
-                        if(tagEnd>=0){
-                           directoryName = 
fileParentPath.substring(tagStart+webappName.length()+1, tagEnd);
-                           this.spellPath(targetPath,directoryName);
-                        }
-                     }else if(StringUtils.isNotEmpty(webappName)&&(tagStart 
=fileParentPath.indexOf(webappName))>=0&&fileParentPath.contains("css")){
-                        int tagEnd = 
fileParentPath.indexOf("\\css",tagStart+webappName.length()+1);
-                        if(tagEnd>=0){
-                           directoryName = 
fileParentPath.substring(tagStart+webappName.length()+1, tagEnd);
-                           this.spellPath(targetPath,directoryName);
-                        }
-                     }else 
if(StringUtils.isEmpty(webappName)&&fileParentPath.contains("css")){
-                        addDownloadPath("css",file,targetPath);
-                     }else 
if(StringUtils.isEmpty(webappName)&&fileParentPath.contains("js")){
-                        addDownloadPath("js",file,targetPath);
-                     }
-                  }
-               }
-               while((tempString = 
reader.readLine())!=null&&file.getName().endsWith(".html")){
-                  String targetString = 
regularJudge("(?m)^\\s*var.*"+suffix+".*$", tempString);
-                  if(StringUtils.isNotEmpty(targetString)){                    
 
-                     String targetStringNew = 
regularJudge("[\\w/\\.-]+\\."+suffix,targetString);
-                     if(StringUtils.isNotEmpty(targetStringNew)){
-                        
if(targetStringNew.startsWith("/"+webappName)&&StringUtils.isNotEmpty(webappName)){
-                           tempString = 
this.downloadAndModifyPath(targetStringNew, tempString, file);
-                        }else 
if(targetStringNew.startsWith("/")&&StringUtils.isEmpty(webappName)){
-                           tempString = 
this.downloadAndModifyPath(targetStringNew, tempString, file);
-                        }
-                     }
+                                       String fileParentPath = 
file.getParent() + File.separator;
+                                       String directoryName = "";
+                                       if (StringUtils.isNotEmpty(webappName)
+                                                       && (tagStart = 
fileParentPath.indexOf(webappName)) >= 0
+                                                       && 
fileParentPath.contains("js")) {
+                                               int tagEnd = 
fileParentPath.indexOf("\\js", tagStart
+                                                               + 
webappName.length() + 1);
+                                               if (tagEnd >= 0) {
+                                                       directoryName = 
fileParentPath.substring(tagStart
+                                                                       + 
webappName.length() + 1, tagEnd);
+                                                       
this.spellPath(targetPath, directoryName);
+                                               }
+                                       } else if 
(StringUtils.isNotEmpty(webappName)
+                                                       && (tagStart = 
fileParentPath.indexOf(webappName)) >= 0
+                                                       && 
fileParentPath.contains("css")) {
+                                               int tagEnd = 
fileParentPath.indexOf("\\css", tagStart
+                                                               + 
webappName.length() + 1);
+                                               if (tagEnd >= 0) {
+                                                       directoryName = 
fileParentPath.substring(tagStart
+                                                                       + 
webappName.length() + 1, tagEnd);
+                                                       
this.spellPath(targetPath, directoryName);
+                                               }
+                                       } else if 
(StringUtils.isEmpty(webappName)
+                                                       && 
fileParentPath.contains("css")) {
+                                               addDownloadPath("css", file, 
targetPath);
+                                       } else if 
(StringUtils.isEmpty(webappName)
+                                                       && 
fileParentPath.contains("js")) {
+                                               addDownloadPath("js", file, 
targetPath);
+                                       }
+                               }
+                       }
+                       while ((tempString = reader.readLine()) != null
+                                       && file.getName().endsWith(".html")) {
+                               String targetString = 
regularJudge("(?m)^\\s*var.*" + suffix
+                                               + ".*$", tempString);
+                               if (StringUtils.isNotEmpty(targetString)) {
+                                       String targetStringNew = 
regularJudge("[\\w/\\.-]+\\."
+                                                       + suffix, targetString);
+                                       if 
(StringUtils.isNotEmpty(targetStringNew)) {
+                                               if 
(targetStringNew.startsWith("/" + webappName)
+                                                               && 
StringUtils.isNotEmpty(webappName)) {
+                                                       tempString = 
this.downloadAndModifyPath(
+                                                                       
targetStringNew, tempString, file);
+                                               } else if 
(targetStringNew.startsWith("/")
+                                                               && 
StringUtils.isEmpty(webappName)) {
+                                                       tempString = 
this.downloadAndModifyPath(
+                                                                       
targetStringNew, tempString, file);
+                                               }
+                                       }
+                               }
+                               String str = 
regularJudge("[\\s.]*background-image:\\s*url.*",
+                                               tempString);
+                               if (StringUtils.isNotEmpty(str)) {
+                                       String targetName = 
regularJudge("[\\w/]*\\." + suffix, str);
+                                       if (StringUtils.isNotEmpty(targetName)) 
{
+                                               if (targetName.startsWith("/" + 
webappName)
+                                                               && 
StringUtils.isNotEmpty(webappName)) {
+                                                       tempString = 
this.downloadAndModifyPath(targetName,
+                                                                       
tempString, file);
+                                               } else if 
(targetName.startsWith("/")
+                                                               && 
StringUtils.isEmpty(webappName)) {
+                                                       tempString = 
this.downloadAndModifyPath(targetName,
+                                                                       
tempString, file);
                   }
-                  String str = 
regularJudge("[\\s.]*background-image:\\s*url.*", tempString);
-                  if(StringUtils.isNotEmpty(str)){
-                     String targetName = regularJudge("[\\w/]*\\."+suffix, 
str);
-                     if(StringUtils.isNotEmpty(targetName)){
-                        
if(targetName.startsWith("/"+webappName)&&StringUtils.isNotEmpty(webappName)){
-                           tempString = this.downloadAndModifyPath(targetName, 
tempString, file);
-                        }else 
if(targetName.startsWith("/")&&StringUtils.isEmpty(webappName)){
-                           tempString = this.downloadAndModifyPath(targetName, 
tempString, file);
                         }
                      }
+                               outputData += tempString + "\r\n";
                   }
-                  outputData+=tempString+"\r\n";
-               }
-         }catch (IOException e) {
-            log.error("Something wrong while reading ,",e);
-         }finally{
-            if(reader!=null){
+               } catch (IOException e) {
+                       log.error("Something wrong while reading ,", e);
+               } finally {
+                       if (reader != null) {
                reader.close();
             }
          }
          return outputData;
       }
+
    public boolean isDownloading() {
       return (endTime == -1);
    }
 
-
    public Exception getException() {
       return exception;
    }
 
-
    public long getEndTime() {
       return endTime;
    }
 
-
    public long getStartTime() {
       return startTime;
    }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to