Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Private Attributes
txDriverProcessor Class Reference

Driver for running XSLTMark on standalone. More...

Inheritance diagram for txDriverProcessor:
Inheritance graph
[legend]
Collaboration diagram for txDriverProcessor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 txDriverProcessor ()
int loadStylesheet (char *filename)
int setInputDocument (char *filename)
int openOutput (char *outputFilename)
int runTransform ()
int closeOutput ()
int terminate ()
 ~txDriverProcessor ()
nsresult transform (nsACString &aXMLPath, ostream &aOut, ErrorObserver &aErr)
 Methods that print the result to a stream.
nsresult transform (nsACString &aXMLPath, nsACString &aXSLPath, ostream &aOut, ErrorObserver &aErr)
 Transform a XML document given by path with the given stylesheet.
nsresult transform (txXPathNode &aXMLDoc, ostream &aOut, ErrorObserver &aErr)
 Transform a XML document.
nsresult transform (txXPathNode &aXMLDoc, txStylesheet *aXSLNode, ostream &aOut, ErrorObserver &aErr)
 Transform a XML document with the given stylesheet.

Static Public Member Functions

static MBool init ()
 Initialisation and shutdown routines.
static void shutdown ()
static nsresult execute (txExecutionState &aEs)

Static Protected Member Functions

static void getHrefFromStylesheetPI (Document &xmlDocument, nsAString &href)
 Parses all XML Stylesheet PIs associated with the given XML document.
static void parseStylesheetPI (const nsAFlatString &data, nsAString &type, nsAString &href)
 Parses the contents of data, returns the type and href pseudo attributes.
static txXPathNodeparsePath (const nsACString &aPath, ErrorObserver &aErr)
 Create a Document from a path.

Private Attributes

txXPathNodemXML
nsRefPtr< txStylesheetmStylesheet
SimpleErrorObserver mObserver
ofstream * mOut

Detailed Description

Driver for running XSLTMark on standalone.

See http://www.datapower.com/XSLTMark/

Definition at line 53 of file txXSLTMarkDriver.cpp.


Constructor & Destructor Documentation

Definition at line 57 of file txXSLTMarkDriver.cpp.

                        : mXML(0), mOut(0)
    {
    }

Definition at line 106 of file txXSLTMarkDriver.cpp.

    {
        delete mXML;
        delete mOut;
    }

Member Function Documentation

Definition at line 87 of file txXSLTMarkDriver.cpp.

    {
        if (mOut)
            mOut->close();
        delete mOut;
        mOut = 0;
        return 0;
    }
nsresult txXSLTProcessor::execute ( txExecutionState aEs) [static, inherited]

Definition at line 93 of file txXSLTProcessor.cpp.

