Author: sskracic Date: 2005-11-10 19:22:03 +0100 (Thu, 10 Nov 2005) New Revision: 991 Added: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/WhiteListFilenameFilter.java Modified: trunk/ccm-ldn-theme/pdl/com/arsdigita/london/themes/ThemeFile.pdl trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/dispatcher/ThemeDownloadServlet.java trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/ThemeFilesList.java trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/listeners/ApproveThemeActionListener.java trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeDevelopmentFileManager.java trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileManager.java trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileUtil.java trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemePublishedFileManager.java Log: Completing most of theme enhancements work. Downloading and publishing operations will skip files not in the whitelist. 'is_deleted' flag is now copied from draft to live files on every 'publish' operation. Modified: trunk/ccm-ldn-theme/pdl/com/arsdigita/london/themes/ThemeFile.pdl =================================================================== --- trunk/ccm-ldn-theme/pdl/com/arsdigita/london/themes/ThemeFile.pdl 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/pdl/com/arsdigita/london/themes/ThemeFile.pdl 2005-11-10 18:22:03 UTC (rev 991) @@ -45,3 +45,20 @@ ThemeFile[0..n] themeFiles = join theme_themes.theme_id to theme_files.theme_id; } +data operation bulkFileUpdate { + do { + update theme_files set + is_deleted = (select t2.is_deleted from theme_files t2 + where t2.theme_id = :themeID + and t2.file_path = theme_files.file_path + and t2.version = 'draft'), + last_modified_date = :timestamp + where + theme_id = :themeID + and version = 'live' + and file_path in (select t3.file_path from theme_files t3 + where t3.theme_id = :themeID + and t3.version = 'draft') + } +} + Modified: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/dispatcher/ThemeDownloadServlet.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/dispatcher/ThemeDownloadServlet.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/dispatcher/ThemeDownloadServlet.java 2005-11-10 18:22:03 UTC (rev 991) @@ -5,12 +5,12 @@ * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -19,51 +19,43 @@ package com.arsdigita.london.theme.dispatcher; -import com.arsdigita.london.theme.Theme; -import com.arsdigita.london.theme.ThemeConstants; -import com.arsdigita.london.theme.util.ManifestReader; -import com.arsdigita.util.IO; -import com.arsdigita.util.Files; -import com.arsdigita.xml.Document; -import com.arsdigita.xml.Element; -import com.arsdigita.web.BaseServlet; +import com.arsdigita.cms.ContentType; +import com.arsdigita.dispatcher.AccessDeniedException; import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.kernel.Party; import com.arsdigita.kernel.Kernel; +import com.arsdigita.kernel.Party; import com.arsdigita.kernel.permissions.PermissionService; import com.arsdigita.kernel.permissions.PrivilegeDescriptor; -import com.arsdigita.dispatcher.AccessDeniedException; +import com.arsdigita.kernel.permissions.UniversalPermissionDescriptor; +import com.arsdigita.london.theme.Theme; +import com.arsdigita.london.theme.ThemeConstants; +import com.arsdigita.london.theme.util.ManifestReader; +import com.arsdigita.london.theme.util.WhiteListFilenameFilter; +import com.arsdigita.packaging.RegistryConfig; +import com.arsdigita.util.Files; +import com.arsdigita.util.IO; +import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.web.BaseServlet; import com.arsdigita.web.LoginSignal; -import com.arsdigita.cms.ContentType; - -import javax.servlet.ServletException; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import java.io.IOException; -import java.io.InputStream; +import com.arsdigita.web.Web; +import com.arsdigita.xml.Document; +import com.arsdigita.xml.Element; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FilenameFilter; -import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; import java.net.URL; import java.util.Iterator; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; - -import javax.xml.parsers.ParserConfigurationException; - -import java.math.BigDecimal; -import java.util.Iterator; -import com.arsdigita.web.Web; -import com.arsdigita.util.UncheckedWrapperException; -import com.arsdigita.kernel.permissions.UniversalPermissionDescriptor; -import com.arsdigita.kernel.permissions.PermissionService; -import com.arsdigita.kernel.permissions.PrivilegeDescriptor; -import com.arsdigita.packaging.RegistryConfig; -import com.arsdigita.web.LoginSignal; import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; @@ -72,8 +64,8 @@ * against content types into one. */ public class ThemeDownloadServlet extends BaseServlet implements ThemeConstants { - - private static final Logger s_log = + + private static final Logger s_log = Logger.getLogger(ThemeDownloadServlet.class); public static final String THEME_ID = "themeID"; @@ -87,12 +79,12 @@ } UniversalPermissionDescriptor universalPermission = - new UniversalPermissionDescriptor(PrivilegeDescriptor.ADMIN, + new UniversalPermissionDescriptor(PrivilegeDescriptor.ADMIN, party.getOID()); if (! PermissionService.checkPermission(universalPermission)) { throw new AccessDeniedException( - "user " + party.getOID() + " doesn't have the " + + "user " + party.getOID() + " doesn't have the " + PrivilegeDescriptor.ADMIN.getName() + " admin privileges"); } } @@ -112,7 +104,7 @@ sreq.getParameter(THEME_ID), e); throw new UncheckedWrapperException ("Unable to convert the themeID in to a BigDecimal " + - sreq.getParameter(THEME_ID), e); + sreq.getParameter(THEME_ID), e); } } Theme theme = null; @@ -136,12 +128,12 @@ File currentRoot = new File(Web.getServletContext().getRealPath("/")); File webapps = currentRoot.getParentFile(); - // if we have a Theme, we send back either prod or dev, depending on + // if we have a Theme, we send back either prod or dev, depending on // the url. If we don't have a theme, then we return everything. if (theme != null) { File downloadFiles = null; String prefix = null; - // If "themes-prod" is ever moved to a different directory, + // If "themes-prod" is ever moved to a different directory, // we could then get rid of the "type" argument (see below in // DirectoryFilter) String type = null; @@ -155,12 +147,12 @@ type = DEV_DIR_STUB; } sresp.setHeader("Content-Disposition", - "attachment; filename=\"" + prefix + theme.getURL() + + "attachment; filename=\"" + prefix + theme.getURL() + ".zip\""); Files.writeZipFile - (sresp.getOutputStream(), - Files.listFilesInTree(downloadFiles, + (sresp.getOutputStream(), + Files.listFilesInTree(downloadFiles, new DirectoryFilter(theme.getURL(), type)), downloadFiles); } else if (theme == null) { @@ -172,16 +164,16 @@ ClassLoader loader = Thread.currentThread().getContextClassLoader(); sresp.setHeader("Content-Disposition", - "attachment; filename=\"" + ALL_STYLES_ZIP_NAME + - "\""); + "attachment; filename=\"" + ALL_STYLES_ZIP_NAME + + "\""); ZipOutputStream out = new ZipOutputStream(sresp.getOutputStream()); for (int i = 0; i < packages.length; i++) { String current = packages[i] + ".web.mf"; InputStream is = loader.getResourceAsStream(current); if (is != null) { - ZipWriterManifestReader reader = - new ZipWriterManifestReader(is, out, current, + ZipWriterManifestReader reader = + new ZipWriterManifestReader(is, out, current, packages[i]); reader.setFileName(packages[i]); reader.processFile(); @@ -189,18 +181,18 @@ s_log.warn("Unable to open up resource " + current); } } - + // Special case add the auto-generated XSL fiel for content types Iterator paths = ContentType.getXSLFileURLs(); out.putNextEntry(new ZipEntry("waf-xsl/__ccm__/servlet/content-type/index.xsl")); IO.copy(multiplexXSLFiles(paths), out); - - + + out.close(); - } - } - + } + } + // XXX copy+paste of Templating.multiplexXSLFiles but with some // URL munging. Should be reconciled later public static InputStream multiplexXSLFiles(Iterator paths) { @@ -229,19 +221,19 @@ } /** - * This provides a filter so that only files in a given directory + * This provides a filter so that only files in a given directory * are used. This is necessary so that we can be efficient when * creating our zip. Without this, we would have to iterate through - * the file list an extra time. If the + * the file list an extra time. If the */ - private class DirectoryFilter implements FilenameFilter { + private class DirectoryFilter extends WhiteListFilenameFilter implements FilenameFilter { // there has to be a better way to do this...I have a hard // time believing that this filter is actually necessary...can we // do this by adding some magic to the Files.createZipFile class? // we could always iterate through the results ot listFilesInTree // but that seems like a worse solution than this. private String m_directoryName; - // If "themes-prod" is ever moved to a different directory, + // If "themes-prod" is ever moved to a different directory, // we could then get rid of the "type" argument private String m_type; DirectoryFilter(String directoryName, String type) { @@ -250,9 +242,10 @@ } public boolean accept(File dir, String name) { - return dir.getAbsolutePath().indexOf("/" + m_type + "/" + m_directoryName) > -1 - || (m_directoryName.equals(name) && dir.getAbsolutePath().endsWith("/" + m_type)); - + return super.accept(dir, name) && + (dir.getAbsolutePath().indexOf("/" + m_type + "/" + m_directoryName) > -1 + || (m_directoryName.equals(name) && dir.getAbsolutePath().endsWith("/" + m_type))); + } } @@ -260,7 +253,7 @@ private class ZipWriterManifestReader extends ManifestReader { private ZipOutputStream m_out; - ZipWriterManifestReader(InputStream stream, + ZipWriterManifestReader(InputStream stream, ZipOutputStream out, String fileName, String possibleServletContext) { @@ -277,7 +270,7 @@ try { ServletContext actualContext = getActualContext(filePath); - + if (actualContext != null) { String realPath = actualContext.getRealPath("/"); String packageName = getFileName(); @@ -315,7 +308,7 @@ } catch (IOException e) { throw new UncheckedWrapperException("Error reading from " + filePath + " or writing to the zip file"); } - } + } } } - + Modified: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/ThemeFilesList.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/ThemeFilesList.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/ThemeFilesList.java 2005-11-10 18:22:03 UTC (rev 991) @@ -28,7 +28,7 @@ import com.arsdigita.london.theme.ThemeFileCollection; import com.arsdigita.london.theme.ui.listeners.FileRemovalRequestListener; import com.arsdigita.london.theme.util.GlobalizationUtil; -import com.arsdigita.london.theme.util.ThemeFileUtil; +import com.arsdigita.london.theme.util.WhiteListFilenameFilter; import com.arsdigita.toolbox.ui.FormatStandards; import com.arsdigita.util.Files; import com.arsdigita.web.Web; @@ -108,7 +108,7 @@ } else { childElement = folderElement.newChildElement(XML_FILE, XML_NS); childElement.addAttribute("inWhiteList", - String.valueOf(ThemeFileUtil.inWhiteList(tempFile))); + String.valueOf(WhiteListFilenameFilter.inWhiteList(list[i]))); ThemeFile dbtFile = (ThemeFile) themeFiles.get(tempFile.getAbsolutePath()); childElement.addAttribute("inDatabase", String.valueOf(dbtFile != null)); if (dbtFile != null) { Modified: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/listeners/ApproveThemeActionListener.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/listeners/ApproveThemeActionListener.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/ui/listeners/ApproveThemeActionListener.java 2005-11-10 18:22:03 UTC (rev 991) @@ -5,12 +5,12 @@ * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -18,35 +18,41 @@ package com.arsdigita.london.theme.ui.listeners; -import com.arsdigita.london.theme.ui.ThemeSelectionModel; -import com.arsdigita.london.theme.ThemeConstants; -import com.arsdigita.london.theme.ThemeFile; -import com.arsdigita.london.theme.util.ThemeFileUtil; import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionListener; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.london.subsite.Subsite; import com.arsdigita.london.theme.Theme; +import com.arsdigita.london.theme.ThemeConstants; +import com.arsdigita.london.theme.ThemeFile; import com.arsdigita.london.theme.ThemeObserver; +import com.arsdigita.london.theme.ui.ThemeSelectionModel; +import com.arsdigita.london.theme.util.ThemeFileUtil; +import com.arsdigita.london.theme.util.WhiteListFilenameFilter; +import com.arsdigita.persistence.DataOperation; +import com.arsdigita.persistence.SessionManager; import com.arsdigita.util.Files; import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.web.Web; -import com.arsdigita.kernel.Kernel; -import com.arsdigita.london.subsite.Subsite; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.Date; - +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; import org.apache.log4j.Logger; /** * This approves the theme and pushes it to the production file location * This action means that the user wants to approve the themes and - * push them live. This is done by copying the files from + * push them live. This is done by copying the files from * * @author Randy Graebner <ra...@re...> */ public class ApproveThemeActionListener implements ThemeConstants, ActionListener { - - private static final Logger s_log = + + private static final Logger s_log = Logger.getLogger(ApproveThemeActionListener.class); private ThemeSelectionModel m_model; @@ -54,54 +60,72 @@ public ApproveThemeActionListener(ThemeSelectionModel model) { m_model = model; } - + public void actionPerformed(ActionEvent e) { // First, we rename the current production directory // so that if there is an exception, we can try to move it // back in to place Theme theme = m_model.getSelectedTheme(e.getPageState()); File currentRoot = new File(Web.getServletContext().getRealPath("/")); - File oldProd = new File(currentRoot, PROD_THEMES_BASE_DIR + + File oldProd = new File(currentRoot, PROD_THEMES_BASE_DIR + theme.getURL()); File backupFile = new File(oldProd.getAbsolutePath() + ".bak"); if (oldProd.exists()) { oldProd.renameTo(backupFile); - } else { - // let's make sure the correct directories are there - oldProd.mkdirs(); } - + oldProd.mkdirs(); // now, we copy the "dev" directory to the "prd" directory File newProd = new File(currentRoot, PROD_THEMES_BASE_DIR); - File devDir = new File(currentRoot, DEV_THEMES_BASE_DIR + + File devDir = new File(currentRoot, DEV_THEMES_BASE_DIR + theme.getURL()); try { - Files.copy(devDir, newProd); - + // sort filepaths to be copied alphabetically, so that the + // directory is always created before the files contained therein + Set filesToCopy = new TreeSet(Arrays.asList(Files.listFilesInTree(devDir, + new WhiteListFilenameFilter()))); + for (Iterator it=filesToCopy.iterator(); it.hasNext(); ) { + String path = (String) it.next(); + File src = new File(devDir, path); + if (src.isDirectory()) { + s_log.debug("creating directory " + path); + new File(newProd, theme.getURL() + File.separator + path).mkdirs(); + } else { + s_log.debug("Copying file " + path); + Files.copy(src, new File(newProd, theme.getURL() + File.separator + path)); + } + } + // assuming that went well, we need to move the devDir in to - // the database as the latest "live" files - ThemeFileUtil.updateDatabaseFiles(devDir, theme, + // the database as the latest "live" files + // but before we do that, we copy is_deleted flag from + // development to published files + DataOperation op = SessionManager.getSession().retrieveDataOperation( + "com.arsdigita.london.theme.bulkFileUpdate"); + op.setParameter("themeID", theme.getID()); + op.setParameter("timestamp", new Date()); + op.execute(); + ThemeFileUtil.updateDatabaseFiles(devDir, theme, devDir.getAbsolutePath(), true, ThemeFile.LIVE); // since we are publishing, we also want to share the DEV files - ThemeFileUtil.updateDatabaseFiles(devDir, theme, + ThemeFileUtil.updateDatabaseFiles(devDir, theme, devDir.getAbsolutePath(), true, ThemeFile.DRAFT); // add the observer to make sure that it syncs with other // servers in the cluster theme.addObserver(new ThemeObserver()); } catch (IOException ex) { - String errorMsg = "There was an error moving files from " + - devDir.getAbsolutePath() + " to " + + String errorMsg = "There was an error moving files from " + + devDir.getAbsolutePath() + " to " + newProd.getAbsolutePath(); s_log.error(errorMsg, ex); // delete the directory and move the oldProd back Files.delete(new File(newProd + theme.getURL())); if (oldProd.exists()) { - oldProd.renameTo(new File(currentRoot, PROD_THEMES_BASE_DIR + + oldProd.renameTo(new File(currentRoot, PROD_THEMES_BASE_DIR + theme.getURL())); } throw new UncheckedWrapperException(errorMsg, ex); Modified: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeDevelopmentFileManager.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeDevelopmentFileManager.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeDevelopmentFileManager.java 2005-11-10 18:22:03 UTC (rev 991) @@ -51,7 +51,7 @@ protected ThemeDevelopmentFileManager(int startupDelay, int pollDelay, String baseDirectory) { - super(startupDelay, pollDelay, baseDirectory); + super(s_log, startupDelay, pollDelay, baseDirectory); } Modified: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileManager.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileManager.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileManager.java 2005-11-10 18:22:03 UTC (rev 991) @@ -56,13 +56,11 @@ */ public abstract class ThemeFileManager extends Thread implements ThemeConstants { - private static Logger s_log = - Logger.getLogger(ThemeFileManager.class); + private Logger m_log; // The code in this class borrows heavily from // com.arsdigita.cms.publishToFile.FileManager - // Following true if should keep watching file private boolean m_keepWatchingFiles = true; @@ -78,8 +76,9 @@ private Date m_lastRunDate; - protected ThemeFileManager(int startupDelay, int pollDelay, + protected ThemeFileManager(Logger log, int startupDelay, int pollDelay, String baseDirectory) { + m_log = log; m_startupDelay = startupDelay; m_pollDelay = pollDelay; m_lastRunDate = null; @@ -111,12 +110,12 @@ * file processing. ***/ public void run() { - s_log.info("Start polling file in " + m_startupDelay + "s."); + m_log.info("Start polling file in " + m_startupDelay + "s."); if (m_lastRunDate == null) { // only do the startup delay the first time this is run. sleepSeconds(m_startupDelay); } - s_log.info("Polling file every " + m_pollDelay + "s."); + m_log.info("Polling file every " + m_pollDelay + "s."); while ( (sleepSeconds(m_pollDelay) || m_ignoreInterrupt) && m_keepWatchingFiles ) { // Get the last run date before we do anything, @@ -145,11 +144,11 @@ m_lastRunDate = lastRunDate; } catch (Exception e) { - s_log.warn("Ignoring uncaught exception", e); + m_log.warn("Ignoring uncaught exception", e); } finally { if ( txn.inTxn() ) { txn.abortTxn(); - s_log.info("Aborting transaction"); + m_log.info("Aborting transaction"); } } // we only ignore one interrupt at most @@ -254,7 +253,7 @@ protected void updateTheme(Theme theme) { String stub = getManagerSpecificDirectory(); // sync the files that have the correct dates - s_log.debug("Looking at theme " + theme.getURL()); + m_log.debug("Looking at theme " + theme.getURL()); ThemeFileCollection files = getThemeFilesCollection(theme); if (files == null) { @@ -271,9 +270,9 @@ if (temp.exists()) { boolean success = temp.delete(); if (success) { - s_log.info("Deletion of " + temp + " succeeded"); + m_log.info("Deletion of " + temp + " succeeded"); } else { - s_log.error("Deletion of " + temp + " failed"); + m_log.error("Deletion of " + temp + " failed"); } } continue; @@ -284,14 +283,14 @@ try { // make sure all of the directories exist temp.getParentFile().mkdirs(); - s_log.debug("Writing file " + temp.getAbsolutePath()); + m_log.debug("Writing file " + temp.getAbsolutePath()); byte[] content = files.getThemeFile().getContent(); out = new FileOutputStream(temp); out.write(content); temp.setLastModified(files.getLastModifiedDate().getTime()); } catch (IOException e) { - s_log.error("Error writing file " + + m_log.error("Error writing file " + temp.getAbsolutePath(), e); } finally { try { @@ -299,7 +298,7 @@ out.close(); } } catch (IOException e) { - s_log.error("Could not close output stream", e); + m_log.error("Could not close output stream", e); } } } @@ -315,7 +314,7 @@ sleep(n * 1000); return true; } catch ( InterruptedException e ) { - s_log.info( "Waiting was interrupted."); + m_log.info( "Waiting was interrupted."); return false; } } Modified: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileUtil.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileUtil.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemeFileUtil.java 2005-11-10 18:22:03 UTC (rev 991) @@ -16,14 +16,12 @@ package com.arsdigita.london.theme.util; import com.arsdigita.london.theme.Theme; -import com.arsdigita.london.theme.ThemeApplication; import com.arsdigita.london.theme.ThemeFile; import com.arsdigita.london.theme.ThemeFileCollection; import com.arsdigita.util.Assert; import org.apache.log4j.Logger; import java.util.Date; import java.util.Map; -import java.util.Collection; import java.util.HashMap; import java.io.File; import java.io.IOException; @@ -45,15 +43,6 @@ private static Logger s_log = Logger.getLogger(ThemeFileUtil.class); - public static boolean inWhiteList(File file) { - Collection extensions = ThemeApplication.getConfig().getDownloadFileExtensions(); - String filename = file.getName(); - int extIndex = filename.lastIndexOf(".") + 1; - return extIndex > 0 - && filename.length() > extIndex - && extensions.contains(filename.substring(extIndex).toLowerCase()); - } - /** * this copies the files from the file system to the database. * @@ -129,7 +118,7 @@ boolean overwriteNewerFiles, String fileType) { if (currentFile.isDirectory()) { - File[] files = currentFile.listFiles(); + File[] files = currentFile.listFiles(new WhiteListFilenameFilter()); for (int i = 0; i < files.length; i++) { updateDatabaseFiles(files[i], currentTheme, serverSpecificPath, themeFiles, @@ -137,11 +126,6 @@ } } else { if (currentFile.exists()) { - // Skip the file if its extension is not in white list - if (!inWhiteList(currentFile)) { - s_log.warn("Not updating db: " + currentFile); - return; - } String fullFilePath = currentFile.getAbsolutePath(); String filePath = null; int beginIndex = fullFilePath.indexOf(serverSpecificPath); @@ -170,7 +154,7 @@ && themeFile.getLastModifiedDate() .before(new Date(currentFile.lastModified()))) { themeFile.setDeleted(false); - s_log.warn("Undeleting the file: " + currentFile); + s_log.info("Undeleting the file: " + currentFile); } try { FileInputStream in = new FileInputStream(currentFile); Modified: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemePublishedFileManager.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemePublishedFileManager.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/ThemePublishedFileManager.java 2005-11-10 18:22:03 UTC (rev 991) @@ -48,7 +48,7 @@ protected ThemePublishedFileManager(int startupDelay, int pollDelay, String baseDirectory) { - super(startupDelay, pollDelay, baseDirectory); + super(s_log, startupDelay, pollDelay, baseDirectory); } // is there a way to move this code up in to the parent class? Added: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/WhiteListFilenameFilter.java =================================================================== --- trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/WhiteListFilenameFilter.java 2005-11-10 10:36:28 UTC (rev 990) +++ trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/WhiteListFilenameFilter.java 2005-11-10 18:22:03 UTC (rev 991) @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.arsdigita.london.theme.util; + +import com.arsdigita.london.theme.ThemeApplication; +import java.io.File; +import java.io.FilenameFilter; +import java.util.Collection; + +/** + * Filter that accepts files with extensions in whitelist. + */ +public class WhiteListFilenameFilter implements FilenameFilter { + + private static Collection s_extensions; + + public boolean accept(File dir, String name) { + if (inWhiteList(name)) { + return true; + } + File temp = new File(dir, name); + return temp.exists() && temp.isDirectory(); + } + + public synchronized static boolean inWhiteList(String filename) { + if (s_extensions == null) { + s_extensions = ThemeApplication.getConfig().getDownloadFileExtensions(); + } + int extIndex = filename.lastIndexOf(".") + 1; + return extIndex > 0 + && filename.length() > extIndex + && s_extensions.contains(filename.substring(extIndex).toLowerCase()); + } +} + Property changes on: trunk/ccm-ldn-theme/src/com/arsdigita/london/theme/util/WhiteListFilenameFilter.java ___________________________________________________________________ Name: svn:keywords + Id Author URL |