Skip to content

Instantly share code, notes, and snippets.

@rschumm
Created April 4, 2013 15:43
Show Gist options
  • Save rschumm/5311530 to your computer and use it in GitHub Desktop.
Save rschumm/5311530 to your computer and use it in GitHub Desktop.
Regex etc. gebastel
package ch.schumm.properties;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
public class PropertiesParser {
private static final String MARKER = "<!-- ############################################# -->";
/**
* @param args
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
Properties properties = new Properties();
properties.load(new FileReader(new File(
"Crties")));
String xml = "";
for (Object keyo : properties.keySet()) {
String key = (String) keyo;
String value = properties.getProperty(key);
value = value.replace("/vertrag");
String xp = "<property name=\"" + key + "\" value=\"" + value + "\" />\n";
xml = xml.concat(xp);
}
// System.out.println(xml);
// brokernet-ejb
File file = new File(
"A-INF/dbd.xml");
treatDbdFile(xml, file);
}
private static void treatDbdFile(String xml, File file) throws IOException {
String dbd = FileUtils.readFileToString(file);
// dbd = dbd.replace(MARKER, MARKER.concat(xml).concat(MARKER));
// dbd = dbd.replaceAll(MARKER + ".*" + MARKER, xml);
dbd = Pattern.compile(MARKER + ".*" + MARKER, Pattern.DOTALL).matcher(dbd).replaceAll(MARKER + xml + MARKER);
FileUtils.write(file, dbd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment