Package com.itextpdf.tool.xml.net
Class FileRetrieveImpl
- java.lang.Object
-
- com.itextpdf.tool.xml.net.FileRetrieveImpl
-
- All Implemented Interfaces:
FileRetrieve
public class FileRetrieveImpl extends java.lang.Object implements FileRetrieve
-
-
Constructor Summary
Constructors Constructor Description FileRetrieveImpl()
FileRetrieveImpl(java.io.File rootdir)
Constructs a new FileRetrieveImpl with the given root url's and directoriesFileRetrieveImpl(java.lang.String... strings)
Constructs a new FileRetrieveImpl with the given root url's and directories
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRootDir(java.io.File dir)
Add a root directory.void
addURL(java.lang.String url)
Add a root URL.private java.net.URL
detectWithRootUrls(java.lang.String href)
void
processFromHref(java.lang.String href, ReadingProcessor processor)
ProcessFromHref first tries to create anURL
from the givenhref
, if that throws aMalformedURLException
, it will prepend the given root URLs tohref
until a valid URL is found.
If by then there is no valid url found, this method will see if the givenhref
is a valid file and can read it.
If it's not a valid file or a file that can't be read, the given root directories will be set as root path with the givenhref
as file path until a valid file has been found.void
processFromStream(java.io.InputStream in, ReadingProcessor processor)
Process content from a given stream.private void
read(ReadingProcessor processor, java.io.InputStream in)
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
-
rootdirs
private final java.util.List<java.io.File> rootdirs
-
urls
private final java.util.List<java.lang.String> urls
-
-
Constructor Detail
-
FileRetrieveImpl
public FileRetrieveImpl()
-
FileRetrieveImpl
public FileRetrieveImpl(java.lang.String... strings)
Constructs a new FileRetrieveImpl with the given root url's and directories- Parameters:
strings
- an array of strings, if the String starts with http or https it's taken as URL otherwise we check if it's a directory withFile f = new File(str); f.isDirectory()
-
FileRetrieveImpl
public FileRetrieveImpl(java.io.File rootdir)
Constructs a new FileRetrieveImpl with the given root url's and directories- Parameters:
strings
- an array of strings, if the String starts with http or https it's taken as URL otherwise we check if it's a directory withFile f = new File(str); f.isDirectory()
-
-
Method Detail
-
processFromHref
public void processFromHref(java.lang.String href, ReadingProcessor processor) throws java.io.IOException
ProcessFromHref first tries to create anURL
from the givenhref
, if that throws aMalformedURLException
, it will prepend the given root URLs tohref
until a valid URL is found.
If by then there is no valid url found, this method will see if the givenhref
is a valid file and can read it.
If it's not a valid file or a file that can't be read, the given root directories will be set as root path with the givenhref
as file path until a valid file has been found.- Specified by:
processFromHref
in interfaceFileRetrieve
- Parameters:
href
- the URL to processprocessor
- the ReadingProcessor- Throws:
java.io.IOException
- if something went wrong.
-
detectWithRootUrls
private java.net.URL detectWithRootUrls(java.lang.String href) throws java.net.MalformedURLException
- Parameters:
href
- the reference- Throws:
java.net.MalformedURLException
- if no valid URL could be found.
-
processFromStream
public void processFromStream(java.io.InputStream in, ReadingProcessor processor) throws java.io.IOException
Description copied from interface:FileRetrieve
Process content from a given stream.- Specified by:
processFromStream
in interfaceFileRetrieve
- Parameters:
in
- the stream to processprocessor
- the ReadingProcessor- Throws:
java.io.IOException
- if something went wrong.
-
read
private void read(ReadingProcessor processor, java.io.InputStream in) throws java.io.IOException
- Parameters:
processor
-in
-- Throws:
java.io.IOException
-
addRootDir
public void addRootDir(java.io.File dir)
Add a root directory.- Parameters:
dir
- the root directory
-
addURL
public void addURL(java.lang.String url)
Add a root URL.- Parameters:
url
- the URL
-
-