+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2004 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ Project\r
-//\r
-// PullParserUtil.java\r
-// Since: 2005/01/11\r
-//\r
-// $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/util/xml/pullparser/PullParserUtil.java $ \r
-// $Author: leo $\r
-//--------------------------------------\r
-package org.xerial.util.xml.pullparser;\r
-\r
-import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;\r
-import static org.xmlpull.v1.XmlPullParser.START_TAG;\r
-\r
-import java.io.IOException;\r
-import java.io.Reader;\r
-\r
-import org.xerial.core.XerialError;\r
-import org.xerial.util.xml.XMLErrorCode;\r
-import org.xerial.util.xml.XMLException;\r
-import org.xmlpull.v1.XmlPullParser;\r
-import org.xmlpull.v1.XmlPullParserException;\r
-import org.xmlpull.v1.XmlPullParserFactory;\r
-\r
-/**\r
- * Utilities for XML pull parser\r
- * \r
- * @author leo\r
- * \r
- */\r
-public class PullParserUtil\r
-{\r
-\r
- /**\r
- * Parse until the taget tag is found. When this method returns true, the\r
- * pull parser's cursor is on the START_TAG of the target\r
- * \r
- * @param tagName\r
- * the target\r
- * @param pullParser\r
- * pull parser\r
- * @return true when the target tag is found, otherwise false\r
- * @throws IOException\r
- * when failed to read XML data\r
- * \r
- * @throws XMLException\r
- * when parse error is found\r
- */\r
- static public boolean parseUntil(String tagName, XmlPullParser pullParser) throws XMLException, IOException\r
- {\r
- try\r
- {\r
- while (pullParser.next() != END_DOCUMENT)\r
- {\r
- int state = pullParser.getEventType();\r
- if (state == START_TAG)\r
- {\r
- if (tagName.equals(pullParser.getName()))\r
- return true; // found the target tag\r
- }\r
- }\r
- return false;\r
- }\r
- catch (XmlPullParserException e)\r
- {\r
- throw new XMLException(XMLErrorCode.PARSE_ERROR, e);\r
- }\r
- }\r
-\r
- /**\r
- * Generates a XML pull parser\r
- * \r
- * @param xmlReader\r
- * XML reader\r
- * \r
- * @return an instance of the pull parser\r
- * @throws XerialError\r
- * when failed to create XML pull parser\r
- * \r
- */\r
- static public XmlPullParser newParser(Reader xmlReader) \r
- {\r
- XmlPullParser parser;\r
- try\r
- {\r
- parser = XmlPullParserFactory.newInstance().newPullParser();\r
- parser.setInput(xmlReader);\r
- return parser;\r
- }\r
- catch (XmlPullParserException e)\r
- {\r
- throw new XerialError(XMLErrorCode.FAILED_TO_CREATE_XML_PARSER, e);\r
- }\r
- }\r
-\r
-}\r