1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.xml;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  
19  import javax.xml.stream.XMLEventReader;
20  import javax.xml.stream.XMLInputFactory;
21  import javax.xml.stream.XMLStreamException;
22  import javax.xml.stream.events.XMLEvent;
23  
24  /**
25   * <a href="StAXReaderUtil.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Shuyang Zhou
28   * @author Brian Wing Shun Chan
29   */
30  public class StAXReaderUtil {
31  
32      public static XMLInputFactory getXMLInputFactory() {
33          return _xmlInputFactory;
34      }
35  
36      public static String read(XMLEventReader xmlEventReader)
37          throws XMLStreamException {
38  
39          XMLEvent xmlEvent = xmlEventReader.peek();
40  
41          if (xmlEvent.isCharacters()) {
42              xmlEvent = xmlEventReader.nextEvent();
43  
44              return xmlEvent.asCharacters().getData();
45          }
46          else {
47              return StringPool.BLANK;
48          }
49      }
50  
51      private static XMLInputFactory _xmlInputFactory =
52          XMLInputFactory.newInstance();
53  
54  }