public void play(List<SaxEvent> aSaxEventList) { eventList = aSaxEventList; SaxEvent se; for(currentIndex = 0; currentIndex < eventList.size(); currentIndex++) { se = eventList.get(currentIndex); if(se instanceof StartEvent) { interpreter.startElement((StartEvent) se); // invoke fireInPlay after startElement processing interpreter.getInterpretationContext().fireInPlay(se); } if(se instanceof BodyEvent) { // invoke fireInPlay before characters processing interpreter.getInterpretationContext().fireInPlay(se); interpreter.characters((BodyEvent) se); } if(se instanceof EndEvent) { // invoke fireInPlay before endElement processing interpreter.getInterpretationContext().fireInPlay(se); interpreter.endElement((EndEvent) se); } } }
private void trimHeadAndTail(SaxEventRecorder recorder) { // Let's remove the two <included> events before // adding the events to the player. List<SaxEvent> saxEventList = recorder.saxEventList; if (saxEventList.size() == 0) { return; } SaxEvent first = saxEventList.get(0); if (first != null && first.qName.equalsIgnoreCase(INCLUDED_TAG)) { saxEventList.remove(0); } SaxEvent last = saxEventList.get(recorder.saxEventList.size() - 1); if (last != null && last.qName.equalsIgnoreCase(INCLUDED_TAG)) { saxEventList.remove(recorder.saxEventList.size() - 1); } }
private void performXMLConfiguration(LoggerContext lc) { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); StatusUtil statusUtil = new StatusUtil(context); List<SaxEvent> eventList = jc.recallSafeConfiguration(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); lc.reset(); long threshold = System.currentTimeMillis(); try { jc.doConfigure(mainConfigurationURL); if (statusUtil.hasXMLParsingErrors(threshold)) { fallbackConfiguration(lc, eventList, mainURL); } } catch (JoranException e) { fallbackConfiguration(lc, eventList, mainURL); } }
private void fallbackConfiguration(LoggerContext lc, List<SaxEvent> eventList, URL mainURL) { JoranConfigurator joranConfigurator = new JoranConfigurator(); joranConfigurator.setContext(context); if (eventList != null) { addWarn("Falling back to previously registered safe configuration."); try { lc.reset(); joranConfigurator.informContextOfURLUsedForConfiguration(context, mainURL); joranConfigurator.doConfigure(eventList); addInfo("Re-registering previous fallback configuration once more as a fallback configuration point"); joranConfigurator.registerSafeConfiguration(); } catch (JoranException e) { addError("Unexpected exception thrown by a configuration considered safe.", e); } } else { addWarn("No previous configuration to fall back on."); } }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { this.depth++; if (this.depth != 1) { return; } ic.pushObject(this); this.acceptsProfile = acceptsProfiles(ic, attributes); this.events = new ArrayList<SaxEvent>(); ic.addInPlayListener(this); }
public void doConfigure(final List<SaxEvent> eventList) throws JoranException { buildInterpreter(); // disallow simultaneous configurations of the same context synchronized (context.getConfigurationLock()) { interpreter.getEventPlayer().play(eventList); } }
public void setThenSaxEventList(List<SaxEvent> thenSaxEventList) { IfState state = stack.firstElement(); if(state.active) { state.thenSaxEventList = thenSaxEventList; } else { throw new IllegalStateException("setThenSaxEventList() invoked on inactive IfAction"); } }
public void setElseSaxEventList(List<SaxEvent> elseSaxEventList) { IfState state = stack.firstElement(); if(state.active) { state.elseSaxEventList = elseSaxEventList; } else { throw new IllegalStateException("setElseSaxEventList() invoked on inactive IfAction"); } }
@Override public void end(InterpretationContext ec, String name) throws ActionException { ec.removeInPlayListener(this); Object o = ec.peekObject(); if(o instanceof FruitShell) { FruitShell fs = (FruitShell) o; FruitFactory fruitFactory = new FruitFactory(); fruitFactory.setEventList(new ArrayList<SaxEvent>(seList)); fs.setFruitFactory(fruitFactory); } }
@Override final public void doConfigure(final List<SaxEvent> eventList) throws JoranException { buildInterpreter(); interpreter.getInterpretationContext().pushObject(ff); EventPlayer player = new EventPlayer(interpreter); player.play(eventList); }
@Override public void inPlay(SaxEvent event) { this.events.add(event); }
/** * Recall the event list previously registered as a safe point. */ public List<SaxEvent> recallSafeConfiguration() { return (List<SaxEvent>) context.getObject(SAFE_JORAN_CONFIGURATION); }
public void addEventsDynamically(List<SaxEvent> eventList, int offset) { this.eventList.addAll(currentIndex+offset, eventList); }
void fireInPlay(SaxEvent event) { for (InPlayListener ipl : listenerList) { ipl.inPlay(event); } }
@Override void registerEventList(IfAction ifAction, List<SaxEvent> eventList) { ifAction.setThenSaxEventList(eventList); }
@Override public void end(InterpretationContext ic, String name) throws ActionException { IfState state = stack.pop(); if(!state.active) { return; } Object o = ic.peekObject(); if (o == null) { throw new IllegalStateException("Unexpected null object on stack"); } if (!(o instanceof IfAction)) { throw new IllegalStateException("Unexpected object of type [" + o.getClass() + "] on stack"); } if (o != this) { throw new IllegalStateException( "IfAction different then current one on stack"); } ic.popObject(); if (state.boolResult == null) { addError("Failed to determine \"if then else\" result"); return; } Interpreter interpreter = ic.getJoranInterpreter(); List<SaxEvent> listToPlay = state.thenSaxEventList; if (!state.boolResult) { listToPlay = state.elseSaxEventList; } // if boolResult==false & missing else, listToPlay may be null if(listToPlay != null) { // insert past this event interpreter.getEventPlayer().addEventsDynamically(listToPlay, 1); } }
void removeFirstAndLastFromList(List<SaxEvent> eventList) { eventList.remove(0); eventList.remove(eventList.size() - 1); }
public void inPlay(SaxEvent event) { eventList.add(event); }
@Override void registerEventList(IfAction ifAction, List<SaxEvent> eventList) { ifAction.setElseSaxEventList(eventList); }
protected AbstractAppenderFactoryUsingJoran(List<SaxEvent> eventList, String key, Map<String, String> parentPropertyMap) { this.eventList = removeSiftElement(eventList); this.key = key; this.parentPropertyMap = parentPropertyMap; }
List<SaxEvent> removeSiftElement(List<SaxEvent> eventList) { return eventList.subList(1, eventList.size() - 1); }
public List<SaxEvent> getEventList() { return eventList; }
public void doConfigure(final List<SaxEvent> eventList) throws JoranException { super.doConfigure(eventList); }
public void inPlay(SaxEvent event) { seList.add(event); }
public List<SaxEvent> getSeList() { return seList; }
public void setEventList(List<SaxEvent> eventList) { this.eventList = eventList; }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { seList = new ArrayList<SaxEvent>(); ic.addInPlayListener(this); }
AppenderFactoryUsingJoran(List<SaxEvent> eventList, String key, Map<String, String> parentPropertyMap) { super(eventList, key, parentPropertyMap); }
@Override public void inPlay(SaxEvent event) { seList.add(event); }
/** {@inheritDoc} */ @Override public void inPlay(SaxEvent event) { events.add(event); }
/** * Return a copy of the current event list in the player. * @return * @since 0.9.20 */ public List<SaxEvent> getCopyOfPlayerEventList() { return new ArrayList<SaxEvent>(eventList); }