001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.util;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.io.OutputStream;
022: import java.io.Reader;
023: import java.io.Writer;
024: import java.util.Properties;
025:
026: /**
027: * Strategy interface for persisting <code>java.util.Properties</code>,
028: * allowing for pluggable parsing strategies.
029: *
030: * <p>The default implementation is DefaultPropertiesPersister,
031: * providing the native parsing of <code>java.util.Properties</code>,
032: * but allowing for reading from any Reader and writing to any Writer
033: * (which allows to specify an encoding for a properties file).
034: *
035: * <p>As of Spring 1.2.2, this interface also supports properties XML files,
036: * through the <code>loadFromXml</code> and <code>storeToXml</code> methods.
037: * The default implementations delegate to JDK 1.5's corresponding methods.
038: *
039: * @author Juergen Hoeller
040: * @since 10.03.2004
041: * @see DefaultPropertiesPersister
042: * @see java.util.Properties
043: */
044: public interface PropertiesPersister {
045:
046: /**
047: * Load properties from the given InputStream into the given
048: * Properties object.
049: * @param props the Properties object to load into
050: * @param is the InputStream to load from
051: * @throws IOException in case of I/O errors
052: * @see java.util.Properties#load
053: */
054: void load(Properties props, InputStream is) throws IOException;
055:
056: /**
057: * Load properties from the given Reader into the given
058: * Properties object.
059: * @param props the Properties object to load into
060: * @param reader the Reader to load from
061: * @throws IOException in case of I/O errors
062: */
063: void load(Properties props, Reader reader) throws IOException;
064:
065: /**
066: * Write the contents of the given Properties object to the
067: * given OutputStream.
068: * @param props the Properties object to store
069: * @param os the OutputStream to write to
070: * @param header the description of the property list
071: * @throws IOException in case of I/O errors
072: * @see java.util.Properties#store
073: */
074: void store(Properties props, OutputStream os, String header)
075: throws IOException;
076:
077: /**
078: * Write the contents of the given Properties object to the
079: * given Writer.
080: * @param props the Properties object to store
081: * @param writer the Writer to write to
082: * @param header the description of the property list
083: * @throws IOException in case of I/O errors
084: */
085: void store(Properties props, Writer writer, String header)
086: throws IOException;
087:
088: /**
089: * Load properties from the given XML InputStream into the
090: * given Properties object.
091: * @param props the Properties object to load into
092: * @param is the InputStream to load from
093: * @throws IOException in case of I/O errors
094: * @see java.util.Properties#loadFromXML(java.io.InputStream)
095: */
096: void loadFromXml(Properties props, InputStream is)
097: throws IOException;
098:
099: /**
100: * Write the contents of the given Properties object to the
101: * given XML OutputStream.
102: * @param props the Properties object to store
103: * @param os the OutputStream to write to
104: * @param header the description of the property list
105: * @throws IOException in case of I/O errors
106: * @see java.util.Properties#storeToXML(java.io.OutputStream, String)
107: */
108: void storeToXml(Properties props, OutputStream os, String header)
109: throws IOException;
110:
111: /**
112: * Write the contents of the given Properties object to the
113: * given XML OutputStream.
114: * @param props the Properties object to store
115: * @param os the OutputStream to write to
116: * @param encoding the encoding to use
117: * @param header the description of the property list
118: * @throws IOException in case of I/O errors
119: * @see java.util.Properties#storeToXML(java.io.OutputStream, String, String)
120: */
121: void storeToXml(Properties props, OutputStream os, String header,
122: String encoding) throws IOException;
123:
124: }
|