1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package org.apache.openoffice.ooxml.parser.attribute; 23 24 import java.util.Iterator; 25 26 import javax.xml.stream.XMLStreamReader; 27 28 /** Give access to the attributes that are read from an OOXML stream. 29 */ 30 public class AttributeProvider 31 implements Iterable<String[]> 32 { AttributeProvider(final XMLStreamReader aReader)33 public AttributeProvider (final XMLStreamReader aReader) 34 { 35 maReader = aReader; 36 } 37 38 39 HasAttributes()40 public boolean HasAttributes () 41 { 42 return maReader.getAttributeCount() > 0; 43 } 44 45 46 47 GetValue(final String sKey)48 public String GetValue (final String sKey) 49 { 50 return maReader.getAttributeValue(null, sKey); 51 } 52 53 54 55 @Override iterator()56 public Iterator<String[]> iterator () 57 { 58 return new Iterator<String[]> () 59 { 60 int nIndex = 0; 61 final int nCount = maReader.getAttributeCount(); 62 63 @Override public boolean hasNext() 64 { 65 return nIndex < nCount; 66 } 67 68 @Override public String[] next() 69 { 70 final String[] aResult = new String[] 71 { 72 maReader.getAttributeNamespace(nIndex), 73 maReader.getAttributeLocalName(nIndex), 74 maReader.getAttributeValue(nIndex) 75 }; 76 ++nIndex; 77 return aResult; 78 } 79 80 @Override public void remove() 81 { 82 } 83 84 }; 85 } 86 87 88 89 GetAttributeCount()90 public Integer GetAttributeCount () 91 { 92 return maReader.getAttributeCount(); 93 } 94 95 96 97 98 private final XMLStreamReader maReader; 99 } 100