private void save(CmsParameterConfiguration properties, String source, String target, Set<String> forceWrite) {

        try {
            Set<String> alreadyWritten = new HashSet<String>();

            LineNumberReader lnr = new LineNumberReader(new FileReader(new File(m_configRfsPath + source)));

            FileWriter fw = new FileWriter(new File(m_configRfsPath + target));

            while (true) {
                String line = lnr.readLine();
                if (line == null) {
                    break;
                }
                line = line.trim();

                if ("".equals(line)) {
                    // output empty line
                    fw.write("\n");
                } else if (line.startsWith("#")) {
                    // output comment
                    fw.write(line);
                    fw.write("\n");
                } else {

                    int index = line.indexOf('=');
                    int index1 = line.indexOf("\\=");
                    if ((line.indexOf('=') > -1) && (index1 != (index - 1))) {

                        String key = line.substring(0, line.indexOf('=')).trim();
                        if (alreadyWritten.contains(key)) {
                            continue;
                        }
                        String additionalPrefix = ADDITIONAL_PREFIX;
                        if (key.startsWith(additionalPrefix)) {
                            String additionalPropKey = key.substring(additionalPrefix.length());
                            String additionalContent = m_additionalProperties.get(additionalPropKey);
                            if (additionalContent == null) {
                                fw.write(key + "=\n");
                            } else {
                                fw.write(additionalContent + "\n");
                            }
                            continue;
                        }
                        // write key
                        fw.write((key + "="));
                        try {
                            Object obj = properties.getObject(key);
                            if (obj != null) {
                                String valueToWrite = getPropertyValueToWrite(obj);
                                fw.write(valueToWrite);
                            }

                        } catch (NullPointerException e) {
                            // no value found - do nothing
                        }
                        // add trailing line feed
                        fw.write("\n");

                        // remember that this properties is already written (multi values)
                        alreadyWritten.add(key);
                    }
                }
            }
            if (forceWrite != null) {
                for (String forced : forceWrite) {
                    if (!alreadyWritten.contains(forced) && properties.containsKey(forced)) {
                        fw.write("\n\n");
                        fw.write(forced + "=");
                        try {
                            Object obj = properties.getObject(forced);

                            if (obj != null) {
                                String valueToWrite = getPropertyValueToWrite(obj);
                                fw.write(valueToWrite);
                            }
                        } catch (NullPointerException e) {
                            // no value found - do nothing
                        }
                        fw.write("\n");

                    }
                }
            }

            lnr.close();
            fw.close();
        } catch (Exception e) {
            m_errors.add("Could not save properties to " + target + " \n");
            m_errors.add(e.toString() + "\n");
        }
    }
private void save ( CmsParameterConfiguration properties , String source , String target , Set < String > forceWrite ) { try { Set < String > alreadyWritten = new HashSet < String > ( ) ; LineNumberReader lnr = new LineNumberReader ( new FileReader ( new File ( m_configRfsPath + source ) ) ) ; FileWriter fw = new FileWriter ( new File ( m_configRfsPath + target ) ) ; while ( true ) { String line = lnr . readLine ( ) ; if ( line == null ) { break ; } line = line . trim ( ) ; if ( "" . equals ( line ) ) { fw . write ( "\n" ) ; } else if ( line . startsWith ( "#" ) ) { fw . write ( line ) ; fw . write ( "\n" ) ; } else { int index = line . indexOf ( '=' ) ; int index1 = line . indexOf ( "\\=" ) ; if ( ( line . indexOf ( '=' ) > - 1 ) && ( index1 != ( index - 1 ) ) ) { String key = line . substring ( 0 , line . indexOf ( '=' ) ) . trim ( ) ; if ( alreadyWritten . contains ( key ) ) { continue ; } String additionalPrefix = ADDITIONAL_PREFIX ; if ( key . startsWith ( additionalPrefix ) ) { String additionalPropKey = key . substring ( additionalPrefix . length ( ) ) ; String additionalContent = m_additionalProperties . get ( additionalPropKey ) ; if ( additionalContent == null ) { fw . write ( key + "=\n" ) ; } else { fw . write ( additionalContent + "\n" ) ; } continue ; } fw . write ( ( key + "=" ) ) ; try { Object obj = properties . getObject ( key ) ; if ( obj != null ) { String valueToWrite = getPropertyValueToWrite ( obj ) ; fw . write ( valueToWrite ) ; } } catch ( NullPointerException e ) { } fw . write ( "\n" ) ; alreadyWritten . add ( key ) ; } } } if ( forceWrite != null ) { for ( String forced : forceWrite ) { if ( ! alreadyWritten . contains ( forced ) && properties . containsKey ( forced ) ) { fw . write ( "\n\n" ) ; fw . write ( forced + "=" ) ; try { Object obj = properties . getObject ( forced ) ; if ( obj != null ) { String valueToWrite = getPropertyValueToWrite ( obj ) ; fw . write ( valueToWrite ) ; } } catch ( NullPointerException e ) { } fw . write ( "\n" ) ; } } } lnr . close ( ) ; fw . close ( ) ; } catch ( Exception e ) { m_errors . add ( "Could not save properties to " + target + " \n" ) ; m_errors . add ( e . toString ( ) + "\n" ) ; } }
Saves the properties to a file.<p>

@param properties the properties to be saved
@param source the source file to get the keys from
@param target the target file to save the properties to
@param forceWrite the keys of the properties which should always be written, even if they don't exist in the configuration file