public Document popCreator(ExecutionContext executionContext) { Stack<DOMCreator> domCreatorStack = (Stack<DOMCreator>) executionContext.getAttribute(DOMCreator.class); if(domCreatorStack == null) { throw new IllegalStateException("No DOM Creator Stack available."); } else { try { // Remove the current DOMCreators from the dynamic visitor list... if(!domCreatorStack.isEmpty()) { DOMCreator removedCreator = domCreatorStack.pop(); DynamicSAXElementVisitorList.removeDynamicVisitor(removedCreator, executionContext); return removedCreator.document; } else { return null; } } finally { // Reinstate parent DOMCreators in the dynamic visitor list... if(!domCreatorStack.isEmpty()) { DynamicSAXElementVisitorList.addDynamicVisitor(domCreatorStack.peek(), executionContext); } } } }
public static void propogateDynamicVisitors(ExecutionContext parentExecutionContext, ExecutionContext childExecutionContext) { DynamicSAXElementVisitorList parentList = getList(parentExecutionContext); if(parentList != null) { DynamicSAXElementVisitorList childList = getList(childExecutionContext); if(childList == null) { childList = new DynamicSAXElementVisitorList(childExecutionContext); } childList.visitBefores.addAll(parentList.visitBefores); childList.childVisitors.addAll(parentList.childVisitors); childList.visitAfters.addAll(parentList.visitAfters); } }
public static void addDynamicVisitor(SAXVisitor visitor, ExecutionContext executionContext) { SmooksContentHandler contentHandler = SmooksContentHandler.getHandler(executionContext); SmooksContentHandler nestedContentHandler = contentHandler.getNestedContentHandler(); if(nestedContentHandler == null) { DynamicSAXElementVisitorList list = getList(executionContext); if(visitor instanceof SAXVisitBefore) { list.visitBefores.add((SAXVisitBefore) visitor); } if(visitor instanceof SAXVisitChildren) { list.childVisitors.add((SAXVisitChildren) visitor); } if(visitor instanceof SAXVisitAfter) { list.visitAfters.add((SAXVisitAfter) visitor); } } else { addDynamicVisitor(visitor, nestedContentHandler.getExecutionContext()); } }
List<SAXVisitChildren> dynamicChildVisitors = dynamicVisitorList.getChildVisitors(); if(!dynamicChildVisitors.isEmpty()) { for (SAXVisitChildren dynamicChildVisitor : dynamicChildVisitors) {
public static void removeDynamicVisitor(SAXVisitor visitor, ExecutionContext executionContext) { DynamicSAXElementVisitorList list = getList(executionContext); list.visitBefores.remove(visitor); list.childVisitors.remove(visitor); list.visitAfters.remove(visitor); } }
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... }
List<SAXVisitBefore> dynamicVisitBefores = dynamicVisitorList.getVisitBefores(); if(!dynamicVisitBefores.isEmpty()) { for (SAXVisitBefore dynamicVisitBefore : dynamicVisitBefores) {
List<SAXVisitAfter> dynamicVisitAfters = dynamicVisitorList.getVisitAfters(); if(!dynamicVisitAfters.isEmpty()) { for (SAXVisitAfter dynamicVisitAfter : dynamicVisitAfters) {
@SuppressWarnings("unchecked") public void visitAfter(SAXElement saxElement, ExecutionContext executionContext) throws SmooksException, IOException { Map<String, SAXSerializer> fragmentSerializers = (Map<String, SAXSerializer>) executionContext.getAttribute(FragmentSerializer.class); SAXSerializer serializer = fragmentSerializers.get(bindTo); try { executionContext.getBeanContext().addBean(bindTo, serializer.fragmentWriter.toString().trim(), new Fragment(saxElement)); } finally { DynamicSAXElementVisitorList.removeDynamicVisitor(serializer, executionContext); } }
@SuppressWarnings("unchecked") public void visitBefore(SAXElement saxElement, ExecutionContext executionContext) throws SmooksException, IOException { Map<String, SAXSerializer> fragmentSerializers = (Map<String, SAXSerializer>) executionContext.getAttribute(FragmentSerializer.class); if(fragmentSerializers == null) { fragmentSerializers = new HashMap<String, SAXSerializer>(); executionContext.setAttribute(FragmentSerializer.class, fragmentSerializers); } SAXSerializer serializer = new SAXSerializer(); fragmentSerializers.put(bindTo, serializer); if(!omitXMLDeclaration) { serializer.fragmentWriter.write("<?xml version=\"1.0\"?>\n"); } // Now add a dynamic visitor... DynamicSAXElementVisitorList.addDynamicVisitor(serializer, executionContext); notifyStartBean(new Fragment(saxElement), executionContext); }
public static void addDynamicVisitor(SAXVisitor visitor, ExecutionContext executionContext) { SmooksContentHandler contentHandler = SmooksContentHandler.getHandler(executionContext); SmooksContentHandler nestedContentHandler = contentHandler.getNestedContentHandler(); if(nestedContentHandler == null) { DynamicSAXElementVisitorList list = getList(executionContext); if(visitor instanceof SAXVisitBefore) { list.visitBefores.add((SAXVisitBefore) visitor); } if(visitor instanceof SAXVisitChildren) { list.childVisitors.add((SAXVisitChildren) visitor); } if(visitor instanceof SAXVisitAfter) { list.visitAfters.add((SAXVisitAfter) visitor); } } else { addDynamicVisitor(visitor, nestedContentHandler.getExecutionContext()); } }
List<SAXVisitChildren> dynamicChildVisitors = dynamicVisitorList.getChildVisitors(); if(!dynamicChildVisitors.isEmpty()) { for (SAXVisitChildren dynamicChildVisitor : dynamicChildVisitors) {
public static void removeDynamicVisitor(SAXVisitor visitor, ExecutionContext executionContext) { DynamicSAXElementVisitorList list = getList(executionContext); list.visitBefores.remove(visitor); list.childVisitors.remove(visitor); list.visitAfters.remove(visitor); } }
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... }
List<SAXVisitBefore> dynamicVisitBefores = dynamicVisitorList.getVisitBefores(); if(!dynamicVisitBefores.isEmpty()) { for (SAXVisitBefore dynamicVisitBefore : dynamicVisitBefores) {
List<SAXVisitAfter> dynamicVisitAfters = dynamicVisitorList.getVisitAfters(); if(!dynamicVisitAfters.isEmpty()) { for (SAXVisitAfter dynamicVisitAfter : dynamicVisitAfters) {
@SuppressWarnings("unchecked") public void visitAfter(SAXElement saxElement, ExecutionContext executionContext) throws SmooksException, IOException { Map<String, SAXSerializer> fragmentSerializers = (Map<String, SAXSerializer>) executionContext.getAttribute(FragmentSerializer.class); SAXSerializer serializer = fragmentSerializers.get(bindTo); try { executionContext.getBeanContext().addBean(bindTo, serializer.fragmentWriter.toString().trim(), new Fragment(saxElement)); } finally { DynamicSAXElementVisitorList.removeDynamicVisitor(serializer, executionContext); } }
@SuppressWarnings("unchecked") public void visitBefore(SAXElement saxElement, ExecutionContext executionContext) throws SmooksException, IOException { Map<String, SAXSerializer> fragmentSerializers = (Map<String, SAXSerializer>) executionContext.getAttribute(FragmentSerializer.class); if(fragmentSerializers == null) { fragmentSerializers = new HashMap<String, SAXSerializer>(); executionContext.setAttribute(FragmentSerializer.class, fragmentSerializers); } SAXSerializer serializer = new SAXSerializer(); fragmentSerializers.put(bindTo, serializer); if(!omitXMLDeclaration) { serializer.fragmentWriter.write("<?xml version=\"1.0\"?>\n"); } // Now add a dynamic visitor... DynamicSAXElementVisitorList.addDynamicVisitor(serializer, executionContext); notifyStartBean(new Fragment(saxElement), executionContext); }
@SuppressWarnings({ "unchecked", "WeakerAccess", "UnusedReturnValue" }) public Document popCreator(ExecutionContext executionContext) { Stack<DOMCreator> domCreatorStack = (Stack<DOMCreator>) executionContext.getAttribute(DOMCreator.class); if(domCreatorStack == null) { throw new IllegalStateException("No DOM Creator Stack available."); } else { try { // Remove the current DOMCreators from the dynamic visitor list... if(!domCreatorStack.isEmpty()) { DOMCreator removedCreator = domCreatorStack.pop(); DynamicSAXElementVisitorList.removeDynamicVisitor(removedCreator, executionContext); return removedCreator.document; } else { return null; } } finally { // Reinstate parent DOMCreators in the dynamic visitor list... if(!domCreatorStack.isEmpty()) { DynamicSAXElementVisitorList.addDynamicVisitor(domCreatorStack.peek(), executionContext); } } } }
public static void propogateDynamicVisitors(ExecutionContext parentExecutionContext, ExecutionContext childExecutionContext) { DynamicSAXElementVisitorList parentList = getList(parentExecutionContext); if(parentList != null) { DynamicSAXElementVisitorList childList = getList(childExecutionContext); if(childList == null) { childList = new DynamicSAXElementVisitorList(childExecutionContext); } childList.visitBefores.addAll(parentList.visitBefores); childList.childVisitors.addAll(parentList.childVisitors); childList.visitAfters.addAll(parentList.visitAfters); } }