Author: sshyrkov
Date: Wed Nov 14 19:56:57 2007
New Revision: 19153

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19153&repname=
=3Djahia
Log:
Work in progress: adjust export of template set related classes (initial ve=
rsion - to prevent the export failure)

Added:
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/utils/zip/Fil=
teredDirectoryWalker.java
Modified:
    branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/impo=
rtexport/ImportExportBaseService.java

Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/service=
s/importexport/ImportExportBaseService.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/java/org/jahia/services/importexport/ImportExportBase=
Service.java&rev=3D19153&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/impo=
rtexport/ImportExportBaseService.java (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/services/impo=
rtexport/ImportExportBaseService.java Wed Nov 14 19:56:57 2007
@@ -66,6 +66,7 @@
 import org.apache.commons.id.IdentifierGenerator;
 import org.apache.commons.id.IdentifierGeneratorFactory;
 import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
 import org.apache.slide.content.NodeProperty;
 import org.apache.webdav.lib.WebdavResource;
 import org.apache.xerces.dom.DocumentImpl;
@@ -143,6 +144,7 @@
 import org.jahia.services.workflow.WorkflowService;
 import org.jahia.utils.JahiaTools;
 import org.jahia.utils.LanguageCodeConverters;
+import org.jahia.utils.zip.FilteredDirectoryWalker;
 import org.quartz.CronTrigger;
 import org.quartz.JobDataMap;
 import org.quartz.JobDetail;
@@ -162,8 +164,15 @@
  */
 public class ImportExportBaseService extends JahiaService implements Impor=
tExportService {
 =

-    private static org.apache.log4j.Logger logger =3D
-            org.apache.log4j.Logger.getLogger(ImportExportBaseService.clas=
s);
+    private static final String[] CLASSES_EXCLUDE_PATTERNS =3D new String[=
] {
+            "org/jahia/", "org/apache/",
+            "JahiaAdministrationResources*.properties",
+            "JahiaEnginesResources*.properties",
+            "JahiaMessageResources*.properties", "mbeans-descriptors.xml",
+            "jahiapublickeystore" };
+    =

+    private static Logger logger =3D Logger
+            .getLogger(ImportExportBaseService.class);
 =

     private static ImportExportBaseService instance;
 =

@@ -446,33 +455,14 @@
         }
     }
 =

