|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectinfo.textgrid.utils.linkrewriter.AbstractRewriter
info.textgrid.utils.linkrewriter.ConfigurableXMLRewriter
public class ConfigurableXMLRewriter extends AbstractRewriter implements ILinkRewriter
The configurable XML rewriter allows you to configure where in an XML file link rewriting may occur. You can specify where rewriting will occur and what kind of rewriting will occur there.
Modifier and Type | Class and Description |
---|---|
protected class |
ConfigurableXMLRewriter.Replacer
implementers must implement ConfigurableXMLRewriter.Replacer.apply(String) and can use the other
methods |
Constructor and Description |
---|
ConfigurableXMLRewriter(ImportMapping mapping,
boolean export)
|
Modifier and Type | Method and Description | |
---|---|---|
void |
configure(URI uri)
Configures this XML rewriter for the configuration identified by the given URI. |
|
void |
configure(XmlConfiguration configuration)
Configures this rewriter for the given configuration. |
|
protected static
|
find(Iterable<T> iterable,
QName name)
|
|
URI |
getBase()
Returns the currently active base URI. |
|
static Map<URI,XmlConfiguration> |
getInternalConfigurations()
|
|
static List<String> |
getInternalSpecs()
|
|
Set<String> |
getMissingReferences()
|
|
protected ConfigurableXMLRewriter.Replacer |
getReplacer(ReplaceMethod method)
|
|
ConfigurableXMLRewriter |
recordMissingReferences()
After calls to this function the rewriter will record links to missing references, i.e. |
|
protected String |
replaceAttributeValue(QName element,
QName attribute,
String value)
Helper method that correctly applies the configured replacement to the given attribute in the given element according to the rewriter's current configuration. |
|
protected String |
replaceElementContent(QName element,
String content)
Helper method that correctly applies the configured replacement to the given content according to te given element. |
|
void |
rewrite(InputStream input,
OutputStream output)
Copies contents from input to output, rewriting links according to the mapping and the export setting, in an implementation dependent manner. |
|
void |
setBase(URI base)
Use the given base for the local links. |
Methods inherited from class info.textgrid.utils.linkrewriter.AbstractRewriter |
---|
getMapping, isExport |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface info.textgrid.utils.linkrewriter.ILinkRewriter |
---|
getMapping, isExport |
Constructor Detail |
---|
public ConfigurableXMLRewriter(ImportMapping mapping, boolean export)
Method Detail |
---|
public URI getBase()
setBase(URI)
, or
null
if no base handling will take place.setBase(URI)
public void setBase(URI base)
foo.xml sub +--bar.xml +--baz.xml quux.xmlNow, in your import mapping you will have sub/bar.xml and sub/baz.xml. However, a link from bar.xml to baz.xml will be something like
<ref target="baz.xml">Baz</ref>
. The solution is to call
setBase(URI.create("sub/"))
before
rewriting bar.xml and
baz.xml. This will let the rewriter add the given prefix before looking
for matches in the import case, and it will
relativize the URIs against the base in
the export case.
base
- the base URI used from now on in
rewrite(InputStream, OutputStream)
operations or
null
(the default) to switch this feature off.public void configure(XmlConfiguration configuration)
configuration
- public void configure(URI uri) throws IllegalArgumentException
uri
- an URI or URI fragment identifying the configuration to load.
#foo
internal:textgrid#aggregation
IllegalArgumentException
- if the given URI cannot be resolved to a valid configuration.configure(XmlConfiguration)
,
XmlConfiguration
public static List<String> getInternalSpecs()
public static Map<URI,XmlConfiguration> getInternalConfigurations()
protected ConfigurableXMLRewriter.Replacer getReplacer(ReplaceMethod method)
protected String replaceElementContent(QName element, String content)
element
- The name of the element in which the content occurs.content
- (coalesced) character content if the specified element.protected String replaceAttributeValue(QName element, QName attribute, String value)
element
- Name of the current elementattribute
- Name of the attributevalue
- value of the attribute to rewritepublic void rewrite(InputStream input, OutputStream output) throws IOException, XMLStreamException
This rewriter will rewrite according to the configuration specified using this class's other methods. See also the class documentation.
The rewriter will try to detect the input document's encoding. It will always serialize to an UTF-8 encoded XML document. It will fail on non-wellformed documents.
rewrite
in interface ILinkRewriter
rewrite
in class AbstractRewriter
input
- the stream from which the rewriter readsoutput
- the stream to which the rewriter writes the rewritten codeIOException
- if reading or writing failsXMLStreamException
- on fatal errors during XML processing.protected static <T extends NodeRewriteSpec> T find(Iterable<T> iterable, QName name) throws NoSuchElementException
NoSuchElementException
public ConfigurableXMLRewriter recordMissingReferences()
URI
s but that are not contained in
the ImportMapping
.
public Set<String> getMissingReferences()
null
if nothing has been
recorded.recordMissingReferences()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |