[izpack-changes] r1461 - izpack-src/trunk/src/lib/com/izforge/izpack/util
noreply at berlios.de
noreply at berlios.de
Fri Jun 30 12:33:51 CEST 2006
Author: eppelman
Date: 2006-06-30 12:33:49 +0200 (Fri, 30 Jun 2006)
New Revision: 1461
Modified:
izpack-src/trunk/src/lib/com/izforge/izpack/util/VariableSubstitutor.java
Log:
Added a substitute method variant that gets an InputStream and returns a String
(currently needed to apply the VariableSubstitutor to the ShortcutSpec )
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/util/VariableSubstitutor.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/util/VariableSubstitutor.java 2006-06-30 10:27:32 UTC (rev 1460)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/util/VariableSubstitutor.java 2006-06-30 10:33:49 UTC (rev 1461)
@@ -76,6 +76,9 @@
/** A constant for file type. Plain file with '@' start char. */
protected final static int TYPE_AT = 4;
+
+ /** PLAIN = "plain" */
+ public final static String PLAIN = "plain";
/** A mapping of file type names to corresponding integer constants. */
protected final static Map typeNameToConstantMap;
@@ -196,7 +199,60 @@
return subs;
}
+
+ /**
+ * Substitute method Variant that gets An Input Stream and returns A String
+ *
+ * @param in The Input Stream, with Placeholders
+ * @param out The Substituted String
+ * @param type The used FormatType
+ * @param encoding The used encoding Type
+ * @param hidePasswd Set to true, to hide Password masked Placeholders in Logfile
+ *
+ * @throws IllegalArgumentException If a wrong input was given.
+ * @throws UnsupportedEncodingException If the file comes with a wrong Encoding
+ * @throws IOException If an I/O Error occurs.
+ */
+ public String substitute( InputStream in, String type
+ )
+ throws IllegalArgumentException, UnsupportedEncodingException,
+ IOException
+ {
+ // Check if file type specific default encoding known
+ String encoding = PLAIN;
+ {
+ int t = getTypeConstant( type );
+ switch( t )
+ {
+ case TYPE_JAVA_PROPERTIES:
+ encoding = "ISO-8859-1";
+
+ break;
+
+ case TYPE_XML:
+ encoding = "UTF-8";
+
+ break;
+ }
+ }
+
+ // Create the reader and writer
+ InputStreamReader reader = ( ( encoding != null )
+ ? new InputStreamReader( in, encoding )
+ : new InputStreamReader( in ) );
+ StringWriter writer = new StringWriter( ) ;
+
+ // Copy the data and substitute variables
+ substitute( reader, writer, type );
+
+ // Flush the writer so that everything gets written out
+ writer.flush( );
+
+ return writer.getBuffer().toString();
+ }
+
+
/**
* Substitutes the variables found in the data read from the specified reader. Escapes special
* characters using file type specific escaping if necessary.
More information about the izpack-changes
mailing list