org.inria.ns.reflex.processor.xcl
Class ParseAction

java.lang.Object
  extended by org.inria.ns.reflex.processor.core.AbstractAction
      extended by org.inria.ns.reflex.processor.core.AbstractSetAction
          extended by org.inria.ns.reflex.processor.xcl.ParseAction
All Implemented Interfaces:
Computable, Executable, Preferable, Presentable, NamespaceContextFactory

public class ParseAction
extends AbstractSetAction
implements Preferable

The <xcl:parse> element parses the XML data source specified in the source attribute.

<xcl:parse name="xml" source="{$xmlFile}"
    <xcl:param name="http://xml.org/sax/features/namespace-prefixes" value="true">
</xcl:parse/>

The following optionnal "yes -or- no" attributes may tune the parsing :

NameDefaultDescription
validate no Specifies that the parser will validate documents as they are parsed.
namespace-aware yes Specifies that the parser will provide support for XML namespaces.
coalesce no Specifies that the parser will convert CDATA nodes to Text nodes and append it to the adjacent (if any) text node.
expand-entity-ref yes Specifies that the parser will expand entity reference nodes.
ignore-comments no Specifies that the parser will ignore comments.
ignore-whitespace no Specifies that the parser must eliminate whitespace in element content (sometimes known loosely as 'ignorable whitespace') when parsing.

XML sources

The XML source processed may be :

Additionnaly, if the source attribute is replaced by text-source, the parsing will be performed on the string value of the attribute.

Entity resolution

Entities are resolved with the catalog in use by the processor instance. See ExternalIdentifierResolver.

Error handling

See XMLError.

Passing parameters to the parser

Parameters may be set conditionnally (subactions can be used), like this :

  <xcl:parse name="xml" source="{$xmlFile}">
      <xcl:if test="{$ns-prefixes}">
          <xcl:then><!--set the parameter only if it exists-->
              <xcl:param name="http://xml.org/sax/features/namespace-prefixes" value="{$ns-prefixes}">
          </xcl:then>
      </xcl:if>
  </xcl:parse>

...or more shortly :

  <xcl:parse name="xml" source="{$xmlFile}">
      <!--set the parameter only if it exists-->
      <xcl:param xcl:if="{$ns-prefixes}" name="http://xml.org/sax/features/namespace-prefixes" value="{$ns-prefixes}">
  </xcl:parse>
 

Notice that in the terminology, a parser is using attributes ; the parameters are used to set the attributes of the parser.

Author:
Philippe Poulard
See Also:
ExternalIdentifierResolver

Nested Class Summary
 
Nested classes/interfaces inherited from class org.inria.ns.reflex.processor.core.AbstractAction
AbstractAction.ParameterAdapter, AbstractAction.UselessAction
 
Field Summary
 
Fields inherited from class org.inria.ns.reflex.processor.core.AbstractSetAction
NO_VALUE
 
Fields inherited from class org.inria.ns.reflex.processor.core.AbstractAction
actions, parent, processorInstance
 
Constructor Summary
ParseAction(Expression source, boolean parseText, ParserConfiguration.Impl staticConfiguration, Expression publicId, Expression systemId, int preferred, EvaluableExpression style, EvaluableExpression mode, Element element, AbstractAction parent)
          Create a new instance of ParseAction.
 
Method Summary
static InputSource copyInputSource(InputSource from, InputSource to)
          Field to field copy of an input source.
 Object getComputedValue(DataSet dataSet)
          Return the computed value of the property, by parsing an XML source.
 int getPreferred()
          Return the external identifier preference mode : as-is (0), system (1), or public (2) ; (-1) means to not use a catalog.
static AbstractAction unmarshal(AbstractAction parent, Element element)
          XML unmarshaller for ParseAction.
 
Methods inherited from class org.inria.ns.reflex.processor.core.AbstractSetAction
addProperty, getComputedName, getName, getValue, runAction, scope, unmarshalScope
 
Methods inherited from class org.inria.ns.reflex.processor.core.AbstractAction
addAction, addFallbackAction, createContext, getCanonicalPath, getFallbackAction, getLocalFallbackAction, getLogger, getNamespaceContext, getNode, getParent, recover, recover, removeFallbackAction, reorganize, run, runActions, toPrettyString, toPrettyString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParseAction

public ParseAction(Expression source,
                   boolean parseText,
                   ParserConfiguration.Impl staticConfiguration,
                   Expression publicId,
                   Expression systemId,
                   int preferred,
                   EvaluableExpression style,
                   EvaluableExpression mode,
                   Element element,
                   AbstractAction parent)
            throws XMLException
Create a new instance of ParseAction.

Parameters:
source - The source of the datas to parse, that will be the value of the property, as an Expression.
parseText - true if the source must be parsed as a text source, false otherwise.
staticConfiguration - The set of flags used to configure the parser.
publicId - The public identifier for the document as an expression, or null.
systemId - The system identifier for the document as an expression, or null.
preferred - The external identifier preferred : as-is, system, or public ; -1 means to not use a catalog.
style - The style of parsing : DOM or SAX.
mode - The mode of parsing : strict or lax (allow multiples root elements eventually surrounded by non-blank text nodes, that is to say the parser will be able to parse fragments).
element - The element from which the action has been unmarshalled. Used for namespace prefix resolution when performing XPath expressions.
parent - The action depending from.
Throws:
UnmarshalException - When the "name" attribute is not a valid value template.
XMLException
Method Detail

unmarshal

public static AbstractAction unmarshal(AbstractAction parent,
                                       Element element)
                                throws XMLException
XML unmarshaller for ParseAction.

Parameters:
parent - The action depending from
element - The XML element to unmarshall.
Returns:
The ParseAction created.
Throws:
UnmarshalException - When the element and its content is not those expected.
XMLException

getComputedValue

public Object getComputedValue(DataSet dataSet)
                        throws ExecutionException,
                               XPathException
Return the computed value of the property, by parsing an XML source.

Specified by:
getComputedValue in interface Computable
Specified by:
getComputedValue in class AbstractSetAction
Parameters:
dataSet - The set of datas used when the name is computed.
Returns:
A DOM document, a DOM fragment, or a SAX filter.
Throws:
ExecutionException - If the computation can't be performed.
XPathException
See Also:
Document, DOMFragment, SAXFilter

getPreferred

public int getPreferred()
Return the external identifier preference mode : as-is (0), system (1), or public (2) ; (-1) means to not use a catalog.

Specified by:
getPreferred in interface Preferable
Returns:
The preference mode.

copyInputSource

public static InputSource copyInputSource(InputSource from,
                                          InputSource to)
Field to field copy of an input source.

Parameters:
from - The input source to copy.
to - The target input source, that may be null.
Returns:
The target input source, or the source to copy if the target wa null.