@Test public void testThatCustomAttributeIsResolvedForNestedControl() throws Exception { String controlXml = "<nifty-controls xmlns=\"http: " <controlDefinition name=\"treeMenu\" childRootId=\"#content\">\n" + " <panel childLayout=\"horizontal\">\n" + " <text id=\"#text\" text=\"$caption\"/>\n" + " <panel id=\"#content\" childLayout=\"vertical\"/>\n" + " </panel>\n" + " </controlDefinition>\n" + "</nifty-controls>"; File controlFile = folder.newFile(); PrintWriter writer = new PrintWriter(controlFile); writer.print(controlXml); writer.close(); String mainXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<nifty xmlns=\"http: " <useControls filename=\"" + controlFile.getPath() + "\"/>\n" + " <screen id=\"start\">\n" + " <layer childLayout=\"vertical\">\n" + " <control id=\"test1\" name=\"treeMenu\" caption=\"Test1\">\n" + " <control id=\"test2\" name=\"treeMenu\" caption=\"Test2\"/>\n" + " </control>\n" + " </layer>\n" + " </screen>\n" + "</nifty>"; InputStream inputStream = new ByteArrayInputStream(mainXml.getBytes("ISO-8859-1")); niftyLoader.loadNiftyXml("nifty.nxs", inputStream).create(nifty, nifty.getTimeProvider()); Screen screen = nifty.getScreen("start"); Element outerElement = screen.findElementById("test1#text"); assertEquals("Test1", outerElement.getRenderer(TextRenderer.class).getOriginalText()); Element innerElement = screen.findElementById("test2#text"); assertEquals("Test2", innerElement.getRenderer(TextRenderer.class).getOriginalText()); }
@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); } }
NiftyLoader { @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); } } }
NiftyLoader { @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); } } NiftyLoader(@Nonnull final Nifty nifty, @Nonnull final TimeProvider timeProvider); }
NiftyLoader { @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); } } NiftyLoader(@Nonnull final Nifty nifty, @Nonnull final TimeProvider timeProvider); @Nonnull NiftyType loadNiftyXml(
      @Nonnull final String schemaId,
      @Nonnull @WillClose final InputStream inputStreamXml); @Deprecated boolean validateNiftyXml(@Nonnull @WillClose final InputStream inputStreamXml); boolean validateNiftyXml(
      @Nonnull final String schemaId,
      @Nonnull @WillClose final InputStream inputStreamXml); void loadStyleFile(
      @Nonnull final String schemaId,
      @Nonnull final String styleFilename,
      @Nonnull final NiftyType niftyType,
      @Nonnull final Nifty nifty); void loadControlFile(
      @Nonnull final String schemaId,
      @Nonnull final String controlFilename,
      @Nonnull final NiftyType niftyType); void registerSchema(
      @Nonnull final String schemaId,
      @Nonnull @WillClose final InputStream inputStreamSchema); }
NiftyLoader { @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); } } NiftyLoader(@Nonnull final Nifty nifty, @Nonnull final TimeProvider timeProvider); @Nonnull NiftyType loadNiftyXml(
      @Nonnull final String schemaId,
      @Nonnull @WillClose final InputStream inputStreamXml); @Deprecated boolean validateNiftyXml(@Nonnull @WillClose final InputStream inputStreamXml); boolean validateNiftyXml(
      @Nonnull final String schemaId,
      @Nonnull @WillClose final InputStream inputStreamXml); void loadStyleFile(
      @Nonnull final String schemaId,
      @Nonnull final String styleFilename,
      @Nonnull final NiftyType niftyType,
      @Nonnull final Nifty nifty); void loadControlFile(
      @Nonnull final String schemaId,
      @Nonnull final String controlFilename,
      @Nonnull final NiftyType niftyType); void registerSchema(
      @Nonnull final String schemaId,
      @Nonnull @WillClose final InputStream inputStreamSchema);  }