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();
}