Package edu.uiuc.ncsa.security.core.cf
Class CFLoader
- java.lang.Object
-
- edu.uiuc.ncsa.security.core.cf.CFLoader
-
public class CFLoader extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CFLoader.Builder
-
Field Summary
Fields Modifier and Type Field Description static String
ENV_END_ELEMENT
static String
ENV_START_ELEMENT
static String
ENV_TAG
static String
FILE_TAG
static String
INCLUDE_TAG
static String
KEY_TAG
-
Constructor Summary
Constructors Constructor Description CFLoader()
CFLoader(CFLoader.Builder builder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description File
getFile()
InputStream
getInputStream()
String
getResource()
String
getTagName()
protected boolean
hasFile()
protected boolean
hasInputStream()
protected boolean
hasResource()
protected boolean
isEndEnv(String l)
Does the trimmed line end with an environment end tag?protected boolean
isStartEnv(String l)
Does the trimmed line start and environment entry?CFBundle
loadBundle()
Used with the builder.CFBundle
loadBundle(File file, String tagName)
Loads the specified file.CFBundle
loadBundle(InputStream inputStream, String tagName)
Main entry point for loading a configuration.protected CFBundle
loadBundle(InputStream inputStream, String tagName, EnvStack envStack, Set<String> loadedFiles)
Loads a configuration.CFBundle
loadBundle(String resource, String tagName)
Loads the specified resource as a stream.protected EnvTable<? extends SKey,? extends EnvEntry>
processEnvDocument(InputStream inputStream)
Process a single env document from any source.protected Document
resolveEnvironment(InputStream inputStream, EnvStack stack, Set<String> loadedFiles, boolean isRoot)
Returns a valid XML document with the environment references done.protected Node
resolveFileReferences(Document rootDoc, Node cfg, EnvStack stack, Set<String> visitedFiles)
All the actual work for loading files is done here.void
setFile(File file)
void
setInputStream(InputStream inputStream)
void
setResource(String resource)
CFLoader
setTagName(String tagName)
Supports builder pattern
-
-
-
Field Detail
-
FILE_TAG
public static final String FILE_TAG
- See Also:
- Constant Field Values
-
INCLUDE_TAG
public static final String INCLUDE_TAG
- See Also:
- Constant Field Values
-
ENV_TAG
public static final String ENV_TAG
- See Also:
- Constant Field Values
-
KEY_TAG
public static final String KEY_TAG
- See Also:
- Constant Field Values
-
ENV_START_ELEMENT
public static final String ENV_START_ELEMENT
- See Also:
- Constant Field Values
-
ENV_END_ELEMENT
public static final String ENV_END_ELEMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CFLoader
public CFLoader()
-
CFLoader
public CFLoader(CFLoader.Builder builder)
-
-
Method Detail
-
getTagName
public String getTagName()
-
hasFile
protected boolean hasFile()
-
hasResource
protected boolean hasResource()
-
hasInputStream
protected boolean hasInputStream()
-
getInputStream
public InputStream getInputStream()
-
setInputStream
public void setInputStream(InputStream inputStream)
-
getResource
public String getResource()
-
setResource
public void setResource(String resource)
-
getFile
public File getFile()
-
setFile
public void setFile(File file)
-
setTagName
public CFLoader setTagName(String tagName)
Supports builder pattern- Parameters:
tagName
-- Returns:
-
loadBundle
public CFBundle loadBundle(String resource, String tagName) throws MyConfigurationException, CircularReferenceException
Loads the specified resource as a stream.- Parameters:
resource
-tagName
-- Returns:
- Throws:
MyConfigurationException
CircularReferenceException
-
loadBundle
public CFBundle loadBundle() throws MyConfigurationException, CircularReferenceException
Used with the builder. Set the source and tagname then invoke.- Returns:
- Throws:
MyConfigurationException
CircularReferenceException
-
loadBundle
public CFBundle loadBundle(File file, String tagName) throws MyConfigurationException, CircularReferenceException
Loads the specified file.- Parameters:
file
-tagName
-- Returns:
- Throws:
MyConfigurationException
CircularReferenceException
-
loadBundle
public CFBundle loadBundle(InputStream inputStream, String tagName) throws MyConfigurationException, CircularReferenceException
Main entry point for loading a configuration. This resolves all environment variables and file import, then parses the result as (valid) XML.- Parameters:
inputStream
-- Returns:
- Throws:
MyConfigurationException
CircularReferenceException
-
loadBundle
protected CFBundle loadBundle(InputStream inputStream, String tagName, EnvStack envStack, Set<String> loadedFiles) throws MyConfigurationException, CircularReferenceException
Loads a configuration. This will also have the environment and- Parameters:
inputStream
-loadedFiles
-- Returns:
- Throws:
MyConfigurationException
CircularReferenceException
-
resolveEnvironment
protected Document resolveEnvironment(InputStream inputStream, EnvStack stack, Set<String> loadedFiles, boolean isRoot) throws Throwable
Returns a valid XML document with the environment references done.- Parameters:
inputStream
-stack
-- Returns:
- Throws:
Throwable
-
isStartEnv
protected boolean isStartEnv(String l)
Does the trimmed line start and environment entry?- Parameters:
l
-- Returns:
-
isEndEnv
protected boolean isEndEnv(String l)
Does the trimmed line end with an environment end tag?- Parameters:
l
-- Returns:
-
processEnvDocument
protected EnvTable<? extends SKey,? extends EnvEntry> processEnvDocument(InputStream inputStream) throws Throwable
Process a single env document from any source. The document is a valid XML file and only environment tags are processed. At the end of this, every envionment element will have been processed and put into a table.- Parameters:
inputStream
-- Returns:
- Throws:
Throwable
-
resolveFileReferences
protected Node resolveFileReferences(Document rootDoc, Node cfg, EnvStack stack, Set<String> visitedFiles) throws Throwable
All the actual work for loading files is done here. This looks for elements inside the config tag of the form<file include="path"/>
These are read and each line is inserted into the document. Included files may also include other files, which will be resolved as well. No promise of ordering is done.Nota Bene
Each include is a complete configuration file, not a fragment! They are processed as if independent (with their own env that retains scope).
- Parameters:
cfg
-visitedFiles
- Files already processed. Prevents cycles.- Returns:
- Throws:
Throwable
-
-