The Source implementation is easy. The Result implementation is a bit more difficult to abstract given that it requires knowledge of the builder/factory that needs to be used. Since Abdera uses a custom parser/builder/factory, it would likely need to continue using an Abdera specific result impl.
That said, however, here is the code necessary to provide an OMSource impl: Source xsltsource = new OMSource(omelement); Source xmlsource = new OMSource(omdocument); StreamResult result = new StreamResult(System.out); Transformer transformer = factory.newTransformer(xsltsource); transformer.transform(xmlsource, result); - James ------------- /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. The ASF licenses this file to You * under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. For additional information regarding * copyright in this work, please see the NOTICE file in the top level * directory of this distribution. */ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.Reader; import javax.xml.stream.XMLStreamException; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import org.apache.axiom.om.OMContainer; import org.apache.axiom.om.OMDocument; import org.apache.axiom.om.OMElement; public class OMSource extends StreamSource implements Source { private OMContainer container; public OMSource(OMContainer container) { this.container = container; } public InputStream getInputStream() { if (container == null) return null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (container instanceof OMDocument) ((OMDocument)container).serialize(out); else if (container instanceof OMElement) ((OMElement)container).serialize(out); return new ByteArrayInputStream(out.toByteArray()); } catch (XMLStreamException e) { throw new RuntimeException(e); } } public Reader getReader() { return null; } public void setInputStream(InputStream in) { throw new UnsupportedOperationException(); } public void setReader(Reader reader) { throw new UnsupportedOperationException(); } } - James Davanum Srinivas wrote: > James, > > could we move that extracted code to Axiom? would be great addition! > > -- dims > > On 9/15/06, James M Snell <[EMAIL PROTECTED]> wrote: >> For Apache Abdera (which uses Axiom), I've created Source and Result >> implementations that work with Axiom. See http://tinyurl.com/rkcby to >> see it in action. It would not take much to port the code over so that >> it works with nothing but Axiom. >> >> - James >> >> Mohammad N Fakhar wrote: >> > Hi, i am trying to perform XSLT transformations on SOAP OM elements in >> > axis2 and am wondering what the best way is to accomplish. >> > I can this of two ways: >> > >> > 1) Use staxsource interface like so: >> > >> > OMStAXWrapper wrapper = new >> > OMStAXWrapper(someOMElement.getBuilder(), someOMElement); >> > Source source = new StAXSource(wrapper); >> > >> > xslttransformer.transform(source, someresult); >> > >> > 2) Convert om element to a string and then use a StringReader >> > >> > StringReader reader = new StringReader( >> > someOMElement.toString()); >> > xslttransformer.transform(new StreamSource(reader), >> > someresult); >> > >> > >> > Method 1) has a dependency on jaxp 1.4/jdk 6 which is in beta and I >> don't >> > want to have that dependency. >> > Is there any other obvious, easier way to transform axiom elements with >> > XSLT that you guys know of? >> > >> > thanks, >> > >> > >> > mohammad >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
