[Yanel-commits] rev 23095 - in public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp: rdf src/build src/java/org/wyona/yanel/impl/resources

andi at wyona.com andi at wyona.com
Fri Mar 2 16:25:34 CET 2007


Author: andi
Date: 2007-03-02 16:25:32 +0100 (Fri, 02 Mar 2007)
New Revision: 23095

Added:
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/CreateZip.java
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallInfo.java
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateInfo.java
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/WebAppUpdater.java
Removed:
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallRDF.java
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateRDF.java
Modified:
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/install.rdf
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/update.rdf
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/build/dependencies.xml
   public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateResource.java
Log:
Patch from bug #5206 (WIP), thanks to Simon.


Modified: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/install.rdf
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/install.rdf	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/install.rdf	2007-03-02 15:25:32 UTC (rev 23095)
@@ -1,15 +1,23 @@
 <?xml version="1.0"?>
 
-<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:um="http://www.wyona.org/update-manager/1.0#">
 
-  <Description about="urn:wyona:install-manifest">
-    <em:id>yanel at wyona.com</em:id>
-    <em:version>@VERSION@</em:version>
-    <em:name>Wyona Yanel</em:name>
-    <em:description>Everything is Content.</em:description>
-    <em:contributor>Michael Wechner (Wyona Inc.)</em:contributor>
-    <em:homepageURL>http://yanel.wyona.org/</em:homepageURL>
-    <em:updateURL>http://yanel.wyona.org/download/update.rdf</em:updateURL>
-  </Description>
-</RDF>
+  <rdf:Description rdf:about="urn:wyona:application:install">
+    <um:id>yanel-webapp at wyona.org</um:id>
+    <um:version>@VERSION@</um:version>
+    <um:installtype>@INSTALLTYPE@</um:installtype>
+    <um:name>Wyona Yanel Webapp</um:name>
+    <um:description>Content Management Software</um:description>
+    <um:creator>Wyona</um:creator>
+    <um:homepageURL>http://yanel.wyona.org/</um:homepageURL>
+    <um:updateURL>http://yanel.wyona.org/download/update.rdf</um:updateURL>
+    <um:updateProtect>
+      <rdf:Seq>
+       <rdf:li>WEB-INF/classes/yanel.properties</rdf:li>
+       <rdf:li>WEB-INF/classes/realms.xml</rdf:li>
+      </rdf:Seq>
+    </um:updateProtect>
+  </rdf:Description>
+  
+</rdf:RDF>

Modified: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/update.rdf
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/update.rdf	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/rdf/update.rdf	2007-03-02 15:25:32 UTC (rev 23095)
@@ -4,26 +4,116 @@
   <rdf:Description rdf:about="urn:wyona:application:updates">
     <um:versions>
       <rdf:Seq>
+        <rdf:li rdf:resource="urn:wyona:application:update:1.0-dev-r22342"/>
         <rdf:li rdf:resource="urn:wyona:application:update:1.0-dev-r22343"/>
-        <rdf:li rdf:resource="urn:wyona:application:update:1.0-dev-r22342"/>
+        <rdf:li rdf:resource="urn:wyona:application:update:1.0-dev-r52343"/>
+        <rdf:li rdf:resource="urn:wyona:application:update:1.0-dev-r12343"/>
       </rdf:Seq>
     </um:versions>
   </rdf:Description>  
   
   <rdf:Description rdf:about="urn:wyona:application:update:1.0-dev-r22342">
+    <um:id>yanel-webapp at wyona.org</um:id>
     <um:version>1.0-dev-r22342</um:version>
+    <um:changelog>this fixed and that improved</um:changelog>
     <um:targetApplication>
-      <rdf:Description rdf:about="urn:wyona:targetapplication:tomcat">
-        <um:minVersion>5.0.0</um:minVersion>
-        <um:maxVersion>5.5.*</um:maxVersion>
-	    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-jetty-build-0.1.1.xml</um:updateLink>
-      </rdf:Description>
+      <rdf:Seq>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:tomcat:1.0-dev-r22342"/>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:jetty:1.0-dev-r22342"/>
+      </rdf:Seq>
     </um:targetApplication>
   </rdf:Description>
 
+  <rdf:Description rdf:about="urn:wyona:targetapplication:tomcat:1.0-dev-r22342">
+    <um:id>Apache Tomcat</um:id>
+    <um:minVersion>5.0.0</um:minVersion>
+    <um:maxVersion>5.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-tomcat-update-1.0-dev-r22342.war</um:updateLink>
+  </rdf:Description>
+
+  <rdf:Description rdf:about="urn:wyona:targetapplication:jetty:1.0-dev-r22342">
+    <um:id>jetty</um:id>
+    <um:minVersion>5.0.0</um:minVersion>
+    <um:maxVersion>5.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-jetty-update-1.0-dev-r22342.war</um:updateLink>
+  </rdf:Description>
+
   <rdf:Description rdf:about="urn:wyona:application:update:1.0-dev-r22343">
