Fix for bug 157142 (link transformiix standalone to XPCOM). Better txStack and remove use of NamedMap for documents. r=sicking, sr=jst.

This commit is contained in:
peterv%netscape.com 2003-01-22 03:24:40 +00:00
Родитель 99731a1216
Коммит 80ed9721a4
13 изменённых файлов: 283 добавлений и 88 удалений

Просмотреть файл

@ -58,7 +58,6 @@ LOBJS = ../source/base/Double.$(OBJ_SUFFIX) \
../source/base/Map.$(OBJ_SUFFIX) \
../source/base/NamedMap.$(OBJ_SUFFIX) \
../source/base/SimpleErrorObserver.$(OBJ_SUFFIX) \
../source/base/Stack.$(OBJ_SUFFIX) \
../source/base/txAtoms.$(OBJ_SUFFIX) \
../source/base/txExpandedNameMap.$(OBJ_SUFFIX) \
../source/base/txURIUtils.$(OBJ_SUFFIX) \

Просмотреть файл

@ -1090,13 +1090,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>Stack.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XMLUtils.cpp</PATH>
@ -1632,11 +1625,6 @@
<PATH>ExprLexer.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>Stack.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XMLUtils.cpp</PATH>
@ -2950,13 +2938,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>Stack.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XMLUtils.cpp</PATH>
@ -3508,11 +3489,6 @@
<PATH>ExprLexer.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>Stack.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XMLUtils.cpp</PATH>
@ -3925,12 +3901,6 @@
<PATH>SimpleErrorObserver.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>Stack.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

Просмотреть файл

@ -47,7 +47,6 @@ CPPSRCS = Double.cpp \
Map.cpp \
NamedMap.cpp \
SimpleErrorObserver.cpp \
Stack.cpp \
txAtoms.cpp \
txExpandedNameMap.cpp \
txURIUtils.cpp

Просмотреть файл

@ -0,0 +1,154 @@
//* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com> (original author)
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef txStack_h___
#define txStack_h___
#include "nsVoidArray.h"
class txStack : private nsVoidArray
{
public:
/**
* Returns the specified object from the top of this stack,
* without removing it from the stack.
*
* @return a pointer to the object that is the top of this stack.
*/
void* peek()
{
PRInt32 count = Count() - 1;
NS_ENSURE_TRUE(count >= 0, nsnull);
return ElementAt(count);
}
/**
* Adds the specified object to the top of this stack.
*
* @param obj a pointer to the object that is to be added to the
* top of this stack.
*/
nsresult push(void* aObject)
{
return AppendElement(aObject);
}
/**
* Removes and returns the specified object from the top of this
* stack.
*
* @return a pointer to the object that was the top of this stack.
*/
void* pop()
{
PRInt32 count = Count() - 1;
NS_ENSURE_TRUE(count >= 0, nsnull);
void* object = ElementAt(count);
RemoveElementAt(count);
return object;
}
/**
* Returns true if there are no objects in the stack.
*
* @return true if there are no objects in the stack.
*/
PRBool isEmpty()
{
return (Count() > 0);
}
/**
* Returns the number of elements in the Stack.
*
* @return the number of elements in the Stack.
*/
PRInt32 size()
{
return Count();
}
private:
friend class txStackIterator;
};
class txStackIterator
{
public:
/**
* Creates an iterator for the given stack.
*
* @param aStack the stack to create an iterator for.
*/
txStackIterator(txStack* aStack) : mStack(aStack),
mPosition(0)
{
}
/**
* Returns true if there is more objects on the stack.
*
* @return .
*/
PRBool hasNext()
{
return (mPosition < mStack->Count());
}
/**
* Returns the next object pointer from the stack.
*
* @return .
*/
void* next()
{
if (mPosition == mStack->Count()) {
return nsnull;
}
return mStack->ElementAt(mPosition++);
}
private:
txStack* mStack;
PRUint32 mPosition;
};
#endif /* txStack_h___ */

Просмотреть файл

