private List<SaxEvent> removeIncludeEvents(List<SaxEvent> unsanitizedEventList) { List<SaxEvent> sanitizedEvents = new ArrayList<SaxEvent>(); if (unsanitizedEventList == null) return sanitizedEvents; for (SaxEvent e : unsanitizedEventList) { if (!"include".equalsIgnoreCase(e.getLocalName())) sanitizedEvents.add(e); } return sanitizedEvents; }
private void parseAndRecord(InputStream inputSource, SaxEventRecorder recorder) throws JoranException { recorder.setContext(context); recorder.recordEvents(inputSource); }
void fireInPlay(SaxEvent event) { for (InPlayListener ipl : listenerList) { ipl.inPlay(event); } } }
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())); }
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 endElement(String namespaceURI, String localName, String qName) { saxEventList .add(new EndEvent(namespaceURI, localName, qName, getLocator())); globalElementPath.pop(); }
public void error(SAXParseException spe) throws SAXException { addError(XML_PARSING +" - Parsing error on line " + spe.getLineNumber() + " and column " + spe.getColumnNumber(), spe); }
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"); }
@Override public String toString() { return "BodyEvent(" + getText() + ")" + locator.getLineNumber() + "," + locator.getColumnNumber(); }
final public void recordEvents(InputStream inputStream) throws JoranException { recordEvents(new InputSource(inputStream)); }
@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); } }
@Override public String toString() { return " EndEvent("+getQName()+") ["+locator.getLineNumber()+","+locator.getColumnNumber()+"]"; }
public void warning(SAXParseException spe) throws SAXException { addWarn(XML_PARSING +" - Parsing warning on line " + spe.getLineNumber() + " and column " + spe.getColumnNumber(), spe); }
@Override public String toString() { return "StartEvent("+getQName()+") ["+locator.getLineNumber()+","+locator.getColumnNumber()+"]"; }
public void startElement(StartEvent se) { setDocumentLocator(se.getLocator()); startElement(se.namespaceURI, se.localName, se.qName, se.attributes); }
public void fatalError(SAXParseException spe) throws SAXException { addError(XML_PARSING +" - Parsing fatal error on line " + spe.getLineNumber() + " and column " + spe.getColumnNumber(), spe); }
public void characters(BodyEvent be) { setDocumentLocator(be.locator); String body = be.getText(); List<Action> applicableActionList = actionListStack.peek(); if (body != null) { body = body.trim(); if (body.length() > 0) { // System.out.println("calling body method with ["+body+ "]"); callBodyAction(applicableActionList, body); } } }
private void handleError(String errMsg, Throwable t) throws JoranException { addError(errMsg, t); throw new JoranException(errMsg, t); }
private SAXParser buildSaxParser() throws JoranException { try { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating(false); spf.setNamespaceAware(true); return spf.newSAXParser(); } catch (Exception pce) { String errMsg = "Parser configuration error occurred"; addError(errMsg, pce); throw new JoranException(errMsg, pce); } }