+    <um:id>yanel-webapp at wyona.org</um:id>
     <um:version>1.0-dev-r22343</um:version>
-    <um:updateURL>http://yanel.wyona.org/download/binary-snapshots/unix/wyona-yanel-SNAPSHOT-1.0-dev-r22342-bin.tar.gz</um:updateURL>
+    <um:changelog>that improved and this fixed</um:changelog>
+    <um:targetApplication>
+      <rdf:Seq>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:tomcat:1.0-dev-r22343"/>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:jetty:1.0-dev-r22343"/>
+      </rdf:Seq>
+    </um:targetApplication>
   </rdf:Description>
+  
+  <rdf:Description rdf:about="urn:wyona:targetapplication:tomcat:1.0-dev-r22343">
+    <um:id>Apache Tomcat</um:id>
+    <um:minVersion>5.0.0</um:minVersion>
+    <um:maxVersion>5.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-tomcat-update-1.0-dev-r22343.war</um:updateLink>
+  </rdf:Description>
 
-</rdf:RDF>
+  <rdf:Description rdf:about="urn:wyona:targetapplication:jetty:1.0-dev-r22343">
+    <um:id>jetty</um:id>
+    <um:minVersion>5.0.0</um:minVersion>
+    <um:maxVersion>5.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-jetty-update-1.0-dev-r22343.war</um:updateLink>
+  </rdf:Description>  
+
+  <rdf:Description rdf:about="urn:wyona:application:update:1.0-dev-r52343">
+    <um:id>yanel-webapp at wyona.org</um:id>
+    <um:version>1.0-dev-r52343</um:version>
+    <um:changelog>that improved and this fixed</um:changelog>
+    <um:targetApplication>
+      <rdf:Seq>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:tomcat:1.0-dev-r52343"/>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:jetty:1.0-dev-r52343"/>
+      </rdf:Seq>
+    </um:targetApplication>
+  </rdf:Description>
+  
+  <rdf:Description rdf:about="urn:wyona:targetapplication:tomcat:1.0-dev-r52343">
+    <um:id>Apache Tomcat</um:id>
+    <um:minVersion>6.0.0</um:minVersion>
+    <um:maxVersion>6.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-tomcat-update-1.0-dev-r52343.war</um:updateLink>
+  </rdf:Description>
+
+  <rdf:Description rdf:about="urn:wyona:targetapplication:jetty:1.0-dev-r52343">
+    <um:id>jetty</um:id>
+    <um:minVersion>5.0.0</um:minVersion>
+    <um:maxVersion>5.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-jetty-update-1.0-dev-r52343.war</um:updateLink>
+  </rdf:Description>
+      
+  <rdf:Description rdf:about="urn:wyona:application:update:1.0-dev-r12343">
+    <um:id>yanel-webapp at wyona.org</um:id>
+    <um:version>1.0-dev-r12343</um:version>
+    <um:changelog>that improved and this fixed</um:changelog>
+    <um:targetApplication>
+      <rdf:Seq>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:tomcat:1.0-dev-r12343"/>
+        <rdf:li rdf:resource="urn:wyona:targetapplication:jetty:1.0-dev-r12343"/>
+      </rdf:Seq>
+    </um:targetApplication>
+  </rdf:Description>  
+    
+  <rdf:Description rdf:about="urn:wyona:targetapplication:tomcat:1.0-dev-r12343">
+    <um:id>Apache Tomcat</um:id>
+    <um:minVersion>4.0.0</um:minVersion>
+    <um:maxVersion>4.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-tomcat-update-1.0-dev-r12343.war</um:updateLink>
+  </rdf:Description>
+
+  <rdf:Description rdf:about="urn:wyona:targetapplication:jetty:1.0-dev-r12343">
+    <um:id>jetty</um:id>
+    <um:minVersion>5.0.0</um:minVersion>
+    <um:maxVersion>5.5.*</um:maxVersion>
+    <um:updateLink>http://yanel.wyona.org/download/wyona-yanel-jetty-update-1.0-dev-r12343.war</um:updateLink>
+  </rdf:Description>
+
+</rdf:RDF>
\ No newline at end of file

Modified: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/build/dependencies.xml	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/build/dependencies.xml	2007-03-02 15:25:32 UTC (rev 23095)
@@ -7,12 +7,11 @@
 
     <artifact:dependencies pathId="maven2.classpath" filesetId="maven2.fileset">
       <remoteRepository refid="wyona.remote.repository"/>
-      <dependency groupId="wyona-org-yanel" artifactId="yanel-core"
-                  version="${yanel.source.version}"/>
+      <dependency groupId="wyona-org-yanel" artifactId="yanel-core" version="${yanel.source.version}"/>
       <dependency groupId="avalon-framework" artifactId="avalon-framework-api" version="4.3"/>
       <dependency groupId="avalon-framework" artifactId="avalon-framework-impl" version="4.3"/>                                
