|
| 1 | +/* Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | + * you may not use this file except in compliance with the License. |
| 3 | + * You may obtain a copy of the License at |
| 4 | + * |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + */ |
| 13 | +package org.flowable.bpmn.converter; |
| 14 | + |
| 15 | +import javax.xml.stream.XMLStreamException; |
| 16 | +import javax.xml.stream.XMLStreamReader; |
| 17 | +import javax.xml.stream.util.StreamReaderDelegate; |
| 18 | + |
| 19 | +/** |
| 20 | + * @author Filip Hrisafov |
| 21 | + */ |
| 22 | +public class FlowableXMLStreamReader extends StreamReaderDelegate { |
| 23 | + |
| 24 | + public FlowableXMLStreamReader(XMLStreamReader reader) { |
| 25 | + super(reader); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException { |
| 30 | + try { |
| 31 | + return super.getTextCharacters(sourceStart, target, targetStart, length); |
| 32 | + } catch (IndexOutOfBoundsException e) { |
| 33 | + if (length == 0) { |
| 34 | + // The default java stream reader has a bug where an empty CDATA will throw an IndexOutOfBoundsException |
| 35 | + // When the length to copy is 0, then we should not copy anything and just return 0 |
| 36 | + return 0; |
| 37 | + } |
| 38 | + throw e; |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments