// Javadoc inherited. protected int exprElementEnd(MarinerRequestContext context, PAPIAttributes papiAttributes) throws PAPIException { IncludeAttributes attributes = (IncludeAttributes) papiAttributes; if (attributes.getHref() == null) { throw new PAPIException(exceptionLocalizer.format("include-href-missing")); } else { // @todo this is a bit duff since it relies on markup naming not to change; do this a // different way // Set up the markup that will be sent down the pipeline StringBuffer markup = new StringBuffer(); InputSource inputSource; markup.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); markup .append("<urid:fetch xmlns:urid=\"") .append(Namespace.URID.getURI()) .append("\" href=\"") .append(attributes.getHref()) .append("\""); if (attributes.getParse() != null) { markup.append(" parse=\"").append(attributes.getParse()).append("\""); } if (attributes.getEncoding() != null) { markup.append(" encoding=\"").append(attributes.getEncoding()).append("\""); } markup.append("/>"); if (logger.isDebugEnabled()) { logger.debug("Set up inclusion command as: " + markup.toString()); } inputSource = new InputSource(new StringReader(markup.toString())); // Set up and execute the pipeline to perform the required // inclusion MarinerPageContext pageContext = ContextInternals.getMarinerPageContext(context); XMLReader reader = MarlinSAXHelper.getXMLReader(context); reader.setContentHandler(MarlinSAXHelper.getContentHandler(context)); // @todo this is nasty: we assume that the reader is actually an XMLPipelineFilter XMLPipelineFilter filter = (XMLPipelineFilter) reader; XMLPipelineContext pipelineContext = filter.getPipelineContext(); // set the Base URI in the pipeline's context try { URL baseURI = pageContext.getAbsoluteURL(pageContext.getRequestURL(false)); if (logger.isDebugEnabled()) { logger.debug("Setting Base URI " + baseURI); } pipelineContext.pushBaseURI(baseURI.toExternalForm()); } catch (MalformedURLException e) { throw new PAPIException(e); } PipelineIntegrationUtilities.setUpIntegration( filter, pageContext.getCurrentElement(), context, pageContext.getCurrentOutputBuffer()); if (logger.isDebugEnabled()) { logger.debug("Executing inclusion"); } // Execute the inclusion try { reader.parse(inputSource); } catch (IOException e) { throw new PAPIException(e); } catch (SAXException e) { throw new PAPIException(e); } finally { PipelineIntegrationUtilities.tearDownIntegration(filter); } } if (logger.isDebugEnabled()) { logger.debug("Successful execution of inclusion"); } return CONTINUE_PROCESSING; }