All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.lessvoid.xml.lwxs.processor.IncludeProcessor Maven / Gradle / Ivy

Go to download

Nifty GUI is a Java Library that supports the building of interactive user interfaces for games or similar applications. It utilizes OpenGL for rendering and it can be easily integrated into many rendering systems. The configuration of the GUI is stored in xml files with little supporting Java code. In short Nifty helps you to layout stuff, display it in a cool way and interact with it :)

There is a newer version: 1.4.3
Show newest version
package de.lessvoid.xml.lwxs.processor;

import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader;
import de.lessvoid.xml.lwxs.Schema;
import de.lessvoid.xml.lwxs.elements.Type;
import de.lessvoid.xml.xpp3.Attributes;
import de.lessvoid.xml.xpp3.XmlParser;
import de.lessvoid.xml.xpp3.XmlProcessor;
import org.xmlpull.v1.XmlPullParserFactory;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

public class IncludeProcessor implements XmlProcessor {
  @Nonnull
  private final Map < String, Type > types;
  @Nonnull
  private final XmlPullParserFactory parserFactory;
  @Nonnull
  private final NiftyResourceLoader resourceLoader;

  public IncludeProcessor(
      @Nonnull final XmlPullParserFactory parserFactory,
      @Nonnull final NiftyResourceLoader resourceLoader,
      @Nonnull final Map typesParam) {
    this.resourceLoader = resourceLoader;
    this.types = typesParam;
    this.parserFactory = parserFactory;
  }

  @Override
  public void process(
      @Nonnull final XmlParser xmlParser,
      @Nonnull final Attributes attributes) throws Exception {
    String filename = attributes.get("filename");
    if (filename == null) {
      return;
    }

    Schema niftyXmlSchema = new Schema(parserFactory, resourceLoader);
    XmlParser parser = new XmlParser(parserFactory.newPullParser());
    InputStream stream = resourceLoader.getResourceAsStream(filename);
    if (stream != null) {
      try {
        parser.read(stream);
        parser.nextTag();
        parser.required("nxs", niftyXmlSchema);

        types.putAll(niftyXmlSchema.getTypes());
        xmlParser.nextTag();
      } finally {
        try {
          stream.close();
        } catch (IOException ignored) {}
      }
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy