net.sourceforge.rssowl.util.shop
Class XMLShop

java.lang.Object
  extended by net.sourceforge.rssowl.util.shop.XMLShop

public class XMLShop
extends java.lang.Object

Factory class for XML concerns in RSSOwl

Version:
1.2.4
Author:
Benjamin Pasero

Field Summary
static java.lang.String ALLOW_JAVA_ENCODING
          Feature in Xerces to allow Java Encoding Names
static java.lang.String DOCTYPE_HTML_TRANSITIONAL
          Doctype for the generated HTML
static java.lang.String NULL_DTD
          A DTD URI to use for a non existing DTD
private static java.lang.String[] stripDoubleTags
          Some HTML tags do strip (doubles)
private static java.lang.String[] stripSingleTags
          Some HTML tags do strip (singles)
 
Constructor Summary
private XMLShop()
          This utility class constructor is hidden
 
Method Summary
private static java.lang.String getEncodingFromXML(java.io.InputStreamReader inputReader)
          This Method will read the first line of the given Reader and try to read out the Encoding.
private static java.lang.String getTitleFromFeed(java.io.BufferedReader inputReader)
          Get the title from an InputStream.
static java.lang.String getTitleFromFeed(java.lang.String url, boolean useProxy)
          Try to grab the title from the given feed
private static org.jdom.output.Format getXMLFormat()
          Create a Format to use with the XMLOutputter
static java.io.InputStream getXMLStream(java.lang.String url)
          Method to get the contents of XML as InputStream
static boolean isEncodingSupported(java.lang.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(java.io.InputStream inputStream)
          Check if the file at the given inputstream is a valid "user.xml"
static boolean isValidUserXML(java.lang.String path)
          Check if the file at the given path is a valid "user.xml"
private static java.lang.String parseString(java.lang.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 java.lang.String stripSimpleHTMLTags(java.lang.String text)
          Strip some HTML tags from the given text.
static void writeXML(org.jdom.Document document, java.io.File file)
          Write the document as XML file to the given path
static void writeXML(org.jdom.Document document, java.lang.String filePath)
          Write the document as XML file to the given path
static void writeXML(org.jdom.Document document, java.lang.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 java.lang.String DOCTYPE_HTML_TRANSITIONAL
Doctype for the generated HTML

See Also:
Constant Field Values

NULL_DTD

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

See Also:
Constant Field Values

ALLOW_JAVA_ENCODING

public static final java.lang.String ALLOW_JAVA_ENCODING
Feature in Xerces to allow Java Encoding Names

See Also:
Constant Field Values

stripDoubleTags

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


stripSingleTags

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

Constructor Detail

XMLShop

private XMLShop()
This utility class constructor is hidden

Method Detail

getTitleFromFeed

public static java.lang.String getTitleFromFeed(java.lang.String url,
                                                boolean useProxy)
                                         throws java.io.IOException
Try to grab the title from the given feed

Parameters:
url - Url to the RSS or RDF feed
useProxy - Flag indicating wether a proxy should be used to lookup the title
Returns:
The title from the feed or an empty String
Throws:
java.io.IOException - if an error occurs

getXMLStream

public static java.io.InputStream getXMLStream(java.lang.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(java.lang.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(java.io.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(java.lang.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 java.lang.String stripSimpleHTMLTags(java.lang.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,
                            java.io.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,
                            java.lang.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,
                            java.lang.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 java.lang.String getEncodingFromXML(java.io.InputStreamReader inputReader)
                                            throws java.io.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:
java.io.IOException - In case of an Error.

getTitleFromFeed

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

Parameters:
inputReader - A BufferedReader for the input
Returns:
Title of the file if found
Throws:
java.io.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 java.lang.String parseString(java.lang.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