Gridarta Editor
ArchetypeTypeParser.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.archetypetype;
21 
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.LinkedHashSet;
29 import nu.xom.Attribute;
30 import nu.xom.Element;
31 import nu.xom.Elements;
32 import org.apache.log4j.Category;
33 import org.apache.log4j.Logger;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
36 
43 public class ArchetypeTypeParser {
44 
48  @NotNull
49  private static final int[] EMPTY_INT_ARRAY = new int[0];
50 
54  @NotNull
55  private static final Category LOG = Logger.getLogger(ArchetypeTypeParser.class);
56 
60  @NotNull
62 
67  public ArchetypeTypeParser(@NotNull final ArchetypeAttributeParser archetypeAttributeParser) {
68  this.archetypeAttributeParser = archetypeAttributeParser;
69  }
70 
82  @NotNull
83  public ArchetypeType loadAttributeList(@NotNull final Element typeElement, @NotNull final ErrorViewCollector errorViewCollector, @Nullable final ArchetypeType parentArchetypeType, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final IgnorelistsDefinition ignorelistsDefinition, final boolean isDefaultType) {
84  final String typeName = parseTypeName(typeElement, isDefaultType);
85  if (LOG.isDebugEnabled()) {
86  LOG.debug("loadAttributeList: " + typeName);
87  }
88  final int typeNo = parseTypeNo(typeElement, isDefaultType, typeName, errorViewCollector);
89  final Attribute typeElementAttribute = typeElement.getAttribute(Constants.XML_TYPE_DISPLAY);
90  final String display = typeElementAttribute == null ? "" : typeElementAttribute.getValue();
91  final boolean map = parseMap(typeElement);
92  final int[] inv = parseInv(typeElement, typeName, errorViewCollector);
93  final boolean allowsAllInv = parseAllowsAllInv(typeElement);
94  final Collection<String> ignoreTable = new HashSet<>();
95  final ArchetypeAttributesDefinition typeAttributes = isDefaultType ? new ArchetypeAttributesDefinition() : parseTypeAttributes(typeElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition);
96 
97  final Collection<String> importTypes = new LinkedHashSet<>();
98  for (final Element importTypeElement : new ElementsIterable(typeElement.getChildElements(Constants.XML_ELEMENT_IMPORT_TYPE))) {
99  final String importType = parseImportType(importTypeElement, typeName, errorViewCollector);
100  if (importType != null && !importTypes.add(importType)) {
101  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has duplicate import for '" + importType + "'.");
102  }
103  }
104 
105  final String defaultSectionName = typeNo == -1 ? ArchetypeAttributeSection.GENERAL_SECTION : ArchetypeAttributeSection.SPECIAL_SECTION;
106  final ArchetypeAttributeSection attributeSection = new ArchetypeAttributeSection(defaultSectionName);
107  final ArchetypeType newArchetypeType = new ArchetypeType(typeName, typeNo, display, map, inv, allowsAllInv, parseDescription(typeElement), parseUse(typeElement), typeAttributes);
108  final Iterable<ArchetypeAttributeSection> attributeList = addAttributeList(typeElement, attributeSection, errorViewCollector, typeName, archetypeTypeSet);
109  if (LOG.isDebugEnabled()) {
110  LOG.debug("loadAttributeList: adding default section " + attributeSection);
111  }
112  newArchetypeType.addAttributeSection(attributeSection);
113  for (final ArchetypeAttributeSection archetypeAttributeSection : attributeList) {
114  if (LOG.isDebugEnabled()) {
115  LOG.debug("loadAttributeList: adding section " + archetypeAttributeSection);
116  }
117  newArchetypeType.addAttributeSection(archetypeAttributeSection);
118  }
119  if (parentArchetypeType != null) {
120  if (LOG.isDebugEnabled()) {
121  LOG.debug("loadAttributeList: importing attributes from parent archetype type " + parentArchetypeType.getTypeName());
122  }
123  final Collection<String> autoIgnoreTable = new HashSet<>();
124  for (final ArchetypeAttributeSection archetypeAttributeSection : attributeList) {
125  for (final ArchetypeAttribute attribute : archetypeAttributeSection) {
126  if (LOG.isDebugEnabled()) {
127  LOG.debug("loadAttributeList: auto-ignore: " + attribute.getArchetypeAttributeName() + " [parent]");
128  }
129  autoIgnoreTable.add(attribute.getArchetypeAttributeName());
130  }
131  }
132  for (final ArchetypeAttribute attribute : attributeSection) {
133  if (LOG.isDebugEnabled()) {
134  LOG.debug("loadAttributeList: auto-ignore: " + attribute.getArchetypeAttributeName() + " [this]");
135  }
136  autoIgnoreTable.add(attribute.getArchetypeAttributeName());
137  }
138 
139  if (parentArchetypeType.hasAttribute()) {
140  for (final String importType : importTypes) {
141  if (LOG.isDebugEnabled()) {
142  LOG.debug("loadAttributeList: importing attributes from " + importType);
143  }
144  addImportList(importType, newArchetypeType, errorViewCollector, typeName, archetypeTypeSet, autoIgnoreTable);
145  }
146  }
147 
148  if (LOG.isDebugEnabled()) {
149  LOG.debug("loadAttributeList: importing default attributes from " + parentArchetypeType.getTypeName());
150  }
151  addDefaultList(parentArchetypeType, newArchetypeType, autoIgnoreTable, ignoreTable);
152  }
153 
154  return newArchetypeType;
155  }
156 
165  private static void addDefaultList(@NotNull final Iterable<ArchetypeAttributeSection> archetypeType, @NotNull final ArchetypeType newArchetypeType, @NotNull final Collection<String> autoIgnoreTable, @NotNull final Collection<String> ignoreTable) {
166  for (final ArchetypeAttributeSection archetypeAttributeSection : archetypeType) {
167  for (final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) {
168  // add all attributes from the default_type which are not in the ignoreTable
169  final String archetypeAttributeName = archetypeAttribute.getArchetypeAttributeName();
170  if (ignoreTable.contains(archetypeAttributeName)) {
171  if (LOG.isDebugEnabled()) {
172  LOG.debug("addDefaultList: skipping " + archetypeAttributeName + " because of ignoreTable");
173  }
174  continue;
175  }
176  if (autoIgnoreTable.contains(archetypeAttributeName)) {
177  if (LOG.isDebugEnabled()) {
178  LOG.debug("addDefaultList: skipping " + archetypeAttributeName + " because of autoIgnoreTable");
179  }
180  continue;
181  }
182  if (LOG.isDebugEnabled()) {
183  LOG.debug("addDefaultList: adding " + archetypeAttributeName + " to section " + archetypeAttributeSection);
184  }
185  newArchetypeType.addArchetypeAttribute(archetypeAttributeSection.getSectionName(), archetypeAttribute);
186  }
187  }
188  }
189 
200  private static void addImportList(@NotNull final String importName, @NotNull final ArchetypeType newArchetypeType, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Collection<String> autoIgnoreTable) {
201  final ArchetypeType importType = archetypeTypeSet.getArchetypeType(importName);
202  if (importType == null) {
203  if (LOG.isDebugEnabled()) {
204  LOG.debug("addImportList: skipping " + importName + " because it does not exist");
205  }
206  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, typeName + ": import type \"" + importName + "\" not found!");
207  return;
208  }
209 
210  for (final ArchetypeAttributeSection archetypeAttributeSection : importType) {
211  final String sectionName = archetypeAttributeSection.getSectionName();
212  if (sectionName.equals(ArchetypeAttributeSection.GENERAL_SECTION)) {
213  if (LOG.isDebugEnabled()) {
214  LOG.debug("addImportList: skipping section " + sectionName + " because it is the general section");
215  }
216  continue;
217  }
218 
219  for (final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) {
220  final String attributeName = archetypeAttribute.getArchetypeAttributeName();
221  if (autoIgnoreTable.contains(attributeName)) {
222  if (LOG.isDebugEnabled()) {
223  LOG.debug("addImportList: skipping " + attributeName + " because of autoIgnoreTable");
224  }
225  continue;
226  }
227 
228  if (LOG.isDebugEnabled()) {
229  LOG.debug("addImportList: adding " + archetypeAttribute + " to section " + sectionName);
230  }
231  newArchetypeType.addArchetypeAttribute(sectionName, archetypeAttribute);
232  if (LOG.isDebugEnabled()) {
233  LOG.debug("addImportList: auto-ignore: " + attributeName + " [import]");
234  }
235  autoIgnoreTable.add(attributeName);
236  }
237  }
238  }
239 
250  @Nullable
251  private static String parseImportType(@NotNull final Element importTypeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
252  final Attribute nameAttribute = importTypeElement.getAttribute(Constants.XML_IMPORT_TYPE_NAME);
253  if (nameAttribute == null) {
254  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has " + Constants.XML_ELEMENT_IMPORT_TYPE + " element without '" + Constants.XML_IMPORT_TYPE_NAME + "'.");
255  return null;
256  }
257 
258  final String name = nameAttribute.getValue();
259  if (name.isEmpty()) {
260  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has " + Constants.XML_ELEMENT_IMPORT_TYPE + " element with empty '" + Constants.XML_IMPORT_TYPE_NAME + "'.");
261  return null;
262  }
263 
264  return name;
265  }
266 
274  @NotNull
275  private static String parseTypeName(@NotNull final Element typeElement, final boolean isDefaultType) {
276  return isDefaultType ? "default" : typeElement.getAttribute(Constants.XML_TYPE_NAME).getValue();
277  }
278 
287  private static int parseTypeNo(@NotNull final Element typeElement, final boolean isDefaultType, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
288  if (isDefaultType) {
289  return -1;
290  }
291 
292  final String number = typeElement.getAttribute(Constants.XML_TYPE_NUMBER).getValue();
293  try {
294  return Integer.parseInt(number);
295  } catch (final NumberFormatException ignored) {
296  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has invalid type number '" + number + "'.");
297  return -1;
298  }
299  }
300 
306  private static boolean parseMap(@NotNull final Element typeElement) {
307  final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_MAP);
308  return attribute != null && attribute.getValue().equals("yes");
309  }
310 
319  @Nullable
320  private static int[] parseInv(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
321  final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_INV);
322  if (attribute == null) {
323  return null;
324  }
325 
326  final String inv = attribute.getValue();
327  if (inv.isEmpty()) {
328  return EMPTY_INT_ARRAY;
329  }
330  if (inv.equals("*")) {
331  return null;
332  }
333 
334  final String[] types = StringUtils.PATTERN_COMMA.split(inv, -1);
335  final int[] result = new int[types.length];
336  for (int i = 0; i < types.length; i++) {
337  try {
338  result[i] = Integer.parseInt(types[i]);
339  } catch (final NumberFormatException ignored) {
340  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has invalid inv specification '" + types[i] + "'.");
341  result[i] = -1;
342  }
343  }
344  return result;
345  }
346 
352  private static boolean parseAllowsAllInv(@NotNull final Element typeElement) {
353  final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_ALLOWS_ALL_INV);
354  return attribute != null && attribute.getValue().equals("yes");
355  }
356 
367  @NotNull
368  private static ArchetypeAttributesDefinition parseTypeAttributes(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) {
369  final ArchetypeAttributesDefinition typeAttributes = parseRequiredAttribute(typeElement, typeName, errorViewCollector);
370 
371  final Elements ignoreElements = typeElement.getChildElements(Constants.XML_ELEMENT_IGNORE);
372  if (ignoreElements.size() > 0) {
373  final Element ignoreElement = ignoreElements.get(0);
374  parseAttributeAttributes(ignoreElement, typeName, errorViewCollector, ignoreTable);
375  parseIgnoreListAttribute(ignoreElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition);
376  }
377 
378  return typeAttributes;
379  }
380 
388  @NotNull
389  private static ArchetypeAttributesDefinition parseRequiredAttribute(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
391  final Elements requiredElements = typeElement.getChildElements(Constants.XML_ELEMENT_REQUIRED);
392  if (requiredElements.size() > 0) {
393  for (final Element attributeElement : new ElementsIterable(requiredElements.get(0).getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
394  final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH);
395  if (archAttribute == null) {
396  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'.");
397  continue;
398  }
399  final String attributeValue = archAttribute.getValue();
400  if (attributeValue.isEmpty()) {
401  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " empty '" + Constants.XML_ATTRIBUTE_ARCH + "'.");
402  continue;
403  }
404 
405  final Attribute valueAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_VALUE);
406  if (valueAttribute == null) {
407  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_VALUE + "'.");
408  continue;
409  }
410  final String value = valueAttribute.getValue();
411  if (value.isEmpty()) {
412  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " empty '" + Constants.XML_ATTRIBUTE_VALUE + "'.");
413  continue;
414  }
415 
416  attributes.add(new ArchetypeAttributeDefinition(attributeValue, value));
417  }
418  }
419  return attributes;
420  }
421 
429  private static void parseAttributeAttributes(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable) {
430  for (final Element attributeElement : new ElementsIterable(ignoreElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
431  final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH);
432  if (archAttribute == null) {
433  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'.");
434  continue;
435  }
436 
437  final String attributeValue = archAttribute.getValue();
438  if (attributeValue.isEmpty()) {
439  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " empty '" + Constants.XML_ATTRIBUTE_ARCH + "'.");
440  continue;
441  }
442 
443  ignoreTable.add(attributeValue);
444  }
445  }
446 
455  private static void parseIgnoreListAttribute(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) {
456  for (final Element ignoreListElement : new ElementsIterable(ignoreElement.getChildElements(Constants.XML_ELEMENT_IGNORE_LIST))) {
457  final Attribute nameAttribute = ignoreListElement.getAttribute(Constants.XML_IGNORE_LIST_NAME);
458  if (nameAttribute == null) {
459  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_IGNORE_LIST + " missing '" + Constants.XML_IGNORE_LIST_NAME + "'.");
460  continue;
461  }
462 
463  final String name = nameAttribute.getValue();
464  final Iterable<String> ignoreList = ignorelistsDefinition.get(name);
465  if (ignoreList == null) {
466  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_IGNORE_LIST + " with " + Constants.XML_IGNORE_LIST_NAME + " \"" + name + "\" is undefined.");
467  continue;
468  }
469 
470  for (final String ignoreItem : ignoreList) {
471  ignoreTable.add(ignoreItem);
472  }
473  }
474  }
475 
481  @Nullable
482  private static String parseDescription(@NotNull final Element root) {
483  final Elements elements = root.getChildElements(Constants.XML_DESCRIPTION);
484  return elements.size() == 0 ? null : elements.get(0).getValue().trim();
485  }
486 
492  @Nullable
493  private static String parseUse(@NotNull final Element root) {
494  final Elements elements = root.getChildElements(Constants.XML_USE);
495  return elements.size() == 0 ? null : elements.get(0).getValue().trim();
496  }
497 
510  @NotNull
511  private Iterable<ArchetypeAttributeSection> addAttributeList(@NotNull final Element typeElement, @NotNull final ArchetypeAttributeSection defaultAttributeSection, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet) {
513  for (final Element childElement : new ElementsIterable(typeElement.getChildElements())) {
514  final String childName = childElement.getLocalName();
515 
516  if (childName.equals(Constants.XML_ELEMENT_ATTRIBUTE)) {
517  parseAttribute(childElement, errorViewCollector, typeName, archetypeTypeSet, sections, defaultAttributeSection.getSectionName());
518  } else if (childName.equals(Constants.XML_ELEMENT_SECTION) && childElement.getChildElements().size() > 0) {
519  final Attribute nameAttribute = childElement.getAttribute(Constants.XML_SECTION_NAME);
520  if (nameAttribute == null) {
521  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " contains a " + Constants.XML_ELEMENT_SECTION + " missing '" + Constants.XML_SECTION_NAME + "'.");
522  continue;
523  }
524 
525  final String sectionName = nameAttribute.getValue();
526  if (sectionName.isEmpty()) {
527  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " contains a " + Constants.XML_ELEMENT_SECTION + " with empty '" + Constants.XML_SECTION_NAME + "'.");
528  continue;
529  }
530 
531  for (final Element element : new ElementsIterable(childElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
532  parseAttribute(element, errorViewCollector, typeName, archetypeTypeSet, sections, sectionName);
533  }
534  }
535  }
536  return sections;
537  }
538 
549  private void parseAttribute(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final ArchetypeAttributeSections sections, @NotNull final String sectionName) {
550  final ArchetypeAttribute archetypeAttribute = parseAttribute(attributeElement, errorViewCollector, typeName, archetypeTypeSet);
551  if (archetypeAttribute == null) {
552  return;
553  }
554 
555  final String effectiveSectionName = archetypeAttribute instanceof ArchetypeAttributeText ? archetypeAttribute.getAttributeName() : sectionName; // text attributes get their own section
556  sections.addArchetypeAttribute(effectiveSectionName, archetypeAttribute);
557  }
558 
570  @Nullable
571  private ArchetypeAttribute parseAttribute(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet) {
572  try {
573  return archetypeAttributeParser.load(attributeElement, errorViewCollector, archetypeTypeSet, typeName);
574  } catch (final MissingAttributeException ex) {
575  errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + ": " + ex.getMessage());
576  return null;
577  }
578  }
579 
580 }
static ArchetypeAttributesDefinition parseTypeAttributes(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection< String > ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition)
Parses the type attributes of a "type" or "default_type" Element.
Utility class for string manipulation.
static final String XML_IMPORT_TYPE_NAME
The "name" attribute name of a XML_ELEMENT_IMPORT_TYPE element.
Definition: Constants.java:346
Convenience class for adding messages to a ErrorView instance using a fixed category name...
static final String XML_DESCRIPTION
Description Element Name.
Definition: Constants.java:358
ArchetypeAttribute load(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final String typeName)
Loading the data from an xml element into this object.
ArchetypeTypeParser(@NotNull final ArchetypeAttributeParser archetypeAttributeParser)
Creates a new instance.
static final String GENERAL_SECTION
The name of the "General" section.
Manages ArchetypeType instances, list, and bitmask definitions.
This Class contains the data of one archetype attribute.
static final String XML_ELEMENT_IMPORT_TYPE
Import Type Element Name.
Definition: Constants.java:224
static int [] parseInv(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the "inv" attribute of a "type" Element.
void parseAttribute(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final ArchetypeAttributeSections sections, @NotNull final String sectionName)
Parses an Constants#XML_ELEMENT_ATTRIBUTE element.
Contains the data of one Gridarta Object-Type.
An Exception thrown if an attribute key does not exist.
Utility class for parsing ArchetypeType instances.
static void addDefaultList(@NotNull final Iterable< ArchetypeAttributeSection > archetypeType, @NotNull final ArchetypeType newArchetypeType, @NotNull final Collection< String > autoIgnoreTable, @NotNull final Collection< String > ignoreTable)
Adds all attributes of an ArchetypeType to an ArchetypeAttributeSection that are not ignored...
Constants needed to parse "types.xml" files.
Definition: Constants.java:28
static final String XML_ELEMENT_SECTION
Section Element Name.
Definition: Constants.java:230
static final String SPECIAL_SECTION
The name of the "Special" section.
static final Category LOG
The logger for printing log messages.
static void parseIgnoreListAttribute(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection< String > ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition)
Parses the "ignore_list" children.
final ArchetypeAttributeParser archetypeAttributeParser
The parser to use.
Defines possible error categories for ErrorView instances.
static String parseImportType(@NotNull final Element importTypeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_IMPORT_TYPE of an Constants#XML_ELEMENT_TYPE or Constants#XML_ELEMEN...
static final String XML_TYPE_INV
The name of the "inv" attribute within XML_ELEMENT_TYPE elements.
Definition: Constants.java:174
Base package of all Gridarta classes.
static final String XML_ELEMENT_REQUIRED
Required Element Name.
Definition: Constants.java:212
static final String XML_ELEMENT_IGNORE_LIST
The name of the "ignore_list" element.
Definition: Constants.java:206
static boolean parseMap(@NotNull final Element typeElement)
Parses the "map" attribute of a "type" Element.
static final String XML_TYPE_ALLOWS_ALL_INV
The name of the "allows_all_inv" attribute within XML_ELEMENT_TYPE elements.
Definition: Constants.java:181
ArchetypeType loadAttributeList(@NotNull final Element typeElement, @NotNull final ErrorViewCollector errorViewCollector, @Nullable final ArchetypeType parentArchetypeType, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final IgnorelistsDefinition ignorelistsDefinition, final boolean isDefaultType)
Parses an element which contains a list of Constants#XML_ELEMENT_ATTRIBUTE elements from a types...
static final String XML_ATTRIBUTE_ARCH
The name of the "arch" attribute within XML_ELEMENT_ATTRIBUTE elements.
Definition: Constants.java:243
static final String XML_TYPE_NAME
The name of the "name" attribute within XML_ELEMENT_TYPE or XML_ELEMENT_DEFAULT_TYPE elements...
Definition: Constants.java:153
String getAttributeName()
Returns the user interface attribute name.
static final int [] EMPTY_INT_ARRAY
An empty array of.
static final String XML_USE
Use Element Name.
Definition: Constants.java:364
static final String XML_TYPE_MAP
The name of the "map" attribute within XML_ELEMENT_TYPE elements.
Definition: Constants.java:167
Holds the key/value pair of an archetype attribute definition.
static final String XML_IGNORE_LIST_NAME
The "name" attribute name of a XML_ELEMENT_IGNORE_LIST element.
Definition: Constants.java:340
static final Pattern PATTERN_COMMA
The pattern that matches a single comma (",").
Iterable< ArchetypeAttributeSection > addAttributeList(@NotNull final Element typeElement, @NotNull final ArchetypeAttributeSection defaultAttributeSection, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet)
Parses the Constants#XML_ELEMENT_ATTRIBUTE and Constants#XML_ELEMENT_SECTION children of a "type" or ...
static final String XML_SECTION_NAME
The "name" attribute name of a XML_ELEMENT_SECTION element.
Definition: Constants.java:352
static String parseDescription(@NotNull final Element root)
Parses the Constants#XML_DESCRIPTION child.
static void parseAttributeAttributes(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection< String > ignoreTable)
Parses the Constants#XML_ELEMENT_ATTRIBUTE child.
static int parseTypeNo(@NotNull final Element typeElement, final boolean isDefaultType, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the type number of a "type" or "default_type" Element.
The contents of an <ignorelists> element of a types.xml file.
static final String XML_TYPE_DISPLAY
The name of the "display" attribute within XML_ELEMENT_TYPE elements.
Definition: Constants.java:188
static final String XML_ATTRIBUTE_VALUE
The name of the "value" attribute within XML_ELEMENT_ATTRIBUTE elements.
Definition: Constants.java:257
static String parseUse(@NotNull final Element root)
Parses the Constants#XML_USE child.
void addAttributeSection(@NotNull final ArchetypeAttributeSection newArchetypeAttributeSection)
Adds an ArchetypeAttributeSection.
static final String XML_ELEMENT_IGNORE
Ignore Element Name.
Definition: Constants.java:218
static ArchetypeAttributesDefinition parseRequiredAttribute(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Parses the Constants#XML_ELEMENT_REQUIRED child.
static final String XML_ELEMENT_ATTRIBUTE
The name of the "attribute" element.
Definition: Constants.java:236
An ArchetypeAttribute for selecting text fields.
void addArchetypeAttribute(@NotNull final String sectionName, @NotNull final ArchetypeAttribute archetypeAttribute)
Adds an ArchetypeAttribute to this archetype type.
static void addImportList(@NotNull final String importName, @NotNull final ArchetypeType newArchetypeType, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Collection< String > autoIgnoreTable)
Adds all imported attributes to an ArchetypeAttributeSection.
static final String XML_TYPE_NUMBER
The name of the "number" attribute within XML_ELEMENT_TYPE elements.
Definition: Constants.java:160
static boolean parseAllowsAllInv(@NotNull final Element typeElement)
Parses the "allows_all_inv" attribute of a "type" Element.
static String parseTypeName(@NotNull final Element typeElement, final boolean isDefaultType)
Parses the type name of an Constants#XML_ELEMENT_TYPE or Constants#XML_ELEMENT_DEFAULT_TYPE Element...
ArchetypeAttribute parseAttribute(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet)
Parses an XML attribute element.
void add(@NotNull final ArchetypeAttributeDefinition archetypeAttribute)
Adds an ArchetypeAttributeDefinition.