 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.model.match;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.Locale;
27 import nu.xom.Element;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
138 final String localName = el.getLocalName();
139 if (localName ==
null || !localName.equals(
"GameObjectMatcher")) {
140 throw new ParsingException(
"wrong local element name: expected \"GameObjectMatcher\" but got \"" + localName +
"\"");
144 if (title ==
null || title.isEmpty()) {
147 if (title ==
null || title.isEmpty()) {
152 assert content !=
null;
156 if (env instanceof Element) {
160 envGameObjectMatcher =
null;
165 return new NamedGameObjectMatcher(systemMatcher ? 0 : editType,
id, title, systemMatcher, envGameObjectMatcher, matcher);
175 private static String
getLanguageTitle(@NotNull
final Node el, @NotNull
final String language) {
176 final Nodes nodes = el.query(
"title[lang('" + language +
"')]");
177 return nodes.size() == 0 ? null : nodes.get(0).getValue();
188 final String localName = el.getLocalName();
189 if (localName ==
null) {
236 final Collection<GameObjectMatcher> childMatchers =
new ArrayList<>();
237 for (
int i = 0; i < el.getChildCount(); i++) {
238 final Node childNode = el.getChild(i);
239 if (childNode instanceof Element) {
243 return childMatchers;
255 if (type.equals(
"string")) {
258 if (type.equals(
"int")) {
261 throw new AssertionError(
"impossible value '" + type +
"' for XML_ATTRIB_ATTRIBUTE_TYPE");
274 final int[] types =
new int[typeNrs.length];
275 for (
int i = 0; i < types.length; i++) {
277 types[i] = Integer.parseInt(typeNrs[i]);
278 }
catch (
final NumberFormatException ex) {
292 private static Node
xpathEvaluate(@NotNull
final Node el, @NotNull
final String xpathExpression) {
293 final Nodes nodes = el.query(xpathExpression);
294 assert nodes.size() <= 1;
295 return nodes.size() == 0 ? null : nodes.get(0);
static final String XML_ATTRIB_ATTRIBUTE_NAME
The name of the "name" attribute within XML_ELEMENT_ATTRIB elements.
Base package of all Gridarta classes.
static final String XML_MATCHER_ATTRIBUTE_SYSTEM
The name of the "system" attribute within matcher elements.
static final String XML_ATTRIB_ATTRIBUTE_TYPE
The name of the "type" attribute within XML_ELEMENT_ATTRIB elements.
Class for some default GameObjectMatchers.
static GameObjectMatcher createOrMatcher(@NotNull final Node el)
Creates an OrGameObjectMatcher.
GameObjectMatcherParser()
Private constructor to prevent instantiation.
static String getLanguageTitle(@NotNull final Node el, @NotNull final String language)
Returns the title for a given language.
Interface for classes that match GameObjects.
A AttributeGameObjectMatcher that compares attributes values using "int" type.
static final String XML_ATTRIB_ATTRIBUTE_USEARCHETYPE
The name of the "useArchetype" attribute within {} elements.
static final String XML_ELEMENT_AND
The name of the "And" element.
static final Pattern PATTERN_WHITESPACE
Pattern to match whitespace excluding NL and CR.
static Node xpathEvaluate(@NotNull final Node el, @NotNull final String xpathExpression)
Evaluates an XPath expression and returns the result Node.
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
static final String XML_MATCHER_ATTRIBUTE_ID
The name of the "id" attribute within matcher elements.
An GameObjectMatcher matching certain archetype types.
static GameObjectMatcher createMatcher(@NotNull final Element el)
Creates a GameObjectMatcher from XML.
A GameObjectMatcher that And-combines other.
A AttributeGameObjectMatcher that compares attributes values using "string" type.
static NamedGameObjectMatcher parseMatcher(@NotNull final Element el, final int editType)
Creates a NamedGameObjectMatcher from XML.
static GameObjectMatcher createTypeNrsArchObjectMatcher(@NotNull final Element el)
Creates a TypeNrsGameObjectMatcher.
static final String XML_ELEMENT_OR
The name of the "Or" element.
Utility class for string manipulation.
Thrown when a parsing error occurs.
static GameObjectMatcher createAndMatcher(@NotNull final Node el)
Creates an AndGameObjectMatcher.
static final String XML_MATCHER_ELEMENT_ENV
The name of the "Env" element within matcher elements.
A GameObjectMatcher that Or-combines other.
static GameObjectMatcher createAttributeArchObjectMatcher(@NotNull final Element el)
Creates an AttributeGameObjectMatcher.
static final String XML_TYPENRS_ATTRIBUTE_NUMBERS
The name of the "numbers" attribute within XML_ELEMENT_TYPENRS elements.
static final String XML_ELEMENT_ATTRIB
The name of the "Attrib" element.
static final String XML_ATTRIB_ATTRIBUTE_OP
The name of the "op" attribute within XML_ELEMENT_ATTRIB elements.
static Collection< GameObjectMatcher > getChildMatchers(@NotNull final Node el)
Gets the matchers that are found as children of an XML element.
static final String XML_ATTRIB_ATTRIBUTE_VALUE
The name of the "value" attribute within XML_ELEMENT_ATTRIB elements.
static final String XML_ELEMENT_TYPENRS
The name of the "TypeNrs" element.