Gridarta Editor
GameObjectMatchersParser.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.match;
21 
25 import nu.xom.Document;
26 import nu.xom.Element;
27 import org.apache.log4j.Category;
28 import org.apache.log4j.Logger;
29 import org.jetbrains.annotations.NotNull;
30 
36 
40  @NotNull
41  private static final Category LOG = Logger.getLogger(GameObjectMatchersParser.class);
42 
47  }
48 
55  public static void readGameObjectMatchers(@NotNull final Document document, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ErrorViewCollector errorViewCollector) {
56  int count = 0;
57  int editType = 1;
58  final Element rootElement = document.getRootElement();
59  for (final Element node : new ElementsIterable(rootElement.getChildElements("GameObjectMatcher"))) {
60  final NamedGameObjectMatcher archObjectMatcher;
61  try {
62  archObjectMatcher = GameObjectMatcherParser.parseMatcher(node, editType);
63  } catch (final ParsingException ex) {
64  errorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID, node.getAttribute("id") + ": " + ex.getMessage());
65  continue;
66  }
67  gameObjectMatchers.addGameObjectMatcher(archObjectMatcher);
68  count++;
69  if (editType != 0 && !archObjectMatcher.isSystemMatcher()) {
70  editType <<= 1;
71  if (editType == 0) {
72  errorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID, "too many GameObjectMatchers, ignoring rest");
73  }
74  }
75  }
76  if (LOG.isInfoEnabled()) {
77  LOG.info("Loaded " + count + " GameObjectMatchers.");
78  }
79  }
80 
81 }
Convenience class for adding messages to a ErrorView instance using a fixed category name...
Parser for the GameObjectMatchers.xml file.
Thrown when a parsing error occurs.
Class for some default GameObjectMatchers.
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Defines possible error categories for ErrorView instances.
Base package of all Gridarta classes.
GameObjectMatchersParser()
Private constructor to prevent instantiation.
static NamedGameObjectMatcher parseMatcher(@NotNull final Element el, final int editType)
Creates a NamedGameObjectMatcher from XML.
Maintains GameObjectMatcher instances.
static void readGameObjectMatchers(@NotNull final Document document, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ErrorViewCollector errorViewCollector)
Parses a .xml file defining game object matchers.
static final Category LOG
The Logger for printing log messages.
boolean isSystemMatcher()
Returns whether this matcher is a system matcher.