public final void doConfigure(final InputSource inputSource) throws JoranException { long threshold = System.currentTimeMillis(); if (!ConfigurationWatchListUtil.wasConfigurationWatchListReset(context)) { informContextOfURLUsedForConfiguration(getContext(), null); } SaxEventRecorder recorder = new SaxEventRecorder(context); recorder.recordEvents(inputSource); doConfigure(recorder.saxEventList); // no exceptions a this level StatusUtil statusUtil = new StatusUtil(context); if (statusUtil.noXMLParsingErrorsOccurred(threshold)) { addInfo("Registering current configuration as safe fallback point"); registerSafeConfiguration(); } }
public void error(SAXParseException spe) throws SAXException { addError(XML_PARSING +" - Parsing error on line " + spe.getLineNumber() + " and column " + spe.getColumnNumber(), spe); }
public void warning(SAXParseException spe) throws SAXException { addWarn(XML_PARSING +" - Parsing warning on line " + spe.getLineNumber() + " and column " + spe.getColumnNumber(), spe); }
private void parseAndRecord(InputStream inputSource, SaxEventRecorder recorder) throws JoranException { recorder.setContext(context); recorder.recordEvents(inputSource); }
public List<SaxEvent> recordEvents(InputSource inputSource) throws JoranException { SAXParser saxParser = buildSaxParser(); try { saxParser.parse(inputSource, this); return saxEventList; } catch (IOException ie) { handleError("I/O error occurred while parsing xml file", ie); } catch(SAXException se) { // Exception added into StatusManager via Sax error handling. No need to add it again throw new JoranException("Problem parsing XML document. See previously reported errors.", se); } catch (Exception ex) { handleError("Unexpected exception while parsing XML document.", ex); } throw new IllegalStateException("This point can never be reached"); }
public void characters(char[] ch, int start, int length) { String bodyStr = new String(ch, start, length); SaxEvent lastEvent = getLastEvent(); if (lastEvent instanceof BodyEvent) { BodyEvent be = (BodyEvent) lastEvent; be.append(bodyStr); } else { // ignore space only text if the previous event is not a BodyEvent if (!isSpaceOnly(bodyStr)) { saxEventList.add(new BodyEvent(bodyStr, getLocator())); } } }
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { String tagName = getTagName(localName, qName); globalElementPath.push(tagName); ElementPath current = globalElementPath.duplicate(); saxEventList.add(new StartEvent(current, namespaceURI, localName, qName, atts, getLocator())); }
final public void doConfigure(final InputSource inputSource) throws JoranException { SaxEventRecorder recorder = new SaxEventRecorder(); recorder.setContext(context); recorder.recordEvents(inputSource); buildInterpreter(); // disallow simultaneous configurations of the same context synchronized (context.getConfigurationLock()) { interpreter.play(recorder.saxEventList); } }
public List<SaxEvent> doTest(String filename) throws Exception { SaxEventRecorder recorder = new SaxEventRecorder(context); FileInputStream fis = new FileInputStream(CoreTestConstants.TEST_DIR_PREFIX + "input/joran/"+ filename); recorder.recordEvents(fis); return recorder.getSaxEventList(); }
@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); } }
final public void recordEvents(InputStream inputStream) throws JoranException { recordEvents(new InputSource(inputStream)); }
/** * 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); } }
public void characters(char[] ch, int start, int length) { String body = new String(ch, start, length); if (body == null) { return; } // if the body string is null if (body != null) { String bodyTrimmed = body.trim(); if (bodyTrimmed.length() == 0) { return; } } SaxEvent lastEvent = getLastEvent(); if (lastEvent instanceof BodyEvent) { BodyEvent be = (BodyEvent) lastEvent; be.append(body); } else { saxEventList.add(new BodyEvent(body, getLocator())); } }
public void endElement(String namespaceURI, String localName, String qName) { saxEventList .add(new EndEvent(namespaceURI, localName, qName, getLocator())); globalElementPath.pop(); }
public List<SaxEvent> recordEvents(InputSource inputSource) throws JoranException { Driver parser = buildPullParser(); try { parser.setContentHandler((ContentHandler) this); parser.setErrorHandler(this); parser.parse(inputSource); return saxEventList; } catch (EOFException eof) { handleError(eof.getLocalizedMessage(), new SAXParseException(eof.getLocalizedMessage(), locator, eof)); } catch (IOException ie) { handleError("I/O error occurred while parsing xml file", ie); } catch(SAXException se) { // Exception added into StatusManager via Sax error handling. No need to add it again throw new JoranException("Problem parsing XML document. See previously reported errors.", se); } catch (Exception ex) { handleError("Unexpected exception while parsing XML document.", ex); } throw new IllegalStateException("This point can never be reached"); }
public void characters(char[] ch, int start, int length) { String bodyStr = new String(ch, start, length); SaxEvent lastEvent = getLastEvent(); if (lastEvent instanceof BodyEvent) { BodyEvent be = (BodyEvent) lastEvent; be.append(bodyStr); } else { // ignore space only text if the previous event is not a BodyEvent if (!isSpaceOnly(bodyStr)) { saxEventList.add(new BodyEvent(bodyStr, getLocator())); } } }
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { String q = qName == null || qName.length() == 0 ? localName : qName; String tagName = getTagName(localName, q); globalElementPath.push(tagName); ElementPath current = globalElementPath.duplicate(); saxEventList.add(new StartEvent(current, namespaceURI, localName, q, atts, getLocator())); }
private void parseAndRecord(InputStream inputSource, SaxEventRecorder recorder) throws JoranException { recorder.setContext(context); recorder.recordEvents(inputSource); }
public final void doConfigure(final InputSource inputSource) throws JoranException { long threshold = System.currentTimeMillis(); if (!ConfigurationWatchListUtil.wasConfigurationWatchListReset(context)) { informContextOfURLUsedForConfiguration(getContext(), null); } SaxEventRecorder recorder = new SaxEventRecorder(); recorder.setContext(context); recorder.recordEvents(inputSource); doConfigure(recorder.saxEventList); // no exceptions a this level StatusChecker statusChecker = new StatusChecker(context); if (statusChecker.noXMLParsingErrorsOccurred(threshold)) { addInfo("Registering current configuration as safe fallback point"); registerSafeConfiguration(); } }
public List<SaxEvent> recordEvents(InputSource inputSource) throws JoranException { SAXParser saxParser = buildSaxParser(); try { saxParser.parse(inputSource, this); return saxEventList; } catch (IOException ie) { handleError("I/O error occurred while parsing xml file", ie); } catch (SAXException se) { // Exception added into StatusManager via Sax error handling. No need to add it again throw new JoranException("Problem parsing XML document. See previously reported errors.", se); } catch (Exception ex) { handleError("Unexpected exception while parsing XML document.", ex); } throw new IllegalStateException("This point can never be reached"); }