@@ -0,0 +1,2588 @@
+package de.exciteproject.refext.extract;%0A%0Aimport java.io.BufferedWriter;%0Aimport java.io.File;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport de.exciteproject.refext.util.FileUtils;%0A%0A/**%0A * Class for extracting reference strings from XML files that are annotated with%0A * %3Cref%3E and %3Coth%3E tags.%0A */%0Apublic class XmlReferenceExtractor %7B%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        File inputDir = new File(args%5B0%5D);%0A        File outputDir = new File(args%5B1%5D);%0A        if (!outputDir.exists()) %7B%0A            outputDir.mkdirs();%0A        %7D%0A        XmlReferenceExtractor xmlReferenceExtractor = new XmlReferenceExtractor();%0A        for (File inputFile : inputDir.listFiles()) %7B%0A            File outputFile = new File(outputDir.getAbsolutePath() + File.separator + inputFile.getName());%0A            try %7B%0A                List%3CString%3E references = xmlReferenceExtractor.extract(inputFile);%0A                BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(outputFile));%0A                for (String reference : references) %7B%0A                    bufferedWriter.write(reference);%0A                    bufferedWriter.newLine();%0A                %7D%0A                bufferedWriter.close();%0A            %7D catch (StackOverflowError e) %7B%0A                System.err.println(%22stackoverglow at file: %22 + inputFile.getAbsolutePath());%0A            %7D%0A        %7D%0A%0A    %7D%0A%0A    public List%3CString%3E extract(File inputFile) throws IOException %7B%0A        // TODO add testing%0A        List%3CString%3E references = new ArrayList%3CString%3E();%0A%0A        String fileContent = FileUtils.readFile(inputFile);%0A        Pattern referenceStringPattern = Pattern.compile(%22%3Cref%3E((%5C%5CR%7C%7C.)*)%3C/ref%3E%22);%0A%0A        Matcher matcher = referenceStringPattern.matcher(fileContent);%0A%0A        while (matcher.find()) %7B%0A%0A            String referenceString = matcher.group(1);%0A%0A            // remove %3Coth%3E tags%0A            referenceString = referenceString.replaceAll(%22%3Coth%3E((%5C%5CR%7C%7C.)*)%3C/oth%3E%22, %22%22);%0A            // remove empty lines%0A            referenceString = referenceString.replaceAll(%22%5C%5CR%5C%5Cs*%5C%5CR%22, System.lineSeparator());%0A%0A            // remove dashes at the end of a line when merging%0A            referenceString = referenceString.replaceAll(%22-%5C%5CR%22, %22%22);%0A%0A            // merge all remaining lines by adding a space%0A            referenceString = referenceString.replaceAll(%22%5C%5CR%22, %22 %22);%0A%0A            references.add(referenceString);%0A        %7D%0A        return references;%0A    %7D%0A%0A%7D%0A

Add XmlReferenceExtractor