1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xerces.internal.util; 23 24 import javax.xml.stream.XMLEventReader; 25 import javax.xml.stream.XMLStreamException; 26 import javax.xml.stream.XMLStreamReader; 27 28 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 29 30 /** 31 * <p>An <code>XMLInputSource</code> analogue to <code>javax.xml.transform.stax.StAXSource</code>.</p> 32 * 33 */ 34 public final class StAXInputSource extends XMLInputSource { 35 36 private final XMLStreamReader fStreamReader; 37 private final XMLEventReader fEventReader; 38 private final boolean fConsumeRemainingContent; 39 StAXInputSource(XMLStreamReader source)40 public StAXInputSource(XMLStreamReader source) { 41 this(source, false); 42 } 43 StAXInputSource(XMLStreamReader source, boolean consumeRemainingContent)44 public StAXInputSource(XMLStreamReader source, boolean consumeRemainingContent) { 45 super(null, source.getLocation().getSystemId(), null, false); 46 if (source == null) { 47 throw new IllegalArgumentException("XMLStreamReader parameter cannot be null."); 48 } 49 fStreamReader = source; 50 fEventReader = null; 51 fConsumeRemainingContent = consumeRemainingContent; 52 } 53 StAXInputSource(XMLEventReader source)54 public StAXInputSource(XMLEventReader source) { 55 this(source, false); 56 } 57 StAXInputSource(XMLEventReader source, boolean consumeRemainingContent)58 public StAXInputSource(XMLEventReader source, boolean consumeRemainingContent) { 59 super(null, getEventReaderSystemId(source), null, false); 60 if (source == null) { 61 throw new IllegalArgumentException("XMLEventReader parameter cannot be null."); 62 } 63 fStreamReader = null; 64 fEventReader = source; 65 fConsumeRemainingContent = consumeRemainingContent; 66 } 67 getXMLStreamReader()68 public XMLStreamReader getXMLStreamReader() { 69 return fStreamReader; 70 } 71 getXMLEventReader()72 public XMLEventReader getXMLEventReader() { 73 return fEventReader; 74 } 75 shouldConsumeRemainingContent()76 public boolean shouldConsumeRemainingContent() { 77 return fConsumeRemainingContent; 78 } 79 setSystemId(String systemId)80 public void setSystemId(String systemId){ 81 throw new UnsupportedOperationException("Cannot set the system ID on a StAXInputSource"); 82 } 83 getEventReaderSystemId(XMLEventReader reader)84 private static String getEventReaderSystemId(XMLEventReader reader) { 85 try { 86 if (reader != null) { 87 return reader.peek().getLocation().getSystemId(); 88 } 89 } 90 catch (XMLStreamException e) {} 91 return null; 92 } 93 94 } // StAXInputSource 95