rs.addRule(new ElementSelector("configuration/jmxConfigurator"), new JMXConfiguratorAction()); rs.addRule(new ElementSelector("configuration/include"), new IncludeAction());
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { SaxEventRecorder recorder = new SaxEventRecorder(context); this.attributeInUse = null; this.optional = OptionHelper.toBoolean(attributes.getValue(OPTIONAL_ATTR), false); if (!checkAttributes(attributes)) { return; } InputStream in = getInputStream(ec, attributes); try { if (in != null) { parseAndRecord(in, recorder); // remove the <included> tag from the beginning and </included> from the end trimHeadAndTail(recorder); // offset = 2, because we need to get past this element as well as the end element ec.getJoranInterpreter().getEventPlayer().addEventsDynamically(recorder.saxEventList, 2); } } catch (JoranException e) { addError("Error while parsing " + attributeInUse, e); } finally { close(in); } }
InputStream getInputStream(InterpretationContext ec, Attributes attributes) { URL inputURL = getInputURL(ec, attributes); if (inputURL == null) return null; ConfigurationWatchListUtil.addToWatchList(context, inputURL); return openURL(inputURL); }
URL getInputURL(InterpretationContext ec, Attributes attributes) { String fileAttribute = attributes.getValue(FILE_ATTR); String urlAttribute = attributes.getValue(URL_ATTR); String resourceAttribute = attributes.getValue(RESOURCE_ATTR); if (!OptionHelper.isEmpty(fileAttribute)) { this.attributeInUse = ec.subst(fileAttribute); return filePathAsURL(attributeInUse); } if (!OptionHelper.isEmpty(urlAttribute)) { this.attributeInUse = ec.subst(urlAttribute); return attributeToURL(attributeInUse); } if (!OptionHelper.isEmpty(resourceAttribute)) { this.attributeInUse = ec.subst(resourceAttribute); return resourceAsURL(attributeInUse); } // given previous checkAttributes() check we cannot reach this line throw new IllegalStateException("A URL stream should have been returned"); }
/** * Processes an include * @param ic context * @param url URL to file/resource being included */ @Override protected void processInclude(InterpretationContext ic, URL url) throws JoranException { InputStream in = openURL(url); try { if (in != null) { // add URL to watch list in case the "scan" flag is true, in // which case this URL is periodically checked for changes ConfigurationWatchListUtil.addToWatchList(getContext(), url); // parse the include SaxEventRecorder recorder = createRecorder(in, url); recorder.setContext(getContext()); recorder.recordEvents(in); // remove the leading/trailing tags (<included> or <configuration>) trimHeadAndTail(recorder); ic.getJoranInterpreter().getEventPlayer().addEventsDynamically(recorder.getSaxEventList(), this.eventOffset); } } catch (JoranException e) { optionalWarning("Failed processing [" + url.toString() + "]", e); } finally { close(in); } }
URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
private InputStream getInputStreamByUrl(URL url) { return openURL(url); }
URL getInputURL(InterpretationContext ec, Attributes attributes) { String fileAttribute = attributes.getValue(FILE_ATTR); String urlAttribute = attributes.getValue(URL_ATTR); String resourceAttribute = attributes.getValue(RESOURCE_ATTR); if (!OptionHelper.isEmpty(fileAttribute)) { this.attributeInUse = ec.subst(fileAttribute); return filePathAsURL(attributeInUse); } if (!OptionHelper.isEmpty(urlAttribute)) { this.attributeInUse = ec.subst(urlAttribute); return attributeToURL(attributeInUse); } if (!OptionHelper.isEmpty(resourceAttribute)) { this.attributeInUse = ec.subst(resourceAttribute); return resourceAsURL(attributeInUse); } // given previous checkAttributes() check we cannot reach this line throw new IllegalStateException("A URL stream should have been returned"); }
InputStream openURL(URL url) { try { return url.openStream(); } catch (IOException e) { if (!optional) { String errMsg = "Failed to open [" + url.toString() + "]"; addError(errMsg, e); } return null; } }
private InputStream getInputStreamByResource(URL url) { return openURL(url); }
private InputStream getInputStreamByResource(String resourceAttribute) { URL url = Loader.getResourceBySelfClassLoader(resourceAttribute); if (url == null) { String errMsg = "Could not find resource corresponding to [" + resourceAttribute + "]"; addError(errMsg); return null; } return openURL(url); }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { SaxEventRecorder recorder = new SaxEventRecorder(); this.attributeInUse = null; if (!checkAttributes(attributes)) { return; } InputStream in = getInputStream(ec, attributes); try { if (in != null) { parseAndRecord(in, recorder); } } catch (JoranException e) { addError("Error while parsing " + attributeInUse, e); } finally { close(in); } // remove the <included> tag from the beginning and </included> from the end trimHeadAndTail(recorder); ec.getJoranInterpreter().addEventsDynamically(recorder.saxEventList); }
URL getInputURL(InterpretationContext ec, Attributes attributes) { String fileAttribute = attributes.getValue(FILE_ATTR); String urlAttribute = attributes.getValue(URL_ATTR); String resourceAttribute = attributes.getValue(RESOURCE_ATTR); if (!OptionHelper.isEmpty(fileAttribute)) { this.attributeInUse = ec.subst(fileAttribute); return filePathAsURL(attributeInUse); } if (!OptionHelper.isEmpty(urlAttribute)) { this.attributeInUse = ec.subst(urlAttribute); return attributeToURL(attributeInUse); } if (!OptionHelper.isEmpty(resourceAttribute)) { this.attributeInUse = ec.subst(resourceAttribute); return resourceAsURL(attributeInUse); } // given previous checkAttributes() check we cannot reach this line throw new IllegalStateException("A URL stream should have been returned"); }
URL resourceAsURL(String resourceAttribute) { URL url = Loader.getResourceBySelfClassLoader(resourceAttribute); if (url == null) { if (!optional) { String errMsg = "Could not find resource corresponding to [" + resourceAttribute + "]"; addError(errMsg); } return null; } else return url; }
InputStream getInputStream(InterpretationContext ec, Attributes attributes) { URL inputURL = getInputURL(ec, attributes); if (inputURL == null) return null; ConfigurationWatchListUtil.addToWatchList(context, inputURL); return openURL(inputURL); }
@Before public void setUp() throws Exception { FileTestUtil.makeTestOutputDir(); HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>(); rulesMap.put(new ElementSelector("x"), new NOPAction()); rulesMap.put(new ElementSelector("x/include"), new IncludeAction()); rulesMap.put(new ElementSelector("x/stack"), stackAction); tc = new TrivialConfigurator(rulesMap); tc.setContext(context); }
private InputStream getInputStreamByUrl(URL url) { return openURL(url); }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { SaxEventRecorder recorder = new SaxEventRecorder(); this.attributeInUse = null; if (!checkAttributes(attributes)) { return; } InputStream in = getInputStream(ec, attributes); try { if (in != null) { parseAndRecord(in, recorder); // remove the <included> tag from the beginning and </included> from the end trimHeadAndTail(recorder); // offset = 2, because we need to get past this element as well as the end element ec.getJoranInterpreter().getEventPlayer().addEventsDynamically(recorder.saxEventList, 2); } } catch (JoranException e) { addError("Error while parsing " + attributeInUse, e); } finally { close(in); } }
URL getInputURL(InterpretationContext ec, Attributes attributes) { String fileAttribute = attributes.getValue(FILE_ATTR); String urlAttribute = attributes.getValue(URL_ATTR); String resourceAttribute = attributes.getValue(RESOURCE_ATTR); if (!OptionHelper.isEmpty(fileAttribute)) { this.attributeInUse = ec.subst(fileAttribute); return filePathAsURL(attributeInUse); } if (!OptionHelper.isEmpty(urlAttribute)) { this.attributeInUse = ec.subst(urlAttribute); return attributeToURL(attributeInUse); } if (!OptionHelper.isEmpty(resourceAttribute)) { this.attributeInUse = ec.subst(resourceAttribute); return resourceAsURL(attributeInUse); } // given previous checkAttributes() check we cannot reach this line throw new IllegalStateException("A URL stream should have been returned"); }