public void loadStyleFile( @Nonnull final String schemaId, @Nonnull final String styleFilename, @Nonnull final NiftyType niftyType, @Nonnull final Nifty nifty) throws Exception { log.fine("loading new nifty style xml file [" + styleFilename + "] with schemaId [" + schemaId + "]"); XmlParser parser = new XmlParser(parserFactory.newPullParser()); InputStream stream = null; try { stream = nifty.getResourceAsStream(styleFilename); if (stream == null) { throw new IOException("Failed to load style. Resource \"" + styleFilename + "\" not found"); } parser.read(stream); NiftyStylesType niftyStylesType = (NiftyStylesType) getSchema(schemaId).loadXml(parser); niftyStylesType.loadStyles(this, niftyType, nifty, log); } finally { closeSilently(stream); } }
public void loadControlFile( @Nonnull final String schemaId, @Nonnull final String controlFilename, @Nonnull final NiftyType niftyType) throws Exception { log.fine("loading new nifty controls xml file [" + controlFilename + "] with schemaId [" + schemaId + "]"); XmlParser parser = new XmlParser(parserFactory.newPullParser()); InputStream stream = null; try { stream = nifty.getResourceAsStream(controlFilename); if (stream == null) { throw new IOException("Failed to load control. Resource \"" + controlFilename + "\" not found"); } parser.read(stream); NiftyControlsType niftyControlsType = (NiftyControlsType) getSchema(schemaId).loadXml(parser); niftyControlsType.loadControls(this, niftyType); } finally { closeSilently(stream); } }
public void registerSchema( @Nonnull final String schemaId, @Nonnull @WillClose final InputStream inputStreamSchema) throws Exception { try { Schema niftyXmlSchema = new Schema(parserFactory, nifty.getResourceLoader()); XmlParser parser = new XmlParser(parserFactory.newPullParser()); parser.read(inputStreamSchema); parser.nextTag(); parser.required("nxs", niftyXmlSchema); schemes.put(schemaId, niftyXmlSchema); } finally { closeSilently(inputStreamSchema); } }
@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) {} } } } }
/** * Load a Nifty-GUI XML file and get the type that is defined in the file. The XML file needs to be a valid XML GUI * definition. * * @param schemaId the name of the schema that should be used to validate the XML file * @param inputStreamXml the input stream of the XML file, this stream <b>will be closed</b> by this function * @return the NiftyType that was load from the XML file * @throws Exception in case the loading fails at any point */ @Nonnull public NiftyType loadNiftyXml( @Nonnull final String schemaId, @Nonnull @WillClose final InputStream inputStreamXml) throws Exception { try { long start = timeProvider.getMsTime(); log.fine("loading new nifty xml file with schemaId [" + schemaId + "]"); XmlParser parser = new XmlParser(parserFactory.newPullParser()); parser.read(inputStreamXml); NiftyType niftyType = (NiftyType) getSchema(schemaId).loadXml(parser); niftyType.loadStyles(this, nifty); niftyType.loadControls(this); long end = timeProvider.getMsTime(); log.fine("loaded nifty xml file with schemaId [" + schemaId + "] took [" + (end - start) + " ms]"); return niftyType; } finally { closeSilently(inputStreamXml); } }