Created
April 4, 2013 15:43
-
-
Save rschumm/5311530 to your computer and use it in GitHub Desktop.
Regex etc. gebastel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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