Search in sources :

Example 1 with XMLFilter

use of plugin.overland.gui.XMLFilter in project pcgen by PCGen.

the class RoomBoardFactory method load.

public static RoomBoard load(File dataDir) {
    //Create a new list for the room and board
    PairList<RBCost> inns = new PairList<>();
    PairList<RBCost> foods = new PairList<>();
    PairList<RBCost> animals = new PairList<>();
    File path = new File(dataDir, DIR_RNBPRICE);
    if (path.isDirectory()) {
        File[] dataFiles = path.listFiles(new XMLFilter());
        SAXBuilder builder = new SAXBuilder();
        for (int i = 0; i < dataFiles.length; i++) {
            try {
                Document methodSet = builder.build(dataFiles[i]);
                DocType dt = methodSet.getDocType();
                if (//$NON-NLS-1$
                dt.getElementName().equals("RNBPRICE")) {
                    //Do work here
                    loadRBData(methodSet, inns, foods, animals);
                }
                methodSet = null;
                dt = null;
            } catch (Exception e) {
                Logging.errorPrintLocalised("XML Error with file {0}", dataFiles[i].getName());
                Logging.errorPrint(e.getMessage(), e);
            }
        }
    } else {
        //$NON-NLS-1$
        Logging.errorPrintLocalised("in_plugin_overland_noDatafile", path.getPath());
    }
    return new RoomBoardImplementation(inns, foods, animals);
}
Also used : RBCost(plugin.overland.util.RBCost) SAXBuilder(org.jdom2.input.SAXBuilder) XMLFilter(plugin.overland.gui.XMLFilter) PairList(plugin.overland.util.PairList) Document(org.jdom2.Document) File(java.io.File) DocType(org.jdom2.DocType) ParseException(java.text.ParseException)

Example 2 with XMLFilter

use of plugin.overland.gui.XMLFilter in project pcgen by PCGen.

the class TravelMethodFactory method load.

// ### Factory methods ###
public static Vector<TravelMethod> load(File datadir) {
    //Create a new list for the travel methods
    Vector<TravelMethod> tms = new Vector<>();
    File path = new File(datadir, DIR_TRAVELMETHODS);
    if (path.isDirectory()) {
        File[] dataFiles = path.listFiles(new XMLFilter());
        SAXBuilder builder = new SAXBuilder();
        for (int i = 0; i < dataFiles.length; i++) {
            try {
                Document methodSet = builder.build(dataFiles[i]);
                DocType dt = methodSet.getDocType();
                if (dt.getElementName().equals(XML_ELEMENT_TRAVEL)) {
                    //Do work here
                    TravelMethod tm = TravelMethodFactory.create(methodSet);
                    tms.add(tm);
                }
            } catch (Exception e) {
                Logging.errorPrint(e.getMessage(), e);
            }
        }
    } else {
        //$NON-NLS-1$
        Logging.errorPrintLocalised("in_plugin_overland_noDatafile", path.getPath());
    }
    return tms;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) XMLFilter(plugin.overland.gui.XMLFilter) Document(org.jdom2.Document) Vector(java.util.Vector) File(java.io.File) DocType(org.jdom2.DocType) ParseException(java.text.ParseException)

Aggregations

File (java.io.File)2 ParseException (java.text.ParseException)2 DocType (org.jdom2.DocType)2 Document (org.jdom2.Document)2 SAXBuilder (org.jdom2.input.SAXBuilder)2 XMLFilter (plugin.overland.gui.XMLFilter)2 Vector (java.util.Vector)1 PairList (plugin.overland.util.PairList)1 RBCost (plugin.overland.util.RBCost)1