-      <dependency groupId="jena" artifactId="jena"
-                  version="2.1"/>
+      <dependency groupId="jena" artifactId="jena" version="2.1"/>
+      <dependency groupId="apache-jakarta-commons" artifactId="apache-jakarta-commons-io" version="1.2"/>
     </artifact:dependencies>
 
     <artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">

Added: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/CreateZip.java
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/CreateZip.java	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/CreateZip.java	2007-03-02 15:25:32 UTC (rev 23095)
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2006 Wyona
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * @author Piku Mishra
+ * 
+ */
+public class CreateZip {
+
+    File files[];
+    ZipOutputStream zipOutput;
+
+    public void create(String destFile, File[] files, ArrayList originalPath) {
+        this.files = files;
+        try {
+            zipOutput = new ZipOutputStream(new FileOutputStream(destFile));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        createZip(originalPath);
+        close();
+    }
+    
+    public void createZip(ArrayList originalPath) {
+        try {
+            byte[] buff = new byte[10240];
+            File[] fileList = files;
+
+            for (int i = 0; i < fileList.length; i++) {
+                    FileInputStream fin = new FileInputStream(fileList[i]);
+                    zipOutput.putNextEntry(new ZipEntry(((String) originalPath.get(i))));
+                    int len;
+                    while ((len = fin.read(buff)) > 0) {
+                        zipOutput.write(buff, 0, len);
+                    }
+                    fin.close();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Method used to close the object for ZipOutputStream
+     */
+    public void close() {
+        try {
+            zipOutput.flush();
+            zipOutput.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
\ No newline at end of file

Added: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallInfo.java
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallInfo.java	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallInfo.java	2007-03-02 15:25:32 UTC (rev 23095)
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2006 Wyona
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import org.apache.log4j.Category;
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+
+import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.vocabulary.*;
+import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
+import javax.servlet.http.HttpServletRequest;
+/**
+ * 
+ */
+public class InstallInfo {
+    
+    private static Category log = Category.getInstance(InstallInfo.class);
+    private String id;
+    private String version;
+    private String installtype;
+    private String contextPrefix;
+    private String updateURL;
+    private String osName; //platform
+    private String javaVersion;
+    private String targetApplicationId;
+    private String targetApplicationVersion;
+    private ArrayList protectedFiles = new ArrayList();
+    
+    private String updateManagerNS = "http://www.wyona.org/update-manager/1.0#"; 
+    
+    public InstallInfo(HttpServletRequest request)  throws java.io.FileNotFoundException{
+        String WEBINFPath = request.getSession().getServletContext().getRealPath("WEB-INF");
+        contextPrefix = request.getSession().getServletContext().getServletContextName();
+        if (contextPrefix.equalsIgnoreCase("ROOT")) {
+            contextPrefix = "ROOT";
+        } else {
+            contextPrefix = contextPrefix.toLowerCase();
+        }
+        InputStream installRdfIn = new FileInputStream(new File(WEBINFPath + File.separator + "classes" + File.separator + "install.rdf"));
+        Model model = ModelFactory.createDefaultModel();
+        //read the RDF/XML file
+        model.read(installRdfIn, "");
+        parseModel(model);
+        
+        setServerInfoDetail(request);
+        
+        osName = System.getProperty("os.name");
+        javaVersion = System.getProperty("java.version");
+    }
+
+    private void parseModel(Model model) {
+        Resource install = model.getResource("urn:wyona:application:install");
+        
+        Property idProperty = new PropertyImpl(updateManagerNS, "id");
+        id = install.getRequiredProperty(idProperty).getString();
+        Property versionProperty = new PropertyImpl(updateManagerNS, "version");
+        version = install.getRequiredProperty(versionProperty).getString();
+        Property installtypeProperty = new PropertyImpl(updateManagerNS, "installtype");
+        installtype = install.getRequiredProperty(installtypeProperty).getString();
+        //Property contextPrefixProperty = new PropertyImpl(updateManagerNS, "contextprefix");
+        //contextPrefix = install.getRequiredProperty(contextPrefixProperty).getString();
+
+        Property updateURLProperty = new PropertyImpl(updateManagerNS, "updateURL");
+        updateURL = install.getRequiredProperty(updateURLProperty).getString();
+
+        Property protectedFilesProperty = new PropertyImpl(updateManagerNS, "protectedFiles");
+        Seq protectedFilesSeq = install.getRequiredProperty(protectedFilesProperty).getSeq();
+        
+        NodeIterator protectedFilesIter = protectedFilesSeq.iterator();
+        while (protectedFilesIter.hasNext()) {
+            protectedFiles.add(protectedFilesIter.next().toString());
+        }
+        
+        /*Property targetApplicationProperty = new PropertyImpl(updateManagerNS, "targetApplication");
+        Resource targetApplication = install.getProperty(targetApplicationProperty).getResource();
+        
+        Property targetApplicationIdProperty = new PropertyImpl(updateManagerNS, "id");
+        targetApplicationId = targetApplication.getRequiredProperty(targetApplicationIdProperty).getString();
+        Property targetApplicationVersionProperty = new PropertyImpl(updateManagerNS, "version");
+        targetApplicationVersion = targetApplication.getRequiredProperty(targetApplicationVersionProperty).getString();*/
+        
+    }
+
+    private void setServerInfoDetail(HttpServletRequest request) {
+        //this needs to be implemented for each servlet container since it doesn't seem the string of getServerInfo() is standardized
+        String serverInfo = request.getSession().getServletContext().getServerInfo();
+        
+        if (serverInfo.startsWith("Apache Tomcat")) {
+            targetApplicationId  = serverInfo.split("/")[0];
+            targetApplicationVersion  = serverInfo.split("/")[1];
+        } else {
+            targetApplicationId  = serverInfo.split("/")[0];
+            targetApplicationVersion  = serverInfo.split("/")[1];
+            log.info("the dedection of the servlet container name and version is just a guess. if there is something wrong please implement your servlets getServerInfo() string. thanks :)");
+        }
+        
+    }
+    
+
+    public String getId() {
+        return id;
+    }
+
+    public String getInstalltype() {
+        return installtype;
+    }
+    public String getContextPrefix() {
+        return contextPrefix;
+    }
+
+    public String getUpdateURL() {
+        return updateURL;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public String getJavaVersion() {
+        return javaVersion;
+    }
+
+    public String getOsName() {
+        return osName;
+    }
+
+    public String getTargetApplicationId() {
+        return targetApplicationId;
+    }
+
+    public String getTargetApplicationVersion() {
+        return targetApplicationVersion;
+    }
+
+    public ArrayList getProtectedFiles() {
+        return protectedFiles;
+    }
+    
+}
\ No newline at end of file

Deleted: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallRDF.java
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallRDF.java	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/InstallRDF.java	2007-03-02 15:25:32 UTC (rev 23095)
@@ -1,115 +0,0 @@
-/*
- * Copyright 2006 Wyona
- */
-
-package org.wyona.yanel.impl.resources;
-
-import org.apache.log4j.Category;
-import java.io.File;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import com.hp.hpl.jena.rdf.model.*;
-import com.hp.hpl.jena.vocabulary.*;
-import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
-import javax.servlet.http.HttpServletRequest;
-/**
- * 
- */
-public class InstallRDF {
-    
-    private static Category log = Category.getInstance(InstallRDF.class);
-    private String id;
-    private String version;
-    private String installtype;
-    private String updateURL;
-    private String osName; //platform
-    private String javaVersion;
-    private String targetApplicationId;
-    private String targetApplicationVersion;
-    
-    private String updateManagerNS = "http://www.wyona.org/update-manager/1.0#"; 
-    
-    public InstallRDF(InputStream in, HttpServletRequest request){
-        setServerInfoDetail(request);
-        
-        osName = System.getProperty("os.name");
-        javaVersion = System.getProperty("java.version");
-        
-        Model model = ModelFactory.createDefaultModel();
-        //read the RDF/XML file
-        model.read(in, "");
-        parseModel(model);
-    }
-
-    private void parseModel(Model model) {
-        Resource install = model.getResource("urn:wyona:application:install");
-        
-        Property idProperty = new PropertyImpl(updateManagerNS, "id");
-        id = install.getRequiredProperty(idProperty).getString();
-        Property versionProperty = new PropertyImpl(updateManagerNS, "version");
-        version = install.getRequiredProperty(versionProperty).getString();
-        Property installtypeProperty = new PropertyImpl(updateManagerNS, "installtype");
-        installtype = install.getRequiredProperty(installtypeProperty).getString();
-
-        Property updateURLProperty = new PropertyImpl(updateManagerNS, "updateURL");
-        updateURL = install.getRequiredProperty(updateURLProperty).getString();
-
-        /*Property targetApplicationProperty = new PropertyImpl(updateManagerNS, "targetApplication");
-        Resource targetApplication = install.getProperty(targetApplicationProperty).getResource();
-        
-        Property targetApplicationIdProperty = new PropertyImpl(updateManagerNS, "id");
-        targetApplicationId = targetApplication.getRequiredProperty(targetApplicationIdProperty).getString();
-        Property targetApplicationVersionProperty = new PropertyImpl(updateManagerNS, "version");
-        targetApplicationVersion = targetApplication.getRequiredProperty(targetApplicationVersionProperty).getString();*/
-        
-    }
-
-    private void setServerInfoDetail(HttpServletRequest request) {
-        //this needs to be implemented for each servlet container since it doesn't seem the string of getServerInfo() is standardized
-        String serverInfo = request.getSession().getServletContext().getServerInfo();
-        
-        if (serverInfo.startsWith("Apache Tomcat")) {
-            targetApplicationId  = serverInfo.split("/")[0];
-            targetApplicationVersion  = serverInfo.split("/")[1];
-        } else {
-            targetApplicationId  = serverInfo.split("/")[0];
-            targetApplicationVersion  = serverInfo.split("/")[1];
-            log.info("the dedection of the servlet container name and version is just a guess. if there is something wrong please implement your servlets getServerInfo() string. thanks :)");
-        }
-        
-    }
-    
-
-    public String getId() {
-        return id;
-    }
-
-    public String getInstalltype() {
-        return installtype;
-    }
-
-    public String getUpdateURL() {
-        return updateURL;
-    }
-
-    public String getVersion() {
-        return version;
-    }
-
-    public String getJavaVersion() {
-        return javaVersion;
-    }
-
-    public String getOsName() {
-        return osName;
-    }
-
-    public String getTargetApplicationId() {
-        return targetApplicationId;
-    }
-
-    public String getTargetApplicationVersion() {
-        return targetApplicationVersion;
-    }
-    
-}
\ No newline at end of file

Added: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateInfo.java
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateInfo.java	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateInfo.java	2007-03-02 15:25:32 UTC (rev 23095)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2006 Wyona
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import org.apache.log4j.Category;
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.vocabulary.*;
+import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
+import java.util.HashMap;
+
+/**
+ * 
+ */
+public class UpdateInfo {
+    
+    private static Category log = Category.getInstance(UpdateInfo.class);
+    private ArrayList updateVersions = new ArrayList();
+    private Model updateRdfModel;
+    private InstallInfo installInfo;
+    
+    private String updateManagerNS = "http://www.wyona.org/update-manager/1.0#"; 
+    
+    public UpdateInfo(InputStream in, InstallInfo installInfo) throws Exception{
+        if (installInfo == null) {
+            throw new Exception("InstallInfo should not be null");
+        }
+        if (in == null) {
+            throw new Exception("InputStraeam should not be null");
+        }
+        Model model = ModelFactory.createDefaultModel();
+        //read the RDF/XML file
+        model.read(in, "");
+        this.updateRdfModel = model;
+        this.installInfo = installInfo;
+
+        setUpdateVersions();
+    }
+
+    private void setUpdateVersions() {
+        Resource update = updateRdfModel.getResource("urn:wyona:application:updates");
+        
+        Property versionsProperty = new PropertyImpl(updateManagerNS, "versions");
+        Seq versions = update.getProperty(versionsProperty).getSeq();
+        
+        NodeIterator iter2 = versions.iterator();
+        Property versionProperty = new PropertyImpl(updateManagerNS, "version");
+        Property idProperty = new PropertyImpl(updateManagerNS, "id");
+        Property targetApplicationProperty = new PropertyImpl(updateManagerNS, "targetApplication");
+        Property minVersionProperty = new PropertyImpl(updateManagerNS, "minVersion");
+        Property maxVersionProperty = new PropertyImpl(updateManagerNS, "maxVersion");
+        Property changeLogProperty = new PropertyImpl(updateManagerNS, "changelog");
+        Property updateLinkProperty = new PropertyImpl(updateManagerNS, "updateLink");
+        
+        while (iter2.hasNext()) {
+            Resource versionResource = ((Resource) iter2.next());
+            
+            //check id
+            if (versionResource.getProperty(idProperty).getString().equals(installInfo.getId())) {
+                //check for targetApplicationId
+                Seq targetApplicationSeq = versionResource.getProperty(targetApplicationProperty).getSeq();
+                NodeIterator targetApplicationIter = targetApplicationSeq.iterator();
+                while (targetApplicationIter.hasNext()) {
+                    Resource targetApplicationResource = ((Resource) targetApplicationIter.next());
+                    String test1 = targetApplicationResource.getProperty(idProperty).getString();
+                    String test2 = installInfo.getTargetApplicationId();
+                    System.out.println("taid: "+test1 +" install: "+ test2);
+                    
+                    if (targetApplicationResource.getProperty(idProperty).getString().equals(installInfo.getTargetApplicationId())) {
+
+                        //check for minorVersion
+                        String minVersion = targetApplicationResource.getProperty(minVersionProperty).getString();
+                        String installVersion = installInfo.getTargetApplicationVersion();
+                        VersionComparator versionComparator = new VersionComparator(); 
+                        if (versionComparator.compare(installVersion, minVersion) >= 0) {
+                            //check for maxVersion
+                            String maxVersion = targetApplicationResource.getProperty(maxVersionProperty).getString();
+                            if (versionComparator.compare(maxVersion, installVersion) >= 0) {
+                                HashMap updateVersions = new HashMap();
+                                updateVersions.put("version", versionResource.getProperty(versionProperty).getString());
+                                updateVersions.put("changeLog", versionResource.getProperty(changeLogProperty).getString());
+                                updateVersions.put("updateLink", targetApplicationResource.getProperty(updateLinkProperty).getString());
+                                this.updateVersions.add(updateVersions);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public ArrayList getUpdateVersions() {
+        return updateVersions;
+    }
+}

Deleted: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateRDF.java
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateRDF.java	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateRDF.java	2007-03-02 15:25:32 UTC (rev 23095)
@@ -1,104 +0,0 @@
-/*
- * Copyright 2006 Wyona
- */
-
-package org.wyona.yanel.impl.resources;
-
-import org.apache.log4j.Category;
-import org.wyona.yanel.impl.resources.VersionComparator;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.util.ArrayList;
-import com.hp.hpl.jena.rdf.model.*;
-import com.hp.hpl.jena.vocabulary.*;
-import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
-/**
- * 
- */
-public class UpdateRDF {
-    
-    private static Category log = Category.getInstance(InstallRDF.class);
-    private ArrayList updateVersions = new ArrayList();
-    private Model updateRdfModel;
-    private InstallRDF installRdf;
-    
-    private String updateManagerNS = "http://www.wyona.org/update-manager/1.0#"; 
-    
-    public UpdateRDF(InputStream in, InstallRDF installRdf) throws Exception{
-        Model model = ModelFactory.createDefaultModel();
-        //read the RDF/XML file
-        model.read(in, "");
-        this.updateRdfModel = model;
-        this.installRdf = installRdf;
-        if (installRdf == null) {
-            throw new Exception("InstallRDF should not be null");
-        }
-        setUpdateVersions();
-    }
-
-    private void setUpdateVersions() {
-        Resource update = updateRdfModel.getResource("urn:wyona:application:updates");
-        
-        Property versionsProperty = new PropertyImpl(updateManagerNS, "versions");
-        Seq versions = update.getProperty(versionsProperty).getSeq();
-        
-        NodeIterator iter2 = versions.iterator();
-        Property versionProperty = new PropertyImpl(updateManagerNS, "version");
-        Property idProperty = new PropertyImpl(updateManagerNS, "id");
-        Property targetApplicationProperty = new PropertyImpl(updateManagerNS, "targetApplication");
-        Property minVersionProperty = new PropertyImpl(updateManagerNS, "minVersion");
-        Property maxVersionProperty = new PropertyImpl(updateManagerNS, "maxVersion");
-        Property changeLogProperty = new PropertyImpl(updateManagerNS, "changelog");
-        Property updateLinkProperty = new PropertyImpl(updateManagerNS, "updateLink");
-        
-        while (iter2.hasNext()) {
-            Resource versionResource = ((Resource) iter2.next());
-            
-            //check id
-            if (versionResource.getProperty(idProperty).getString().equals(installRdf.getId())) {
-                //check for targetApplicationId
-                Seq targetApplicationSeq = versionResource.getProperty(targetApplicationProperty).getSeq();
-                NodeIterator targetApplicationIter = targetApplicationSeq.iterator();
-                while (targetApplicationIter.hasNext()) {
-                    Resource targetApplicationResource = ((Resource) targetApplicationIter.next());
-                    String test1 = targetApplicationResource.getProperty(idProperty).getString();
-                    String test2 = installRdf.getTargetApplicationId();
-                    System.out.println("taid: "+test1 +" install: "+ test2);
-                    
-                    if (targetApplicationResource.getProperty(idProperty).getString().equals(installRdf.getTargetApplicationId())) {
-
-                        //check for minorVersion
-                        String minVersion = targetApplicationResource.getProperty(minVersionProperty).getString();
-                        String installVersion = installRdf.getTargetApplicationVersion();
-                        VersionComparator versionComparator = new VersionComparator(); 
-                        if (versionComparator.compare(installVersion, minVersion) >= 0) {
-                            //check for maxVersion
-                            String maxVersion = targetApplicationResource.getProperty(maxVersionProperty).getString();
-                            if (versionComparator.compare(maxVersion, installVersion) >= 0) {
-                                UpdateVersions updateVersions = new UpdateVersions();
-                                updateVersions.version = versionResource.getProperty(versionProperty).getString();
-                                updateVersions.changeLog = versionResource.getProperty(changeLogProperty).getString();
-                                updateVersions.updateLink = targetApplicationResource.getProperty(updateLinkProperty).getString();
-                                this.updateVersions.add(updateVersions);
-                            }
-                        }
-                    }
-                }
-
-                
-            }
-        }
-    }
-
-    public ArrayList getUpdateVersions() {
-        return updateVersions;
-    }
-    
-    public class UpdateVersions {     
-        String version;
-        String changeLog;
-        String updateLink;
-    }
-}

Modified: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateResource.java
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateResource.java	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/UpdateResource.java	2007-03-02 15:25:32 UTC (rev 23095)
@@ -14,7 +14,6 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.wyona.yanel.core.transformation.I18nTransformer;
-import org.wyona.yanel.impl.resources.UpdateRDF.UpdateVersions;
 
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
@@ -26,12 +25,14 @@
 import java.io.ByteArrayInputStream;
 import java.io.FileInputStream;
 import java.util.ArrayList;
+import java.util.HashMap;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import java.io.File;
+
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 import java.net.URL;
@@ -75,11 +76,6 @@
     public View getView(String viewId) throws Exception {
 
         String path = getPath();
-        HttpServletRequest request = getRequest();
-        
-        String submit = request.getParameter("submit");
-        String check = request.getParameter("check");
-        String update = request.getParameter("update");
 
         // Get language
         try {
@@ -102,30 +98,32 @@
         try {
 
                     //install.rdf
-                    String WEBINFPath = request.getSession().getServletContext().getRealPath("WEB-INF");
                     
-                    InputStream installRdfIn= new FileInputStream(new File(WEBINFPath + File.separator + "classes" + File.separator + "install.rdf"));
-                    InstallRDF installRdf = new InstallRDF(installRdfIn, request);
+                    InstallInfo installInfo = new InstallInfo(request);
 
+                    //just testing
+                    System.out.println(installInfo.getId());
+                    System.out.println(installInfo.getInstalltype());
+                    System.out.println(installInfo.getContextPrefix());
+                    System.out.println(installInfo.getOsName());
+                    System.out.println(installInfo.getTargetApplicationId());
+                    System.out.println(installInfo.getTargetApplicationVersion());
+                    System.out.println(installInfo.getUpdateURL());
+                    System.out.println(installInfo.getVersion());
+                    System.out.println(installInfo.getJavaVersion());
+                    for (int i = 0; i < installInfo.getProtectedFiles().size(); i++) {
+                        System.out.println("getProtectedFiles --------" + installInfo.getProtectedFiles().get(i));
+                    }
                     
-                    System.out.println(installRdf.getId());
-                    System.out.println(installRdf.getInstalltype());
-                    System.out.println(installRdf.getOsName());
-                    System.out.println(installRdf.getTargetApplicationId());
-                    System.out.println(installRdf.getTargetApplicationVersion());
-                    System.out.println(installRdf.getUpdateURL());
-                    System.out.println(installRdf.getVersion());
-                    System.out.println(installRdf.getJavaVersion());
                     
                     
-                    
-                    URL UpdateRdfUrl = new URL(installRdf.getUpdateURL());
+                    URL UpdateRdfUrl = new URL(installInfo.getUpdateURL());
                     InputStream updateRdfIn = UpdateRdfUrl.openStream();
-                    UpdateRDF updateRdf = new UpdateRDF(updateRdfIn, installRdf);
+                    UpdateInfo updateInfo = new UpdateInfo(updateRdfIn, installInfo);
                     
 
                     
-                    if (installRdf.getInstalltype().equals("source")) {
+                    if (installInfo.getInstalltype().equals("source")) {
                         StringBuffer message = new StringBuffer();
                         message.append("<p>");
                         message.append("This Yanel was installed from source. You can only use the updater if you installed yanel from binary. Please use svn up, build.sh");
@@ -135,22 +133,39 @@
                         //transformer = TransformerFactory.newInstance().newTransformer();
 
                         
-                    } else if (installRdf.getInstalltype().equals("bin-snapshot")) {
-                        StringBuffer message = new StringBuffer();
-                        message.append("<p>");
-                        message.append("This are the updates which you can get:");
-                        message.append("</p>");
-                        message.append("<ul>");
-                        for (int i = 0; i < updateRdf.getUpdateVersions().size(); i++) {
-                            UpdateVersions test = (UpdateVersions) updateRdf.getUpdateVersions().get(i);
-                            if (test.version != installRdf.getVersion()) {
-                                message.append("<li>Version: " + test.version + " ChangeLog: " + test.changeLog + " Update Link: " + test.updateLink + "</li>");
-                            }
+                    } else if (installInfo.getInstalltype().equals("bin-snapshot")) {
+                if (request.getParameter("update") != null && request.getParameter("update").equals("true")) {
+                    WebAppUpdater webAppUpdater = new WebAppUpdater(request, "");
+                    
+                    StringBuffer message = new StringBuffer();
+                    message.append("<p>");
+                    if (webAppUpdater.update()) {
+                        message.append("Update done.");
+                    } else {
+                        message.append("Update failed.");
+                    }
+                    message.append("</p>");
+                    byteArrayOutputStream = getOutput(message);
+                } else {
+                    StringBuffer message = new StringBuffer();
+                    message.append("<p>");
+                    message.append("This are the updates which you can get:");
+                    message.append("</p>");
+                    message.append("<ul>");
+                    for (int i = 0; i < updateInfo.getUpdateVersions().size(); i++) {
+                        HashMap versionDetails = (HashMap) updateInfo.getUpdateVersions()
+                                .get(i);
+                        if (versionDetails.get("version") != installInfo.getVersion()) {
+                            message.append("<li>Version: " + versionDetails.get("version") + " ChangeLog: "
+                                    + versionDetails.get("changeLog") + " Update Link: " + versionDetails.get("updateLink") + "<form><input type=\"submit\" name=\"update\" value=\"true\"></input></form></li>");
                         }
-                        message.append("</ul>");
-                        byteArrayOutputStream = getOutput(message);
                     }
-                    //this.installRdf.put("updateURL", installRdf.getChild("Description").getChild("um:updateURL").getValue());
+                    message.append("</ul>");
+                    byteArrayOutputStream = getOutput(message);
+                }
+            }
+                    // this.installRdf.put("updateURL",
+                    // installRdf.getChild("Description").getChild("um:updateURL").getValue());
                     //this.installRdf.put("version", installRdf.getChild("Description").getChild("um:version").getValue()); 
                     //transformer.transform(new StreamSource(InstallRdf), new StreamResult(byteArrayOutputStream));
                     
@@ -165,15 +180,14 @@
                     
                     
 
-            SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
-            saxParser.parse(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()),
-                    i18nTransformer);
+            //SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
+            //saxParser.parse(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()),i18nTransformer);
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }
 
         defaultView.setMimeType("application/xhtml+xml");
-        defaultView.setInputStream(i18nTransformer.getInputStream());
+        defaultView.setInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
         return defaultView;
     }
 

Added: public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/WebAppUpdater.java
===================================================================
--- public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/WebAppUpdater.java	2007-03-02 14:45:54 UTC (rev 23094)
+++ public/yanel/trunk/src/realms/welcome-admin/yanel/resources/update-webapp/src/java/org/wyona/yanel/impl/resources/WebAppUpdater.java	2007-03-02 15:25:32 UTC (rev 23095)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 Wyona
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import org.apache.log4j.Category;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.io.FileUtils;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+
+public class WebAppUpdater {
+    
+    private static Category log = Category.getInstance(WebAppUpdater.class);
+    private String contextDirectoryPath;
+    private String UpdateLink;
+    private HttpServletRequest request;
+    private InstallInfo installInfo;
+    
+    
+    public WebAppUpdater(HttpServletRequest request, String UpdateLink) throws Exception {
+        this.request = request;
+        this.contextDirectoryPath = request.getSession().getServletContext().getRealPath(".");
+        this.UpdateLink = UpdateLink;
+        this.installInfo = new InstallInfo(request);
+    }
+    
+    public boolean update() {
+        backUpProtected();
+        try {
+            backUpWar();
+        } catch (Exception e) {
+            log.error("could not back the war file." + e);
+            return false;
+        }
+        return true;
+    }
+    
+    private File getInstalledWar() {
+        return new File(contextDirectoryPath + File.separator + ".." + File.separator + installInfo.getContextPrefix() + ".war");
+    }
+    
+    private File[] getUpdateProtectedFiles() {
+        ArrayList FileNames = installInfo.getProtectedFiles();
+        File[] protectedFiles = new File [FileNames.size()];
+        for (int i = 0; i < FileNames.size(); i++) {
+            File protectedFile = new File(contextDirectoryPath + File.separator + ((String) FileNames.get(i)));
+            protectedFiles[i] = protectedFile; 
+        }
+        return protectedFiles;
+    }
+    
+    private void backUpProtected() {
+        CreateZip protectedFile = new CreateZip();
+        String destFileName = contextDirectoryPath + File.separator + ".." + File.separator + "yanel-conf-" + installInfo.getVersion() + ".zip";
+        protectedFile.create(destFileName, getUpdateProtectedFiles(), installInfo.getProtectedFiles());
+    }
+    
+    private void backUpWar() throws java.io.IOException{
+        FileUtils.copyFile(getInstalledWar(), new File(contextDirectoryPath + File.separator + ".." + File.separator + "yanel-" + installInfo.getVersion() + ".jar"));
+    }
+    
+    private void downloadUpdateWar(String updateLink) throws IOException {
+        URL updateWarUrl = new URL(updateLink);
+        InputStream updateWarIn = updateWarUrl.openStream();
+        
+        OutputStream out = new FileOutputStream(contextDirectoryPath + File.separator + ".." + File.separator + installInfo.getContextPrefix() + ".war");
+    
+        byte[] buf = new byte[1024];
+        int len;
+        while ((len = updateWarIn.read(buf)) > 0) {
+            out.write(buf, 0, len);
+        }
+        updateWarIn.close();
+        out.close();
+    }
+}
\ No newline at end of file




More information about the Yanel-commits mailing list