@ -39,7 +39,6 @@ OBJS = ../base/Double.$(OBJ_SUFFIX) \
../base/Map.$(OBJ_SUFFIX) \
../base/NamedMap.$(OBJ_SUFFIX) \
../base/SimpleErrorObserver.$(OBJ_SUFFIX) \
../base/Stack.$(OBJ_SUFFIX) \
../base/txAtoms.$(OBJ_SUFFIX) \
../base/txExpandedNameMap.$(OBJ_SUFFIX) \
../base/txStringUtils.$(OBJ_SUFFIX) \

Просмотреть файл

@ -41,7 +41,7 @@
#include "ExprParser.h"
#include "ExprLexer.h"
#include "FunctionLib.h"
#include "Stack.h"
#include "txStack.h"
#include "txAtoms.h"
#include "txIXPathContext.h"
#include "txStringUtils.h"
@ -235,8 +235,8 @@ Expr* ExprParser::createExpr(ExprLexer& lexer, txIParseContext* aContext)
Expr* expr = 0;
Stack exprs;
Stack ops;
txStack exprs;
txStack ops;
while (!done) {
@ -280,7 +280,7 @@ Expr* ExprParser::createExpr(ExprLexer& lexer, txIParseContext* aContext)
case Token::MULTIPLY_OP:
case Token::SUBTRACTION_OP:
{
while (!exprs.empty() &&
while (!exprs.isEmpty() &&
precedenceLevel(tok->type)
<= precedenceLevel(((Token*)ops.peek())->type)) {
expr = createBinaryExpr((Expr*)exprs.pop(),
@ -300,13 +300,13 @@ Expr* ExprParser::createExpr(ExprLexer& lexer, txIParseContext* aContext)
// make sure expr != 0
if (!expr) {
while (!exprs.empty()) {
while (!exprs.isEmpty()) {
delete (Expr*)exprs.pop();
}
return 0;
}
while (!exprs.empty()) {
while (!exprs.isEmpty()) {
expr = createBinaryExpr((Expr*)exprs.pop(), expr, (Token*)ops.pop());
}

Просмотреть файл

@ -47,6 +47,78 @@
#include "txVariableMap.h"
#include "XSLTProcessor.h"
DHASH_WRAPPER(txLoadedDocumentsBase, txLoadedDocumentEntry, nsAString&)
txLoadedDocumentsHash::txLoadedDocumentsHash(Document* aSourceDocument,
Document* aStyleDocument)
: mSourceDocument(aSourceDocument),
mStyleDocument(aStyleDocument)
{
if (NS_FAILED(Init(8))) {
return;
}
if (mSourceDocument) {
Add(mSourceDocument);
}
if (mStyleDocument) {
Add(mStyleDocument);
}
}
txLoadedDocumentsHash::~txLoadedDocumentsHash()
{
if (!mHashTable.ops) {
return;
}
nsAutoString baseURI;
if (mSourceDocument) {
mSourceDocument->getBaseURI(baseURI);
txLoadedDocumentEntry* entry = GetEntry(baseURI);
if (entry) {
entry->mDocument = nsnull;
}
}
if (mStyleDocument) {
mStyleDocument->getBaseURI(baseURI);
txLoadedDocumentEntry* entry = GetEntry(baseURI);
if (entry) {
entry->mDocument = nsnull;
}
}
}
void txLoadedDocumentsHash::Add(Document* aDocument)
{
if (!mHashTable.ops) {
return;
}
nsAutoString baseURI;
mSourceDocument->getBaseURI(baseURI);
txLoadedDocumentEntry* entry = AddEntry(baseURI);
if (entry) {
entry->mDocument = aDocument;
}
}
Document* txLoadedDocumentsHash::Get(const nsAString& aURI)
{
if (!mHashTable.ops) {
return nsnull;
}
txLoadedDocumentEntry* entry = GetEntry(aURI);
if (entry) {
return entry->mDocument;
}
return nsnull;
}
/**
* Creates a new ProcessorState for the given XSL document
**/
@ -55,13 +127,12 @@ ProcessorState::ProcessorState(Document* aSourceDocument,
: mOutputHandler(0),
mResultHandler(0),
mOutputHandlerFactory(0),
mLoadedDocuments(aSourceDocument, aXslDocument),
mXslKeys(MB_TRUE),
mDecimalFormats(MB_TRUE),
mEvalContext(0),
mLocalVariables(0),
mGlobalVariableValues(MB_TRUE),
mSourceDocument(aSourceDocument),
xslDocument(aXslDocument),
mRTFDocument(0)
{
NS_ASSERTION(aSourceDocument, "missing source document");
@ -73,21 +144,6 @@ ProcessorState::ProcessorState(Document* aSourceDocument,
mExprHashes[ValueAttr].setOwnership(Map::eOwnsItems);
mPatternHashes[CountAttr].setOwnership(Map::eOwnsItems);
mPatternHashes[FromAttr].setOwnership(Map::eOwnsItems);
// determine xslt properties
if (mSourceDocument) {
nsAutoString baseURI;
mSourceDocument->getBaseURI(baseURI);
loadedDocuments.put(baseURI, mSourceDocument);
}
if (xslDocument) {
nsAutoString baseURI;
xslDocument->getBaseURI(baseURI);
loadedDocuments.put(baseURI, xslDocument);
}
// Make sure all loaded documents get deleted
loadedDocuments.setObjectDeletion(MB_TRUE);
}
/**
@ -100,19 +156,6 @@ ProcessorState::~ProcessorState()
while (iter.hasNext())
delete (ImportFrame*)iter.next();
// Make sure that xslDocument and mSourceDocument aren't deleted along with
// the rest of the documents in the loadedDocuments hash
if (xslDocument) {
nsAutoString baseURI;
xslDocument->getBaseURI(baseURI);
loadedDocuments.remove(baseURI);
}
if (mSourceDocument) {
nsAutoString baseURI;
mSourceDocument->getBaseURI(baseURI);
loadedDocuments.remove(baseURI);
}
// in module the outputhandler is refcounted
#ifdef TX_EXE
delete mOutputHandler;
@ -385,14 +428,16 @@ Node* ProcessorState::retrieveDocument(const nsAString& uri,
NS_LossyConvertUCS2toASCII(frag).get()));
// try to get already loaded document
Document* xmlDoc = (Document*)loadedDocuments.get(docUrl);
Document* xmlDoc = mLoadedDocuments.Get(docUrl);
if (!xmlDoc) {
// open URI
nsAutoString errMsg;
XMLParser xmlParser;
xmlDoc = xmlParser.getDocumentFromURI(docUrl, xslDocument, errMsg);
xmlDoc = xmlParser.getDocumentFromURI(docUrl,
mLoadedDocuments.mStyleDocument,
errMsg);
if (!xmlDoc) {
receiveError(NS_LITERAL_STRING("Couldn't load document '") +
@ -401,7 +446,7 @@ Node* ProcessorState::retrieveDocument(const nsAString& uri,
return NULL;
}
// add to list of documents
loadedDocuments.put(docUrl, xmlDoc);
mLoadedDocuments.Add(xmlDoc);
}
// return element with supplied id if supplied
@ -667,8 +712,9 @@ void ProcessorState::setRTFDocument(Document* aDoc)
Document* ProcessorState::getStylesheetDocument()
{
NS_ASSERTION(xslDocument, "missing stylesheet document");
return xslDocument;
NS_ASSERTION(mLoadedDocuments.mStyleDocument,
"missing stylesheet document");
return mLoadedDocuments.mStyleDocument;
}
/*
@ -1022,7 +1068,7 @@ nsresult ProcessorState::getVariable(PRInt32 aNamespace, nsIAtom* aLName,
// Set up the state we have at the beginning of the transformation
txVariableMap *oldVars = mLocalVariables;
mLocalVariables = 0;
txSingleNodeContext evalContext(mSourceDocument, this);
txSingleNodeContext evalContext(mLoadedDocuments.mSourceDocument, this);
txIEvalContext* priorEC = setEvalContext(&evalContext);
// Compute the variable value
globVar->mFlags = GlobalVariableValue::evaluating;

Просмотреть файл

@ -29,9 +29,7 @@
#define TRANSFRMX_PROCESSORSTATE_H
#include "NodeSet.h"
#include "Stack.h"
#include "ErrorObserver.h"
#include "NamedMap.h"
#include "txPatternParser.h"
#include "Expr.h"
#include "txOutputFormat.h"
@ -42,10 +40,39 @@
#include "XSLTFunctions.h"
#include "txError.h"
#include "nsVoidArray.h"
#include "nsDoubleHashtable.h"
class txVariableMap;
class txXSLKey;
class txLoadedDocumentEntry : public PLDHashStringEntry {
public:
txLoadedDocumentEntry(const void* aKey) : PLDHashStringEntry(aKey)
{
}
~txLoadedDocumentEntry()
{
delete mDocument;
}
Document* mDocument;
};
DECL_DHASH_WRAPPER(txLoadedDocumentsBase, txLoadedDocumentEntry, nsAString&)
class txLoadedDocumentsHash : public txLoadedDocumentsBase
{
public:
txLoadedDocumentsHash(Document* aSourceDocument, Document* aStyleDocument);
~txLoadedDocumentsHash();
void Add(Document* aDocument);
Document* Get(const nsAString& aURI);
private:
friend class ProcessorState;
Document* mSourceDocument;
Document* mStyleDocument;
};
/**
* Class used for keeping the current state of the XSL Processor
*/
@ -418,7 +445,7 @@ private:
* The set of loaded documents. This includes both document() loaded
* documents and xsl:include/xsl:import'ed documents.
*/
NamedMap loadedDocuments;
txLoadedDocumentsHash mLoadedDocuments;
/**
* The set of all available keys
@ -467,9 +494,6 @@ private:
*/
txExpandedNameMap mGlobalVariableValues;
Document* mSourceDocument;
Document* xslDocument;
/**
* Document used to create RTFs
*/

Просмотреть файл

@ -47,6 +47,7 @@
#include "txNodeSetContext.h"
#include "txNodeSorter.h"
#include "txRtfHandler.h"
#include "txStack.h"
#include "txStringUtils.h"
#include "txTextHandler.h"
#include "txTokenizer.h"
@ -866,7 +867,7 @@ txXSLTProcessor::processAction(Node* aAction,
void
txXSLTProcessor::processAttributeSets(Element* aElement,
ProcessorState* aPs,
Stack* aRecursionStack)
txStack* aRecursionStack)
{
nsresult rv = NS_OK;
nsAutoString names;
@ -913,7 +914,7 @@ txXSLTProcessor::processAttributeSets(Element* aElement,
aRecursionStack->pop();
}
else {
Stack recursionStack;
txStack recursionStack;
recursionStack.push(&name);
processAttributeSets(parent, aPs, &recursionStack);
recursionStack.pop();

Просмотреть файл

@ -30,6 +30,8 @@
#include "ProcessorState.h"
class txStack;
class txIGlobalParameter : public TxObject
{
public:
@ -123,7 +125,7 @@ private:
* including themselves, even indirectly
*/
static void processAttributeSets(Element* aElement, ProcessorState* aPs,
Stack* aRecursionStack = 0);
txStack* aRecursionStack = 0);
/**
* Processes the children of the specified element using the given

Просмотреть файл

@ -19,6 +19,7 @@
*/
#include "ProcessorState.h"
#include "NamedMap.h"
#include "txAtoms.h"
#include "txSingleNodeContext.h"
#include "XMLDOMUtils.h"

Просмотреть файл

@ -40,7 +40,7 @@
#define TRANSFRMX_HTML_OUTPUT_H
#include "txXMLOutput.h"
#include "Stack.h"
#include "txStack.h"
class txHTMLOutput : public txXMLOutput
{
@ -109,7 +109,7 @@ private:
MBool isShorthandElement(const nsAString& aName);
MBool isShorthandAttribute(const nsAString& aLocalName);
Stack mCurrentElements;
txStack mCurrentElements;
};
#endif

Просмотреть файл

@ -42,7 +42,7 @@
#include "txXMLEventHandler.h"
#include "dom.h"
#include "List.h"
#include "Stack.h"
#include "txStack.h"
#include "txOutputFormat.h"
#include "XMLUtils.h"
@ -197,7 +197,7 @@ protected:
MBool mInCDATASection;
PRUint32 mIndentLevel;
txList mAttributes;
Stack mCDATASections;
txStack mCDATASections;
private:
PRUnichar mBuffer[4];