net.anotheria.asg.generator.parser.XMLPreprocessor Maven / Gradle / Ivy
package net.anotheria.asg.generator.parser;
import net.anotheria.asg.generator.util.IncludedDocuments;
import net.anotheria.util.IOUtils;
import net.anotheria.util.StringUtils;
import java.io.*;
import java.util.List;
/**
* This class preprocess an xml file. Its mainly used to put together a splitted xml file.
* @author another
*
*/
@SuppressWarnings("ALL")
public final class XMLPreprocessor {
/**
* Include commands 'tag'.
*/
private static final String INCLUDE_COMMAND = "@include:";
/**
* Loads a file from the disk. Include marks are replaced with the content of the included files.
* @param f
* @return
* @throws IOException
*/
public static String loadFile(File f, IncludedDocuments includedDocuments) throws IOException {
if (!f.exists())
throw new IOException("File doesn't exists: "+f.getAbsolutePath());
int buffLineNumber = 0;
String content = IOUtils.readFileAtOnceAsString(f.getAbsolutePath());
boolean includeDocumentIsNull = true;
if (includedDocuments != null){
includeDocumentIsNull = false;
if ( !includedDocuments.isListEmpty()){
buffLineNumber = includedDocuments.getLastInsertLine();
}
}
List tags = StringUtils.extractTags(content, '<', '>');
for (String t : tags){
if (!t.startsWith("