@SuppressWarnings("RedundantThrows") public void characters(char[] ch, int start, int length) throws SAXException { if(currentTextType != TextType.CDATA) { _characters(ch, start, length); } else { cdataNodeBuilder.append(ch, start, length); } }
public void comment(char[] ch, int start, int length) throws SAXException { currentTextType = TextType.COMMENT; characters(ch, start, length); currentTextType = TextType.TEXT; }
public void cleanup() { if(saxHandler != null) { saxHandler.cleanup(); } } }
} catch(Throwable t) { String errorMsg = "Error in '" + dynamicVisitAfter.getClass().getName() + "' while processing the visitAfter event."; processVisitorException(t, errorMsg); visitAfter(mapping); visitAfter(mapping); if(defaultSerializationOn && applyDefaultSerialization()) { try { defaultSerializer.visitAfter(currentProcessor.element, execContext); flushCurrentWriter();
} catch(Throwable t) { String errorMsg = "Error in '" + mapping.getContentHandler().getClass().getName() + "' while processing the onChildElement event."; processVisitorException(currentProcessor.element, t, mapping, VisitSequence.AFTER, errorMsg); if(defaultSerializationOn && applyDefaultSerialization()) { try { defaultSerializer.onChildElement(currentProcessor.element, childElement, execContext); } catch(Throwable t) { String errorMsg = "Error in '" + dynamicChildVisitor.getClass().getName() + "' while processing the onChildElement event."; processVisitorException(t, errorMsg);
element.setWriter(getWriter()); onChildElement(element); } else { element = new WriterManagedSAXElement(elementQName, startEvent.atts, null); visitBefore(element, elementVisitorConfig);
XMLReader saxReader = getXMLReader(executionContext); saxHandler = new SAXHandler(getExecContext(), writer); saxHandler.detachHandler();
private void processVisitorException(SAXElement element, Throwable error, ContentHandlerConfigMap configMapping, VisitSequence visitSequence, String errorMsg) throws SmooksException { if (eventListener != null) { eventListener.onEvent(new ElementVisitEvent(element, configMapping, visitSequence, error)); } processVisitorException(error, errorMsg); }
private void flushCurrentWriter() { Writer writer = getWriter(); if(writer != null) { try { writer.flush(); } catch (IOException e) { logger.debug("Error flushing writer.", e); } } }
public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException { Smooks smooks = getSmooksInstance(); ExecutionContext nestedExecutionContext = smooks.createExecutionContext(); // In case there's an attached event listener... nestedExecutionContext.setEventListener(executionContext.getEventListener()); // Copy over the XMLReader stack... AbstractParser.setReaders(AbstractParser.getReaders(executionContext), nestedExecutionContext); // Attach the NamespaceDeclarationStack to the nested execution context... NamespaceDeclarationStack nsStack = NamespaceMappings.getNamespaceDeclarationStack(executionContext); NamespaceMappings.setNamespaceDeclarationStack(nsStack, nestedExecutionContext); SmooksContentHandler parentContentHandler = SmooksContentHandler.getHandler(executionContext); if(parentContentHandler.getNestedContentHandler() != null) { throw new SmooksException("Illegal use of more than one nested content handler fired on the same element."); } SmooksContentHandler nestedContentHandler = new SAXHandler(nestedExecutionContext, element.getWriter(this), parentContentHandler); DynamicSAXElementVisitorList.propogateDynamicVisitors(executionContext, nestedExecutionContext); // Attach the XMLReader instance to the nested ExecutionContext and then swap the content handler on // the XMLReader to be the nested handler created here. All events wll be forwarded to the .. XMLReader xmlReader = AbstractParser.getXMLReader(executionContext); AbstractParser.attachXMLReader(xmlReader, nestedExecutionContext); xmlReader.setContentHandler(nestedContentHandler); executionContext.setAttribute(NestedExecutionVisitor.class, nestedExecutionContext); // Note we do not execute the Smooks filterSource methods for a nested instance... we just install // the content handler and redirect the reader events to it... }
} catch(Throwable t) { String errorMsg = "Error in '" + dynamicVisitAfter.getClass().getName() + "' while processing the visitAfter event."; processVisitorException(t, errorMsg); visitAfter(mapping); visitAfter(visitAfterMapping); if(defaultSerializationOn && applyDefaultSerialization()) { try { defaultSerializer.visitAfter(currentProcessor.element, execContext); flushCurrentWriter();
processVisitorException(currentProcessor.element, t, mapping, VisitSequence.AFTER, errorMsg); if(defaultSerializationOn && applyDefaultSerialization()) { try { defaultSerializer.onChildElement(currentProcessor.element, childElement, execContext); } catch(Throwable t) { String errorMsg = "Error in '" + dynamicChildVisitor.getClass().getName() + "' while processing the onChildElement event."; processVisitorException(t, errorMsg);
element.setWriter(getWriter()); onChildElement(element); } else { element = new WriterManagedSAXElement(elementQName, startEvent.atts, null); visitBefore(element, elementVisitorConfig);
XMLReader saxReader = getXMLReader(executionContext); saxHandler = new SAXHandler(getExecContext(), writer); saxHandler.detachHandler();
private void processVisitorException(SAXElement element, Throwable error, ContentHandlerConfigMap configMapping, VisitSequence visitSequence, String errorMsg) throws SmooksException { if (eventListener != null) { eventListener.onEvent(new ElementVisitEvent(element, configMapping, visitSequence, error)); } processVisitorException(error, errorMsg); }
private void flushCurrentWriter() { Writer writer = getWriter(); if(writer != null) { try { writer.flush(); } catch (IOException e) { logger.debug("Error flushing writer.", e); } } }
public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException { Smooks smooks = getSmooksInstance(); ExecutionContext nestedExecutionContext = smooks.createExecutionContext(); // In case there's an attached event listener... nestedExecutionContext.setEventListener(executionContext.getEventListener()); // Copy over the XMLReader stack... AbstractParser.setReaders(AbstractParser.getReaders(executionContext), nestedExecutionContext); // Attach the NamespaceDeclarationStack to the nested execution context... NamespaceDeclarationStack nsStack = NamespaceMappings.getNamespaceDeclarationStack(executionContext); NamespaceMappings.setNamespaceDeclarationStack(nsStack, nestedExecutionContext); SmooksContentHandler parentContentHandler = SmooksContentHandler.getHandler(executionContext); if(parentContentHandler.getNestedContentHandler() != null) { throw new SmooksException("Illegal use of more than one nested content handler fired on the same element."); } SmooksContentHandler nestedContentHandler = new SAXHandler(nestedExecutionContext, element.getWriter(this), parentContentHandler); DynamicSAXElementVisitorList.propogateDynamicVisitors(executionContext, nestedExecutionContext); // Attach the XMLReader instance to the nested ExecutionContext and then swap the content handler on // the XMLReader to be the nested handler created here. All events wll be forwarded to the .. XMLReader xmlReader = AbstractParser.getXMLReader(executionContext); AbstractParser.attachXMLReader(xmlReader, nestedExecutionContext); xmlReader.setContentHandler(nestedContentHandler); executionContext.setAttribute(NestedExecutionVisitor.class, nestedExecutionContext); // Note we do not execute the Smooks filterSource methods for a nested instance... we just install // the content handler and redirect the reader events to it... }
} catch(Throwable t) { String errorMsg = "Error in '" + dynamicVisitAfter.getClass().getName() + "' while processing the visitAfter event."; processVisitorException(t, errorMsg); visitAfter(mapping); visitAfter(visitAfterMapping); if(defaultSerializationOn && applyDefaultSerialization()) { try { defaultSerializer.visitAfter(currentProcessor.element, execContext); flushCurrentWriter();
processVisitorException(currentProcessor.element, t, mapping, VisitSequence.AFTER, errorMsg); if(defaultSerializationOn && applyDefaultSerialization()) { try { defaultSerializer.onChildElement(currentProcessor.element, childElement, execContext); } catch(Throwable t) { String errorMsg = "Error in '" + dynamicChildVisitor.getClass().getName() + "' while processing the onChildElement event."; processVisitorException(t, errorMsg);
element.setWriter(getWriter()); onChildElement(element); } else { element = new WriterManagedSAXElement(elementQName, startEvent.atts, null); visitBefore(element, elementVisitorConfig);