зеркало из https://github.com/mozilla/pjs.git
Make the XPath engine handle CDATA sections as text-nodes.
b=92786 r=peterv, pike sr=jst Mixed small fixes and comments. b=99792 r=peterv sr=jst
This commit is contained in:
Родитель
f1514ed510
Коммит
521f46f929
|
@ -269,7 +269,8 @@ String* StringListIterator::next() {
|
|||
else {
|
||||
currentItem = stringList->firstItem;
|
||||
allowRemove = MB_TRUE;
|
||||
return currentItem->strptr;
|
||||
if (currentItem)
|
||||
return currentItem->strptr;
|
||||
}
|
||||
return 0;
|
||||
} //-- next
|
||||
|
|
|
@ -85,36 +85,12 @@ istream* URIUtils::getInputStream
|
|||
return inStream;
|
||||
|
||||
} //-- getInputStream
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the document base of the href argument
|
||||
* @return the document base of the given href
|
||||
**/
|
||||
void URIUtils::getDocumentBase(const String& href, String& dest) {
|
||||
#ifndef TX_EXE
|
||||
String docBase("");
|
||||
nsCOMPtr<nsIURI> pURL;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIIOService> pService(do_GetService(NS_IOSERVICE_CONTRACTID,
|
||||
&result));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
// XXX This is ugly, there must be an easier (cleaner way).
|
||||
char *uriStr = (((String)href).getConstNSString()).ToNewCString();
|
||||
result = pService->NewURI(uriStr, nsnull, getter_AddRefs(pURL));
|
||||
nsCRT::free(uriStr);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIURL> tURL = do_QueryInterface(pURL);
|
||||
nsXPIDLCString temp;
|
||||
|
||||
tURL->SetFileName("");
|
||||
tURL->GetSpec(getter_Copies(temp));
|
||||
docBase = (const char *)temp;
|
||||
}
|
||||
}
|
||||
dest.append(docBase);
|
||||
#else
|
||||
//-- use temp str so the subString method doesn't destroy dest
|
||||
String docBase("");
|
||||
|
||||
|
@ -138,8 +114,8 @@ void URIUtils::getDocumentBase(const String& href, String& dest) {
|
|||
delete uri;
|
||||
}
|
||||
dest.append(docBase);
|
||||
#endif
|
||||
} //-- getDocumentBase
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Resolves the given href argument, using the given documentBase
|
||||
|
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* 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 TransforMiiX XSLT processor.
|
||||
*
|
||||
* The Initial Developer of the Original Code is The MITRE Corporation.
|
||||
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
|
||||
*
|
||||
* Portions created by Keith Visco as a Non MITRE employee,
|
||||
* (C) 1999 Keith Visco. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Keith Visco, kvisco@ziplink.net
|
||||
* -- original author.
|
||||
*
|
||||
* Larry Fitzpatrick, OpenText, lef@opentext.com
|
||||
* -- 19990806
|
||||
* -- moved initialization of constant shorts and chars to
|
||||
* URIUtils.cpp
|
||||
*
|
||||
* Peter Van der Beken
|
||||
* -- 20000326
|
||||
* -- added Mozilla integration code
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TRANSFRMX_URIUTILS_H
|
||||
#define TRANSFRMX_URIUTILS_H
|
||||
|
||||
#include "TxString.h"
|
||||
#include "baseutils.h"
|
||||
#ifdef TX_EXE
|
||||
#include <fstream.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* A utility class for URI handling
|
||||
* Not yet finished, only handles file URI at this point
|
||||
**/
|
||||
|
||||
class URIUtils {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static const String HTTP_PROTOCOL;
|
||||
static const String FILE_PROTOCOL;
|
||||
|
||||
/**
|
||||
* the path separator for an URI
|
||||
**/
|
||||
static const char HREF_PATH_SEP;
|
||||
|
||||
/**
|
||||
* The Device separator for an URI
|
||||
**/
|
||||
static const char DEVICE_SEP;
|
||||
|
||||
/**
|
||||
* The Port separator for an URI
|
||||
**/
|
||||
static const char PORT_SEP;
|
||||
|
||||
/**
|
||||
* The Protocal separator for an URI
|
||||
**/
|
||||
static const char PROTOCOL_SEP;
|
||||
|
||||
|
||||
static istream* getInputStream
|
||||
(const String& href, String& errMsg);
|
||||
|
||||
/**
|
||||
* Returns the document base of the href argument
|
||||
* The document base will be appended to the given dest String
|
||||
**/
|
||||
static void getDocumentBase(const String& href, String& dest);
|
||||
|
||||
/**
|
||||
* Resolves the given href argument, using the given documentBase
|
||||
* if necessary.
|
||||
* The new resolved href will be appended to the given dest String
|
||||
**/
|
||||
static void resolveHref(const String& href, const String& base, String& dest);
|
||||
|
||||
/**
|
||||
* Returns the fragment identifier of the given URI, or "" if none exists
|
||||
* frag is cleared before the idetifier is appended
|
||||
**/
|
||||
static void getFragmentIdentifier(const String& href, String& frag);
|
||||
|
||||
/**
|
||||
* Returns the document location of given the URI (ie everything except
|
||||
* fragment). docUri is cleared before the URI is appended
|
||||
**/
|
||||
static void getDocumentURI(const String& href, String& docUri);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static const short PROTOCOL_MODE;
|
||||
static const short HOST_MODE;
|
||||
static const short PORT_MODE;
|
||||
static const short PATH_MODE;
|
||||
|
||||
struct ParsedURI {
|
||||
MBool isMalformed;
|
||||
String fragmentIdentifier;
|
||||
String host;
|
||||
String protocol;
|
||||
String port;
|
||||
String path;
|
||||
};
|
||||
|
||||
static istream* openStream(ParsedURI* uri);
|
||||
static ParsedURI* parseURI(const String& uri);
|
||||
|
||||
|
||||
|
||||
}; //-- URIUtils
|
||||
|
||||
/* */
|
||||
#endif
|
|
@ -114,6 +114,8 @@ double AttributeExpr::getDefaultPriority(Node* node, Node* context, ContextState
|
|||
**/
|
||||
MBool AttributeExpr::matches(Node* node, Node* context, ContextState* cs) {
|
||||
|
||||
//XXX need to filter out namespace-declaration attributes!
|
||||
|
||||
if ( (!node) || (node->getNodeType() != Node::ATTRIBUTE_NODE) )
|
||||
return MB_FALSE;
|
||||
|
||||
|
@ -159,7 +161,6 @@ MBool AttributeExpr::matches(Node* node, Node* context, ContextState* cs) {
|
|||
* @return the String representation of this NodeExpr.
|
||||
**/
|
||||
void AttributeExpr::toString(String& dest) {
|
||||
dest.append('@');
|
||||
if (isNameWild && isNamespaceWild) dest.append('*');
|
||||
else {
|
||||
dest.append(this->prefix);
|
||||
|
|
|
@ -93,10 +93,10 @@ MBool BasicNodeExpr::matches(Node* node, Node* context, ContextState* cs) {
|
|||
return (MBool)(node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE &&
|
||||
!nodeNameSet || nodeName.isEqual(node->getNodeName()));
|
||||
default: //-- node()
|
||||
if (node->getNodeType() == Node::TEXT_NODE)
|
||||
if (node->getNodeType() == Node::TEXT_NODE ||
|
||||
node->getNodeType() == Node::CDATA_SECTION_NODE)
|
||||
return !cs->isStripSpaceAllowed(node);
|
||||
return MB_TRUE;
|
||||
break;
|
||||
}
|
||||
return MB_TRUE;
|
||||
} //-- matches
|
||||
|
|
|
@ -276,7 +276,7 @@ void LocationStep::toString(String& str) {
|
|||
str.append("ancestor-or-self::");
|
||||
break;
|
||||
case ATTRIBUTE_AXIS:
|
||||
str.append("attribute::");
|
||||
str.append("@");
|
||||
break;
|
||||
case DESCENDANT_AXIS:
|
||||
str.append("descendant::");
|
||||
|
|
|
@ -350,6 +350,7 @@ double NodeSet::numberValue() {
|
|||
**/
|
||||
void NodeSet::stringValue(String& str) {
|
||||
if ( size()>0) {
|
||||
// XXX Sort by document order here
|
||||
XMLDOMUtils::getNodeValue(get(0), &str);
|
||||
}
|
||||
} //-- stringValue
|
||||
|
|
|
@ -167,8 +167,10 @@ void PathExpr::evalDescendants (Expr* expr, Node* context,
|
|||
|
||||
Node* child = context->getFirstChild();
|
||||
while (child) {
|
||||
if (!(filterWS && (child->getNodeType() == Node::TEXT_NODE) &&
|
||||
XMLUtils::shouldStripTextnode(child->getNodeValue())))
|
||||
if (!(filterWS &&
|
||||
(child->getNodeType() == Node::TEXT_NODE ||
|
||||
child->getNodeType() == Node::CDATA_SECTION_NODE) &&
|
||||
XMLUtils::shouldStripTextnode(child->getNodeValue())))
|
||||
evalDescendants(expr, child, cs, resNodes);
|
||||
child = child->getNextSibling();
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ void StringResult::stringValue(String& str) {
|
|||
} //-- stringValue
|
||||
|
||||
MBool StringResult::booleanValue() {
|
||||
return (MBool)(this->value.length());
|
||||
return value.length() > 0;
|
||||
} //-- booleanValue
|
||||
|
||||
double StringResult::numberValue() {
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* 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 TransforMiiX XSLT processor.
|
||||
*
|
||||
* The Initial Developer of the Original Code is The MITRE Corporation.
|
||||
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
|
||||
*
|
||||
* Portions created by Keith Visco as a Non MITRE employee,
|
||||
* (C) 1999 Keith Visco. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Keith Visco, kvisco@ziplink.net
|
||||
* -- original author.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Expr.h"
|
||||
|
||||
/**
|
||||
* Evaluates this Expr based on the given context node and processor state
|
||||
* @param context the context node for evaluation of this Expr
|
||||
* @param ps the ContextState containing the stack information needed
|
||||
* for evaluation
|
||||
* @return the result of the evaluation
|
||||
**/
|
||||
ExprResult* TextExpr::evaluate(Node* context, ContextState* cs) {
|
||||
|
||||
NodeSet* nodeSet = new NodeSet();
|
||||
|
||||
if ( !context ) return nodeSet;
|
||||
|
||||
Node* node = context->getFirstChild();
|
||||
while (node) {
|
||||
if ( node->getNodeType() == Node::TEXT_NODE )
|
||||
nodeSet->add(node);
|
||||
node = node->getNextSibling();
|
||||
}
|
||||
|
||||
return nodeSet;
|
||||
} //-- evaluate
|
||||
|
||||
/**
|
||||
* Returns the default priority of this Pattern based on the given Node,
|
||||
* context Node, and ContextState.
|
||||
**/
|
||||
double TextExpr::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
|
||||
return -0.5;
|
||||
} //-- getDefaultPriority
|
||||
|
||||
/**
|
||||
* Determines whether this NodeExpr matches the given node within
|
||||
* the given context
|
||||
**/
|
||||
MBool TextExpr::matches(Node* node, Node* context, ContextState* cs) {
|
||||
if ( node ) {
|
||||
if(node->getNodeType() == Node::TEXT_NODE)
|
||||
return !cs->isStripSpaceAllowed(node);
|
||||
}
|
||||
return MB_FALSE;
|
||||
} //-- matches
|
||||
|
||||
|
||||
/**
|
||||
* Returns the String representation of this NodeExpr.
|
||||
* @param dest the String to use when creating the String
|
||||
* representation. The String representation will be appended to
|
||||
* any data in the destination String, to allow cascading calls to
|
||||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this NodeExpr.
|
||||
**/
|
||||
void TextExpr::toString(String& dest) {
|
||||
dest.append("text()");
|
||||
} //-- toString
|
||||
|
|
@ -804,6 +804,7 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) {
|
|||
break;
|
||||
}
|
||||
case Node::TEXT_NODE:
|
||||
case Node::CDATA_SECTION_NODE:
|
||||
if (!XMLUtils::shouldStripTextnode(node->getNodeValue()))
|
||||
return MB_FALSE;
|
||||
return isStripSpaceAllowed(node->getParentNode());
|
||||
|
@ -954,6 +955,7 @@ ProcessorState::XMLSpaceMode ProcessorState::getXMLSpaceMode(Node* node) {
|
|||
break;
|
||||
}
|
||||
case Node::TEXT_NODE:
|
||||
case Node::CDATA_SECTION_NODE:
|
||||
//-- we will only see this the first time through the loop
|
||||
//-- if the argument node is a text node
|
||||
break;
|
||||
|
|
|
@ -960,7 +960,8 @@ void XSLTProcessor::processAction
|
|||
short nodeType = xslAction->getNodeType();
|
||||
|
||||
//-- handle text nodes
|
||||
if (nodeType == Node::TEXT_NODE) {
|
||||
if (nodeType == Node::TEXT_NODE ||
|
||||
nodeType == Node::CDATA_SECTION_NODE) {
|
||||
String textValue;
|
||||
if ( ps->isXSLStripSpaceAllowed(xslAction) ) {
|
||||
//-- strip whitespace
|
||||
|
@ -968,7 +969,7 @@ void XSLTProcessor::processAction
|
|||
//-- I was thinking about removing whitespace while reading in the
|
||||
//-- XSL document, but this won't handle the case of Dynamic XSL
|
||||
//-- documents
|
||||
const String curValue = ((Text*)xslAction)->getData();
|
||||
const String curValue = xslAction->getNodeValue();
|
||||
|
||||
//-- set leading + trailing whitespace stripping flags
|
||||
#ifdef DEBUG_ah
|
||||
|
@ -984,7 +985,7 @@ void XSLTProcessor::processAction
|
|||
else textValue=curValue;
|
||||
}
|
||||
else {
|
||||
textValue = ((Text*)xslAction)->getData();
|
||||
textValue = xslAction->getNodeValue();
|
||||
}
|
||||
//-- create new text node and add it to the result tree
|
||||
//-- if necessary
|
||||
|
@ -1131,6 +1132,7 @@ void XSLTProcessor::processAction
|
|||
else {
|
||||
notifyError("missing required name attribute for xsl:call-template");
|
||||
}
|
||||
break;
|
||||
}
|
||||
// xsl:if
|
||||
case XSLType::CHOOSE :
|
||||
|
@ -1249,7 +1251,11 @@ void XSLTProcessor::processAction
|
|||
{
|
||||
String selectAtt = actionElement->getAttribute(SELECT_ATTR);
|
||||
|
||||
if ( selectAtt.length() == 0 ) selectAtt = "*"; //-- default
|
||||
if (selectAtt.length() == 0)
|
||||
{
|
||||
notifyError("missing required select attribute for xsl:for-each");
|
||||
break;
|
||||
}
|
||||
|
||||
pExpr = ps->getPatternExpr(selectAtt);
|
||||
|
||||
|
@ -1816,8 +1822,10 @@ void XSLTProcessor::processTemplateParams
|
|||
}
|
||||
else break;
|
||||
}
|
||||
else if (nodeType == Node::TEXT_NODE) {
|
||||
if (!XMLUtils::isWhitespace(((Text*)tmpNode)->getData())) break;
|
||||
else if (nodeType == Node::TEXT_NODE ||
|
||||
nodeType == Node::CDATA_SECTION_NODE) {
|
||||
if (!XMLUtils::isWhitespace(tmpNode->getNodeValue()))
|
||||
break;
|
||||
}
|
||||
tmpNode = tmpNode->getNextSibling();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче