net.sourceforge.rssowl.util.shop
Class XMLShop

java.lang.Object
  extended bynet.sourceforge.rssowl.util.shop.XMLShop

public class XMLShop
extends Object

Factory class for XML concerns in RSSOwl

Version:
1.1.3
Author:
Benjamin Pasero

Field Summary
static String DOCTYPE_HTML_TRANSITIONAL
          Doctype for the generated HTML
static String NULL_DTD
          A DTD URI to use for a non existing DTD
private static String[] stripDoubleTags
          Some HTML tags do strip (doubles)
private static String[] stripSingleTags
          Some HTML tags do strip (singles)
 
Constructor Summary
private XMLShop()
          This utility class constructor is hidden
 
Method Summary
private static String getEncodingFromXML(InputStreamReader inputReader)
          This Method will read the first line of the given Reader and try to read out the Encoding.
private static String getTitleFromFeed(BufferedReader inputReader)
          Get the title from an InputStream.
static String getTitleFromFeed(String url)
          Try to grab the title from the given feed
static org.jdom.Document getXMLDocument(String url)
          Retrieve the parsed XML document from a URL / Path
private static org.jdom.output.Format getXMLFormat()
          Create a Format to use with the XMLOutputter
static InputStream getXMLStream(String url)
          Method to get the contents of XML as InputStream
static boolean isEncodingSupported(String encoding)
          Check if the given Encoding is known to Apache Xerces XML Parser
static boolean isValidUserXML(org.jdom.Document document)
          Check if the given document is a valid "user.xml"
static boolean isValidUserXML(InputStream inputStream)
          Check if the file at the given inputstream is a valid "user.xml"
static boolean isValidUserXML(String path)
          Check if the file at the given path is a valid "user.xml"
private static String parseString(String str)
          Parse a String as XML to have possible entities resolved.
static void setDefaultEntityResolver(org.jdom.input.SAXBuilder builder)
          Ignore the DTD of the XML and set the default DTD "entities.dtd" that provides common entities taken from the HTML 4.01 Spec (W3C).
static String stripSimpleHTMLTags(String text)
          Strip some HTML tags from the given text.
static void writeXML(org.jdom.Document document, File file)
          Write the document as XML file to the given path
static void writeXML(org.jdom.Document document, String filePath)
          Write the document as XML file to the given path
static void writeXML(org.jdom.Document document, String filePath, boolean deleteOnExit)
          Write the document as XML file to the given path
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOCTYPE_HTML_TRANSITIONAL

public static final String DOCTYPE_HTML_TRANSITIONAL
Doctype for the generated HTML

See Also:
Constant Field Values

NULL_DTD

public static final String NULL_DTD
A DTD URI to use for a non existing DTD

See Also:
Constant Field Values

stripDoubleTags

private static String[] stripDoubleTags
Some HTML tags do strip (doubles)


stripSingleTags

private static String[] stripSingleTags
Some HTML tags do strip (singles)

Constructor Detail

XMLShop

private XMLShop()
This utility class constructor is hidden

Method Detail

getTitleFromFeed

public static String getTitleFromFeed(String url)
                               throws IOException
Try to grab the title from the given feed

Parameters:
url - Url to the RSS or RDF feed
Returns:
The title from the feed or an empty String
Throws:
IOException - if an error occurs

getXMLDocument

public static org.jdom.Document getXMLDocument(String url)
                                        throws org.jdom.JDOMException,
                                               IOException,
                                               NewsfeedFactoryException,
                                               IllegalArgumentException
Retrieve the parsed XML document from a URL / Path

Parameters:
url - The URL / Path to the XML
Returns:
document The parsed XML document
Throws:
org.jdom.JDOMException - If an error occurs
IOException - If an error occurs
NewsfeedFactoryException - If an error occurs
IllegalArgumentException - If an error occurs

getXMLStream

public static InputStream getXMLStream(String url)
Method to get the contents of XML as InputStream

Parameters:
url - Url / Path to the XML
Returns:
InputStream of the xml

isEncodingSupported

public static boolean isEncodingSupported(String encoding)
Check if the given Encoding is known to Apache Xerces XML Parser

Parameters:
encoding - The encoding name as String
Returns:
boolean TRUE in case the encoding is supported

isValidUserXML

public static boolean isValidUserXML(org.jdom.Document document)
Check if the given document is a valid "user.xml"

Parameters:
document - The document to check for valid user xml
Returns:
TRUE if document is valid

isValidUserXML

public static boolean isValidUserXML(InputStream inputStream)
Check if the file at the given inputstream is a valid "user.xml"

Parameters:
inputStream - InputStream holding the contents of the XML
Returns:
TRUE if file is valid

isValidUserXML

public static boolean isValidUserXML(String path)
Check if the file at the given path is a valid "user.xml"

Parameters:
path - Path to the import file
Returns:
TRUE if file is valid

setDefaultEntityResolver

public static void setDefaultEntityResolver(org.jdom.input.SAXBuilder builder)
Ignore the DTD of the XML and set the default DTD "entities.dtd" that provides common entities taken from the HTML 4.01 Spec (W3C).

Parameters:
builder - The builder to set the default Entityresolver

stripSimpleHTMLTags

public static String stripSimpleHTMLTags(String text)
Strip some HTML tags from the given text.

Parameters:
text - The text to strip the HTML tags from
Returns:
String HTML stripped text

writeXML

public static void writeXML(org.jdom.Document document,
                            File file)
Write the document as XML file to the given path

Parameters:
document - The XML Document
file - The file where to write the XML contents

writeXML

public static void writeXML(org.jdom.Document document,
                            String filePath)
Write the document as XML file to the given path

Parameters:
document - The XML Document
filePath - The file where to write the XML contents

writeXML

public static void writeXML(org.jdom.Document document,
                            String filePath,
                            boolean deleteOnExit)
Write the document as XML file to the given path

Parameters:
document - The XML Document
filePath - The file where to write the XML contents
deleteOnExit - If TRUE, delete the XML on exit

getEncodingFromXML

private static String getEncodingFromXML(InputStreamReader inputReader)
                                  throws IOException
This Method will read the first line of the given Reader and try to read out the Encoding. A very typical first line of most XML Documents is for example:

Parameters:
inputReader - The Reader that should have a XML as content.
Returns:
String Either the found Encoding or NULL.
Throws:
IOException - In case of an Error.

getTitleFromFeed

private static String getTitleFromFeed(BufferedReader inputReader)
                                throws IOException
Get the title from an InputStream.

Parameters:
inputReader - A BufferedReader for the input
Returns:
Title of the file if found
Throws:
IOException - if an error occurs

getXMLFormat

private static org.jdom.output.Format getXMLFormat()
Create a Format to use with the XMLOutputter

Returns:
Format The format to use with XMLOutputter

parseString

private static String parseString(String str)
Parse a String as XML to have possible entities resolved.

Parameters:
str - The String to parse
Returns:
The parsed String


RSSOwl - RSS / RDF / Atom Newsreader

SourceForge.net Logo