Package org.jivesoftware.util
Class SAXReaderUtil
- java.lang.Object
-
- org.jivesoftware.util.SAXReaderUtil
-
public final class SAXReaderUtil extends Object
A utility class that provides a level of abstraction around the creation of a SAXReader instance suitable for XMPP parsing, as well as maintaining a set of readers ready, available for (bulk) processing.- Author:
- Guus der Kinderen, guus.der.kinderen@gmail.com
-
-
Field Summary
Fields Modifier and Type Field Description static SystemProperty<Integer>
PARSER_SERVICE_CORE_POOL_SIZE
The number of threads to keep in the SAX Reader pool, even if they are idle.static SystemProperty<Duration>
PARSER_SERVICE_KEEP_ALIVE_TIME
When the number of threads in the SAX reader pool is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.static SystemProperty<Integer>
PARSER_SERVICE_MAX_POOL_SIZE
The maximum number of threads to allow in the SAX Reader pool.
-
Constructor Summary
Constructors Constructor Description SAXReaderUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.dom4j.Document
readDocument(File file)
Parses an XML Document from the content provided by a file.static org.dom4j.Document
readDocument(InputStream stream)
Parses an XML Document from the content provided by an input stream.static org.dom4j.Document
readDocument(Reader reader)
Parses an XML Document from the content provided by a reader.static org.dom4j.Document
readDocument(String text)
Parses an XML Document from the provided text.static Future<org.dom4j.Document>
readDocumentAsync(File file)
Schedules parsing of content of afile into an XML Document as an asynchronous process.static Future<org.dom4j.Document>
readDocumentAsync(InputStream stream)
Schedules parsing of the provided input stream into an XML Document as an asynchronous process.static Future<org.dom4j.Document>
readDocumentAsync(Reader reader)
Schedules parsing of the provided reader into an XML Document as an asynchronous process.static Future<org.dom4j.Document>
readDocumentAsync(String text)
Schedules parsing of the provided text into an XML Document as an asynchronous process.static org.dom4j.Element
readRootElement(File file)
Parses an XML Document from the content provided by a file and returns the root element of the document.static org.dom4j.Element
readRootElement(InputStream stream)
Parses an XML Document from the content provided by an input stream and returns the root element of the document.static org.dom4j.Element
readRootElement(Reader reader)
Parses an XML Document from the content provided by a reader and returns the root element of the document.static org.dom4j.Element
readRootElement(String text)
Parses an XML Document from the provided text and returns the root element of the document.
-
-
-
Field Detail
-
PARSER_SERVICE_CORE_POOL_SIZE
public static final SystemProperty<Integer> PARSER_SERVICE_CORE_POOL_SIZE
The number of threads to keep in the SAX Reader pool, even if they are idle.
-
PARSER_SERVICE_MAX_POOL_SIZE
public static final SystemProperty<Integer> PARSER_SERVICE_MAX_POOL_SIZE
The maximum number of threads to allow in the SAX Reader pool.
-
PARSER_SERVICE_KEEP_ALIVE_TIME
public static final SystemProperty<Duration> PARSER_SERVICE_KEEP_ALIVE_TIME
When the number of threads in the SAX reader pool is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.
-
-
Method Detail
-
readDocumentAsync
public static Future<org.dom4j.Document> readDocumentAsync(@Nonnull InputStream stream)
Schedules parsing of the provided input stream into an XML Document as an asynchronous process. This method returns aFuture
object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.- Parameters:
stream
- The data to be parsed as an XML Document.- Returns:
- A Future representing pending completion of parsing the provided data as an XML Document.
-
readDocument
public static org.dom4j.Document readDocument(@Nonnull InputStream stream) throws ExecutionException, InterruptedException
Parses an XML Document from the content provided by an input stream. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented inreadDocumentAsync(InputStream)
. When a parser is not immediately available, this method will block until one becomes available.- Parameters:
stream
- The data to be parsed as an XML Document.- Returns:
- an XML Document.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
readRootElement
public static org.dom4j.Element readRootElement(@Nonnull InputStream stream) throws ExecutionException, InterruptedException
Parses an XML Document from the content provided by an input stream and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()- Parameters:
stream
- The data to be parsed as an XML Document.- Returns:
- an XML Document root element.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
readDocumentAsync
public static Future<org.dom4j.Document> readDocumentAsync(@Nonnull String text)
Schedules parsing of the provided text into an XML Document as an asynchronous process. This method returns aFuture
object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.- Parameters:
text
- The data to be parsed as an XML Document.- Returns:
- A Future representing pending completion of parsing the provided data as an XML Document.
-
readDocument
public static org.dom4j.Document readDocument(@Nonnull String text) throws ExecutionException, InterruptedException
Parses an XML Document from the provided text. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented inreadDocumentAsync(String)
. When a parser is not immediately available, this method will block until one becomes available.- Parameters:
text
- The data to be parsed as an XML Document.- Returns:
- an XML Document.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
readRootElement
public static org.dom4j.Element readRootElement(@Nonnull String text) throws ExecutionException, InterruptedException
Parses an XML Document from the provided text and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()- Parameters:
text
- The data to be parsed as an XML Document.- Returns:
- an XML Document root element.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
readDocumentAsync
public static Future<org.dom4j.Document> readDocumentAsync(@Nonnull Reader reader)
Schedules parsing of the provided reader into an XML Document as an asynchronous process. This method returns aFuture
object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.- Parameters:
reader
- The data to be parsed as an XML Document.- Returns:
- A Future representing pending completion of parsing the provided data as an XML Document.
-
readDocument
public static org.dom4j.Document readDocument(@Nonnull Reader reader) throws ExecutionException, InterruptedException
Parses an XML Document from the content provided by a reader. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented inreadDocumentAsync(Reader)
. When a parser is not immediately available, this method will block until one becomes available.- Parameters:
reader
- The data to be parsed as an XML Document.- Returns:
- an XML Document.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
readRootElement
public static org.dom4j.Element readRootElement(@Nonnull Reader reader) throws ExecutionException, InterruptedException
Parses an XML Document from the content provided by a reader and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()- Parameters:
reader
- The data to be parsed as an XML Document.- Returns:
- an XML Document root element.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
readDocumentAsync
public static Future<org.dom4j.Document> readDocumentAsync(@Nonnull File file)
Schedules parsing of content of afile into an XML Document as an asynchronous process. This method returns aFuture
object that can be used to obtain the result of the asynchronous process. The XML parsing is delegated to a limited set of parsers, that is fronted by an Executor Service. The amount of parsers that are available is equal to the amount of threads available in the Executor Service. This can be optimized by using the SystemProperties in this class.- Parameters:
file
- The data to be parsed as an XML Document.- Returns:
- A Future representing pending completion of parsing the provided data as an XML Document.
-
readDocument
public static org.dom4j.Document readDocument(@Nonnull File file) throws ExecutionException, InterruptedException
Parses an XML Document from the content provided by a file. Equivalent to calling readDocumentAsync(input).get() The XML parsing is delegated to a limited set of parsers, as documented inreadDocumentAsync(File)
. When a parser is not immediately available, this method will block until one becomes available.- Parameters:
file
- The data to be parsed as an XML Document.- Returns:
- an XML Document.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
readRootElement
public static org.dom4j.Element readRootElement(@Nonnull File file) throws ExecutionException, InterruptedException
Parses an XML Document from the content provided by a file and returns the root element of the document. Equivalent to calling readDocument(input).getRootElement()- Parameters:
file
- The data to be parsed as an XML Document.- Returns:
- an XML Document root element.
- Throws:
ExecutionException
- on any error that occurs during parsing (this typically has aDocumentException
as its cause).InterruptedException
- when the task that is scheduled to perform the parsing gets interrupted during the execution of the task.
-
-