[New] Added StrolchXmlParser to quickly parse from a file
This commit is contained in:
parent
62a441e038
commit
6cc22c21a8
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,13 +22,13 @@ import java.util.Date;
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
import li.strolch.utils.helper.StringHelper;
|
import li.strolch.utils.helper.StringHelper;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
|
@ -62,8 +62,8 @@ public class XmlModelSaxFileReader extends XmlModelSaxReader {
|
||||||
|
|
||||||
String includeFileS = attributes.getValue(Tags.FILE);
|
String includeFileS = attributes.getValue(Tags.FILE);
|
||||||
if (StringHelper.isEmpty(includeFileS)) {
|
if (StringHelper.isEmpty(includeFileS)) {
|
||||||
throw new IllegalArgumentException(MessageFormat.format(
|
throw new IllegalArgumentException(
|
||||||
"The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$
|
MessageFormat.format("The attribute {0} is missing for IncludeFile!", Tags.FILE)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
File includeFile = new File(this.modelFile.getParentFile(), includeFileS);
|
File includeFile = new File(this.modelFile.getParentFile(), includeFileS);
|
||||||
|
|
Loading…
Reference in New Issue