Key template modes, template names, decimalformats, attributesets and keys on expanded name rather then qualified name.

b=96082 r=peterv sr=jst
This commit is contained in:
sicking%bigfoot.com 2002-07-10 05:04:24 +00:00
Родитель 78012324a3
Коммит b81f2611ce
15 изменённых файлов: 256 добавлений и 160 удалений

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

@ -64,7 +64,7 @@ txExpandedNameMap::~txExpandedNameMap()
* @param aValue value of item to add * @param aValue value of item to add
* @return errorcode * @return errorcode
*/ */
nsresult txExpandedNameMap::add(txExpandedName& aKey, TxObject* aValue) nsresult txExpandedNameMap::add(const txExpandedName& aKey, TxObject* aValue)
{ {
int i; int i;
// Check if there already is an item with this key // Check if there already is an item with this key
@ -88,6 +88,7 @@ nsresult txExpandedNameMap::add(txExpandedName& aKey, TxObject* aValue)
mItems[mItemCount].mNamespaceID = aKey.mNamespaceID; mItems[mItemCount].mNamespaceID = aKey.mNamespaceID;
mItems[mItemCount].mLocalName = aKey.mLocalName; mItems[mItemCount].mLocalName = aKey.mLocalName;
TX_IF_ADDREF_ATOM(mItems[mItemCount].mLocalName);
mItems[mItemCount].mValue = aValue; mItems[mItemCount].mValue = aValue;
++mItemCount; ++mItemCount;
@ -101,7 +102,7 @@ nsresult txExpandedNameMap::add(txExpandedName& aKey, TxObject* aValue)
* @param aValue value of item to set * @param aValue value of item to set
* @return errorcode * @return errorcode
*/ */
nsresult txExpandedNameMap::set(txExpandedName& aKey, TxObject* aValue) nsresult txExpandedNameMap::set(const txExpandedName& aKey, TxObject* aValue)
{ {
int i; int i;
// Check if there already is an item with this key // Check if there already is an item with this key
@ -129,6 +130,7 @@ nsresult txExpandedNameMap::set(txExpandedName& aKey, TxObject* aValue)
mItems[mItemCount].mNamespaceID = aKey.mNamespaceID; mItems[mItemCount].mNamespaceID = aKey.mNamespaceID;
mItems[mItemCount].mLocalName = aKey.mLocalName; mItems[mItemCount].mLocalName = aKey.mLocalName;
TX_IF_ADDREF_ATOM(mItems[mItemCount].mLocalName);
mItems[mItemCount].mValue = aValue; mItems[mItemCount].mValue = aValue;
++mItemCount; ++mItemCount;
@ -140,7 +142,7 @@ nsresult txExpandedNameMap::set(txExpandedName& aKey, TxObject* aValue)
* @param aKey key for item to get * @param aKey key for item to get
* @return item with specified key, or null if no such item exists * @return item with specified key, or null if no such item exists
*/ */
TxObject* txExpandedNameMap::get(txExpandedName& aKey) TxObject* txExpandedNameMap::get(const txExpandedName& aKey)
{ {
int i; int i;
for (i = 0; i < mItemCount; ++i) { for (i = 0; i < mItemCount; ++i) {

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

@ -56,7 +56,7 @@ public:
* @param aValue value of item to add * @param aValue value of item to add
* @return errorcode * @return errorcode
*/ */
nsresult add(txExpandedName& aKey, TxObject* aValue); nsresult add(const txExpandedName& aKey, TxObject* aValue);
/* /*
* Sets an item, if an item with this key already exists it is overwritten * Sets an item, if an item with this key already exists it is overwritten
@ -65,14 +65,14 @@ public:
* @param aValue value of item to set * @param aValue value of item to set
* @return errorcode * @return errorcode
*/ */
nsresult set(txExpandedName& aKey, TxObject* aValue); nsresult set(const txExpandedName& aKey, TxObject* aValue);
/* /*
* Gets an item * Gets an item
* @param aKey key for item to get * @param aKey key for item to get
* @return item with specified key, or null if no such item exists * @return item with specified key, or null if no such item exists
*/ */
TxObject* get(txExpandedName& aKey); TxObject* get(const txExpandedName& aKey);
class iterator { class iterator {
public: public:

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

@ -53,7 +53,9 @@
ProcessorState::ProcessorState(Document* aSourceDocument, ProcessorState::ProcessorState(Document* aSourceDocument,
Document* aXslDocument, Document* aXslDocument,
Document* aResultDocument) Document* aResultDocument)
: mEvalContext(0), : mXslKeys(MB_TRUE),
mDecimalFormats(MB_TRUE),
mEvalContext(0),
mSourceDocument(aSourceDocument), mSourceDocument(aSourceDocument),
xslDocument(aXslDocument), xslDocument(aXslDocument),
resultDocument(aResultDocument) resultDocument(aResultDocument)
@ -82,16 +84,8 @@ ProcessorState::ProcessorState(Document* aSourceDocument,
loadedDocuments.put(xslDocument->getBaseURI(), xslDocument); loadedDocuments.put(xslDocument->getBaseURI(), xslDocument);
} }
// make sure all keys are deleted
xslKeys.setObjectDeletion(MB_TRUE);
// Make sure all loaded documents get deleted // Make sure all loaded documents get deleted
loadedDocuments.setObjectDeletion(MB_TRUE); loadedDocuments.setObjectDeletion(MB_TRUE);
// add predefined default decimal format
defaultDecimalFormatSet = MB_FALSE;
decimalFormats.put(String(), new txDecimalFormat);
decimalFormats.setObjectDeletion(MB_TRUE);
} }
/** /**
@ -130,10 +124,12 @@ void ProcessorState::addAttributeSet(Element* aAttributeSet,
if (!aAttributeSet) if (!aAttributeSet)
return; return;
String name; String nameStr;
if (!aAttributeSet->getAttr(txXSLTAtoms::name, txExpandedName name;
kNameSpaceID_None, name)) { aAttributeSet->getAttr(txXSLTAtoms::name, kNameSpaceID_None, nameStr);
String err("missing required name attribute for xsl:attribute-set"); nsresult rv = name.init(nameStr, aAttributeSet, MB_FALSE);
if (NS_FAILED(rv)) {
String err("missing or malformed name for xsl:attribute-set");
receiveError(err); receiveError(err);
return; return;
} }
@ -141,7 +137,7 @@ void ProcessorState::addAttributeSet(Element* aAttributeSet,
NodeSet* attSet = (NodeSet*)aImportFrame->mNamedAttributeSets.get(name); NodeSet* attSet = (NodeSet*)aImportFrame->mNamedAttributeSets.get(name);
if (!attSet) { if (!attSet) {
attSet = new NodeSet(); attSet = new NodeSet();
aImportFrame->mNamedAttributeSets.put(name, attSet); aImportFrame->mNamedAttributeSets.add(name, attSet);
} }
// Add xsl:attribute elements to attSet // Add xsl:attribute elements to attSet
@ -179,18 +175,28 @@ void ProcessorState::addTemplate(Element* aXslTemplate,
{ {
NS_ASSERTION(aXslTemplate, "missing template"); NS_ASSERTION(aXslTemplate, "missing template");
String name; nsresult rv = NS_OK;
String nameStr;
if (aXslTemplate->getAttr(txXSLTAtoms::name, if (aXslTemplate->getAttr(txXSLTAtoms::name,
kNameSpaceID_None, name)) { kNameSpaceID_None, nameStr)) {
// check for duplicates txExpandedName name;
Element* tmp = (Element*)aImportFrame->mNamedTemplates.get(name); rv = name.init(nameStr, aXslTemplate, MB_FALSE);
if (tmp) { if (NS_FAILED(rv)) {
String err("Duplicate template name: "); String err("missing or malformed template name: '");
err.append(name); err.append(nameStr);
receiveError(err); err.append('\'');
receiveError(err, NS_ERROR_FAILURE);
return;
}
rv = aImportFrame->mNamedTemplates.add(name, aXslTemplate);
if (NS_FAILED(rv)) {
String err("Unable to add template named '");
err.append(nameStr);
err.append("'. Does that name already exist?");
receiveError(err, NS_ERROR_FAILURE);
return; return;
} }
aImportFrame->mNamedTemplates.put(name, aXslTemplate);
} }
String match; String match;
@ -198,9 +204,20 @@ void ProcessorState::addTemplate(Element* aXslTemplate,
// This is no error, see section 6 Named Templates // This is no error, see section 6 Named Templates
return; return;
} }
// get the txList for the right mode // get the txList for the right mode
String mode; String modeStr;
aXslTemplate->getAttr(txXSLTAtoms::mode, kNameSpaceID_None, mode); txExpandedName mode;
if (aXslTemplate->getAttr(txXSLTAtoms::mode, kNameSpaceID_None, modeStr)) {
rv = mode.init(modeStr, aXslTemplate, MB_FALSE);
if (NS_FAILED(rv)) {
String err("malformed template-mode name: '");
err.append(modeStr);
err.append('\'');
receiveError(err, NS_ERROR_FAILURE);
return;
}
}
txList* templates = txList* templates =
(txList*)aImportFrame->mMatchableTemplates.get(mode); (txList*)aImportFrame->mMatchableTemplates.get(mode);
@ -210,7 +227,11 @@ void ProcessorState::addTemplate(Element* aXslTemplate,
NS_ASSERTION(0, "out of memory"); NS_ASSERTION(0, "out of memory");
return; return;
} }
aImportFrame->mMatchableTemplates.put(mode, templates); rv = aImportFrame->mMatchableTemplates.add(mode, templates);
if (NS_FAILED(rv)) {
delete templates;
return;
}
} }
// Check for explicit default priority // Check for explicit default priority
@ -284,8 +305,9 @@ void ProcessorState::addLREStylesheet(Document* aStylesheet,
NS_ASSERTION(aStylesheet, "missing stylesheet"); NS_ASSERTION(aStylesheet, "missing stylesheet");
// get the txList for null mode // get the txList for null mode
txExpandedName nullMode;
txList* templates = txList* templates =
(txList*)aImportFrame->mMatchableTemplates.get(NULL_STRING); (txList*)aImportFrame->mMatchableTemplates.get(nullMode);
if (!templates) { if (!templates) {
templates = new txList; templates = new txList;
@ -293,14 +315,14 @@ void ProcessorState::addLREStylesheet(Document* aStylesheet,
// XXX ErrorReport: out of memory // XXX ErrorReport: out of memory
return; return;
} }
aImportFrame->mMatchableTemplates.put(NULL_STRING, templates); aImportFrame->mMatchableTemplates.add(nullMode, templates);
} }
// Add the template to the list of templates // Add the template to the list of templates
txPattern* root = new txRootPattern(MB_TRUE); txPattern* root = new txRootPattern(MB_TRUE);
MatchableTemplate* nt = 0; MatchableTemplate* nt = 0;
if (root) if (root)
nt = new MatchableTemplate(aStylesheet, root, Double::NaN); nt = new MatchableTemplate(aStylesheet, root, 0.5);
if (!nt) { if (!nt) {
delete root; delete root;
// XXX ErrorReport: out of memory // XXX ErrorReport: out of memory
@ -383,21 +405,6 @@ List* ProcessorState::getImportFrames()
return &mImportFrames; return &mImportFrames;
} }
/*
* Find template in specified mode matching the supplied node
* @param aNode node to find matching template for
* @param aMode mode of the template
* @param aImportFrame out-param, is set to the ImportFrame containing
* the found template
* @return root-node of found template, null if none is found
*/
Node* ProcessorState::findTemplate(Node* aNode,
const String& aMode,
ImportFrame** aImportFrame)
{
return findTemplate(aNode, aMode, 0, aImportFrame);
}
/* /*
* Find template in specified mode matching the supplied node. Only search * Find template in specified mode matching the supplied node. Only search
* templates imported by a specific ImportFrame * templates imported by a specific ImportFrame
@ -410,7 +417,7 @@ Node* ProcessorState::findTemplate(Node* aNode,
* @return root-node of found template, null if none is found * @return root-node of found template, null if none is found
*/ */
Node* ProcessorState::findTemplate(Node* aNode, Node* ProcessorState::findTemplate(Node* aNode,
const String& aMode, const txExpandedName& aMode,
ImportFrame* aImportedBy, ImportFrame* aImportedBy,
ImportFrame** aImportFrame) ImportFrame** aImportFrame)
{ {
@ -463,13 +470,17 @@ Node* ProcessorState::findTemplate(Node* aNode,
#ifdef PR_LOGGING #ifdef PR_LOGGING
char *nodeBuf = 0, *modeBuf = 0; char *nodeBuf = 0, *modeBuf = 0;
String mode;
if (aMode.mLocalName) {
TX_GET_ATOM_STRING(aMode.mLocalName, mode);
}
if (matchTemplate) { if (matchTemplate) {
char *matchBuf = 0, *uriBuf = 0; char *matchBuf = 0, *uriBuf = 0;
PR_LOG(txLog::xslt, PR_LOG_DEBUG, PR_LOG(txLog::xslt, PR_LOG_DEBUG,
("MatchTemplate, Pattern %s, Mode %s, Stylesheet %s, " \ ("MatchTemplate, Pattern %s, Mode %s, Stylesheet %s, " \
"Node %s\n", "Node %s\n",
(matchBuf = ((Element*)matchTemplate)->getAttribute(String("match")).toCharArray()), (matchBuf = ((Element*)matchTemplate)->getAttribute(String("match")).toCharArray()),
(modeBuf = aMode.toCharArray()), (modeBuf = mode.toCharArray()),
(uriBuf = matchTemplate->getBaseURI().toCharArray()), (uriBuf = matchTemplate->getBaseURI().toCharArray()),
(nodeBuf = aNode->getNodeName().toCharArray()))); (nodeBuf = aNode->getNodeName().toCharArray())));
#ifdef TX_EXE #ifdef TX_EXE
@ -484,7 +495,7 @@ Node* ProcessorState::findTemplate(Node* aNode,
PR_LOG(txLog::xslt, PR_LOG_DEBUG, PR_LOG(txLog::xslt, PR_LOG_DEBUG,
("No match, Node %s, Mode %s\n", ("No match, Node %s, Mode %s\n",
(nodeBuf = aNode->getNodeName().toCharArray()), (nodeBuf = aNode->getNodeName().toCharArray()),
(modeBuf = aMode.toCharArray()))); (modeBuf = mode.toCharArray())));
} }
#ifdef TX_EXE #ifdef TX_EXE
delete [] nodeBuf; delete [] nodeBuf;
@ -517,7 +528,7 @@ void ProcessorState::setCurrentTemplateRule(TemplateRule* aTemplateRule)
* Returns the AttributeSet associated with the given name * Returns the AttributeSet associated with the given name
* or null if no AttributeSet is found * or null if no AttributeSet is found
*/ */
NodeSet* ProcessorState::getAttributeSet(const String& aName) NodeSet* ProcessorState::getAttributeSet(const txExpandedName& aName)
{ {
NodeSet* attset = new NodeSet; NodeSet* attset = new NodeSet;
if (!attset) if (!attset)
@ -586,7 +597,7 @@ txPattern* ProcessorState::getPattern(Element* aElem, PatternAttr aAttr)
return pattern; return pattern;
} }
String attr; String attr;
MBool hasAttr; MBool hasAttr = MB_FALSE;
switch (aAttr) { switch (aAttr) {
case CountAttr: case CountAttr:
hasAttr = aElem->getAttr(txXSLTAtoms::count, kNameSpaceID_None, hasAttr = aElem->getAttr(txXSLTAtoms::count, kNameSpaceID_None,
@ -620,7 +631,7 @@ txPattern* ProcessorState::getPattern(Element* aElem, PatternAttr aAttr)
* Returns the template associated with the given name, or * Returns the template associated with the given name, or
* null if not template is found * null if not template is found
*/ */
Element* ProcessorState::getNamedTemplate(String& aName) Element* ProcessorState::getNamedTemplate(const txExpandedName& aName)
{ {
ImportFrame* frame; ImportFrame* frame;
txListIterator frameIter(&mImportFrames); txListIterator frameIter(&mImportFrames);
@ -735,16 +746,22 @@ void ProcessorState::shouldStripSpace(String& aNames, Element* aElement,
**/ **/
MBool ProcessorState::addKey(Element* aKeyElem) MBool ProcessorState::addKey(Element* aKeyElem)
{ {
String keyName; nsresult rv = NS_OK;
aKeyElem->getAttr(txXSLTAtoms::name, kNameSpaceID_None, keyName); String keyQName;
if (!XMLUtils::isValidQName(keyName)) aKeyElem->getAttr(txXSLTAtoms::name, kNameSpaceID_None, keyQName);
txExpandedName keyName;
rv = keyName.init(keyQName, aKeyElem, MB_FALSE);
if (NS_FAILED(rv))
return MB_FALSE; return MB_FALSE;
txXSLKey* xslKey = (txXSLKey*)xslKeys.get(keyName);
txXSLKey* xslKey = (txXSLKey*)mXslKeys.get(keyName);
if (!xslKey) { if (!xslKey) {
xslKey = new txXSLKey(this); xslKey = new txXSLKey(this);
if (!xslKey) if (!xslKey)
return MB_FALSE; return MB_FALSE;
xslKeys.put(keyName, xslKey); rv = mXslKeys.add(keyName, xslKey);
if (NS_FAILED(rv))
return MB_FALSE;
} }
txPattern* match = 0; txPattern* match = 0;
txPSParseContext pContext(this, aKeyElem); txPSParseContext pContext(this, aKeyElem);
@ -769,8 +786,9 @@ MBool ProcessorState::addKey(Element* aKeyElem)
* Adds the supplied xsl:key to the set of keys * Adds the supplied xsl:key to the set of keys
* returns NULL if no such key exists * returns NULL if no such key exists
**/ **/
txXSLKey* ProcessorState::getKey(String& keyName) { txXSLKey* ProcessorState::getKey(txExpandedName& keyName)
return (txXSLKey*)xslKeys.get(keyName); {
return (txXSLKey*)mXslKeys.get(keyName);
} }
/* /*
@ -780,13 +798,20 @@ txXSLKey* ProcessorState::getKey(String& keyName) {
MBool ProcessorState::addDecimalFormat(Element* element) MBool ProcessorState::addDecimalFormat(Element* element)
{ {
// build new DecimalFormat structure // build new DecimalFormat structure
nsresult rv = NS_OK;
MBool success = MB_TRUE; MBool success = MB_TRUE;
txDecimalFormat* format = new txDecimalFormat; txDecimalFormat* format = new txDecimalFormat;
if (!format) if (!format)
return MB_FALSE; return MB_FALSE;
String formatName, attValue; String formatNameStr, attValue;
element->getAttr(txXSLTAtoms::name, kNameSpaceID_None, formatName); txExpandedName formatName;
if (element->getAttr(txXSLTAtoms::name, kNameSpaceID_None,
formatNameStr)) {
rv = formatName.init(formatNameStr, element, MB_FALSE);
if (NS_FAILED(rv))
return MB_FALSE;
}
if (element->getAttr(txXSLTAtoms::decimalSeparator, if (element->getAttr(txXSLTAtoms::decimalSeparator,
kNameSpaceID_None, attValue)) { kNameSpaceID_None, attValue)) {
@ -866,26 +891,18 @@ MBool ProcessorState::addDecimalFormat(Element* element)
} }
// Does an existing format with that name exist? // Does an existing format with that name exist?
// (name="" means default format) txDecimalFormat* existing =
(txDecimalFormat*)mDecimalFormats.get(formatName);
txDecimalFormat* existing = NULL;
if (defaultDecimalFormatSet || !formatName.isEmpty()) {
existing = (txDecimalFormat*)decimalFormats.get(formatName);
}
else {
// We are overriding the predefined default format which is always
// allowed
delete decimalFormats.remove(formatName);
defaultDecimalFormatSet = MB_TRUE;
}
if (existing) { if (existing) {
success = existing->isEqual(format); success = existing->isEqual(format);
delete format; delete format;
} }
else { else {
decimalFormats.put(formatName, format); rv = mDecimalFormats.add(formatName, format);
if (NS_FAILED(rv)) {
delete format;
success = MB_FALSE;
}
} }
return success; return success;
@ -894,9 +911,13 @@ MBool ProcessorState::addDecimalFormat(Element* element)
/* /*
* Returns a decimal format or NULL if no such format exists. * Returns a decimal format or NULL if no such format exists.
*/ */
txDecimalFormat* ProcessorState::getDecimalFormat(String& name) txDecimalFormat* ProcessorState::getDecimalFormat(const txExpandedName& aName)
{ {
return (txDecimalFormat*)decimalFormats.get(name); txDecimalFormat* format = (txDecimalFormat*)mDecimalFormats.get(aName);
if (!format && !aName.mLocalName &&
aName.mNamespaceID == kNameSpaceID_None)
return &mDefaultDecimalFormat;
return format;
} }
/** /**
@ -1006,11 +1027,11 @@ nsresult ProcessorState::resolveFunctionCall(txAtom* aName, PRInt32 aID,
return NS_OK; return NS_OK;
} }
if (CHECK_FN(key)) { if (CHECK_FN(key)) {
aFunction = new txKeyFunctionCall(this); aFunction = new txKeyFunctionCall(this, aElem);
return NS_OK; return NS_OK;
} }
if (CHECK_FN(formatNumber)) { if (CHECK_FN(formatNumber)) {
aFunction = new txFormatNumberFunctionCall(this); aFunction = new txFormatNumberFunctionCall(this, aElem);
return NS_OK; return NS_OK;
} }
if (CHECK_FN(current)) { if (CHECK_FN(current)) {
@ -1081,9 +1102,11 @@ ProcessorState::XMLSpaceMode ProcessorState::getXMLSpaceMode(Node* aNode)
} }
ProcessorState::ImportFrame::ImportFrame(ImportFrame* aFirstNotImported) ProcessorState::ImportFrame::ImportFrame(ImportFrame* aFirstNotImported)
: mNamedTemplates(MB_FALSE),
mMatchableTemplates(MB_TRUE),
mNamedAttributeSets(MB_TRUE),
mFirstNotImported(aFirstNotImported)
{ {
mNamedAttributeSets.setObjectDeletion(MB_TRUE);
mFirstNotImported = aFirstNotImported;
} }
ProcessorState::ImportFrame::~ImportFrame() ProcessorState::ImportFrame::~ImportFrame()
@ -1094,23 +1117,16 @@ ProcessorState::ImportFrame::~ImportFrame()
delete (txNameTestItem*)whiteIter.next(); delete (txNameTestItem*)whiteIter.next();
// Delete templates in mMatchableTemplates // Delete templates in mMatchableTemplates
StringList* templKeys = mMatchableTemplates.keys(); txExpandedNameMap::iterator iter(mMatchableTemplates);
if (templKeys) { while (iter.next()) {
StringListIterator keysIter(templKeys); txListIterator templIter((txList*)iter.value());
String* key;
while ((key = keysIter.next())) {
txList* templList = (txList*)mMatchableTemplates.get(*key);
txListIterator templIter(templList);
MatchableTemplate* templ; MatchableTemplate* templ;
while ((templ = (MatchableTemplate*)templIter.next())) { while ((templ = (MatchableTemplate*)templIter.next())) {
delete templ->mMatch; delete templ->mMatch;
delete templ; delete templ;
} }
delete templList;
} }
} }
delete templKeys;
}
/* /*
* txPSParseContext * txPSParseContext

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

@ -39,9 +39,10 @@
#include "txOutputFormat.h" #include "txOutputFormat.h"
#include "Map.h" #include "Map.h"
#include "txIXPathContext.h" #include "txIXPathContext.h"
#include "txExpandedNameMap.h"
#include "XSLTFunctions.h"
class txXSLKey; class txXSLKey;
class txDecimalFormat;
/** /**
* Class used for keeping the current state of the XSL Processor * Class used for keeping the current state of the XSL Processor
@ -71,17 +72,17 @@ public:
~ImportFrame(); ~ImportFrame();
// Map of named templates // Map of named templates
NamedMap mNamedTemplates; txExpandedNameMap mNamedTemplates;
// Map of template modes, each item in the map is a list // Map of template modes, each item in the map is a list
// of templates // of templates
NamedMap mMatchableTemplates; txExpandedNameMap mMatchableTemplates;
// List of whitespace preserving and stripping nametests // List of whitespace preserving and stripping nametests
txList mWhiteNameTests; txList mWhiteNameTests;
// Map of named attribute sets // Map of named attribute sets
NamedMap mNamedAttributeSets; txExpandedNameMap mNamedAttributeSets;
// Output format, as specified by the xsl:output elements // Output format, as specified by the xsl:output elements
txOutputFormat mOutputFormat; txOutputFormat mOutputFormat;
@ -128,7 +129,7 @@ public:
* Returns the AttributeSet associated with the given name * Returns the AttributeSet associated with the given name
* or null if no AttributeSet is found * or null if no AttributeSet is found
**/ **/
NodeSet* getAttributeSet(const String& aName); NodeSet* getAttributeSet(const txExpandedName& aName);
/** /**
* Returns the source node currently being processed * Returns the source node currently being processed
@ -139,7 +140,7 @@ public:
* Returns the template associated with the given name, or * Returns the template associated with the given name, or
* null if not template is found * null if not template is found
*/ */
Element* getNamedTemplate(String& aName); Element* getNamedTemplate(const txExpandedName& aName);
/** /**
* Returns the OutputFormat which contains information on how * Returns the OutputFormat which contains information on how
@ -203,8 +204,11 @@ public:
* @return root-node of found template, null if none is found * @return root-node of found template, null if none is found
*/ */
Node* findTemplate(Node* aNode, Node* findTemplate(Node* aNode,
const String& aMode, const txExpandedName& aMode,
ImportFrame** aImportFrame); ImportFrame** aImportFrame)
{
return findTemplate(aNode, aMode, 0, aImportFrame);
}
/* /*
* Find template in specified mode matching the supplied node. Only search * Find template in specified mode matching the supplied node. Only search
@ -218,7 +222,7 @@ public:
* @return root-node of found template, null if none is found * @return root-node of found template, null if none is found
*/ */
Node* findTemplate(Node* aNode, Node* findTemplate(Node* aNode,
const String& aMode, const txExpandedName& aMode,
ImportFrame* aImportedBy, ImportFrame* aImportedBy,
ImportFrame** aImportFrame); ImportFrame** aImportFrame);
@ -227,7 +231,7 @@ public:
*/ */
struct TemplateRule { struct TemplateRule {
ImportFrame* mFrame; ImportFrame* mFrame;
const String* mMode; const txExpandedName* mMode;
NamedMap* mParams; NamedMap* mParams;
}; };
@ -274,7 +278,7 @@ public:
* Returns the key with the supplied name * Returns the key with the supplied name
* returns NULL if no such key exists * returns NULL if no such key exists
**/ **/
txXSLKey* getKey(String& keyName); txXSLKey* getKey(txExpandedName& keyName);
/* /*
* Adds a decimal format. Returns false if the format already exists * Adds a decimal format. Returns false if the format already exists
@ -285,7 +289,7 @@ public:
/** /**
* Returns a decimal format or NULL if no such format exists. * Returns a decimal format or NULL if no such format exists.
**/ **/
txDecimalFormat* getDecimalFormat(String& name); txDecimalFormat* getDecimalFormat(const txExpandedName& name);
/* /*
* Virtual methods from txIEvalContext * Virtual methods from txIEvalContext
@ -372,18 +376,17 @@ private:
/** /**
* The set of all available keys * The set of all available keys
**/ **/
NamedMap xslKeys; txExpandedNameMap mXslKeys;
/* /*
* A list of all avalible decimalformats * The set of all avalible decimalformats
*/ */
NamedMap decimalFormats; txExpandedNameMap mDecimalFormats;
/* /*
* bool indicating if the default decimal format has been explicitly set * Default decimal-format
* by the stylesheet
*/ */
MBool defaultDecimalFormatSet; txDecimalFormat mDefaultDecimalFormat;
/* /*
* List of hashes with parsed expression. Every listitem holds the * List of hashes with parsed expression. Every listitem holds the

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

@ -1018,14 +1018,16 @@ void XSLTProcessor::process(Node* node,
return; return;
ProcessorState::ImportFrame *frame; ProcessorState::ImportFrame *frame;
Node* xslTemplate = ps->findTemplate(node, mode, &frame); txExpandedName nullMode;
processMatchedTemplate(xslTemplate, node, 0, NULL_STRING, frame, ps); Node* xslTemplate = ps->findTemplate(node, nullMode, &frame);
processMatchedTemplate(xslTemplate, node, 0, nullMode, frame, ps);
} //-- process } //-- process
void XSLTProcessor::processAction(Node* aNode, void XSLTProcessor::processAction(Node* aNode,
Node* aXSLTAction, Node* aXSLTAction,
ProcessorState* aPs) ProcessorState* aPs)
{ {
nsresult rv = NS_OK;
NS_ASSERTION(aXSLTAction, "We need an action to process."); NS_ASSERTION(aXSLTAction, "We need an action to process.");
if (!aXSLTAction) if (!aXSLTAction)
return; return;
@ -1152,9 +1154,20 @@ void XSLTProcessor::processAction(Node* aNode,
// Process xsl:with-param elements // Process xsl:with-param elements
NamedMap* actualParams = processParameters(actionElement, aNode, aPs); NamedMap* actualParams = processParameters(actionElement, aNode, aPs);
String mode; // Get mode
actionElement->getAttr(txXSLTAtoms::mode, String modeStr;
kNameSpaceID_None, mode); txExpandedName mode;
if (actionElement->getAttr(txXSLTAtoms::mode,
kNameSpaceID_None, modeStr)) {
rv = mode.init(modeStr, actionElement, MB_FALSE);
if (NS_FAILED(rv)) {
String err("malformed mode-name in xsl:apply-templates");
aPs->receiveError(err);
TX_IF_RELEASE_ATOM(localName);
delete actualParams;
return;
}
}
txNodeSetContext evalContext(nodeSet, aPs); txNodeSetContext evalContext(nodeSet, aPs);
txIEvalContext* priorEC = txIEvalContext* priorEC =
@ -1255,16 +1268,20 @@ void XSLTProcessor::processAction(Node* aNode,
} }
// xsl:call-template // xsl:call-template
else if (localName == txXSLTAtoms::callTemplate) { else if (localName == txXSLTAtoms::callTemplate) {
String templateName; String nameStr;
if (actionElement->getAttr(txXSLTAtoms::name, txExpandedName templateName;
kNameSpaceID_None, templateName)) { actionElement->getAttr(txXSLTAtoms::name,
kNameSpaceID_None, nameStr);
rv = templateName.init(nameStr, actionElement, MB_FALSE);
if (NS_SUCCEEDED(rv)) {
Element* xslTemplate = aPs->getNamedTemplate(templateName); Element* xslTemplate = aPs->getNamedTemplate(templateName);
if (xslTemplate) { if (xslTemplate) {
#ifdef PR_LOGGING #ifdef PR_LOGGING
char *nameBuf = 0, *uriBuf = 0; char *nameBuf = 0, *uriBuf = 0;
PR_LOG(txLog::xslt, PR_LOG_DEBUG, PR_LOG(txLog::xslt, PR_LOG_DEBUG,
("CallTemplate, Name %s, Stylesheet %s\n", ("CallTemplate, Name %s, Stylesheet %s\n",
(nameBuf = templateName.toCharArray()), (nameBuf = nameStr.toCharArray()),
(uriBuf = xslTemplate->getBaseURI().toCharArray()))); (uriBuf = xslTemplate->getBaseURI().toCharArray())));
delete nameBuf; delete nameBuf;
delete uriBuf; delete uriBuf;
@ -1275,7 +1292,7 @@ void XSLTProcessor::processAction(Node* aNode,
} }
} }
else { else {
String err("missing required name attribute for xsl:call-template"); String err("missing or malformed name in xsl:call-template");
aPs->receiveError(err, NS_ERROR_FAILURE); aPs->receiveError(err, NS_ERROR_FAILURE);
} }
} }
@ -1507,7 +1524,6 @@ void XSLTProcessor::processAction(Node* aNode,
#ifdef TX_EXE #ifdef TX_EXE
cout << "xsl:message - "<< message << endl; cout << "xsl:message - "<< message << endl;
#else #else
nsresult rv;
nsCOMPtr<nsIConsoleService> consoleSvc = nsCOMPtr<nsIConsoleService> consoleSvc =
do_GetService("@mozilla.org/consoleservice;1", &rv); do_GetService("@mozilla.org/consoleservice;1", &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "xsl:message couldn't get console service"); NS_ASSERTION(NS_SUCCEEDED(rv), "xsl:message couldn't get console service");
@ -1640,6 +1656,7 @@ void XSLTProcessor::processAction(Node* aNode,
**/ **/
void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode, ProcessorState* aPs) void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode, ProcessorState* aPs)
{ {
nsresult rv = NS_OK;
String names; String names;
PRInt32 namespaceID; PRInt32 namespaceID;
if (aElement->getNamespaceID() == kNameSpaceID_XSLT) if (aElement->getNamespaceID() == kNameSpaceID_XSLT)
@ -1651,15 +1668,25 @@ void XSLTProcessor::processAttributeSets(Element* aElement, Node* aNode, Process
// Split names // Split names
txTokenizer tokenizer(names); txTokenizer tokenizer(names);
String name; String nameStr;
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
tokenizer.nextToken(name); tokenizer.nextToken(nameStr);
txExpandedName name;
rv = name.init(nameStr, aElement, MB_FALSE);
if (NS_FAILED(rv)) {
String err("missing or malformed name in use-attribute-sets");
aPs->receiveError(err);
return;
}
txStackIterator attributeSets(&mAttributeSetStack); txStackIterator attributeSets(&mAttributeSetStack);
while (attributeSets.hasNext()) { while (attributeSets.hasNext()) {
String* test = (String*)attributeSets.next(); if (name == *(txExpandedName*)attributeSets.next()) {
if (test->isEqual(name)) String err("circular inclusion detected in use-attribute-sets");
aPs->receiveError(err);
return; return;
} }
}
NodeSet* attSet = aPs->getAttributeSet(name); NodeSet* attSet = aPs->getAttributeSet(name);
if (attSet) { if (attSet) {
@ -1835,7 +1862,7 @@ void XSLTProcessor::processTemplate(Node* node, Node* xslTemplate, ProcessorStat
void XSLTProcessor::processMatchedTemplate(Node* aXslTemplate, void XSLTProcessor::processMatchedTemplate(Node* aXslTemplate,
Node* aNode, Node* aNode,
NamedMap* aParams, NamedMap* aParams,
const String& aMode, const txExpandedName& aMode,
ProcessorState::ImportFrame* aFrame, ProcessorState::ImportFrame* aFrame,
ProcessorState* aPs) ProcessorState* aPs)
{ {
@ -1864,7 +1891,7 @@ void XSLTProcessor::processMatchedTemplate(Node* aXslTemplate,
**/ **/
void XSLTProcessor::processDefaultTemplate(Node* node, void XSLTProcessor::processDefaultTemplate(Node* node,
ProcessorState* ps, ProcessorState* ps,
const String& mode) const txExpandedName& mode)
{ {
NS_ASSERTION(node, "context node is NULL in call to XSLTProcessor::processTemplate!"); NS_ASSERTION(node, "context node is NULL in call to XSLTProcessor::processTemplate!");

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

@ -298,7 +298,7 @@ private:
void processMatchedTemplate(Node* aXslTemplate, void processMatchedTemplate(Node* aXslTemplate,
Node* aNode, Node* aNode,
NamedMap* aParams, NamedMap* aParams,
const String& aMode, const txExpandedName& aMode,
ProcessorState::ImportFrame* aFrame, ProcessorState::ImportFrame* aFrame,
ProcessorState* aPs); ProcessorState* aPs);
/** /**
@ -309,7 +309,7 @@ private:
**/ **/
void processDefaultTemplate(Node* node, void processDefaultTemplate(Node* node,
ProcessorState* ps, ProcessorState* ps,
const String& mode); const txExpandedName& mode);
void processStylesheet(Document* aSource, void processStylesheet(Document* aSource,
Document* aStylesheet, Document* aStylesheet,

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

@ -1,4 +1,5 @@
#include "XSLTFunctions.h" #include "XSLTFunctions.h"
#include "ProcessorState.h"
#include "Names.h" #include "Names.h"
/* /*

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

@ -37,6 +37,7 @@
*/ */
#include "XSLTFunctions.h" #include "XSLTFunctions.h"
#include "ProcessorState.h"
#include "XMLDOMUtils.h" #include "XMLDOMUtils.h"
#include "Names.h" #include "Names.h"
#include "txIXPathContext.h" #include "txIXPathContext.h"

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

@ -1,4 +1,5 @@
#include "XSLTFunctions.h" #include "XSLTFunctions.h"
#include "ProcessorState.h"
#include "XMLUtils.h" #include "XMLUtils.h"
#include "Names.h" #include "Names.h"
#include "txIXPathContext.h" #include "txIXPathContext.h"

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

@ -34,10 +34,12 @@
#include "Expr.h" #include "Expr.h"
#include "ExprResult.h" #include "ExprResult.h"
#include "TxString.h" #include "TxString.h"
#include "ProcessorState.h"
#include "Map.h" #include "Map.h"
#include "NamedMap.h"
#include "List.h" #include "List.h"
#include "txXSLTPatterns.h"
class ProcessorState;
/** /**
* The definition for the XSLT document() function * The definition for the XSLT document() function
**/ **/
@ -70,7 +72,7 @@ public:
/* /*
* Creates a new key() function call * Creates a new key() function call
*/ */
txKeyFunctionCall(ProcessorState* aPs); txKeyFunctionCall(ProcessorState* aPs, Node* aQNameResolveNode);
/* /*
* Evaluates a key() xslt-functioncall. First argument is name of key * Evaluates a key() xslt-functioncall. First argument is name of key
@ -82,6 +84,7 @@ public:
private: private:
ProcessorState* mProcessorState; ProcessorState* mProcessorState;
Node* mQNameResolveNode;
}; };
/* /*
@ -181,7 +184,7 @@ public:
/** /**
* Creates a new format-number() function call * Creates a new format-number() function call
**/ **/
txFormatNumberFunctionCall(ProcessorState* aPs); txFormatNumberFunctionCall(ProcessorState* aPs, Node* aQNameResolveNode);
/** /**
* Virtual function from FunctionCall * Virtual function from FunctionCall
@ -202,6 +205,7 @@ private:
}; };
ProcessorState* mPs; ProcessorState* mPs;
Node* mQNameResolveNode;
}; };
/** /**

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

@ -37,6 +37,7 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "XSLTFunctions.h" #include "XSLTFunctions.h"
#include "ProcessorState.h"
#include "primitives.h" #include "primitives.h"
#include "Names.h" #include "Names.h"
#include "txIXPathContext.h" #include "txIXPathContext.h"
@ -58,10 +59,12 @@ const UNICODE_CHAR txFormatNumberFunctionCall::FORMAT_QUOTE = '\'';
/* /*
* Creates a new format-number function call * Creates a new format-number function call
*/ */
txFormatNumberFunctionCall::txFormatNumberFunctionCall(ProcessorState* aPs) : txFormatNumberFunctionCall::txFormatNumberFunctionCall(ProcessorState* aPs,
FunctionCall(FORMAT_NUMBER_FN) Node* aQNameResolveNode)
: FunctionCall(FORMAT_NUMBER_FN),
mPs(aPs),
mQNameResolveNode(aQNameResolveNode)
{ {
mPs = aPs;
} }
/* /*
@ -73,6 +76,7 @@ txFormatNumberFunctionCall::txFormatNumberFunctionCall(ProcessorState* aPs) :
*/ */
ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext) ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
{ {
nsresult rv = NS_OK;
if (!requireParams(2, 3, aContext)) if (!requireParams(2, 3, aContext))
return new StringResult(); return new StringResult();
@ -81,12 +85,17 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
double value; double value;
String formatStr; String formatStr;
String formatName; txExpandedName formatName;
value = evaluateToNumber((Expr*)iter.next(), aContext); value = evaluateToNumber((Expr*)iter.next(), aContext);
evaluateToString((Expr*)iter.next(), aContext, formatStr); evaluateToString((Expr*)iter.next(), aContext, formatStr);
if (iter.hasNext()) if (iter.hasNext()) {
evaluateToString((Expr*)iter.next(), aContext, formatName); String formatQName;
evaluateToString((Expr*)iter.next(), aContext, formatQName);
rv = formatName.init(formatQName, mQNameResolveNode, MB_FALSE);
if (NS_FAILED(rv))
formatName.mNamespaceID = kNameSpaceID_Unknown;
}
txDecimalFormat* format = mPs->getDecimalFormat(formatName); txDecimalFormat* format = mPs->getDecimalFormat(formatName);
if (!format) { if (!format) {

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

@ -19,6 +19,7 @@
*/ */
#include "XSLTFunctions.h" #include "XSLTFunctions.h"
#include "ProcessorState.h"
#include "Names.h" #include "Names.h"
#include "XMLDOMUtils.h" #include "XMLDOMUtils.h"
#include "txSingleNodeContext.h" #include "txSingleNodeContext.h"
@ -31,10 +32,12 @@
/* /*
* Creates a new key function call * Creates a new key function call
*/ */
txKeyFunctionCall::txKeyFunctionCall(ProcessorState* aPs) : txKeyFunctionCall::txKeyFunctionCall(ProcessorState* aPs,
FunctionCall(KEY_FN) Node* aQNameResolveNode) :
FunctionCall(KEY_FN),
mProcessorState(aPs),
mQNameResolveNode(aQNameResolveNode)
{ {
mProcessorState = aPs;
} }
/* /*
@ -57,11 +60,17 @@ ExprResult* txKeyFunctionCall::evaluate(txIEvalContext* aContext)
} }
txListIterator iter(&params); txListIterator iter(&params);
String keyName; String keyQName;
evaluateToString((Expr*)iter.next(), aContext, keyName); evaluateToString((Expr*)iter.next(), aContext, keyQName);
Expr* param = (Expr*) iter.next(); Expr* param = (Expr*) iter.next();
txXSLKey* key = mProcessorState->getKey(keyName); txExpandedName keyName;
txXSLKey* key = 0;
nsresult rv = keyName.init(keyQName, mQNameResolveNode, MB_FALSE);
if (NS_SUCCEEDED(rv)) {
key = mProcessorState->getKey(keyName);
}
if (!key) { if (!key) {
String err("No key with that name in: "); String err("No key with that name in: ");
toString(err); toString(err);

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

@ -250,7 +250,6 @@ nsresult txPatternParser::createKeyPattern(ExprLexer& aLexer,
ProcessorState* aPs, ProcessorState* aPs,
txPattern*& aPattern) txPattern*& aPattern)
{ {
nsresult rv = NS_OK;
// check for '(' Literal, Literal ')' // check for '(' Literal, Literal ')'
if (aLexer.nextToken()->type != Token::L_PAREN && if (aLexer.nextToken()->type != Token::L_PAREN &&
aLexer.peek()->type != Token::LITERAL) aLexer.peek()->type != Token::LITERAL)
@ -262,7 +261,19 @@ nsresult txPatternParser::createKeyPattern(ExprLexer& aLexer,
const String& value = aLexer.nextToken()->value; const String& value = aLexer.nextToken()->value;
if (aLexer.nextToken()->type != Token::R_PAREN) if (aLexer.nextToken()->type != Token::R_PAREN)
return NS_ERROR_XPATH_PARSE_FAILED; return NS_ERROR_XPATH_PARSE_FAILED;
aPattern = new txKeyPattern(aPs, key, value);
if (!XMLUtils::isValidQName(key))
return NS_ERROR_XPATH_PARSE_FAILED;
txAtom *prefix = 0, *localName = 0;
PRInt32 namespaceID;
nsresult rv = resolveQName(key, prefix, aContext, localName, namespaceID);
if (NS_FAILED(rv))
return rv;
aPattern = new txKeyPattern(aPs, prefix, localName, namespaceID, value);
TX_IF_RELEASE_ATOM(prefix);
TX_RELEASE_ATOM(localName);
return aPattern ? NS_OK : NS_ERROR_OUT_OF_MEMORY; return aPattern ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
} }

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

@ -40,6 +40,7 @@
#include "txNodeSetContext.h" #include "txNodeSetContext.h"
#include "txForwardContext.h" #include "txForwardContext.h"
#include "XSLTFunctions.h" #include "XSLTFunctions.h"
#include "ProcessorState.h"
#ifndef TX_EXE #ifndef TX_EXE
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsIContent.h" #include "nsIContent.h"
@ -459,7 +460,14 @@ void txKeyPattern::toString(String& aDest)
aDest.append("txKeyPattern{"); aDest.append("txKeyPattern{");
#endif #endif
aDest.append("key('"); aDest.append("key('");
aDest.append(mName); String tmp;
if (mPrefix) {
TX_GET_ATOM_STRING(mPrefix, tmp);
aDest.append(tmp);
aDest.append(':');
}
TX_GET_ATOM_STRING(mName.mLocalName, tmp);
aDest.append(tmp);
aDest.append(", "); aDest.append(", ");
aDest.append(mValue); aDest.append(mValue);
aDest.append("')"); aDest.append("')");

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

@ -40,6 +40,7 @@
#define TX_XSLT_PATTERNS_H #define TX_XSLT_PATTERNS_H
#include "Expr.h" #include "Expr.h"
#include "XMLUtils.h"
class ProcessorState; class ProcessorState;
class txPattern : public TxObject class txPattern : public TxObject
@ -175,9 +176,10 @@ private:
class txKeyPattern : public txPattern class txKeyPattern : public txPattern
{ {
public: public:
txKeyPattern(ProcessorState* aPs, const String& aName, txKeyPattern(ProcessorState* aPs, txAtom* aPrefix, txAtom* aLocalName,
const String& aValue) PRInt32 aNSID, const String& aValue)
: mProcessorState(aPs), mName(aName), mValue(aValue) : mProcessorState(aPs), mName(aNSID, aLocalName), mPrefix(aPrefix),
mValue(aValue)
{ {
} }
@ -187,7 +189,9 @@ public:
private: private:
ProcessorState* mProcessorState; ProcessorState* mProcessorState;
String mName, mValue; txExpandedName mName;
txAtom* mPrefix;
String mValue;
}; };
class txStepPattern : public PredicateList, public txPattern class txStepPattern : public PredicateList, public txPattern