-    public void exportClasses(OutputStream out, ProcessingContext jParams)=
 throws IOException {
-        String path =3D Jahia.getSettings().getClassDiskPath();
-
+    private void exportClasses(OutputStream out, ProcessingContext jParams=
) throws IOException {
         ZipOutputStream zout =3D new ZipOutputStream(out);
-        Set excludes =3D  new HashSet();
-        excludes.add("/org/jahia");
-        excludes.add("/org/apache");
-
-        File[] rb =3D new File(path).listFiles(new FilenameFilter() {
-            public boolean accept(File dir, String name) {
-                return name.startsWith("JahiaAdministrationResources") ||
-                        name.startsWith("JahiaEnginesResources") ||
-                        name.startsWith("JahiaMessageResources");
-            }
-        });
-        for (int i =3D 0; i < rb.length; i++) {
-            File file =3D rb[i];
-            excludes.add("/"+file.getName());
-        }
-
-        excludes.add("/mbeans-descriptors.xml");
-        excludes.add("/jahiapublickeystore");
-        addFiles(new File(path), "", excludes, zout);
+        new FilteredDirectoryWalker(new File(Jahia.getSettings()
+                .getClassDiskPath()), CLASSES_EXCLUDE_PATTERNS, true).zip(=
zout);
         zout.finish();
     }
 =

-    private void exportTpl(OutputStream out, ProcessingContext jParams, Ja=
hiaSite s) throws IOException {
+    private void exportTplOld(OutputStream out, ProcessingContext jParams,=
 JahiaSite s) throws IOException {
         ZipOutputStream zout =3D new ZipOutputStream(out);
 =

         String path =3D Jahia.getSettings().getJahiaTemplatesDiskPath() + =
File.separator + s.getSiteKey();
@@ -569,6 +559,104 @@
         zout.finish();
     }
 =

+    private void exportTpl(OutputStream out, ProcessingContext jParams, Ja=
hiaSite s) throws IOException {
+        ZipOutputStream zout =3D new ZipOutputStream(out);
+
+//        String path =3D Jahia.getSettings().getJahiaTemplatesDiskPath() =
+ File.separator + s.getSiteKey();
+//
+//        int homeId =3D s.getHomeContentPage().getPageTemplateID(jParams);
+//
+//        File f =3D new File(path);
+//        HashSet excludes =3D new HashSet();
+//        excludes.add("/templates.xml");
+//        excludes.add("/classes.jar");
+//        addFiles(f, "", excludes, zout);
+
+        // export classes
+        zout.putNextEntry(new ZipEntry("classes.jar"));
+        exportClasses(zout, jParams);
+
+//        try {
+//            zout.putNextEntry(new ZipEntry("templates.xml"));
+//            DataWriter h =3D new DataWriter(new OutputStreamWriter(zout,=
 "UTF-8"));
+//            Enumeration en =3D ServicesRegistry.getInstance().getJahiaPa=
geTemplateService().getPageTemplates(s.getID(), false);
+//
+//            h.startElement("", "tpml", "tpml", new AttributesImpl());
+//
+//            AttributesImpl atts =3D new AttributesImpl();
+//            atts.addAttribute("","name", "name", "CDATA", "package-name"=
);
+//            h.startElement("", "parameter", "parameter", atts);
+//            h.characters(s.getSiteKey().toCharArray(),0,s.getSiteKey().l=
ength());
+//            h.endElement("", "parameter", "parameter");
+//
+//            atts =3D new AttributesImpl();
+//            atts.addAttribute("","name", "name", "CDATA", "root-folder");
+//            h.startElement("", "parameter", "parameter", atts);
+//            h.endElement("", "parameter", "parameter");
+//
+//            atts =3D new AttributesImpl();
+//            atts.addAttribute("","name", "name", "CDATA", "classes-file"=
);
+//            h.startElement("", "parameter", "parameter", atts);
+//            h.characters("classes.jar");
+//            h.endElement("", "parameter", "parameter");
+//
+//            atts =3D new AttributesImpl();
+//            atts.addAttribute("","name", "name", "CDATA", "classes-root"=
);
+//            h.startElement("", "parameter", "parameter", atts);
+//            h.endElement("", "parameter", "parameter");
+//
+//            boolean homeFound =3D false;
+//
+//            while (en.hasMoreElements()) {
+//                JahiaPageDefinition jpd =3D (JahiaPageDefinition) en.nex=
tElement();
+//                atts =3D new AttributesImpl();
+//                atts.addAttribute("","browsable", "browsable", "CDATA", =
"1");
+//                atts.addAttribute("","visible", "visible", "CDATA", "1");
+//
+//                if (!homeFound && (jpd.getID() =3D=3D homeId || !en.hasM=
oreElements())) {
+//                    atts.addAttribute("","homepage", "homepage", "CDATA"=
, "1");
+//                    homeFound =3D true;
+//                }
+//
+//                if (s.getDefaultTemplateID() =3D=3D jpd.getID()) {
+//                    atts.addAttribute("","default", "default", "CDATA", =
"1");
+//                }
+//                h.startElement("", "template", "template", atts);
+//
+//                atts =3D new AttributesImpl();
+//                atts.addAttribute("","name", "name", "CDATA", "name");
+//                h.startElement("", "parameter", "parameter", atts);
+//                h.characters(jpd.getName().toCharArray(),0,jpd.getName()=
.length());
+//                h.endElement("", "parameter", "parameter");
+//
+//                atts =3D new AttributesImpl();
+//                atts.addAttribute("","name", "name", "CDATA", "filename"=
);
+//                h.startElement("", "parameter", "parameter", atts);
+//                String sourcePath =3D jpd.getSourcePath();
+//                sourcePath =3D sourcePath.substring(sourcePath.indexOf(s=
.getSiteKey())+s.getSiteKey().length()+1);
+//                h.characters(sourcePath.toCharArray(),0,sourcePath.lengt=
h());
+//                h.endElement("", "parameter", "parameter");
+//
+//                atts =3D new AttributesImpl();
+//                atts.addAttribute("","name", "name", "CDATA", "display-n=
ame");
+//                h.startElement("", "parameter", "parameter", atts);
+//                h.characters(jpd.getName().toCharArray(),0,jpd.getName()=
.length());
+//                h.endElement("", "parameter", "parameter");
+//
+//                h.endElement("", "template", "template");
+//            }
+//
+//            h.endElement("", "tpml", "tpml");
+//            h.flush();
+//        } catch (JahiaException e) {
+//            logger.error("Cannot export templates",e);
+//        } catch (SAXException e) {
+//            logger.error("Cannot export templates",e);
+//        }
+
+        zout.finish();
+    }
+
     private void getAllFiles(DAVFileAccess file, Set files) {
         if (!file.isCollection()) {
                        files.add(file);

Added: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/utils/zip/=
FilteredDirectoryWalker.java
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/utils/zip/FilteredDirectoryWalk=
er.java&rev=3D19153&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/utils/zip/Fil=
teredDirectoryWalker.java (added)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/java/org/jahia/utils/zip/Fil=
teredDirectoryWalker.java Wed Nov 14 19:56:57 2007
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2002-2007 Jahia Ltd
+ *
+ * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =

+ * Version 1.0 (the "License"), or (at your option) any later version; you=
 may =

+ * not use this file except in compliance with the License. You should hav=
e =

+ * received a copy of the License along with this program; if not, you may=
 obtain =

+ * a copy of the License at =

+ *
+ *  http://www.jahia.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software =

+ * distributed under the License is distributed on an "AS IS" BASIS, =

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied=
. =

+ * See the License for the specific language governing permissions and =

+ * limitations under the License.
+ */
+package org.jahia.utils.zip;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.io.DirectoryWalker;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOCase;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+
+/**
+ * Utility class for zipping a directory tree content considering path
+ * inclusion/exclusion filters.
+ * =

+ * @author Sergiy Shyrkov
+ */
+public class FilteredDirectoryWalker extends DirectoryWalker {
+
+    private static class PathFilter extends WildcardFileFilter {
+
+        private boolean doExclusion;
+
+        private String[] wildcards;
+
+        public PathFilter(String[] wildcards, boolean doExclusion) {
+            super(wildcards);
+            this.wildcards =3D wildcards;
+            this.doExclusion =3D doExclusion;
+        }
+
+        @Override
+        public boolean accept(File file) {
+            if (!doExclusion && file.isDirectory())
+                return true;
+
+            String path =3D file.getPath();
+            boolean accept =3D doExclusion;
+            for (int i =3D 0; i < wildcards.length; i++) {
+                boolean matches =3D FilenameUtils.wildcardMatch(path,
+                        wildcards[i], IOCase.SENSITIVE);
+                if (doExclusion) {
+                    if (matches) {
+                        accept =3D false;
+                        break;
+                    }
+                } else {
+                    if (matches) {
+                        accept =3D true;
+                        break;
+                    }
+                }
+            }
+            return accept;
+        }
+    }
+
+    private static String[] convertPatterns(File baseDir, String[] pathPat=
terns) {
+        String[] convertedPatterns =3D new String[pathPatterns.length];
+        for (int i =3D 0; i < pathPatterns.length; i++) {
+            convertedPatterns[i] =3D new File(baseDir,
+                    convertSeparator(pathPatterns[i])).getPath();
+        }
+
+        return convertedPatterns;
+    }
+
+    private static String convertSeparator(String pathPattern) {
+        return File.separatorChar !=3D '/' ? pathPattern.replace('/',
+                File.separatorChar) : pathPattern;
+    }
+
+    private File startDirectory;
+
+    public FilteredDirectoryWalker(File startDirectory,
+            List<String> pathPatterns) {
+        this(startDirectory, pathPatterns, false);
+    }
+
+    public FilteredDirectoryWalker(File startDirectory,
+            List<String> pathPatterns, boolean doExcludeFiltering) {
+        this(startDirectory, pathPatterns.toArray(new String[pathPatterns
+                .size()]), doExcludeFiltering);
+    }
+
+    public FilteredDirectoryWalker(File startDirectory, String[] pathPatte=
rns) {
+        this(startDirectory, pathPatterns, false);
+    }
+
+    public FilteredDirectoryWalker(File startDirectory, String[] pathPatte=
rns,
+            boolean doExcludeFiltering) {
+        super(new PathFilter(convertPatterns(startDirectory, pathPatterns),
+                doExcludeFiltering), -1);
+        this.startDirectory =3D startDirectory;
+    }
+
+    @Override
+    protected void handleFile(File file, int depth, Collection results)
+            throws IOException {
+        results.add(file);
+    }
+
+    public void zip(ZipOutputStream zout) throws IOException {
+        List<File> results =3D new LinkedList<File>();
+        walk(startDirectory, results);
+        for (File file : results) {
+            if (file.getPath().length() <=3D startDirectory.getPath().leng=
th())
+                continue;
+
+            if (zout !=3D null) {
+                zout.putNextEntry(new ZipEntry(file.getPath().substring(
+                        startDirectory.getPath().length() + 1)));
+                zout.write(FileUtils.readFileToByteArray(file));
+            } else {
+                System.out.println(file);
+            }
+        }
+    }
+}

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to