[New] Added StrolchXmlParser to quickly parse from a file

This commit is contained in:
Robert von Burg 2017-03-02 15:00:35 +01:00
parent 62a441e038
commit 6cc22c21a8
2 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,28 @@
package li.strolch.model.xml;
import java.io.File;
import li.strolch.model.Order;
import li.strolch.model.Resource;
import li.strolch.model.activity.Activity;
public class StrolchXmlParser {
public static Resource parseAndReturnResource(File file, String id) {
SimpleStrolchElementListener elementListener = new SimpleStrolchElementListener();
new XmlModelSaxFileReader(elementListener, file, false).parseFile();
return elementListener.getResource(id);
}
public static Order parseAndReturnOrder(File file, String id) {
SimpleStrolchElementListener elementListener = new SimpleStrolchElementListener();
new XmlModelSaxFileReader(elementListener, file, false).parseFile();
return elementListener.getOrder(id);
}
public static Activity parseAndReturnActivity(File file, String id) {
SimpleStrolchElementListener elementListener = new SimpleStrolchElementListener();
new XmlModelSaxFileReader(elementListener, file, false).parseFile();
return elementListener.getActivity(id);
}
}

View File

@ -22,13 +22,13 @@ import java.util.Date;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.utils.helper.StringHelper;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@ -62,8 +62,8 @@ public class XmlModelSaxFileReader extends XmlModelSaxReader {
String includeFileS = attributes.getValue(Tags.FILE);
if (StringHelper.isEmpty(includeFileS)) {
throw new IllegalArgumentException(MessageFormat.format(
"The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$
throw new IllegalArgumentException(
MessageFormat.format("The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$
}
File includeFile = new File(this.modelFile.getParentFile(), includeFileS);