001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.converter.jaxp; 018 019 import java.io.InputStream; 020 import java.io.OutputStream; 021 import java.io.Reader; 022 import java.io.Writer; 023 024 import javax.xml.stream.XMLEventReader; 025 import javax.xml.stream.XMLEventWriter; 026 import javax.xml.stream.XMLInputFactory; 027 import javax.xml.stream.XMLOutputFactory; 028 import javax.xml.stream.XMLStreamException; 029 import javax.xml.stream.XMLStreamReader; 030 import javax.xml.stream.XMLStreamWriter; 031 import javax.xml.transform.Result; 032 import javax.xml.transform.Source; 033 034 import org.apache.camel.Converter; 035 036 /** 037 * A converter of StAX objects 038 * 039 * @version $Revision: 36321 $ 040 */ 041 @Converter 042 public class StaxConverter { 043 private XMLInputFactory inputFactory; 044 private XMLOutputFactory outputFactory; 045 046 @Converter 047 public XMLEventWriter createXMLEventWriter(OutputStream out) throws XMLStreamException { 048 return getOutputFactory().createXMLEventWriter(out); 049 } 050 051 @Converter 052 public XMLEventWriter createXMLEventWriter(Writer writer) throws XMLStreamException { 053 return getOutputFactory().createXMLEventWriter(writer); 054 } 055 056 @Converter 057 public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException { 058 return getOutputFactory().createXMLEventWriter(result); 059 } 060 061 @Converter 062 public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream) throws XMLStreamException { 063 return getOutputFactory().createXMLStreamWriter(outputStream); 064 } 065 066 @Converter 067 public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException { 068 return getOutputFactory().createXMLStreamWriter(writer); 069 } 070 071 @Converter 072 public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException { 073 return getOutputFactory().createXMLStreamWriter(result); 074 } 075 076 @Converter 077 public XMLStreamReader createXMLStreamReader(InputStream in) throws XMLStreamException { 078 return getInputFactory().createXMLStreamReader(in); 079 } 080 081 @Converter 082 public XMLStreamReader createXMLStreamReader(Reader in) throws XMLStreamException { 083 return getInputFactory().createXMLStreamReader(in); 084 } 085 086 @Converter 087 public XMLStreamReader createXMLStreamReader(Source in) throws XMLStreamException { 088 return getInputFactory().createXMLStreamReader(in); 089 } 090 091 @Converter 092 public XMLEventReader createXMLEventReader(InputStream in) throws XMLStreamException { 093 return getInputFactory().createXMLEventReader(in); 094 } 095 096 @Converter 097 public XMLEventReader createXMLEventReader(Reader in) throws XMLStreamException { 098 return getInputFactory().createXMLEventReader(in); 099 } 100 101 @Converter 102 public XMLEventReader createXMLEventReader(XMLStreamReader in) throws XMLStreamException { 103 return getInputFactory().createXMLEventReader(in); 104 } 105 106 @Converter 107 public XMLEventReader createXMLEventReader(Source in) throws XMLStreamException { 108 return getInputFactory().createXMLEventReader(in); 109 } 110 111 // Properties 112 //------------------------------------------------------------------------- 113 114 public XMLInputFactory getInputFactory() { 115 if (inputFactory == null) { 116 inputFactory = XMLInputFactory.newInstance(); 117 } 118 return inputFactory; 119 } 120 121 public void setInputFactory(XMLInputFactory inputFactory) { 122 this.inputFactory = inputFactory; 123 } 124 125 public XMLOutputFactory getOutputFactory() { 126 if (outputFactory == null) { 127 outputFactory = XMLOutputFactory.newInstance(); 128 } 129 return outputFactory; 130 } 131 132 public void setOutputFactory(XMLOutputFactory outputFactory) { 133 this.outputFactory = outputFactory; 134 } 135 }