{
    nsresult rv = NS_OK;
    txInstruction* instr;
    while ((instr = aEs.getNextInstruction())) {
        rv = instr->execute(aEs);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void txStandaloneXSLTProcessor::getHrefFromStylesheetPI ( Document xmlDocument,
nsAString &  href 
) [static, protected, inherited]

Parses all XML Stylesheet PIs associated with the given XML document.

Parses the XML Stylesheet PIs associated with the given XML document.

If any stylesheet PIs are found with type="text/xsl" the href pseudo attribute value will be added to the given href argument. If multiple text/xsl stylesheet PIs are found, the one closest to the end of the document is used.

If a stylesheet PIs is found with type="text/xsl", type="text/xml" or type="application/xml" the href pseudo attribute value will be appended to the given href argument. If multiple XSLT stylesheet PIs are found, the first one is used.

Definition at line 243 of file txStandaloneXSLTProcessor.cpp.

{
    Node* node = xmlDocument.getFirstChild();
    nsAutoString type;
    nsAutoString tmpHref;
    while (node) {
        if (node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
            nsAutoString target;
            node->getNodeName(target);
            if (target.EqualsLiteral("xml-stylesheet")) {
                nsAutoString data;
                node->getNodeValue(data);
                type.Truncate();
                tmpHref.Truncate();
                parseStylesheetPI(data, type, tmpHref);
                if (type.EqualsLiteral("text/xsl") ||
                    type.EqualsLiteral("text/xml") ||
                    type.EqualsLiteral("application/xml")) {
                    href = tmpHref;
                    return;
                }
            }
        }
        node = node->getNextSibling();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

TX_LG_IMPL MBool txXSLTProcessor::init ( ) [static, inherited]

Initialisation and shutdown routines.

Initilizes and cleansup all dependant classes

Definition at line 54 of file txXSLTProcessor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int txDriverProcessor::loadStylesheet ( char *  filename) [inline]

Definition at line 61 of file txXSLTMarkDriver.cpp.

    {
        txParsedURL url;
        url.init(NS_ConvertASCIItoUCS2(filename));
        nsresult rv =
            TX_CompileStylesheetPath(url, getter_AddRefs(mStylesheet));
        return NS_SUCCEEDED(rv) ? 0 : 1;
    }

Here is the call graph for this function:

int txDriverProcessor::openOutput ( char *  outputFilename) [inline]

Definition at line 75 of file txXSLTMarkDriver.cpp.

    {
        mOut = new ofstream(outputFilename);
        return mXML ? 0 : 1;
    }
txXPathNode * txStandaloneXSLTProcessor::parsePath ( const nsACString &  aPath,
ErrorObserver aErr 
) [static, protected, inherited]

Create a Document from a path.

Parameters:
aPathpath to the xml file
aErrErrorObserver
Returns:
Document XML Document, or null on error

Definition at line 359 of file txStandaloneXSLTProcessor.cpp.

{
    NS_ConvertASCIItoUCS2 path(aPath);

    ifstream xmlInput(PromiseFlatCString(aPath).get(), ios::in);
    if (!xmlInput) {
        aErr.receiveError(NS_LITERAL_STRING("Couldn't open ") + path);
        return 0;
    }
    // parse source
    txXPathNode* xmlDoc;
    nsAutoString errors;
    nsresult rv = txParseFromStream(xmlInput, path, errors, &xmlDoc);
    xmlInput.close();
    if (NS_FAILED(rv) || !xmlDoc) {
        aErr.receiveError(NS_LITERAL_STRING("Parsing error \"") + errors +
                          NS_LITERAL_STRING("\""));
    }
    return xmlDoc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void txStandaloneXSLTProcessor::parseStylesheetPI ( const nsAFlatString data,
nsAString &  type,
nsAString &  href 
) [static, protected, inherited]

Parses the contents of data, returns the type and href pseudo attributes.

Definition at line 290 of file txStandaloneXSLTProcessor.cpp.

{
  nsAFlatString::const_char_iterator start, end;
  aData.BeginReading(start);
  aData.EndReading(end);
  nsAFlatString::const_char_iterator iter;
  PRInt8 found = 0;

  while (start != end) {
    SKIP_WHITESPACE(start, end);
    iter = start;
    SKIP_ATTR_NAME(iter, end);

    // Remember the attr name.
    const nsAString & attrName = Substring(start, iter);

    // Now check whether this is a valid name="value" pair.
    start = iter;
    SKIP_WHITESPACE(start, end);
    if (*start != '=') {
      // No '=', so this is not a name="value" pair.  We don't know
      // what it is, and we have no way to handle it.
      break;
    }

    // Have to skip the value.
    ++start;
    SKIP_WHITESPACE(start, end);
    PRUnichar q = *start;
    if (q != QUOTE && q != APOSTROPHE) {
      // Not a valid quoted value, so bail.
      break;
    }

    ++start;  // Point to the first char of the value.
    iter = start;
    while (iter != end && *iter != q) {
      ++iter;
    }
    if (iter == end) {
      // Oops, unterminated quoted string.
      break;
    }
    
    // At this point attrName holds the name of the "attribute" and
    // the value is between start and iter.
    if (attrName.EqualsLiteral("type")) {
      aType = Substring(start, iter);
      ++found;
    }
    else if (attrName.EqualsLiteral("href")) {
      aHref = Substring(start, iter);
      ++found;
    }

    // Stop if we found both attributes
    if (found == 2) {
      break;
    }

    // Resume scanning after the end of the attribute value.
    start = iter;
    ++start;  // To move past the quote char.
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 80 of file txXSLTMarkDriver.cpp.

    {
        if (!mXML || !mStylesheet || !mOut)
            return 1;
        nsresult rv = transform(*mXML, mStylesheet, *mOut, mObserver);
        return NS_FAILED(rv);
    }

Here is the call graph for this function:

int txDriverProcessor::setInputDocument ( char *  filename) [inline]

Definition at line 69 of file txXSLTMarkDriver.cpp.

    {
        delete mXML;
        mXML = parsePath(nsDependentCString(filename), mObserver);
        return mXML ? 0 : 1;
    }

Here is the call graph for this function:

void txXSLTProcessor::shutdown ( ) [static, inherited]

Definition at line 80 of file txXSLTProcessor.cpp.

Here is the caller graph for this function:

Definition at line 95 of file txXSLTMarkDriver.cpp.

    {
        delete mXML;
        mXML = 0;
        if (mOut && mOut->is_open())
            mOut->close();
        delete mOut;
        mOut = 0;
        mStylesheet = 0;
        return 0;
    }
nsresult txStandaloneXSLTProcessor::transform ( nsACString &  aXMLPath,
ostream &  aOut,
ErrorObserver aErr 
) [inherited]

Methods that print the result to a stream.

txStandaloneXSLTProcessor

Transform a XML document given by path. The stylesheet is retrieved by a processing instruction, or an error is returned.

Parameters:
aXMLPathpath to the source document
aOutstream to which the result is feeded
aErrerror observer
Returns:
NS_OK if transformation was successful

Transform a XML document given by path. The stylesheet is retrieved by a processing instruction, or an error is returned.

Definition at line 125 of file txStandaloneXSLTProcessor.cpp.

{
    txXPathNode* xmlDoc = parsePath(aXMLPath, aErr);
    if (!xmlDoc) {
        return NS_ERROR_FAILURE;
    }

    // transform
    nsresult rv = transform(*xmlDoc, aOut, aErr);

    delete xmlDoc;

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txStandaloneXSLTProcessor::transform ( nsACString &  aXMLPath,
nsACString &  aXSLPath,
ostream &  aOut,
ErrorObserver aErr 
) [inherited]

Transform a XML document given by path with the given stylesheet.

Parameters:
aXMLPathpath to the source document
aXSLPathpath to the style document
aOutstream to which the result is feeded
aErrerror observer
Returns:
NS_OK if transformation was successful

Definition at line 146 of file txStandaloneXSLTProcessor.cpp.

{
    txXPathNode* xmlDoc = parsePath(aXMLPath, aErr);
    if (!xmlDoc) {
        return NS_ERROR_FAILURE;
    }
    txParsedURL path;
    path.init(NS_ConvertASCIItoUCS2(aXSLPath));
    nsRefPtr<txStylesheet> style;
    nsresult rv = TX_CompileStylesheetPath(path, getter_AddRefs(style));
    if (NS_FAILED(rv)) {
        delete xmlDoc;
        return rv;
    }
    // transform
    rv = transform(*xmlDoc, style, aOut, aErr);

    delete xmlDoc;

    return rv;
}

Here is the call graph for this function:

nsresult txStandaloneXSLTProcessor::transform ( txXPathNode aXMLDoc,
ostream &  aOut,
ErrorObserver aErr 
) [inherited]

Transform a XML document.

The stylesheet is retrieved by a processing instruction, or an error is returned.

Parameters:
aXMLDocsource document
aOutstream to which the result is feeded
aErrerror observer
Returns:
NS_OK if transformation was successful

The stylesheet is retrieved by a processing instruction, or an error is returned.

Definition at line 176 of file txStandaloneXSLTProcessor.cpp.

{
    Document* xmlDoc;
    nsresult rv = txXPathNativeNode::getDocument(aXMLDoc, &xmlDoc);
    NS_ENSURE_SUCCESS(rv, rv);

    // get stylesheet path
    nsAutoString stylePath, basePath;
    xmlDoc->getBaseURI(basePath);
    getHrefFromStylesheetPI(*xmlDoc, stylePath);
    txParsedURL base, ref, resolved;
    base.init(basePath);
    ref.init(stylePath);
    base.resolve(ref, resolved);

    nsRefPtr<txStylesheet> style;
    rv = TX_CompileStylesheetPath(resolved, getter_AddRefs(style));
    NS_ENSURE_SUCCESS(rv, rv);

    // transform
    rv = transform(aXMLDoc, style, aOut, aErr);

    return rv;
}

Here is the call graph for this function:

nsresult txStandaloneXSLTProcessor::transform ( txXPathNode aXMLDoc,
txStylesheet aXSLNode,
ostream &  aOut,
ErrorObserver aErr 
) [inherited]

Transform a XML document with the given stylesheet.

Processes the given XML Document using the given XSL document and prints the results to the given ostream argument.

Parameters:
aXMLDocsource document
aXSLNodestyle node
aOutstream to which the result is feeded
aErrerror observer
Returns:
NS_OK if transformation was successful

Definition at line 207 of file txStandaloneXSLTProcessor.cpp.

{
    // Create a new txEvalState
    txExecutionState es(aStylesheet);

    // XXX todo es.addErrorObserver(aErr);

    txStandaloneHandlerFactory handlerFactory(&es, &aOut);

#ifndef XP_WIN
    bool sync = aOut.sync_with_stdio(false);
#endif
    es.mOutputHandlerFactory = &handlerFactory;

    es.init(aSource, nsnull);

    // Process root of XML source document
    nsresult rv = txXSLTProcessor::execute(es);
    es.end(rv);

#ifndef XP_WIN
    aOut.sync_with_stdio(sync);
#endif

    return rv;
}

Here is the call graph for this function:


Member Data Documentation

SimpleErrorObserver txDriverProcessor::mObserver [private]

Definition at line 114 of file txXSLTMarkDriver.cpp.

ofstream* txDriverProcessor::mOut [private]

Definition at line 115 of file txXSLTMarkDriver.cpp.

Definition at line 113 of file txXSLTMarkDriver.cpp.

Definition at line 112 of file txXSLTMarkDriver.cpp.


The documentation for this class was generated from the following file: