Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 23163 invoked from network); 1 Dec 2008 13:16:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Dec 2008 13:16:14 -0000 Received: (qmail 32367 invoked by uid 500); 1 Dec 2008 13:16:25 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 32330 invoked by uid 500); 1 Dec 2008 13:16:25 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 32321 invoked by uid 99); 1 Dec 2008 13:16:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2008 05:16:25 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2008 13:14:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 32E3423889C0; Mon, 1 Dec 2008 05:15:44 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r722065 - in /incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl: PropertiesUtil.java RepositoryObserver.java Date: Mon, 01 Dec 2008 13:15:43 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081201131544.32E3423889C0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Mon Dec 1 05:15:43 2008 New Revision: 722065 URL: http://svn.apache.org/viewvc?rev=722065&view=rev Log: SLING-747 - refactor / code cleanup Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/PropertiesUtil.java (with props) Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/PropertiesUtil.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/PropertiesUtil.java?rev=722065&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/PropertiesUtil.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/PropertiesUtil.java Mon Dec 1 05:15:43 2008 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.sling.jcr.jcrinstall.jcr.impl; + +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.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Load/save Properties */ +class PropertiesUtil { + private final Logger log = LoggerFactory.getLogger(getClass()); + + Properties loadProperties(File f) { + final Properties props = new Properties(); + if(f.exists()) { + InputStream is = null; + try { + is = new FileInputStream(f); + props.load(is); + } catch(IOException ioe) { + log.warn("Error reading " + f.getName(), ioe); + } finally { + if(is!=null) { + try { + is.close(); + } catch(IOException ignore) { + + } + } + } + } + return props; + } + + void saveProperties(Properties props, File f) { + OutputStream os = null; + try { + os = new FileOutputStream(f); + props.store(os, getClass().getSimpleName()); + } catch(IOException ioe) { + log.warn("Error saving " + f.getName(), ioe); + } finally { + if(os!=null) { + try { + os.close(); + } catch(IOException ignore) { + + } + } + } + } +} Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/PropertiesUtil.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/PropertiesUtil.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=722065&r1=722064&r2=722065&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Mon Dec 1 05:15:43 2008 @@ -19,11 +19,6 @@ package org.apache.sling.jcr.jcrinstall.jcr.impl; 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.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; @@ -72,6 +67,7 @@ private RegexpFilter folderNameFilter; private RegexpFilter filenameFilter; private ResourceOverrideRules roRules; + private final PropertiesUtil propertiesUtil = new PropertiesUtil(); private boolean running; /** @scr.reference */ @@ -272,7 +268,7 @@ // that don't match the new regexp // TODO this happens right after activate() is called on this service, // might conflict with ongoing SCR activities? - final Properties props = loadProperties(serviceDataFile); + final Properties props = propertiesUtil.loadProperties(serviceDataFile); final String oldRegexp = props.getProperty(DATA_LAST_FOLDER_REGEXP); if(oldRegexp != null && !oldRegexp.equals(folderNameFilter.getRegexp())) { log.info("Folder name regexp has changed, uninstalling non-applicable resources ( {} -> {} )", @@ -296,7 +292,7 @@ } } props.setProperty(DATA_LAST_FOLDER_REGEXP, folderNameFilter.getRegexp()); - saveProperties(props, serviceDataFile); + propertiesUtil.saveProperties(props, serviceDataFile); // Check if any deletions happened while this // service was inactive: create a fake WatchFolder @@ -379,46 +375,6 @@ osgiController.executeScheduledOperations(); } - Properties loadProperties(File f) { - final Properties props = new Properties(); - if(f.exists()) { - InputStream is = null; - try { - is = new FileInputStream(f); - props.load(is); - } catch(IOException ioe) { - log.warn("Error reading " + f.getName(), ioe); - } finally { - if(is!=null) { - try { - is.close(); - } catch(IOException ignore) { - - } - } - } - } - return props; - } - - void saveProperties(Properties props, File f) { - OutputStream os = null; - try { - os = new FileOutputStream(f); - props.store(os, getClass().getSimpleName()); - } catch(IOException ioe) { - log.warn("Error saving " + f.getName(), ioe); - } finally { - if(os!=null) { - try { - os.close(); - } catch(IOException ignore) { - - } - } - } - } - public void bundleChanged(BundleEvent event) { lastBundleEvent = System.currentTimeMillis(); }