private InputStream genXmlSource()

in src/main/java/org/apache/sling/scripting/xproc/cocoon/generator/SlingGenerator.java [78:99]


	private InputStream genXmlSource() throws Exception {
	
		String xmlPath = request.getResource().getPath() + ".xml";
		
		// The source is a xml file
		Resource xmlResource = this.request.getResourceResolver().resolve(xmlPath);
		InputStream xmlSourceFile = xmlResource.adaptTo(InputStream.class);
		if (xmlSourceFile != null) 
			return xmlSourceFile;
		
		// The source is dynamically generated 
		RequestDispatcher dispatcher = request.getRequestDispatcher(xmlPath);
		SlingGeneratorServletOutputStream output = new SlingGeneratorServletOutputStream();
		ServletResponse newResponse = new SlingGeneratorServletResponse(response, output);
		dispatcher.include(request, newResponse);
		byte[] bytes = output.toByteArray();
		if (bytes.length > 0)
			return new ByteArrayInputStream(bytes);
		
		return null;
		
	}