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

Modified Files:
        DownloadThread.java 
Log Message:
CMSC-1086(Modify the liveUrl used in downloading.)


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-1086


Index: DownloadThread.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload/DownloadThread.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- DownloadThread.java 14 Oct 2008 09:39:33 -0000      1.12
+++ DownloadThread.java 11 Dec 2008 08:34:30 -0000      1.13
@@ -82,7 +82,6 @@
             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) {
@@ -102,7 +101,7 @@
          File file = new File(downloadSettings.getTempPath());//get the files 
which wget last download
          setupSuffix();
          modifyDownloadPath();
-         downloadAssociatedCss(file,new FileNameFilter(".css",".html"));
+         downloadAssociatedCss(file,new FileNameFilter(".css",".html"));//find 
the hidden css (@import)
          findAssociatedFiles(file, new MyFilenameFilter(".css", ".js", 
".html"));
          redownload(redownloadfiles);
          redownloadfiles.clear();//this will avoid to redownload picture in 
different request
@@ -422,7 +421,7 @@
    }
 
    /**
-    * the method is used to filter files by the suffixes
+    * the class is used to filter files by the suffixes
     */
    static class MyFilenameFilter implements FilenameFilter {
       private String suffix = "";
@@ -436,7 +435,6 @@
       }
 
       public boolean accept(File dir, String name) {
-         // TODO Auto-generated method stub
          if (new File(dir, name).isFile()) {
             return name.endsWith(suffix) || name.endsWith(suffix1)
                   || name.endsWith(suffix2);
@@ -480,10 +478,12 @@
       String path = webPath + str1;
       if (!redownloadfiles.contains(path))
          redownloadfiles.add(path);
+         System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeee-->"+path); 
    }
 
    private String getUrl() {
-      return downloadSettings.getLiveUrl();
+      modifyDownloadPath();
+      return webPath;
    }
 
    /**Use the filter to find the associated files which last wget downloads,
@@ -640,16 +640,22 @@
          String tempString, File file) {
       String downloadPath;
       if (StringUtils.isEmpty(webappName)) {
-         downloadPath = webPath + targetStringNew.substring(1);
+         String webPathNew = getRootFile(file,webPath);
+         if(!webPathNew.endsWith("/")){
+            webPathNew += "/";
+         }
+         downloadPath = webPathNew + targetStringNew.substring(1);
       } else {
          downloadPath = webPath
                + targetStringNew.substring(targetStringNew.indexOf(webappName) 
+webappName.length()+ 1);
       }
-      if (!redownloadfiles.contains(downloadPath))
+      if (!redownloadfiles.contains(downloadPath)){
          redownloadfiles.add(downloadPath);
-      
+         System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeee-->"+downloadPath);
+      }
       String filePath = file.getParent();
       String lurl = changeUrl(getUrl());
+      lurl = getRootFile(file,lurl);
       if(lurl.contains("/")){
          lurl = regularReplace(lurl,"/","\\\\");
       }
@@ -684,16 +690,32 @@
       }
       return tempString;
    }
+   private String getRootFile(File file,String url){
+      String filepath = file.getAbsolutePath();
+      if(StringUtils.isEmpty(webappName)){
+         String[] paraUrl = url.split("/");
+         for(String pUrl:paraUrl){
+            String newPath = 
filepath.substring(0,filepath.indexOf(pUrl)+pUrl.length());
+            File fileRoot = new File(newPath);
+            if(fileRoot.listFiles().length>1){
+               return pUrl;
+            }
 
+         }
+      }
+      return url;
+   }
    private void addDownloadPath(String str, File file, String targetPath) {
       String filepath = file.getAbsolutePath();
       String url = changeUrl(getUrl());
 //    String url = "web.finalist.hk\\finalist"; 
+
+//      log.info("##########################-->  url="+url);
+//      log.info("##########################-->  filepath="+filepath);
+      url = getRootFile(file,url);
       if(url.contains("/")){
          url = regularReplace(url,"/","\\\\");
       }
-      log.info("##########################-->  url="+url);
-      log.info("##########################-->  filepath="+filepath);
       int tagStart = filepath.indexOf(url);
       String u = filepath.substring(tagStart);
       int tagEnd = u.indexOf("\\" + str);
@@ -701,9 +723,12 @@
       String ss = regularReplace(m, "\\\\", "/");
       String str1 = regularReplace(targetPath, "\\.\\.", ss);
        
-      if (!redownloadfiles.contains(str1))
+      if (!redownloadfiles.contains(str1)){
          redownloadfiles.add(str1);
+         System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeee-->"+str1);
+      }
    }
+   /*this method intercept the protocol such as http:// according to "//"*/
    private String changeUrl(String url){
       String exUrl = url;
       if(url.contains("//")){
@@ -769,34 +794,20 @@
             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)) {
+               if (StringUtils.isNotEmpty(targetStringNew)&& 
targetStringNew.startsWith("/")) {
                      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)) {
+               if (StringUtils.isNotEmpty(targetName)&& 
targetName.startsWith("/")) {
                      tempString = this.downloadAndModifyPath(targetName,
                            tempString, file);
                   }
                }
-            }
             str = regularJudge("[\\w/_:.]*#top_anchor",tempString);
             if(StringUtils.isNotEmpty(str)){
                tempString = regularReplace(tempString,str,"#top_anchor");
@@ -825,7 +836,7 @@
    }
 
    
-   private void recurFindCss(File file,FileNameFilter fileNameFilter) {
+   private void recurFindCss(File file,FileNameFilter fileNameFilter) throws 
IOException {
         if (!file.exists()) {
             return;
          }
@@ -838,7 +849,7 @@
                      reader = new BufferedReader(new FileReader(files[i]));
                      String tempString = null;
                      while ((tempString = reader.readLine()) != null) {
-                        String regex = "[EMAIL 
PROTECTED](\"(\\S+)\"\\)\\s*;?\\s*";
+                        String regex = "[EMAIL 
PROTECTED](?\"(\\S+)\"\\)?[\\s\\S]*;?\\s*";
                         Pattern p2 = Pattern.compile(regex);
                         Matcher matcher = p2.matcher(tempString);
                        // System.out.print("--->"+matcher.group(1));
@@ -866,6 +877,10 @@
                   } 
                   catch (IOException e) {
                      log.info("IOException-------->"+e.getMessage());
+                  }finally{
+                     if (reader != null) {
+                        reader.close();
+                     }
                   }
 
             } else if (files[i].isDirectory()) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to