From: <aki...@us...> - 2014-03-08 20:14:53
|
Revision: 9677 http://sourceforge.net/p/gridarta/code/9677 Author: akirschbaum Date: 2014-03-08 20:14:48 +0000 (Sat, 08 Mar 2014) Log Message: ----------- Rewrite parser for TreasureLists.xml. Modified Paths: -------------- trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java =================================================================== --- trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java 2014-03-08 19:53:12 UTC (rev 9676) +++ trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java 2014-03-08 20:14:48 UTC (rev 9677) @@ -20,12 +20,11 @@ package net.sf.gridarta.model.treasurelist; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import net.sf.japi.xml.NodeListIterator; +import net.sf.gridarta.utils.xml.ElementsIterable; +import nu.xom.Document; +import nu.xom.Element; import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Document; -import org.w3c.dom.Element; /** * Utility class for loadings the TreasureLists.xml file. @@ -51,21 +50,17 @@ public static Map<String, TreasureTreeNode> parseTreasureLists(@NotNull final Document specialTreasureListsDocument) { final Map<String, TreasureTreeNode> specialTreasureLists = new HashMap<String, TreasureTreeNode>(); - final Element rootElement = specialTreasureListsDocument.getDocumentElement(); - assert rootElement != null && rootElement.getNodeName().equalsIgnoreCase("lists"); + final Element rootElement = specialTreasureListsDocument.getRootElement(); + assert rootElement != null && rootElement.getLocalName().equalsIgnoreCase("lists"); - final NodeListIterator<Element> it = new NodeListIterator<Element>(rootElement, "list"); - while (it.hasNext()) { - final Element list = it.next(); - final String listName = list.getAttribute("name"); + for (final Element list : new ElementsIterable(rootElement.getChildElements("list"))) { + final String listName = list.getAttribute("name").getValue(); assert listName != null; final TreasureTreeNode folder = new TreasureTreeNode(new FolderTreasureObj(listName)); - final Iterator<Element> it2 = new NodeListIterator<Element>(list, "entry"); - while (it2.hasNext()) { - final Element entry = it2.next(); - final String entryName = entry.getAttribute("name"); + for (final Element entry : new ElementsIterable(list.getChildElements("entry"))) { + final String entryName = entry.getAttribute("name").getValue(); assert entryName != null; specialTreasureLists.put(entryName, folder); Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java =================================================================== --- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 19:53:12 UTC (rev 9676) +++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 20:14:48 UTC (rev 9677) @@ -114,12 +114,12 @@ import net.sf.gridarta.utils.xml.ParseUtils; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; +import nu.xom.Document; import nu.xom.ParsingException; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -259,7 +259,7 @@ gameObjectSpells = loadArchetypeSpells(projectFactory.getSpellType(), gameObjectFactory, archetypeSet); numberSpells = loadSpellFile(projectFactory.getSpellFile(), errorView, projectSettings, xmlHelper); scriptsFile = new File(projectSettings.getMapsDirectory(), projectFactory.getScriptsDir()); - final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, xmlHelper.getDocumentBuilder(), projectSettings); + final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, projectSettings); treasureTree = TreasureLoader.parseTreasures(errorView, specialTreasureLists, configSource, projectSettings); final NamedFilter defaultFilterList = new NamedFilter(Collections.<NamedGameObjectMatcher>emptyList()); final PluginParameterFactory<G, A, R> pluginParameterFactory = new PluginParameterFactory<G, A, R>(archetypeSet, mapManager, projectSettings, pathManager); @@ -326,7 +326,7 @@ } final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, url); try { - final nu.xom.Document document; + final Document document; final InputStream inputStream = url.openStream(); try { document = ParseUtils.readXmlStream(inputStream, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID)); @@ -443,7 +443,7 @@ } @NotNull - public static Map<String, TreasureTreeNode> loadSpecialTreasureLists(@NotNull final ErrorView errorView, @NotNull final DocumentBuilder documentBuilder, @NotNull final ProjectSettings projectSettings) { + public static Map<String, TreasureTreeNode> loadSpecialTreasureLists(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) { Map<String, TreasureTreeNode> specialTreasureLists; try { final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), "TreasureLists.xml"); @@ -451,19 +451,17 @@ try { final InputStream inputStream = url.openStream(); try { - documentBuilder.setErrorHandler(new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID)); - try { - final Document specialTreasureListsDocument = documentBuilder.parse(new InputSource(inputStream)); - specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument); - } finally { - documentBuilder.setErrorHandler(null); - } + final Document specialTreasureListsDocument = ParseUtils.readXmlStream(inputStream, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID)); + specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument); } finally { inputStream.close(); } } catch (final IOException ex) { treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); specialTreasureLists = Collections.emptyMap(); + } catch (final ParsingException ex) { + treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); + specialTreasureLists = Collections.emptyMap(); } catch (final SAXException ex) { treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage()); specialTreasureLists = Collections.emptyMap(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |