Compare commits

..

1 Commits

Author SHA1 Message Date
(no author)
258dc9fead This commit was manufactured by cvs2svn to create branch 'src'.
git-svn-id: svn://10.0.0.236/branches/src@33658 18797224-902f-48f8-a5cc-f745e15eee43
1999-06-03 23:10:01 +00:00
140 changed files with 18627 additions and 8538 deletions

View File

@@ -1,113 +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.
*
*/
/**
* Represents a AdditiveExpr, an binary expression that
* performs an additive operation between it's lvalue and rvalue:
* + : addition
* - : subtraction
**/
#include "Expr.h"
/**
* Creates a new AdditiveExpr using the given operator
**/
AdditiveExpr::AdditiveExpr(Expr* leftExpr, Expr* rightExpr, short op) {
this->op = op;
this->leftExpr = leftExpr;
this->rightExpr = rightExpr;
} //-- AdditiveExpr
AdditiveExpr::~AdditiveExpr() {
delete leftExpr;
delete rightExpr;
} //-- ~AdditiveExpr
/**
* 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* AdditiveExpr::evaluate(Node* context, ContextState* cs) {
double rightDbl = Double::NaN;
ExprResult* exprRes = 0;
if ( rightExpr ) {
exprRes = rightExpr->evaluate(context, cs);
if ( exprRes ) rightDbl = exprRes->numberValue();
delete exprRes;
}
double leftDbl = Double::NaN;
if ( leftExpr ) {
exprRes = leftExpr->evaluate(context, cs);
if ( exprRes ) leftDbl = exprRes->numberValue();
delete exprRes;
}
double result = 0;
switch ( op ) {
case SUBTRACTION:
result = leftDbl - rightDbl;
break;
default:
result = leftDbl + rightDbl;
break;
}
return new NumberResult(result);
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void AdditiveExpr::toString(String& str) {
if ( leftExpr ) leftExpr->toString(str);
else str.append("null");
switch ( op ) {
case SUBTRACTION:
str.append(" - ");
break;
default:
str.append(" + ");
break;
}
if ( rightExpr ) rightExpr->toString(str);
else str.append("null");
} //-- toString

View File

@@ -1,96 +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.
*
*/
/**
* AttributeValueTemplate
**/
#include "Expr.h"
/**
* Create a new AttributeValueTemplate
**/
AttributeValueTemplate::AttributeValueTemplate() {};
/**
* Default destructor
**/
AttributeValueTemplate::~AttributeValueTemplate() {
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
iter->next(); //advance iterator to allow remove
Expr* expr = (Expr*)iter->remove();
delete expr;
}
delete iter;
} //-- ~AttributeValueTemplate
/**
* Adds the given Expr to this AttributeValueTemplate
**/
void AttributeValueTemplate::addExpr(Expr* expr) {
if (expr) expressions.add(expr);
} //-- addExpr
/**
* 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* AttributeValueTemplate::evaluate(Node* context, ContextState* cs) {
ListIterator* iter = expressions.iterator();
String result;
while ( iter->hasNext() ) {
Expr* expr = (Expr*)iter->next();
ExprResult* exprResult = expr->evaluate(context, cs);
exprResult->stringValue(result);
delete exprResult;
}
delete iter;
return new StringResult(result);
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void AttributeValueTemplate::toString(String& str) {
ListIterator* iter = expressions.iterator();
while ( iter->hasNext() ) {
str.append('{');
Expr* expr = (Expr*)iter->next();
expr->toString(str);
str.append('}');
}
delete iter;
} //-- toString

View File

@@ -1,112 +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.
*
* Marc Schefer, schefer@xo3.com
* -- fixed a bug regarding Or expressions
* - If the left hand was false, the right hand expression
* was not getting checked.
*
*/
/**
* Represents a BooleanExpr, a binary expression that
* performs a boolean operation between it's lvalue and rvalue.
**/
#include "Expr.h"
/**
* Creates a new BooleanExpr using the given operator
**/
BooleanExpr::BooleanExpr(Expr* leftExpr, Expr* rightExpr, short op) {
this->op = op;
this->leftExpr = leftExpr;
this->rightExpr = rightExpr;
} //-- BooleanExpr
BooleanExpr::~BooleanExpr() {
delete leftExpr;
delete rightExpr;
} //-- ~BooleanExpr
/**
* 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* BooleanExpr::evaluate(Node* context, ContextState* cs) {
MBool lval = MB_FALSE;
ExprResult* exprRes = 0;
if ( leftExpr ) {
exprRes = leftExpr->evaluate(context, cs);
if ( exprRes ) lval = exprRes->booleanValue();
delete exprRes;
}
//-- check left expression for early decision
if (( op == OR ) && (lval)) return new BooleanResult(MB_TRUE);
else if ((op == AND) && (!lval)) return new BooleanResult(MB_FALSE);
MBool rval = MB_FALSE;
if ( rightExpr ) {
exprRes = rightExpr->evaluate(context, cs);
if ( exprRes ) rval = exprRes->booleanValue();
delete exprRes;
}
//-- just use rval, since we already checked lval
return new BooleanResult(rval);
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void BooleanExpr::toString(String& str) {
if ( leftExpr ) leftExpr->toString(str);
else str.append("null");
switch ( op ) {
case OR:
str.append(" or ");
break;
default:
str.append(" and ");
break;
}
if ( rightExpr ) rightExpr->toString(str);
else str.append("null");
} //-- toString

View File

@@ -1,108 +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.
*
* Marina Mechtcheriakova, mmarina@mindspring.com
* -- added lang() implementation
*
*/
#include "FunctionLib.h"
#include "Names.h"
/**
* Creates a default BooleanFunctionCall, which always evaluates to False
**/
BooleanFunctionCall::BooleanFunctionCall(short type) : FunctionCall()
{
switch ( type ) {
case TX_BOOLEAN :
name = XPathNames::BOOLEAN_FN;
break;
case TX_LANG:
name = XPathNames::LANG_FN;
break;
case TX_NOT :
name = XPathNames::NOT_FN;
break;
case TX_TRUE :
name = XPathNames::TRUE_FN;
break;
default:
name = XPathNames::FALSE_FN;
break;
}
this->type = type;
} //-- BooleanFunctionCall
/**
* 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* BooleanFunctionCall::evaluate(Node* context, ContextState* cs) {
MBool result = MB_FALSE;
ListIterator* iter = params.iterator();
Expr* param = 0;
String err;
switch ( type ) {
case TX_BOOLEAN :
if ( requireParams(1,1,cs) ) {
param = (Expr*)iter->next();
ExprResult* exprResult = param->evaluate(context, cs);
result = exprResult->booleanValue();
delete exprResult;
}
break;
case TX_LANG:
if ( requireParams(1,1,cs) ) {
String arg1, lang;
evaluateToString((Expr*)iter->next(),context, cs, arg1);
lang = ((Element*)context)->getAttribute(XML_LANG_ATTR);
arg1.toUpperCase(); // case-insensitive comparison
lang.toUpperCase();
result = (MBool)(lang.indexOf(arg1) == 0);
}
break;
case TX_NOT :
if ( requireParams(1,1,cs) ) {
param = (Expr*)iter->next();
ExprResult* exprResult = param->evaluate(context, cs);
result = (MBool)(!exprResult->booleanValue());
delete exprResult;
}
break;
case TX_TRUE :
result = MB_TRUE;
break;
default:
break;
}
delete iter;
return new BooleanResult(result);
} //-- evaluate

View File

@@ -1,66 +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.
*
*/
/*
* Boolean Expression result
*/
#include "ExprResult.h"
/**
* Default Constructor
**/
BooleanResult::BooleanResult() {
value = MB_FALSE;
} //-- BooleanResult
/**
* Creates a new BooleanResult with the value of the given MBool parameter
* @param boolean the MBool to use for initialization of this BooleanResult's value
**/
BooleanResult::BooleanResult(MBool boolean) {
this->value = boolean;
} //-- BooleanResult
/*
* Virtual Methods from ExprResult
*/
short BooleanResult::getResultType() {
return ExprResult::BOOLEAN;
} //-- getResultType
void BooleanResult::stringValue(String& str) {
if ( value ) str.append("true");
else str.append("false");
} //-- toString
MBool BooleanResult::booleanValue() {
return this->value;
} //-- toBoolean
double BooleanResult::numberValue() {
return ( value ) ? 1.0 : 0.0;
} //-- toNumber

View File

@@ -1,58 +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 "FunctionLib.h"
/**
* Creates an Error FunctionCall with no error message
**/
ErrorFunctionCall::ErrorFunctionCall() : FunctionCall(XPathNames::ERROR_FN) {};
/**
* Creates an Error FunctionCall with the given error message
**/
ErrorFunctionCall::ErrorFunctionCall
(const String& errorMsg) : FunctionCall(XPathNames::ERROR_FN)
{
//-- copy errorMsg
this->errorMessage = errorMsg;
} //-- ErrorFunctionCall
/**
* 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* ErrorFunctionCall::evaluate(Node* context, ContextState* cs) {
return new StringResult( errorMessage);
} //-- evaluate
void ErrorFunctionCall::setErrorMessage(String& errorMsg) {
//-- copy errorMsg
this->errorMessage = errorMsg;
} //-- setError

View File

@@ -1,44 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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 Initial Developer of the Original Code is Jonas Sicking.
* Portions created by Jonas Sicking are Copyright (C) 2001, Jonas Sicking.
* All rights reserved.
*
* Contributor(s):
* Jonas Sicking, sicking@bigfoot.com
* -- original author.
*/
#include "Expr.h"
Expr::~Expr() {
}
/*
* Determines whether this Expr matches the given node within
* the given context.
*/
MBool Expr::matches(Node* node, Node* context, ContextState* cs)
{
NS_ASSERTION(0, "Expr::matches() called");
return MB_FALSE;
}
/*
* Returns the default priority of this Expr based on the given Node,
* context Node, and ContextState.
*/
double Expr::getDefaultPriority(Node* node, Node* context, ContextState* cs)
{
NS_ASSERTION(0, "Expr::matches() called");
return 0;
}

View File

@@ -1,790 +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 Fitzpatick, OpenText, lef@opentext.com
* -- 19990806
* - changed constant short declarations in many of the classes
* with enumerations, commented with //--LF
* Jonas Sicking, sicking@bigfoot.com
* -- removal of Patterns and some restructuring
* in the class set
*
*/
#ifndef TRANSFRMX_EXPR_H
#define TRANSFRMX_EXPR_H
#include "TxString.h"
#include "ErrorObserver.h"
#include "NodeSet.h"
#include "Stack.h"
#include "ExprResult.h"
#include "baseutils.h"
#include "TxObject.h"
#include "primitives.h"
#include "NamespaceResolver.h"
/*
XPath class definitions.
Much of this code was ported from XSL:P.
*/
//necessary prototypes
class FunctionCall;
typedef class Expr Pattern;
typedef class Expr PatternExpr;
/**
* The expression context and state class used when evaluating XPath Expressions.
**/
class ContextState : public NamespaceResolver, public ErrorObserver {
public:
/**
* Returns the value of a given variable binding within the current scope
* @param the name to which the desired variable value has been bound
* @return the ExprResult which has been bound to the variable with
* the given name
**/
virtual ExprResult* getVariable(String& name) = 0;
/**
* Returns the Stack of context NodeSets
* @return the Stack of context NodeSets
**/
virtual Stack* getNodeSetStack() = 0;
virtual MBool isStripSpaceAllowed(Node* node) = 0;
/**
* Returns a call to the function that has the given name.
* This method is used for XPath Extension Functions.
* @return the FunctionCall for the function with the given name.
**/
virtual FunctionCall* resolveFunctionCall(const String& name) = 0;
/**
* Sorts the given NodeSet by DocumentOrder.
* @param nodes the NodeSet to sort
*
* Note: I will be moving this functionality elsewhere soon
**/
virtual void sortByDocumentOrder(NodeSet* nodes) = 0;
}; //-- ContextState
/**
* A Base Class for all XSL Expressions
**/
class Expr : public TxObject {
public:
/**
* Virtual destructor, important for subclasses
**/
virtual ~Expr();
/**
* 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
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0;
/**
* Determines whether this Expr matches the given node within
* the given context
**/
virtual MBool matches(Node* node, Node* context, ContextState* cs);
/**
* Returns the default priority of this Expr based on the given Node,
* context Node, and ContextState.
**/
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
virtual void toString(String& str) = 0;
}; //-- Expr
/**
* This class represents a FunctionCall as defined by the XPath 1.0
* Recommendation.
**/
class FunctionCall : public Expr {
public:
static const String INVALID_PARAM_COUNT;
static const String INVALID_PARAM_VALUE;
virtual ~FunctionCall();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs) = 0;
virtual MBool matches(Node* node, Node* context, ContextState* cs);
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
virtual void toString(String& dest);
/**
* Adds the given parameter to this FunctionCall's parameter list
* @param expr the Expr to add to this FunctionCall's parameter list
**/
void addParam(Expr* expr);
virtual MBool requireParams(int paramCountMin, ContextState* cs);
virtual MBool requireParams(int paramCountMin,
int paramCountMax,
ContextState* cs);
protected:
List params;
FunctionCall();
FunctionCall(const String& name);
/**
* Evaluates the given Expression and converts it's result to a String.
* The value is appended to the given destination String
**/
void evaluateToString
(Expr* expr, Node* context, ContextState* cs, String& dest);
/**
* Evaluates the given Expression and converts it's result to a number.
**/
double evaluateToNumber(Expr* expr, Node* context, ContextState* cs);
/*
* Evaluates the given Expression and converts it's result to a NodeSet.
* If the result is not a NodeSet NULL is returned.
*/
NodeSet* evaluateToNodeSet(Expr* aExpr, Node* aContext, ContextState* aCs);
String name;
}; //-- FunctionCall
/**
* Represents an AttributeValueTemplate
**/
class AttributeValueTemplate: public Expr {
public:
AttributeValueTemplate();
virtual ~AttributeValueTemplate();
/**
* Adds the given Expr to this AttributeValueTemplate
**/
void addExpr(Expr* expr);
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
List expressions;
};
/*
* This class represents a NodeTest as defined by the XPath spec
*/
class txNodeTest {
public:
virtual ~txNodeTest() {}
/*
* Determines whether this txNodeTest matches the given node
*/
virtual MBool matches(Node* aNode, ContextState* aCs) = 0;
/*
* Returns the default priority of this txNodeTest
*/
virtual double getDefaultPriority() = 0;
/*
* Returns the String representation of this txNodeTest.
* @param aDest the String to use when creating the string representation.
* The string representation will be appended to the string.
*/
virtual void toString(String& aDest) = 0;
};
/*
* This class represents a NameTest as defined by the XPath spec
*/
class txNameTest : public txNodeTest {
public:
/*
* Creates a new txNameTest with the given type and the given
* principal node type
*/
txNameTest(String& aName, Node::NodeType aNodeType);
~txNameTest();
/*
* Virtual methods from txNodeTest
*/
MBool matches(Node* aNode, ContextState* aCs);
double getDefaultPriority();
void toString(String& aDest);
private:
String mPrefix;
txAtom* mLocalName;
Node::NodeType mNodeType;
};
/*
* This class represents a NodeType as defined by the XPath spec
*/
class txNodeTypeTest : public txNodeTest {
public:
enum NodeType {
COMMENT_TYPE,
TEXT_TYPE,
PI_TYPE,
NODE_TYPE
};
/*
* Creates a new txNodeTypeTest of the given type
*/
txNodeTypeTest(NodeType aNodeType);
~txNodeTypeTest();
/*
* Sets the name of the node to match. Only availible for pi nodes
*/
void setNodeName(const String& aName);
/*
* Virtual methods from txNodeTest
*/
MBool matches(Node* aNode, ContextState* aCs);
double getDefaultPriority();
void toString(String& aDest);
private:
NodeType mNodeType;
txAtom* mNodeName;
};
/**
* Represents an ordered list of Predicates,
* for use with Step and Filter Expressions
**/
class PredicateList {
public:
/**
* Creates a new PredicateList
**/
PredicateList();
/**
* Destructor, will delete all Expressions in the list, so remove
* any you may need
**/
virtual ~PredicateList();
/**
* Adds the given Expr to the list
* @param expr the Expr to add to the list
**/
void add(Expr* expr);
void evaluatePredicates(NodeSet* nodes, ContextState* cs);
/**
* returns true if this predicate list is empty
**/
MBool isEmpty();
/**
* Returns the String representation of this PredicateList.
* @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 PredicateList.
**/
virtual void toString(String& dest);
private:
//-- list of predicates
List predicates;
}; //-- PredicateList
class LocationStep : public PredicateList, public Expr {
public:
// Axis Identifier Types
//-- LF changed from static const short to enum
enum LocationStepType {
ANCESTOR_AXIS = 0,
ANCESTOR_OR_SELF_AXIS,
ATTRIBUTE_AXIS,
CHILD_AXIS,
DESCENDANT_AXIS,
DESCENDANT_OR_SELF_AXIS,
FOLLOWING_AXIS,
FOLLOWING_SIBLING_AXIS,
NAMESPACE_AXIS,
PARENT_AXIS,
PRECEDING_AXIS,
PRECEDING_SIBLING_AXIS,
SELF_AXIS
};
/**
* Creates a new LocationStep using the given NodeExpr and Axis Identifier
* @param nodeExpr the NodeExpr to use when matching Nodes
* @param axisIdentifier the Axis Identifier in which to search for nodes
**/
LocationStep(txNodeTest* aNodeTest, LocationStepType aAxisIdentifier);
/**
* Destructor, will delete all predicates and the given NodeExpr
**/
virtual ~LocationStep();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual MBool matches(Node* node, Node* context, ContextState* cs);
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
virtual void toString(String& dest);
private:
txNodeTest* mNodeTest;
LocationStepType mAxisIdentifier;
void fromDescendants(Node* context, ContextState* cs, NodeSet* nodes);
void fromDescendantsRev(Node* context, ContextState* cs, NodeSet* nodes);
}; //-- LocationStep
class FilterExpr : public PredicateList, public Expr {
public:
/**
* Creates a new FilterExpr using the given Expr
* @param expr the Expr to use for evaluation
**/
FilterExpr(Expr* expr);
/**
* Destructor, will delete all predicates and the given Expr
**/
virtual ~FilterExpr();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual MBool matches(Node* node, Node* context, ContextState* cs);
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
virtual void toString(String& dest);
private:
Expr* expr;
}; //-- FilterExpr
class NumberExpr : public Expr {
public:
NumberExpr(double dbl);
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
double _value;
};
/**
* Represents a String expression
**/
class StringExpr : public Expr {
public:
StringExpr(const String& value);
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
String value;
}; //-- StringExpr
/**
* Represents an AdditiveExpr, a binary expression that
* performs an additive operation between it's lvalue and rvalue:
* + : add
* - : subtract
**/
class AdditiveExpr : public Expr {
public:
//-- AdditiveExpr Types
//-- LF, changed from static const short to enum
enum _AdditiveExprType { ADDITION = 1, SUBTRACTION };
AdditiveExpr(Expr* leftExpr, Expr* rightExpr, short op);
~AdditiveExpr();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
short op;
Expr* leftExpr;
Expr* rightExpr;
}; //-- AdditiveExpr
/**
* Represents an UnaryExpr. Returns the negative value of it's expr.
**/
class UnaryExpr : public Expr {
public:
UnaryExpr(Expr* expr);
~UnaryExpr();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
Expr* expr;
}; //-- UnaryExpr
/**
* Represents a BooleanExpr, a binary expression that
* performs a boolean operation between it's lvalue and rvalue.
**/
class BooleanExpr : public Expr {
public:
//-- BooleanExpr Types
enum _BooleanExprType { AND = 1, OR };
BooleanExpr(Expr* leftExpr, Expr* rightExpr, short op);
~BooleanExpr();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
short op;
Expr* leftExpr;
Expr* rightExpr;
}; //-- BooleanExpr
/**
* Represents a MultiplicativeExpr, a binary expression that
* performs a multiplicative operation between it's lvalue and rvalue:
* * : multiply
* mod : modulus
* div : divide
*
**/
class MultiplicativeExpr : public Expr {
public:
//-- MultiplicativeExpr Types
//-- LF, changed from static const short to enum
enum _MultiplicativeExprType { DIVIDE = 1, MULTIPLY, MODULUS };
MultiplicativeExpr(Expr* leftExpr, Expr* rightExpr, short op);
~MultiplicativeExpr();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
short op;
Expr* leftExpr;
Expr* rightExpr;
}; //-- MultiplicativeExpr
/**
* Represents a RelationalExpr, an expression that compares it's lvalue
* to it's rvalue using:
* = : equal to
* < : less than
* > : greater than
* <= : less than or equal to
* >= : greater than or equal to
*
**/
class RelationalExpr : public Expr {
public:
//-- RelationalExpr Types
//-- LF, changed from static const short to enum
enum _RelationalExprType {
EQUAL = 1,
NOT_EQUAL,
LESS_THAN,
GREATER_THAN,
LESS_OR_EQUAL,
GREATER_OR_EQUAL
};
RelationalExpr(Expr* leftExpr, Expr* rightExpr, short op);
~RelationalExpr();
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
short op;
Expr* leftExpr;
Expr* rightExpr;
MBool compareResults(ExprResult* left, ExprResult* right);
}; //-- RelationalExpr
/**
* VariableRefExpr
* Represents a variable reference ($refname)
**/
class VariableRefExpr : public Expr {
public:
VariableRefExpr(const String& name);
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual void toString(String& str);
private:
String name;
}; //-- VariableRefExpr
/**
* Represents a PathExpr
**/
class PathExpr : public Expr {
public:
//-- Path Operators
//-- RELATIVE_OP is the default
//-- LF, changed from static const short to enum
enum PathOperator { RELATIVE_OP, DESCENDANT_OP };
/**
* Creates a new PathExpr
**/
PathExpr();
/**
* Destructor, will delete all Expressions
**/
virtual ~PathExpr();
/**
* Adds the Expr to this PathExpr
* @param expr the Expr to add to this PathExpr
**/
void addExpr(Expr* expr, PathOperator pathOp);
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual MBool matches(Node* node, Node* context, ContextState* cs);
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
virtual void toString(String& dest);
private:
struct PathExprItem {
Expr* expr;
PathOperator pathOp;
};
List expressions;
/**
* Selects from the descendants of the context node
* all nodes that match the Expr
* -- this will be moving to a Utility class
**/
void evalDescendants(Expr* expr,
Node* context,
ContextState* cs,
NodeSet* resNodes);
}; //-- PathExpr
/**
* This class represents a RootExpr, which only matches the Document node
**/
class RootExpr : public Expr {
public:
/**
* Creates a new RootExpr
* @param aSerialize should this RootExpr be serialized
*/
RootExpr(MBool aSerialize);
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual MBool matches(Node* node, Node* context, ContextState* cs);
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
virtual void toString(String& dest);
private:
// When a RootExpr is used in a PathExpr it shouldn't be serialized
MBool mSerialize;
}; //-- RootExpr
/**
* Represents a UnionExpr
**/
class UnionExpr : public Expr {
public:
/**
* Creates a new UnionExpr
**/
UnionExpr();
/**
* Destructor, will delete all Path Expressions
**/
virtual ~UnionExpr();
/**
* Adds the PathExpr to this UnionExpr
* @param expr the Expr to add to this UnionExpr
**/
void addExpr(Expr* expr);
/**
* Virtual methods from Expr
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
virtual MBool matches(Node* node, Node* context, ContextState* cs);
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
virtual void toString(String& dest);
private:
List expressions;
}; //-- UnionExpr
/* */
#endif

View File

@@ -1,508 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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.
* -- fixed bug with '<=' and '>=' reported by Bob Miller
*
* Bob Miller, Oblix Inc., kbob@oblix.com
* -- fixed bug with single quotes inside double quotes
*
* Marina Mechtcheriakova, mmarina@mindspring.com
* -- Fixed bug in parse method so that we make sure we check for
* axis identifier wild cards, such as ancestor::*
*
* Axel Hecht <axel@pike.org>
* -- big beating, general overhaul
*
*/
/**
* Lexical analyzer for XPath expressions
**/
#include "ExprLexer.h"
//---------------------------/
//- Implementation of Token -/
//---------------------------/
/**
* Default constructor for Token
**/
Token::Token()
{
this->type =0;
} //-- Token;
/**
* Constructor for Token
* @param type, the type of Token being represented
**/
Token::Token(short type)
{
this->type = type;
} //-- Token;
/**
* Constructor for Token
* @param value the value of this Token
* @param type, the type of Token being represented
**/
Token::Token(const String& value, short type)
{
this->type = type;
//-- make copy of value String
this->value = value;
} //-- Token
Token::Token(UNICODE_CHAR uniChar, short type)
{
this->type = type;
this->value.append(uniChar);
} //-- Token
/**
* Copy Constructor
**/
Token::Token(const Token& token)
{
this->type = token.type;
this->value = token.value;
} //-- Token
/**
* Destructor for Token
**/
Token::~Token()
{
//-- currently nothing is needed
} //-- ~Token
//--------------------------------/
//- Implementation of ExprLexer -/
//-------------------------------/
/*
* Complex Tokens
*/
//-- Nodetype tokens
const String ExprLexer::COMMENT = "comment";
const String ExprLexer::NODE = "node";
const String ExprLexer::PROC_INST = "processing-instruction";
const String ExprLexer::TEXT = "text";
//-- boolean
const String ExprLexer::AND = "and";
const String ExprLexer::OR = "or";
//-- multiplicative operators
const String ExprLexer::MODULUS = "mod";
const String ExprLexer::DIVIDE = "div";
/**
* The set of Lexer error messages
**/
const String ExprLexer::error_message[] =
{
"VariableReference expected",
"Operator expected",
"Literal is not closed",
": not expected",
"! not expected, use != or not()",
"found a unkown character"
};
//---------------/
//- Contructors -/
//---------------/
/**
* Creates a new ExprLexer using the given String
**/
ExprLexer::ExprLexer(const String& pattern)
{
firstItem = 0;
lastItem = 0;
tokenCount = 0;
prevToken = 0;
endToken.type = Token::END;
parse(pattern);
currentItem = firstItem;
} //-- ExprLexer
/**
* Destroys this instance of an ExprLexer
**/
ExprLexer::~ExprLexer()
{
//-- delete tokens
currentItem = firstItem;
while (currentItem) {
TokenListItem* temp = currentItem->next;
delete currentItem->token;
delete currentItem;
currentItem = temp;
}
} //-- ~ExprLexer
MBool ExprLexer::hasMoreTokens()
{
return (currentItem != 0);
} //-- hasMoreTokens
Token* ExprLexer::nextToken()
{
if (currentItem) {
Token* token = currentItem->token;
currentItem = currentItem->next;
return token;
}
return &endToken;
} //-- nextToken
void ExprLexer::pushBack()
{
if (!currentItem)
currentItem = lastItem;
else
currentItem = currentItem->previous;
} //-- pushBack
Token* ExprLexer::peek()
{
if (currentItem)
return currentItem->token;
return &endToken;
} //-- peek
void ExprLexer::addToken(Token* token)
{
TokenListItem* tlItem = new TokenListItem;
tlItem->token = token;
tlItem->next = 0;
if (lastItem) {
tlItem->previous = lastItem;
lastItem->next = tlItem;
}
if (!firstItem)
firstItem = tlItem;
lastItem = tlItem;
prevToken = token;
++tokenCount;
} //-- addToken
/**
* Returns true if the following Token should be an operator.
* This is a helper for the first bullet of [XPath 3.7]
* Lexical Structure
**/
MBool ExprLexer::nextIsOperatorToken(Token* token)
{
if (!token || token->type == Token::NULL_TOKEN)
return MB_FALSE;
/* This relies on the tokens having the right order in ExprLexer.h */
if (token->type >= Token::COMMA &&
token->type <= Token::UNION_OP)
return MB_FALSE;
return MB_TRUE;
} //-- nextIsOperatorToken
/**
* Parses the given String into the set of Tokens
**/
void ExprLexer::parse(const String& pattern)
{
if (pattern.isEmpty())
return;
String tokenBuffer;
PRInt32 iter = 0, start;
PRInt32 size = pattern.length();
short defType;
UNICODE_CHAR ch;
//-- initialize previous token, this will automatically get
//-- deleted when it goes out of scope
Token nullToken('\0', Token::NULL_TOKEN);
prevToken = &nullToken;
while (iter < size) {
ch = pattern.charAt(iter);
defType = Token::CNAME;
if (ch==DOLLAR_SIGN) {
if (++iter == size || !isLetter(ch=pattern.charAt(iter))) {
// Error, VariableReference expected
errorPos = iter;
errorCode = ERROR_UNRESOLVED_VAR_REFERENCE;
if (firstItem)
firstItem->token->type=Token::ERROR;
else
addToken(new Token('\0',Token::ERROR));
iter=size; // bail
}
else
defType = Token::VAR_REFERENCE;
}
// just reuse the QName parsing, which will use defType
// the token to construct
if (isLetter(ch)) {
// NCName, can get QName or OperatorName;
// FunctionName, NodeName, and AxisSpecifier may want whitespace,
// and are dealt with below
start = iter;
while (++iter < size &&
isNCNameChar(pattern.charAt(iter))) /* just go */ ;
PRInt32 end = iter;
if (pattern.charAt(iter)==COLON) {
// try QName or wildcard, might need to step back for axis
if (++iter < size)
if (isLetter(pattern.charAt(iter)))
while (++iter < size &&
isNCNameChar(pattern.charAt(iter))) /* just go */ ;
else if (pattern.charAt(iter)=='*'
&& defType != Token::VAR_REFERENCE)
++iter; /* eat wildcard for NameTest, bail for var ref at COLON */
else
iter--; // step back
}
if (nextIsOperatorToken(prevToken)) {
if (pattern.subString(start,end,subStr).isEqual(AND))
defType = Token::AND_OP;
else if (pattern.subString(start,end,subStr).isEqual(OR))
defType = Token::OR_OP;
else if (pattern.subString(start,end,subStr).isEqual(MODULUS))
defType = Token::MODULUS_OP;
else if (pattern.subString(start,end,subStr).isEqual(DIVIDE))
defType = Token::DIVIDE_OP;
else {
// Error "operator expected"
// XXX QUESTION: spec is not too precise
// badops is sure an error, but is bad:ops, too? We say yes!
errorPos = iter;
errorCode = ERROR_OP_EXPECTED;
if (firstItem)
firstItem->token->type=Token::ERROR;
else
addToken(new Token('\0',Token::ERROR));
iter=size; // bail
}
}
addToken(new Token(pattern.subString(start,iter,subStr),defType));
}
else if (isDigit(ch)) {
start = iter;
while (++iter < size &&
isDigit(pattern.charAt(iter))) /* just go */;
if (pattern.charAt(iter)=='.')
while (++iter < size &&
isDigit(pattern.charAt(iter))) /* just go */;
addToken(new Token(pattern.subString(start,iter,subStr),Token::NUMBER));
}
else {
switch (ch) {
//-- ignore whitespace
case SPACE:
case TX_TAB:
case TX_CR:
case TX_LF:
++iter;
break;
case S_QUOTE :
case D_QUOTE :
start=iter;
iter = pattern.indexOf(ch,start+1);
if (iter==NOT_FOUND) {
// XXX Error reporting "unclosed literal"
errorPos = start;
errorCode = ERROR_UNCLOSED_LITERAL;
if (firstItem)
firstItem->token->type=Token::ERROR;
else
addToken(new Token('\0',Token::ERROR));
iter=size; // bail
}
else {
addToken(new Token(pattern.subString(start+1,iter,subStr),
Token::LITERAL));
++iter;
}
break;
case PERIOD:
// period can be .., .(DIGITS)+ or ., check next
if (++iter < size) {
ch=pattern.charAt(iter);
if (isDigit(ch)) {
start=iter-1;
while (++iter < size &&
isDigit(pattern.charAt(iter))) /* just go */;
addToken(new Token(pattern.subString(start,iter,subStr),
Token::NUMBER));
}
else if (ch==PERIOD) {
addToken(new Token(pattern.subString(iter-1,iter++,subStr),
Token::PARENT_NODE));
}
else
addToken(new Token(PERIOD, Token::SELF_NODE));
}
else
addToken(new Token(ch, Token::SELF_NODE));
// iter++ is already in the number test
break;
case COLON: // QNames are dealt above, must be axis ident
if (++iter < size && pattern.charAt(iter)==COLON &&
prevToken->type == Token::CNAME) {
prevToken->type = Token::AXIS_IDENTIFIER;
++iter;
}
else {
// XXX Error report "colon is neither QName nor axis"
errorPos = iter;
errorCode = ERROR_COLON;
if (firstItem)
firstItem->token->type=Token::ERROR;
else
addToken(new Token('\0',Token::ERROR));
iter=size; // bail
}
break;
case FORWARD_SLASH :
if (++iter < size && pattern.charAt(iter)==ch) {
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
Token::ANCESTOR_OP));
}
else {
addToken(new Token(ch, Token::PARENT_OP));
}
break;
case BANG : // can only be !=
if (++iter < size && pattern.charAt(iter)==EQUAL) {
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
Token::NOT_EQUAL_OP));
}
else {
// Error ! is not not()
errorPos = iter;
errorCode = ERROR_BANG;
if (firstItem)
firstItem->token->type=Token::ERROR;
else
addToken(new Token('\0',Token::ERROR));
iter=size; // bail
}
break;
case EQUAL:
addToken(new Token(ch,Token::EQUAL_OP));
++iter;
break;
case L_ANGLE:
if (++iter < size && pattern.charAt(iter)==EQUAL) {
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
Token::LESS_OR_EQUAL_OP));
}
else
addToken(new Token(ch,Token::LESS_THAN_OP));
break;
case R_ANGLE:
if (++iter < size && pattern.charAt(iter)==EQUAL) {
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
Token::GREATER_OR_EQUAL_OP));
}
else
addToken(new Token(ch,Token::GREATER_THAN_OP));
break;
case HYPHEN :
addToken(new Token(ch,Token::SUBTRACTION_OP));
++iter;
break;
case ASTERIX:
if (nextIsOperatorToken(prevToken))
addToken(new Token(ch,Token::MULTIPLY_OP));
else
addToken(new Token(ch,Token::CNAME));
++iter;
break;
case L_PAREN:
if (prevToken->type == Token::CNAME) {
if (prevToken->value.isEqual(COMMENT))
prevToken->type = Token::COMMENT;
else if (prevToken->value.isEqual(NODE))
prevToken->type = Token::NODE;
else if (prevToken->value.isEqual(PROC_INST))
prevToken->type = Token::PROC_INST;
else if (prevToken->value.isEqual(TEXT))
prevToken->type = Token::TEXT;
else
prevToken->type = Token::FUNCTION_NAME;
}
++iter;
addToken(new Token(ch,Token::L_PAREN));
break;
case R_PAREN:
++iter;
addToken(new Token(ch,Token::R_PAREN));
break;
case L_BRACKET:
++iter;
addToken(new Token(ch,Token::L_BRACKET));
break;
case R_BRACKET:
++iter;
addToken(new Token(ch,Token::R_BRACKET));
break;
case COMMA:
++iter;
addToken(new Token(ch,Token::COMMA));
break;
case AT_SIGN :
++iter;
addToken(new Token(ch,Token::AT_SIGN));
break;
case PLUS:
++iter;
addToken(new Token(ch,Token::ADDITION_OP));
break;
case VERT_BAR:
++iter;
addToken(new Token(ch,Token::UNION_OP));
break;
default:
// Error, don't grok character :-(
errorPos = iter;
errorCode = ERROR_UNKNOWN_CHAR;
if (firstItem)
firstItem->token->type=Token::ERROR;
else
addToken(new Token('\0',Token::ERROR));
iter=size; // bail
}
}
}
} //-- parse

View File

@@ -1,277 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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
* -- changed constant short declarations in Token and ExprLexer to
* enumerations, commented with //--LF
*
*/
#ifndef MITREXSL_EXPRLEXER_H
#define MITREXSL_EXPRLEXER_H
#include "TxString.h"
#include "baseutils.h"
/**
* A Token class for the ExprLexer.
*
* This class was ported from XSL:P, an open source Java based
* XSLT processor, written by yours truly.
**/
class Token {
public:
//---------------/
//- Token Types -/
//---------------/
//-- LF - changed from static const short declarations to enum
//-- token types
enum TokenType {
//-- Trivial Tokens
ERROR = 0,
NULL_TOKEN,
LITERAL,
NUMBER,
CNAME,
FUNCTION_NAME,
VAR_REFERENCE,
PARENT_NODE,
SELF_NODE,
R_PAREN,
R_BRACKET, // 10
/**
* start of tokens for 3.7, bullet 1
* ExprLexer::nextIsOperatorToken bails if the tokens aren't
* consecutive.
**/
COMMA,
AT_SIGN,
L_PAREN,
L_BRACKET,
AXIS_IDENTIFIER,
//-------------/
//- operators -/
//-------------/
//-- boolean ops
AND_OP, // 16
OR_OP,
//-- relational
EQUAL_OP, // 18
NOT_EQUAL_OP,
LESS_THAN_OP,
GREATER_THAN_OP,
LESS_OR_EQUAL_OP,
GREATER_OR_EQUAL_OP,
//-- additive operators
ADDITION_OP, // 24
SUBTRACTION_OP,
//-- multiplicative
DIVIDE_OP , // 26
MULTIPLY_OP,
MODULUS_OP,
//-- path operators
PARENT_OP, // 29
ANCESTOR_OP,
UNION_OP,
/**
* end of tokens for 3.7, bullet 1 -/
**/
//-- node type tokens
COMMENT, // 32
NODE,
PROC_INST,
TEXT,
//-- Special endtoken
END // 36
};
/**
* Default Constructor
**/
Token();
Token(short type);
Token(const String& value, short type);
Token(UNICODE_CHAR uniChar, short type);
/**
* Copy Constructor
**/
Token(const Token& token);
~Token();
String value;
short type;
}; //--Token
/**
* A class for splitting an "Expr" String into tokens and
* performing basic Lexical Analysis.
*
* This class was ported from XSL:P, an open source Java based XSL processor
**/
class ExprLexer {
public:
/*
* Trivial Tokens
*/
//-- LF, changed to enum
enum _TrivialTokens {
D_QUOTE = '\"',
S_QUOTE = '\'',
L_PAREN = '(',
R_PAREN = ')',
L_BRACKET = '[',
R_BRACKET = ']',
L_ANGLE = '<',
R_ANGLE = '>',
COMMA = ',',
PERIOD = '.',
ASTERIX = '*',
FORWARD_SLASH = '/',
EQUAL = '=',
BANG = '!',
VERT_BAR = '|',
AT_SIGN = '@',
DOLLAR_SIGN = '$',
PLUS = '+',
HYPHEN = '-',
COLON = ':',
//-- whitespace tokens
SPACE = ' ',
TX_TAB = '\t',
TX_CR = '\n',
TX_LF = '\r'
};
enum _error_consts {
ERROR_UNRESOLVED_VAR_REFERENCE = 0,
ERROR_OP_EXPECTED,
ERROR_UNCLOSED_LITERAL,
ERROR_COLON,
ERROR_BANG,
ERROR_UNKNOWN_CHAR
};
static const String error_message[];
PRInt32 errorPos;
short errorCode;
/*
* Complex Tokens
*/
//-- Nodetype tokens
static const String COMMENT;
static const String NODE;
static const String PROC_INST;
static const String TEXT;
//-- boolean
static const String AND;
static const String OR;
//-- Multiplicative
static const String MODULUS;
static const String DIVIDE;
/*
* Default Token Set
*/
static const Token TOKENS[];
static const short NUMBER_OF_TOKENS;
/**
* Constructor for ExprLexer
**/
ExprLexer(const String& pattern);
~ExprLexer();
/**
* Functions for iterating over the TokenList
**/
Token* nextToken();
Token* peek();
void pushBack();
MBool hasMoreTokens();
private:
struct TokenListItem {
Token* token;
TokenListItem* next;
TokenListItem* previous;
};
TokenListItem* currentItem;
TokenListItem* firstItem;
TokenListItem* lastItem;
int tokenCount;
Token* prevToken;
Token endToken;
void addToken(Token* token);
/**
* Returns true if the following Token should be an operator.
* This is a helper for the first bullet of [XPath 3.7]
* Lexical Structure
**/
MBool nextIsOperatorToken(Token* token);
/**
* Returns true if the given character represents an Alpha letter
* Implemented in ExprLexerChars.cpp
**/
static MBool isLetter(UNICODE_CHAR ch);
/**
* Returns true if the given character represents a numeric letter (digit)
* Implemented in ExprLexerChars.cpp
**/
static MBool isDigit(UNICODE_CHAR ch);
/**
* Returns true if the given character is an allowable NCName character
* Implemented in ExprLexerChars.cpp
**/
static MBool isNCNameChar(UNICODE_CHAR ch);
String subStr;
void parse(const String& pattern);
}; //-- ExprLexer
#endif

View File

@@ -1,372 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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 Axel Hecht. Portions
* created by Axel Hecht are Copyright (C) 2001 Axel Hecht. All
* Rights Reserved.
*
* Contributor(s):
* Axel Hecht <axel@pike.org> (Original Author)
*/
#include "ExprLexer.h"
// macros for inclusion of char range headers
#define TX_CHAR_RANGE(ch, a, b) if (ch < a) return MB_FALSE; \
if (ch <= b) return MB_TRUE
#define TX_MATCH_CHAR(ch, a) if (ch < a) return MB_FALSE; \
if (ch == a) return MB_TRUE
/**
* Returns true if the given character represents a numeric letter (digit)
**/
MBool ExprLexer::isDigit(UNICODE_CHAR ch)
{
TX_CHAR_RANGE(ch, '0', '9');
return MB_FALSE;
} //-- isDigit
/**
* Returns true if the given character represents an Alpha letter
**/
MBool ExprLexer::isLetter(UNICODE_CHAR ch)
{
/* Letter = BaseChar | Ideographic; and _ */
TX_CHAR_RANGE(ch, 0x0041, 0x005A);
TX_MATCH_CHAR(ch, 0x005F); /* '_' */
TX_CHAR_RANGE(ch, 0x0061, 0x007A);
TX_CHAR_RANGE(ch, 0x00C0, 0x00D6);
TX_CHAR_RANGE(ch, 0x00D8, 0x00F6);
TX_CHAR_RANGE(ch, 0x00F8, 0x00FF);
TX_CHAR_RANGE(ch, 0x0100, 0x0131);
TX_CHAR_RANGE(ch, 0x0134, 0x013E);
TX_CHAR_RANGE(ch, 0x0141, 0x0148);
TX_CHAR_RANGE(ch, 0x014A, 0x017E);
TX_CHAR_RANGE(ch, 0x0180, 0x01C3);
TX_CHAR_RANGE(ch, 0x01CD, 0x01F0);
TX_CHAR_RANGE(ch, 0x01F4, 0x01F5);
TX_CHAR_RANGE(ch, 0x01FA, 0x0217);
TX_CHAR_RANGE(ch, 0x0250, 0x02A8);
TX_CHAR_RANGE(ch, 0x02BB, 0x02C1);
TX_MATCH_CHAR(ch, 0x0386);
TX_CHAR_RANGE(ch, 0x0388, 0x038A);
TX_MATCH_CHAR(ch, 0x038C);
TX_CHAR_RANGE(ch, 0x038E, 0x03A1);
TX_CHAR_RANGE(ch, 0x03A3, 0x03CE);
TX_CHAR_RANGE(ch, 0x03D0, 0x03D6);
TX_MATCH_CHAR(ch, 0x03DA);
TX_MATCH_CHAR(ch, 0x03DC);
TX_MATCH_CHAR(ch, 0x03DE);
TX_MATCH_CHAR(ch, 0x03E0);
TX_CHAR_RANGE(ch, 0x03E2, 0x03F3);
TX_CHAR_RANGE(ch, 0x0401, 0x040C);
TX_CHAR_RANGE(ch, 0x040E, 0x044F);
TX_CHAR_RANGE(ch, 0x0451, 0x045C);
TX_CHAR_RANGE(ch, 0x045E, 0x0481);
TX_CHAR_RANGE(ch, 0x0490, 0x04C4);
TX_CHAR_RANGE(ch, 0x04C7, 0x04C8);
TX_CHAR_RANGE(ch, 0x04CB, 0x04CC);
TX_CHAR_RANGE(ch, 0x04D0, 0x04EB);
TX_CHAR_RANGE(ch, 0x04EE, 0x04F5);
TX_CHAR_RANGE(ch, 0x04F8, 0x04F9);
TX_CHAR_RANGE(ch, 0x0531, 0x0556);
TX_MATCH_CHAR(ch, 0x0559);
TX_CHAR_RANGE(ch, 0x0561, 0x0586);
TX_CHAR_RANGE(ch, 0x05D0, 0x05EA);
TX_CHAR_RANGE(ch, 0x05F0, 0x05F2);
TX_CHAR_RANGE(ch, 0x0621, 0x063A);
TX_CHAR_RANGE(ch, 0x0641, 0x064A);
TX_CHAR_RANGE(ch, 0x0671, 0x06B7);
TX_CHAR_RANGE(ch, 0x06BA, 0x06BE);
TX_CHAR_RANGE(ch, 0x06C0, 0x06CE);
TX_CHAR_RANGE(ch, 0x06D0, 0x06D3);
TX_MATCH_CHAR(ch, 0x06D5);
TX_CHAR_RANGE(ch, 0x06E5, 0x06E6);
TX_CHAR_RANGE(ch, 0x0905, 0x0939);
TX_MATCH_CHAR(ch, 0x093D);
TX_CHAR_RANGE(ch, 0x0958, 0x0961);
TX_CHAR_RANGE(ch, 0x0985, 0x098C);
TX_CHAR_RANGE(ch, 0x098F, 0x0990);
TX_CHAR_RANGE(ch, 0x0993, 0x09A8);
TX_CHAR_RANGE(ch, 0x09AA, 0x09B0);
TX_MATCH_CHAR(ch, 0x09B2);
TX_CHAR_RANGE(ch, 0x09B6, 0x09B9);
TX_CHAR_RANGE(ch, 0x09DC, 0x09DD);
TX_CHAR_RANGE(ch, 0x09DF, 0x09E1);
TX_CHAR_RANGE(ch, 0x09F0, 0x09F1);
TX_CHAR_RANGE(ch, 0x0A05, 0x0A0A);
TX_CHAR_RANGE(ch, 0x0A0F, 0x0A10);
TX_CHAR_RANGE(ch, 0x0A13, 0x0A28);
TX_CHAR_RANGE(ch, 0x0A2A, 0x0A30);
TX_CHAR_RANGE(ch, 0x0A32, 0x0A33);
TX_CHAR_RANGE(ch, 0x0A35, 0x0A36);
TX_CHAR_RANGE(ch, 0x0A38, 0x0A39);
TX_CHAR_RANGE(ch, 0x0A59, 0x0A5C);
TX_MATCH_CHAR(ch, 0x0A5E);
TX_CHAR_RANGE(ch, 0x0A72, 0x0A74);
TX_CHAR_RANGE(ch, 0x0A85, 0x0A8B);
TX_MATCH_CHAR(ch, 0x0A8D);
TX_CHAR_RANGE(ch, 0x0A8F, 0x0A91);
TX_CHAR_RANGE(ch, 0x0A93, 0x0AA8);
TX_CHAR_RANGE(ch, 0x0AAA, 0x0AB0);
TX_CHAR_RANGE(ch, 0x0AB2, 0x0AB3);
TX_CHAR_RANGE(ch, 0x0AB5, 0x0AB9);
TX_MATCH_CHAR(ch, 0x0ABD);
TX_MATCH_CHAR(ch, 0x0AE0);
TX_CHAR_RANGE(ch, 0x0B05, 0x0B0C);
TX_CHAR_RANGE(ch, 0x0B0F, 0x0B10);
TX_CHAR_RANGE(ch, 0x0B13, 0x0B28);
TX_CHAR_RANGE(ch, 0x0B2A, 0x0B30);
TX_CHAR_RANGE(ch, 0x0B32, 0x0B33);
TX_CHAR_RANGE(ch, 0x0B36, 0x0B39);
TX_MATCH_CHAR(ch, 0x0B3D);
TX_CHAR_RANGE(ch, 0x0B5C, 0x0B5D);
TX_CHAR_RANGE(ch, 0x0B5F, 0x0B61);
TX_CHAR_RANGE(ch, 0x0B85, 0x0B8A);
TX_CHAR_RANGE(ch, 0x0B8E, 0x0B90);
TX_CHAR_RANGE(ch, 0x0B92, 0x0B95);
TX_CHAR_RANGE(ch, 0x0B99, 0x0B9A);
TX_MATCH_CHAR(ch, 0x0B9C);
TX_CHAR_RANGE(ch, 0x0B9E, 0x0B9F);
TX_CHAR_RANGE(ch, 0x0BA3, 0x0BA4);
TX_CHAR_RANGE(ch, 0x0BA8, 0x0BAA);
TX_CHAR_RANGE(ch, 0x0BAE, 0x0BB5);
TX_CHAR_RANGE(ch, 0x0BB7, 0x0BB9);
TX_CHAR_RANGE(ch, 0x0C05, 0x0C0C);
TX_CHAR_RANGE(ch, 0x0C0E, 0x0C10);
TX_CHAR_RANGE(ch, 0x0C12, 0x0C28);
TX_CHAR_RANGE(ch, 0x0C2A, 0x0C33);
TX_CHAR_RANGE(ch, 0x0C35, 0x0C39);
TX_CHAR_RANGE(ch, 0x0C60, 0x0C61);
TX_CHAR_RANGE(ch, 0x0C85, 0x0C8C);
TX_CHAR_RANGE(ch, 0x0C8E, 0x0C90);
TX_CHAR_RANGE(ch, 0x0C92, 0x0CA8);
TX_CHAR_RANGE(ch, 0x0CAA, 0x0CB3);
TX_CHAR_RANGE(ch, 0x0CB5, 0x0CB9);
TX_MATCH_CHAR(ch, 0x0CDE);
TX_CHAR_RANGE(ch, 0x0CE0, 0x0CE1);
TX_CHAR_RANGE(ch, 0x0D05, 0x0D0C);
TX_CHAR_RANGE(ch, 0x0D0E, 0x0D10);
TX_CHAR_RANGE(ch, 0x0D12, 0x0D28);
TX_CHAR_RANGE(ch, 0x0D2A, 0x0D39);
TX_CHAR_RANGE(ch, 0x0D60, 0x0D61);
TX_CHAR_RANGE(ch, 0x0E01, 0x0E2E);
TX_MATCH_CHAR(ch, 0x0E30);
TX_CHAR_RANGE(ch, 0x0E32, 0x0E33);
TX_CHAR_RANGE(ch, 0x0E40, 0x0E45);
TX_CHAR_RANGE(ch, 0x0E81, 0x0E82);
TX_MATCH_CHAR(ch, 0x0E84);
TX_CHAR_RANGE(ch, 0x0E87, 0x0E88);
TX_MATCH_CHAR(ch, 0x0E8A);
TX_MATCH_CHAR(ch, 0x0E8D);
TX_CHAR_RANGE(ch, 0x0E94, 0x0E97);
TX_CHAR_RANGE(ch, 0x0E99, 0x0E9F);
TX_CHAR_RANGE(ch, 0x0EA1, 0x0EA3);
TX_MATCH_CHAR(ch, 0x0EA5);
TX_MATCH_CHAR(ch, 0x0EA7);
TX_CHAR_RANGE(ch, 0x0EAA, 0x0EAB);
TX_CHAR_RANGE(ch, 0x0EAD, 0x0EAE);
TX_MATCH_CHAR(ch, 0x0EB0);
TX_CHAR_RANGE(ch, 0x0EB2, 0x0EB3);
TX_MATCH_CHAR(ch, 0x0EBD);
TX_CHAR_RANGE(ch, 0x0EC0, 0x0EC4);
TX_CHAR_RANGE(ch, 0x0F40, 0x0F47);
TX_CHAR_RANGE(ch, 0x0F49, 0x0F69);
TX_CHAR_RANGE(ch, 0x10A0, 0x10C5);
TX_CHAR_RANGE(ch, 0x10D0, 0x10F6);
TX_MATCH_CHAR(ch, 0x1100);
TX_CHAR_RANGE(ch, 0x1102, 0x1103);
TX_CHAR_RANGE(ch, 0x1105, 0x1107);
TX_MATCH_CHAR(ch, 0x1109);
TX_CHAR_RANGE(ch, 0x110B, 0x110C);
TX_CHAR_RANGE(ch, 0x110E, 0x1112);
TX_MATCH_CHAR(ch, 0x113C);
TX_MATCH_CHAR(ch, 0x113E);
TX_MATCH_CHAR(ch, 0x1140);
TX_MATCH_CHAR(ch, 0x114C);
TX_MATCH_CHAR(ch, 0x114E);
TX_MATCH_CHAR(ch, 0x1150);
TX_CHAR_RANGE(ch, 0x1154, 0x1155);
TX_MATCH_CHAR(ch, 0x1159);
TX_CHAR_RANGE(ch, 0x115F, 0x1161);
TX_MATCH_CHAR(ch, 0x1163);
TX_MATCH_CHAR(ch, 0x1165);
TX_MATCH_CHAR(ch, 0x1167);
TX_MATCH_CHAR(ch, 0x1169);
TX_CHAR_RANGE(ch, 0x116D, 0x116E);
TX_CHAR_RANGE(ch, 0x1172, 0x1173);
TX_MATCH_CHAR(ch, 0x1175);
TX_MATCH_CHAR(ch, 0x119E);
TX_MATCH_CHAR(ch, 0x11A8);
TX_MATCH_CHAR(ch, 0x11AB);
TX_CHAR_RANGE(ch, 0x11AE, 0x11AF);
TX_CHAR_RANGE(ch, 0x11B7, 0x11B8);
TX_MATCH_CHAR(ch, 0x11BA);
TX_CHAR_RANGE(ch, 0x11BC, 0x11C2);
TX_MATCH_CHAR(ch, 0x11EB);
TX_MATCH_CHAR(ch, 0x11F0);
TX_MATCH_CHAR(ch, 0x11F9);
TX_CHAR_RANGE(ch, 0x1E00, 0x1E9B);
TX_CHAR_RANGE(ch, 0x1EA0, 0x1EF9);
TX_CHAR_RANGE(ch, 0x1F00, 0x1F15);
TX_CHAR_RANGE(ch, 0x1F18, 0x1F1D);
TX_CHAR_RANGE(ch, 0x1F20, 0x1F45);
TX_CHAR_RANGE(ch, 0x1F48, 0x1F4D);
TX_CHAR_RANGE(ch, 0x1F50, 0x1F57);
TX_MATCH_CHAR(ch, 0x1F59);
TX_MATCH_CHAR(ch, 0x1F5B);
TX_MATCH_CHAR(ch, 0x1F5D);
TX_CHAR_RANGE(ch, 0x1F5F, 0x1F7D);
TX_CHAR_RANGE(ch, 0x1F80, 0x1FB4);
TX_CHAR_RANGE(ch, 0x1FB6, 0x1FBC);
TX_MATCH_CHAR(ch, 0x1FBE);
TX_CHAR_RANGE(ch, 0x1FC2, 0x1FC4);
TX_CHAR_RANGE(ch, 0x1FC6, 0x1FCC);
TX_CHAR_RANGE(ch, 0x1FD0, 0x1FD3);
TX_CHAR_RANGE(ch, 0x1FD6, 0x1FDB);
TX_CHAR_RANGE(ch, 0x1FE0, 0x1FEC);
TX_CHAR_RANGE(ch, 0x1FF2, 0x1FF4);
TX_CHAR_RANGE(ch, 0x1FF6, 0x1FFC);
TX_MATCH_CHAR(ch, 0x2126);
TX_CHAR_RANGE(ch, 0x212A, 0x212B);
TX_MATCH_CHAR(ch, 0x212E);
TX_CHAR_RANGE(ch, 0x2180, 0x2182);
TX_MATCH_CHAR(ch, 0x3007);
TX_CHAR_RANGE(ch, 0x3021, 0x3029);
TX_CHAR_RANGE(ch, 0x3041, 0x3094);
TX_CHAR_RANGE(ch, 0x30A1, 0x30FA);
TX_CHAR_RANGE(ch, 0x3105, 0x312C);
TX_CHAR_RANGE(ch, 0x4E00, 0x9FA5);
TX_CHAR_RANGE(ch, 0xAC00, 0xD7A3);
return MB_FALSE;
} //-- isAlphaChar
/**
* Returns true if the given character is an allowable NCName character
**/
MBool ExprLexer::isNCNameChar(UNICODE_CHAR ch)
{
/* NCNameChar = Letter | Digit ('0'-'9') | '.' | '-' | '_' |
CombiningChar | Extender */
if (isLetter(ch)) return MB_TRUE; /* Letter | '_' */
TX_CHAR_RANGE(ch, 0x002D, 0x002E); /* '-' | '.' */
TX_CHAR_RANGE(ch, 0x0030, 0x0039); /* Digit */
TX_MATCH_CHAR(ch, 0x00B7);
TX_MATCH_CHAR(ch, 0x02D0);
TX_MATCH_CHAR(ch, 0x02D1);
TX_CHAR_RANGE(ch, 0x0300, 0x0345);
TX_CHAR_RANGE(ch, 0x0360, 0x0361);
TX_MATCH_CHAR(ch, 0x0387);
TX_CHAR_RANGE(ch, 0x0483, 0x0486);
TX_CHAR_RANGE(ch, 0x0591, 0x05A1);
TX_CHAR_RANGE(ch, 0x05A3, 0x05B9);
TX_CHAR_RANGE(ch, 0x05BB, 0x05BD);
TX_MATCH_CHAR(ch, 0x05BF);
TX_CHAR_RANGE(ch, 0x05C1, 0x05C2);
TX_MATCH_CHAR(ch, 0x05C4);
TX_MATCH_CHAR(ch, 0x0640);
TX_CHAR_RANGE(ch, 0x064B, 0x0652);
TX_MATCH_CHAR(ch, 0x0670);
TX_CHAR_RANGE(ch, 0x06D6, 0x06DC);
TX_CHAR_RANGE(ch, 0x06DD, 0x06DF);
TX_CHAR_RANGE(ch, 0x06E0, 0x06E4);
TX_CHAR_RANGE(ch, 0x06E7, 0x06E8);
TX_CHAR_RANGE(ch, 0x06EA, 0x06ED);
TX_CHAR_RANGE(ch, 0x0901, 0x0903);
TX_MATCH_CHAR(ch, 0x093C);
TX_CHAR_RANGE(ch, 0x093E, 0x094C);
TX_MATCH_CHAR(ch, 0x094D);
TX_CHAR_RANGE(ch, 0x0951, 0x0954);
TX_CHAR_RANGE(ch, 0x0962, 0x0963);
TX_CHAR_RANGE(ch, 0x0981, 0x0983);
TX_MATCH_CHAR(ch, 0x09BC);
TX_MATCH_CHAR(ch, 0x09BE);
TX_MATCH_CHAR(ch, 0x09BF);
TX_CHAR_RANGE(ch, 0x09C0, 0x09C4);
TX_CHAR_RANGE(ch, 0x09C7, 0x09C8);
TX_CHAR_RANGE(ch, 0x09CB, 0x09CD);
TX_MATCH_CHAR(ch, 0x09D7);
TX_CHAR_RANGE(ch, 0x09E2, 0x09E3);
TX_MATCH_CHAR(ch, 0x0A02);
TX_MATCH_CHAR(ch, 0x0A3C);
TX_MATCH_CHAR(ch, 0x0A3E);
TX_MATCH_CHAR(ch, 0x0A3F);
TX_CHAR_RANGE(ch, 0x0A40, 0x0A42);
TX_CHAR_RANGE(ch, 0x0A47, 0x0A48);
TX_CHAR_RANGE(ch, 0x0A4B, 0x0A4D);
TX_CHAR_RANGE(ch, 0x0A70, 0x0A71);
TX_CHAR_RANGE(ch, 0x0A81, 0x0A83);
TX_MATCH_CHAR(ch, 0x0ABC);
TX_CHAR_RANGE(ch, 0x0ABE, 0x0AC5);
TX_CHAR_RANGE(ch, 0x0AC7, 0x0AC9);
TX_CHAR_RANGE(ch, 0x0ACB, 0x0ACD);
TX_CHAR_RANGE(ch, 0x0B01, 0x0B03);
TX_MATCH_CHAR(ch, 0x0B3C);
TX_CHAR_RANGE(ch, 0x0B3E, 0x0B43);
TX_CHAR_RANGE(ch, 0x0B47, 0x0B48);
TX_CHAR_RANGE(ch, 0x0B4B, 0x0B4D);
TX_CHAR_RANGE(ch, 0x0B56, 0x0B57);
TX_CHAR_RANGE(ch, 0x0B82, 0x0B83);
TX_CHAR_RANGE(ch, 0x0BBE, 0x0BC2);
TX_CHAR_RANGE(ch, 0x0BC6, 0x0BC8);
TX_CHAR_RANGE(ch, 0x0BCA, 0x0BCD);
TX_MATCH_CHAR(ch, 0x0BD7);
TX_CHAR_RANGE(ch, 0x0C01, 0x0C03);
TX_CHAR_RANGE(ch, 0x0C3E, 0x0C44);
TX_CHAR_RANGE(ch, 0x0C46, 0x0C48);
TX_CHAR_RANGE(ch, 0x0C4A, 0x0C4D);
TX_CHAR_RANGE(ch, 0x0C55, 0x0C56);
TX_CHAR_RANGE(ch, 0x0C82, 0x0C83);
TX_CHAR_RANGE(ch, 0x0CBE, 0x0CC4);
TX_CHAR_RANGE(ch, 0x0CC6, 0x0CC8);
TX_CHAR_RANGE(ch, 0x0CCA, 0x0CCD);
TX_CHAR_RANGE(ch, 0x0CD5, 0x0CD6);
TX_CHAR_RANGE(ch, 0x0D02, 0x0D03);
TX_CHAR_RANGE(ch, 0x0D3E, 0x0D43);
TX_CHAR_RANGE(ch, 0x0D46, 0x0D48);
TX_CHAR_RANGE(ch, 0x0D4A, 0x0D4D);
TX_MATCH_CHAR(ch, 0x0D57);
TX_MATCH_CHAR(ch, 0x0E31);
TX_CHAR_RANGE(ch, 0x0E34, 0x0E3A);
TX_MATCH_CHAR(ch, 0x0E46);
TX_CHAR_RANGE(ch, 0x0E47, 0x0E4E);
TX_MATCH_CHAR(ch, 0x0EB1);
TX_CHAR_RANGE(ch, 0x0EB4, 0x0EB9);
TX_CHAR_RANGE(ch, 0x0EBB, 0x0EBC);
TX_MATCH_CHAR(ch, 0x0EC6);
TX_CHAR_RANGE(ch, 0x0EC8, 0x0ECD);
TX_CHAR_RANGE(ch, 0x0F18, 0x0F19);
TX_MATCH_CHAR(ch, 0x0F35);
TX_MATCH_CHAR(ch, 0x0F37);
TX_MATCH_CHAR(ch, 0x0F39);
TX_MATCH_CHAR(ch, 0x0F3E);
TX_MATCH_CHAR(ch, 0x0F3F);
TX_CHAR_RANGE(ch, 0x0F71, 0x0F84);
TX_CHAR_RANGE(ch, 0x0F86, 0x0F8B);
TX_CHAR_RANGE(ch, 0x0F90, 0x0F95);
TX_MATCH_CHAR(ch, 0x0F97);
TX_CHAR_RANGE(ch, 0x0F99, 0x0FAD);
TX_CHAR_RANGE(ch, 0x0FB1, 0x0FB7);
TX_MATCH_CHAR(ch, 0x0FB9);
TX_CHAR_RANGE(ch, 0x20D0, 0x20DC);
TX_MATCH_CHAR(ch, 0x20E1);
TX_MATCH_CHAR(ch, 0x3005);
TX_CHAR_RANGE(ch, 0x302A, 0x302F);
TX_CHAR_RANGE(ch, 0x3031, 0x3035);
TX_MATCH_CHAR(ch, 0x3099);
TX_MATCH_CHAR(ch, 0x309A);
TX_CHAR_RANGE(ch, 0x309D, 0x309E);
TX_CHAR_RANGE(ch, 0x30FC, 0x30FE);
return MB_FALSE;
} //-- isNCNameChar

View File

@@ -1,914 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.
*
* Olivier Gerardin, ogerardin@vo.lu
* -- added support for number function calls
* -- fixed a bug in CreateExpr (@xxx=/yyy was parsed as @xxx=@xxx/yyy)
*
* Marina Mechtcheriakova
* -- added support for lang()
* -- fixed bug in ::parsePredicates,
* made sure we continue looking for more predicates.
*
*/
/**
* ExprParser
* This class is used to parse XSL Expressions
* @see ExprLexer
**/
#include "ExprParser.h"
#include "FunctionLib.h"
#include "Names.h"
/**
* Creates a new ExprParser
**/
ExprParser::ExprParser() {};
/**
* Default Destructor
**/
ExprParser::~ExprParser() {};
/**
* Creates an Attribute Value Template using the given value
* This should move to XSLProcessor class
**/
AttributeValueTemplate* ExprParser::createAttributeValueTemplate
(const String& attValue)
{
AttributeValueTemplate* avt = new AttributeValueTemplate();
if (attValue.isEmpty())
return avt; //XXX should return 0, but that causes crash in lre12
PRInt32 size = attValue.length();
int cc = 0;
UNICODE_CHAR nextCh;
UNICODE_CHAR ch;
String buffer;
MBool inExpr = MB_FALSE;
MBool inLiteral = MB_FALSE;
UNICODE_CHAR endLiteral;
nextCh = attValue.charAt(cc);
while (cc++ < size) {
ch = nextCh;
nextCh = cc != size ? attValue.charAt(cc) : 0;
// if in literal just add ch to buffer
if (inLiteral && (ch != endLiteral)) {
buffer.append(ch);
continue;
}
switch ( ch ) {
case '\'' :
case '"' :
buffer.append(ch);
if (inLiteral)
inLiteral = MB_FALSE;
else if (inExpr) {
inLiteral = MB_TRUE;
endLiteral = ch;
}
break;
case '{' :
if (!inExpr) {
// Ignore case where we find two {
if (nextCh == ch) {
buffer.append(ch); //-- append '{'
cc++;
nextCh = cc != size ? attValue.charAt(cc) : 0;
}
else {
if (!buffer.isEmpty())
avt->addExpr(new StringExpr(buffer));
buffer.clear();
inExpr = MB_TRUE;
}
}
else
buffer.append(ch); //-- simply append '{'
break;
case '}':
if (inExpr) {
inExpr = MB_FALSE;
Expr* expr = createExpr(buffer);
if (!expr) {
delete avt;
return 0;
}
avt->addExpr(expr);
buffer.clear();
}
else if (nextCh == ch) {
buffer.append(ch);
cc++;
nextCh = cc != size ? attValue.charAt(cc) : 0;
}
else {
//XXX ErrorReport: unmatched '}' found
delete avt;
return 0;
}
break;
default:
buffer.append(ch);
break;
}
}
if (inExpr) {
//XXX ErrorReport: ending '}' missing
delete avt;
return 0;
}
if (!buffer.isEmpty())
avt->addExpr(new StringExpr(buffer));
return avt;
} //-- createAttributeValueTemplate
Expr* ExprParser::createExpr(const String& aExpression)
{
ExprLexer lexer(aExpression);
return createExpr(lexer);
} //-- createExpr
Pattern* ExprParser::createPattern(const String& aPattern)
{
ExprLexer lexer(aPattern);
return createUnionExpr(lexer);
} //-- createPatternExpr
//--------------------/
//- Private Methods -/
//-------------------/
/**
* Creates a binary Expr for the given operator
**/
Expr* ExprParser::createBinaryExpr (Expr* left, Expr* right, Token* op) {
if (!op)
return 0;
switch (op->type) {
//-- additive ops
case Token::ADDITION_OP :
return new AdditiveExpr(left, right, AdditiveExpr::ADDITION);
case Token::SUBTRACTION_OP:
return new AdditiveExpr(left, right, AdditiveExpr::SUBTRACTION);
//-- case boolean ops
case Token::AND_OP:
return new BooleanExpr(left, right, BooleanExpr::AND);
case Token::OR_OP:
return new BooleanExpr(left, right, BooleanExpr::OR);
//-- equality ops
case Token::EQUAL_OP :
return new RelationalExpr(left, right, RelationalExpr::EQUAL);
case Token::NOT_EQUAL_OP :
return new RelationalExpr(left, right, RelationalExpr::NOT_EQUAL);
//-- relational ops
case Token::LESS_THAN_OP:
return new RelationalExpr(left, right, RelationalExpr::LESS_THAN);
case Token::GREATER_THAN_OP:
return new RelationalExpr(left, right, RelationalExpr::GREATER_THAN);
case Token::LESS_OR_EQUAL_OP:
return new RelationalExpr(left, right, RelationalExpr::LESS_OR_EQUAL);
case Token::GREATER_OR_EQUAL_OP:
return new RelationalExpr(left, right, RelationalExpr::GREATER_OR_EQUAL);
//-- multiplicative ops
case Token::DIVIDE_OP :
return new MultiplicativeExpr(left, right, MultiplicativeExpr::DIVIDE);
case Token::MODULUS_OP :
return new MultiplicativeExpr(left, right, MultiplicativeExpr::MODULUS);
case Token::MULTIPLY_OP :
return new MultiplicativeExpr(left, right, MultiplicativeExpr::MULTIPLY);
default:
break;
}
return 0;
//return new ErrorExpr();
} //-- createBinaryExpr
Expr* ExprParser::createExpr(ExprLexer& lexer) {
MBool done = MB_FALSE;
Expr* expr = 0;
Stack exprs;
Stack ops;
while (!done) {
MBool unary = MB_FALSE;
while (lexer.peek()->type == Token::SUBTRACTION_OP) {
unary = !unary;
lexer.nextToken();
}
expr = createUnionExpr(lexer);
if (!expr)
break;
if (unary)
expr = new UnaryExpr(expr);
Token* tok = lexer.nextToken();
switch (tok->type) {
case Token::ADDITION_OP:
case Token::DIVIDE_OP:
//-- boolean ops
case Token::AND_OP :
case Token::OR_OP :
//-- equality ops
case Token::EQUAL_OP:
case Token::NOT_EQUAL_OP:
//-- relational ops
case Token::LESS_THAN_OP:
case Token::GREATER_THAN_OP:
case Token::LESS_OR_EQUAL_OP:
case Token::GREATER_OR_EQUAL_OP:
//-- multiplicative ops
case Token::MODULUS_OP:
case Token::MULTIPLY_OP:
case Token::SUBTRACTION_OP:
{
while (!exprs.empty() &&
precedenceLevel(tok->type)
<= precedenceLevel(((Token*)ops.peek())->type)) {
expr = createBinaryExpr((Expr*)exprs.pop(),
expr,
(Token*)ops.pop());
}
exprs.push(expr);
ops.push(tok);
break;
}
default:
lexer.pushBack();
done = MB_TRUE;
break;
}
}
// make sure expr != 0
if (!expr) {
while (!exprs.empty()) {
delete (Expr*)exprs.pop();
}
return 0;
}
while (!exprs.empty()) {
expr = createBinaryExpr((Expr*)exprs.pop(), expr, (Token*)ops.pop());
}
return expr;
} //-- createExpr
Expr* ExprParser::createFilterExpr(ExprLexer& lexer) {
Token* tok = lexer.nextToken();
Expr* expr = 0;
switch (tok->type) {
case Token::FUNCTION_NAME :
lexer.pushBack();
expr = createFunctionCall(lexer);
break;
case Token::VAR_REFERENCE :
expr = new VariableRefExpr(tok->value);
break;
case Token::L_PAREN:
expr = createExpr(lexer);
if (!expr)
return 0;
if (lexer.nextToken()->type != Token::R_PAREN) {
lexer.pushBack();
//XXX ErrorReport: right parenthesis expected
delete expr;
return 0;
}
break;
case Token::LITERAL :
expr = new StringExpr(tok->value);
break;
case Token::NUMBER:
{
expr = new NumberExpr(Double::toDouble(tok->value));
break;
}
default:
// this should never ever happen.
lexer.pushBack();
//XXX ErrorReport: error in parser, please report on bugzilla.mozilla.org
return 0;
break;
}
if (!expr)
return 0;
if (lexer.peek()->type == Token::L_BRACKET) {
FilterExpr* filterExpr = new FilterExpr(expr);
//-- handle predicates
if (!parsePredicates(filterExpr, lexer)) {
delete filterExpr;
return 0;
}
expr = filterExpr;
}
return expr;
} //-- createFilterExpr
FunctionCall* ExprParser::createFunctionCall(ExprLexer& lexer) {
FunctionCall* fnCall = 0;
Token* tok = lexer.nextToken();
if (tok->type != Token::FUNCTION_NAME) {
//XXX ErrorReport: error in parser, please report on bugzilla.mozilla.org
return 0;
}
String fnName = tok->value;
//-- compare function names
//-- * we should hash these names for speed
if (XPathNames::BOOLEAN_FN.isEqual(tok->value)) {
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_BOOLEAN);
}
else if (XPathNames::CONCAT_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::CONCAT);
}
else if (XPathNames::CONTAINS_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::CONTAINS);
}
else if (XPathNames::COUNT_FN.isEqual(tok->value)) {
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::COUNT);
}
else if (XPathNames::FALSE_FN.isEqual(tok->value)) {
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_FALSE);
}
else if (XPathNames::ID_FN.isEqual(tok->value)) {
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::ID);
}
else if (XPathNames::LANG_FN.isEqual(tok->value)) {
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_LANG);
}
else if (XPathNames::LAST_FN.isEqual(tok->value)) {
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::LAST);
}
else if (XPathNames::LOCAL_NAME_FN.isEqual(tok->value)) {
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::LOCAL_NAME);
}
else if (XPathNames::NAME_FN.isEqual(tok->value)) {
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::NAME);
}
else if (XPathNames::NAMESPACE_URI_FN.isEqual(tok->value)) {
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::NAMESPACE_URI);
}
else if (XPathNames::NORMALIZE_SPACE_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::NORMALIZE_SPACE);
}
else if (XPathNames::NOT_FN.isEqual(tok->value)) {
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_NOT);
}
else if (XPathNames::POSITION_FN.isEqual(tok->value)) {
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::POSITION);
}
else if (XPathNames::STARTS_WITH_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::STARTS_WITH);
}
else if (XPathNames::STRING_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::STRING);
}
else if (XPathNames::STRING_LENGTH_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::STRING_LENGTH);
}
else if (XPathNames::SUBSTRING_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING);
}
else if (XPathNames::SUBSTRING_AFTER_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING_AFTER);
}
else if (XPathNames::SUBSTRING_BEFORE_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING_BEFORE);
}
else if (XPathNames::SUM_FN.isEqual(tok->value)) {
fnCall = new NumberFunctionCall(NumberFunctionCall::SUM);
}
else if (XPathNames::TRANSLATE_FN.isEqual(tok->value)) {
fnCall = new StringFunctionCall(StringFunctionCall::TRANSLATE);
}
else if (XPathNames::TRUE_FN.isEqual(tok->value)) {
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_TRUE);
}
else if (XPathNames::NUMBER_FN.isEqual(tok->value)) {
fnCall = new NumberFunctionCall(NumberFunctionCall::NUMBER);
}
else if (XPathNames::ROUND_FN.isEqual(tok->value)) {
fnCall = new NumberFunctionCall(NumberFunctionCall::ROUND);
}
else if (XPathNames::CEILING_FN.isEqual(tok->value)) {
fnCall = new NumberFunctionCall(NumberFunctionCall::CEILING);
}
else if (XPathNames::FLOOR_FN.isEqual(tok->value)) {
fnCall = new NumberFunctionCall(NumberFunctionCall::FLOOR);
}
else {
//-- Most likely an Extension Function, or error, but it's
//-- not our job to report an invalid function call here
fnCall = new ExtensionFunctionCall(fnName);
}
//-- handle parametes
if (!parseParameters(fnCall, lexer)) {
delete fnCall;
return 0;
}
return fnCall;
} //-- createFunctionCall
LocationStep* ExprParser::createLocationStep(ExprLexer& lexer) {
//-- child axis is default
LocationStep::LocationStepType axisIdentifier = LocationStep::CHILD_AXIS;
txNodeTest* nodeTest = 0;
//-- get Axis Identifier or AbbreviatedStep, if present
Token* tok = lexer.peek();
switch (tok->type) {
case Token::AXIS_IDENTIFIER:
{
//-- eat token
lexer.nextToken();
//-- should switch to a hash here for speed if necessary
if (ANCESTOR_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::ANCESTOR_AXIS;
}
else if (ANCESTOR_OR_SELF_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::ANCESTOR_OR_SELF_AXIS;
}
else if (ATTRIBUTE_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
}
else if (CHILD_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::CHILD_AXIS;
}
else if (DESCENDANT_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::DESCENDANT_AXIS;
}
else if (DESCENDANT_OR_SELF_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::DESCENDANT_OR_SELF_AXIS;
}
else if (FOLLOWING_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::FOLLOWING_AXIS;
}
else if (FOLLOWING_SIBLING_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::FOLLOWING_SIBLING_AXIS;
}
else if (NAMESPACE_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::NAMESPACE_AXIS;
}
else if (PARENT_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::PARENT_AXIS;
}
else if (PRECEDING_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::PRECEDING_AXIS;
}
else if (PRECEDING_SIBLING_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::PRECEDING_SIBLING_AXIS;
}
else if (SELF_AXIS.isEqual(tok->value)) {
axisIdentifier = LocationStep::SELF_AXIS;
}
else {
//XXX ErrorReport: unknow axis
return 0;
}
break;
}
case Token::AT_SIGN:
//-- eat token
lexer.nextToken();
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
break;
case Token::PARENT_NODE :
//-- eat token
lexer.nextToken();
axisIdentifier = LocationStep::PARENT_AXIS;
nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE);
if (!nodeTest) {
//XXX out of memory
return 0;
}
break;
case Token::SELF_NODE :
//-- eat token
lexer.nextToken();
axisIdentifier = LocationStep::SELF_AXIS;
nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE);
if (!nodeTest) {
//XXX out of memory
return 0;
}
break;
default:
break;
}
//-- get NodeTest unless an AbbreviatedStep was found
if (!nodeTest) {
tok = lexer.nextToken();
switch (tok->type) {
case Token::CNAME :
switch (axisIdentifier) {
case LocationStep::ATTRIBUTE_AXIS:
nodeTest = new txNameTest(tok->value, Node::ATTRIBUTE_NODE);
break;
// XXX Namespace: handle namespaces here
default:
nodeTest = new txNameTest(tok->value, Node::ELEMENT_NODE);
break;
}
if (!nodeTest) {
//XXX ErrorReport: out of memory
return 0;
}
break;
default:
lexer.pushBack();
nodeTest = createNodeTest(lexer);
if (!nodeTest) {
return 0;
}
}
}
LocationStep* lstep = new LocationStep(nodeTest, axisIdentifier);
if (!lstep) {
//XXX out of memory
delete nodeTest;
return 0;
}
//-- handle predicates
if (!parsePredicates(lstep, lexer)) {
delete lstep;
return 0;
}
return lstep;
} //-- createLocationPath
/**
* This method only handles comment(), text(), processing-instructing() and node()
*
**/
txNodeTest* ExprParser::createNodeTest(ExprLexer& lexer) {
txNodeTest* nodeTest = 0;
Token* nodeTok = lexer.nextToken();
switch (nodeTok->type) {
case Token::COMMENT:
nodeTest = new txNodeTypeTest(txNodeTypeTest::COMMENT_TYPE);
break;
case Token::NODE :
nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE);
break;
case Token::PROC_INST :
nodeTest = new txNodeTypeTest(txNodeTypeTest::PI_TYPE);
break;
case Token::TEXT :
nodeTest = new txNodeTypeTest(txNodeTypeTest::TEXT_TYPE);
break;
default:
lexer.pushBack();
// XXX ErrorReport: unexpected token
return 0;
}
if (!nodeTest) {
//XXX out of memory
return 0;
}
if (lexer.nextToken()->type != Token::L_PAREN) {
lexer.pushBack();
//XXX ErrorReport: left parenthesis expected
delete nodeTest;
return 0;
}
if (nodeTok->type == Token::PROC_INST &&
lexer.peek()->type == Token::LITERAL) {
Token* tok = lexer.nextToken();
((txNodeTypeTest*)nodeTest)->setNodeName(tok->value);
}
if (lexer.nextToken()->type != Token::R_PAREN) {
lexer.pushBack();
//XXX ErrorReport: right parenthesis expected (or literal for pi)
delete nodeTest;
return 0;
}
return nodeTest;
} //-- createNodeExpr
/**
* Creates a PathExpr using the given ExprLexer
* @param lexer the ExprLexer for retrieving Tokens
**/
Expr* ExprParser::createPathExpr(ExprLexer& lexer) {
Expr* expr = 0;
Token* tok = lexer.peek();
// is this a root expression?
if (tok->type == Token::PARENT_OP) {
lexer.nextToken();
if (!isLocationStepToken(lexer.peek()))
return new RootExpr(MB_TRUE);
lexer.pushBack();
}
// parse first step (possibly a FilterExpr)
if (tok->type != Token::PARENT_OP &&
tok->type != Token::ANCESTOR_OP) {
if (isFilterExprToken(tok)) {
expr = createFilterExpr(lexer);
}
else
expr = createLocationStep(lexer);
if (!expr)
return 0;
// is this a singlestep path expression?
tok = lexer.peek();
if (tok->type != Token::PARENT_OP &&
tok->type != Token::ANCESTOR_OP)
return expr;
}
else {
expr = new RootExpr(MB_FALSE);
if (!expr) {
// XXX ErrorReport: out of memory
return 0;
}
}
// We have a PathExpr containing several steps
PathExpr* pathExpr = new PathExpr();
if (!pathExpr) {
// XXX ErrorReport: out of memory
delete expr;
return 0;
}
pathExpr->addExpr(expr, PathExpr::RELATIVE_OP);
// this is ugly
while (1) {
PathExpr::PathOperator pathOp;
tok = lexer.nextToken();
switch (tok->type) {
case Token::ANCESTOR_OP :
pathOp = PathExpr::DESCENDANT_OP;
break;
case Token::PARENT_OP :
pathOp = PathExpr::RELATIVE_OP;
break;
default:
lexer.pushBack();
return pathExpr;
}
expr = createLocationStep(lexer);
if (!expr) {
delete pathExpr;
return 0;
}
pathExpr->addExpr(expr, pathOp);
}
return pathExpr;
} //-- createPathExpr
/**
* Creates a PathExpr using the given ExprLexer
* XXX temporary use as top of XSLT Pattern
* @param lexer the ExprLexer for retrieving Tokens
**/
Expr* ExprParser::createUnionExpr(ExprLexer& lexer) {
Expr* expr = createPathExpr(lexer);
if (!expr)
return 0;
if (lexer.peek()->type != Token::UNION_OP)
return expr;
UnionExpr* unionExpr = new UnionExpr();
unionExpr->addExpr(expr);
while (lexer.peek()->type == Token::UNION_OP) {
lexer.nextToken(); //-- eat token
expr = createPathExpr(lexer);
if (!expr) {
delete unionExpr;
return 0;
}
unionExpr->addExpr(expr);
}
return unionExpr;
} //-- createUnionExpr
MBool ExprParser::isFilterExprToken(Token* token) {
switch (token->type) {
case Token::LITERAL:
case Token::NUMBER:
case Token::FUNCTION_NAME:
case Token::VAR_REFERENCE:
case Token::L_PAREN: // grouping expr
return MB_TRUE;
default:
return MB_FALSE;
}
} //-- isFilterExprToken
MBool ExprParser::isLocationStepToken(Token* token) {
switch (token->type) {
case Token::AXIS_IDENTIFIER :
case Token::AT_SIGN :
case Token::PARENT_NODE :
case Token::SELF_NODE :
return MB_TRUE;
default:
return isNodeTypeToken(token);
}
} //-- isLocationStepToken
MBool ExprParser::isNodeTypeToken(Token* token) {
switch (token->type) {
case Token::CNAME:
case Token::COMMENT:
case Token::NODE :
case Token::PROC_INST :
case Token::TEXT :
return MB_TRUE;
default:
return MB_FALSE;
}
} //-- isNodeTypeToken
/**
* Using the given lexer, parses the tokens if they represent a predicate list
* If an error occurs a non-zero String pointer will be returned containing the
* error message.
* @param predicateList, the PredicateList to add predicate expressions to
* @param lexer the ExprLexer to use for parsing tokens
* @return 0 if successful, or a String pointer to the error message
**/
MBool ExprParser::parsePredicates(PredicateList* predicateList, ExprLexer& lexer) {
while (lexer.peek()->type == Token::L_BRACKET) {
//-- eat Token
lexer.nextToken();
Expr* expr = createExpr(lexer);
if (!expr)
return MB_FALSE;
predicateList->add(expr);
if (lexer.nextToken()->type != Token::R_BRACKET) {
lexer.pushBack();
//XXX ErrorReport: right bracket expected
return MB_FALSE;
}
}
return MB_TRUE;
} //-- parsePredicates
/**
* Using the given lexer, parses the tokens if they represent a parameter list
* If an error occurs a non-zero String pointer will be returned containing the
* error message.
* @param list, the List to add parameter expressions to
* @param lexer the ExprLexer to use for parsing tokens
* @return MB_TRUE if successful, or a MB_FALSE otherwise
**/
MBool ExprParser::parseParameters(FunctionCall* fnCall, ExprLexer& lexer) {
if (lexer.nextToken()->type != Token::L_PAREN) {
lexer.pushBack();
//XXX ErrorReport: left parenthesis expected
return MB_FALSE;
}
if (lexer.peek()->type == Token::R_PAREN) {
lexer.nextToken();
return MB_TRUE;
}
while (1) {
Expr* expr = createExpr(lexer);
if (!expr)
return MB_FALSE;
fnCall->addParam(expr);
switch (lexer.nextToken()->type) {
case Token::R_PAREN :
return MB_TRUE;
case Token::COMMA: //-- param separator
break;
default:
lexer.pushBack();
//XXX ErrorReport: right parenthesis or comma expected
return MB_FALSE;
}
}
return MB_FALSE;
} //-- parseParameters
short ExprParser::precedenceLevel(short tokenType) {
switch (tokenType) {
case Token::OR_OP:
return 1;
case Token::AND_OP:
return 2;
//-- equality
case Token::EQUAL_OP:
case Token::NOT_EQUAL_OP:
return 3;
//-- relational
case Token::LESS_THAN_OP:
case Token::GREATER_THAN_OP:
case Token::LESS_OR_EQUAL_OP:
case Token::GREATER_OR_EQUAL_OP:
return 4;
//-- additive operators
case Token::ADDITION_OP:
case Token::SUBTRACTION_OP:
return 5;
//-- multiplicative
case Token::DIVIDE_OP:
case Token::MULTIPLY_OP:
case Token::MODULUS_OP:
return 6;
default:
break;
}
return 0;
} //-- precedenceLevel

View File

@@ -1,95 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.
*
*/
/**
* ExprParser
* This class is used to parse XSL Expressions
* @see ExprLexer
**/
#ifndef MITREXSL_EXPRPARSER_H
#define MITREXSL_EXPRPARSER_H
#include "TxString.h"
#include "ExprLexer.h"
#include "Expr.h"
#include "List.h"
class ExprParser {
public:
/**
* Creates a new ExprParser
**/
ExprParser();
/**
* destroys the ExprParser
**/
~ExprParser();
Expr* createExpr(const String& aExpression);
Pattern* createPattern(const String& aPattern);
/**
* Creates an Attribute Value Template using the given value
**/
AttributeValueTemplate* createAttributeValueTemplate(const String& attValue);
private:
Expr* createBinaryExpr (Expr* left, Expr* right, Token* op);
Expr* createExpr (ExprLexer& lexer);
Expr* createFilterExpr (ExprLexer& lexer);
FunctionCall* createFunctionCall (ExprLexer& lexer);
LocationStep* createLocationStep (ExprLexer& lexer);
txNodeTest* createNodeTest (ExprLexer& lexer);
Expr* createPathExpr (ExprLexer& lexer);
Expr* createUnionExpr (ExprLexer& lexer);
MBool isFilterExprToken (Token* tok);
MBool isLocationStepToken (Token* tok);
MBool isNodeTypeToken (Token* tok);
static short precedenceLevel (short tokenType);
/**
* Using the given lexer, parses the tokens if they represent a predicate list
* If an error occurs a non-zero String pointer will be returned containing the
* error message.
* @param predicateList, the PredicateList to add predicate expressions to
* @param lexer the ExprLexer to use for parsing tokens
* @return 0 if successful, or a String pointer to the error message
**/
MBool parsePredicates(PredicateList* predicateList, ExprLexer& lexer);
MBool parseParameters(FunctionCall* fnCall, ExprLexer& lexer);
}; //-- ExprParser
#endif

View File

@@ -1,140 +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
* -- changed constant short result types to enum
*
*/
#ifndef TRANSFRMX_EXPRRESULT_H
#define TRANSFRMX_EXPRRESULT_H
#include "TxObject.h"
#include "primitives.h"
/*
* ExprResult
*
* Classes Represented:
* BooleanResult, ExprResult, NumberResult, StringResult
*
* Note: for NodeSet, see NodeSet.h
*/
class ExprResult : public TxObject {
public:
//-- ResultTypes
enum ResultType {
NODESET = 1,
STRING,
BOOLEAN,
TREE_FRAGMENT,
NUMBER
};
virtual ~ExprResult() {};
/**
* Returns the type of ExprResult represented
* @return the type of ExprResult represented
**/
virtual short getResultType() = 0;
/**
* Creates a String representation of this ExprResult
* @param str the destination string to append the String representation to.
**/
virtual void stringValue(String& str) = 0;
/**
* Converts this ExprResult to a Boolean (MBool) value
* @return the Boolean value
**/
virtual MBool booleanValue() = 0;
/**
* Converts this ExprResult to a Number (double) value
* @return the Number value
**/
virtual double numberValue() = 0;
};
class BooleanResult : public ExprResult {
public:
BooleanResult();
BooleanResult(MBool boolean);
virtual short getResultType();
virtual void stringValue(String& str);
virtual MBool booleanValue();
virtual double numberValue();
private:
MBool value;
};
class NumberResult : public ExprResult {
public:
NumberResult();
NumberResult(double dbl);
double getValue() const;
MBool isNaN() const;
virtual short getResultType();
virtual void stringValue(String& str);
virtual MBool booleanValue();
virtual double numberValue();
private:
double value;
};
class StringResult : public ExprResult {
public:
StringResult();
StringResult(const String& str);
StringResult(const char* str);
virtual short getResultType();
virtual void stringValue(String& str);
virtual MBool booleanValue();
virtual double numberValue();
private:
String value;
};
#endif

View File

@@ -1,123 +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 XSL:P XSLT processor.
*
* The Initial Developer of the Original Code is Keith Visco.
* Portions created by Keith Visco are Copyright (C) 1999, 2000 Keith Visco.
* All Rights Reserved.
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
*/
#include "FunctionLib.h"
const String ExtensionFunctionCall::UNDEFINED_FUNCTION = "Undefined Function: ";
/**
* Creates an ExtensionFunctionCall with the given function name.
* @param name the name of the extension function which to invoke
**/
ExtensionFunctionCall::ExtensionFunctionCall(const String& name) : FunctionCall(name)
{
this->fname = name;
this->fnCall = 0;
} //-- ExtensionFunctionCall
/**
* Deletes an instance of ExtensionFunctioncall
**/
ExtensionFunctionCall::~ExtensionFunctionCall() {
delete fnCall;
} //-- ~ExtensionFunctionCall
/**
* 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* ExtensionFunctionCall::evaluate(Node* context, ContextState* cs) {
//-- check for existing function call resolution
if (!fnCall) {
fnCall = cs->resolveFunctionCall(fname);
if (!fnCall) {
String err(UNDEFINED_FUNCTION);
err.append(fname);
return new StringResult(err);
}
//copy parameters
ListIterator* iter = params.iterator();
while (iter->hasNext()) {
fnCall->addParam( new ExprWrapper( (Expr*) iter->next() ) );
}
delete iter;
}
//-- delegate
return fnCall->evaluate(context, cs);
} //-- evaluate
//---------------------------------/
//- Implementation of ExprWrapper -/
//---------------------------------/
/**
* Creates a new ExprWrapper for the given Expr
**/
ExprWrapper::ExprWrapper(Expr* expr) {
this->expr = expr;
}
/**
* Destructor for ExprWrapper
**/
ExprWrapper::~ExprWrapper() {
//-- DO NOTHING!
}
/**
* 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* ExprWrapper::evaluate(Node* context, ContextState* cs) {
//-- just delegate
if (!expr) return 0; // <-- hopefully this will never happen
return expr->evaluate(context, cs);
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void ExprWrapper::toString(String& str) {
//-- just delegate
if (expr) expr->toString(str);
} //-- toString

View File

@@ -1,129 +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.
* Bob Miller, kbob@oblix.com
* -- plugged core leak.
*
*/
#include "Expr.h"
//-- Implementation of FilterExpr --/
/**
* Creates a new FilterExpr using the given Expr
* @param expr the Expr to use for evaluation
**/
FilterExpr::FilterExpr(Expr* expr) : PredicateList() {
this->expr = expr;
} //-- FilterExpr
/**
* Destroys this FilterExpr, all predicates and the expr will be deleted
**/
FilterExpr::~FilterExpr() {
delete expr;
} //-- ~FilterExpr
//-----------------------------/
//- Virtual methods from Expr -/
//-----------------------------/
/**
* 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 ProcessorState containing the stack information needed
* for evaluation
* @return the result of the evaluation
* @see Expr
**/
ExprResult* FilterExpr::evaluate(Node* context, ContextState* cs) {
if (!context || !expr)
return new NodeSet;
ExprResult* exprResult = expr->evaluate(context, cs);
if (!exprResult)
return 0;
if (exprResult->getResultType() == ExprResult::NODESET) {
// Result is a nodeset, filter it.
cs->sortByDocumentOrder((NodeSet*)exprResult);
evaluatePredicates((NodeSet*)exprResult, cs);
}
else if(!isEmpty()) {
// We can't filter a non-nodeset
String err("Expecting nodeset as result of: ");
expr->toString(err);
cs->recieveError(err);
delete exprResult;
return new NodeSet;
}
return exprResult;
} //-- evaluate
/**
* Returns the default priority of this Pattern based on the given Node,
* context Node, and ContextState.
**/
double FilterExpr::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
NS_ASSERTION(0, "FilterExpr is not allowed in Patterns");
if (isEmpty())
return expr->getDefaultPriority(node, context, cs);
return 0.5;
} //-- getDefaultPriority
/**
* Determines whether this Expr matches the given node within
* the given context
**/
MBool FilterExpr::matches(Node* node, Node* context, ContextState* cs) {
if (!expr)
return MB_FALSE;
ExprResult* exprResult = evaluate(node, cs);
if (!exprResult)
return MB_FALSE;
MBool result = MB_FALSE;
if(exprResult->getResultType() == ExprResult::NODESET)
result = ((NodeSet*)exprResult)->contains(node);
delete exprResult;
return result;
} //-- matches
/**
* Creates a String representation of this Expr
* @param str the destination String to append to
* @see Expr
**/
void FilterExpr::toString(String& str) {
if ( expr ) expr->toString(str);
else str.append("null");
PredicateList::toString(str);
} //-- toString

View File

@@ -1,226 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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"
/**
* This class represents a FunctionCall as defined by the XSL Working Draft
**/
const String FunctionCall::INVALID_PARAM_COUNT =
"invalid number of parameters for function: ";
const String FunctionCall::INVALID_PARAM_VALUE =
"invalid parameter value for function: ";
//- Constructors -/
/**
* Creates a new FunctionCall
**/
FunctionCall::FunctionCall() {
this->name = "void";
} //-- FunctionCall
/**
* Creates a new FunctionCall with the given function
* Note: The object references in parameters will be deleted when this
* FunctionCall gets destroyed.
**/
FunctionCall::FunctionCall(const String& name)
{
//-- copy name
this->name = name;
} //-- FunctionCall
/**
* Destructor
**/
FunctionCall::~FunctionCall()
{
ListIterator* iter = params.iterator();
while (iter->hasNext()) {
iter->next();
Expr* expr = (Expr*) iter->remove();
delete expr;
}
delete iter;
} //-- ~FunctionCall
//------------------/
//- Public Methods -/
//------------------/
/**
* Adds the given parameter to this FunctionCall's parameter list
* @param expr the Expr to add to this FunctionCall's parameter list
**/
void FunctionCall::addParam(Expr* expr)
{
if (expr)
params.add(expr);
} //-- addParam
/**
* Returns the default priority of this Expr based on the given Node,
* context Node, and ContextState.
**/
double FunctionCall::getDefaultPriority(Node* node,
Node* context,
ContextState* cs)
{
return 0.5;
} //-- getDefaultPriority
/**
* Determines whether this Expr matches the given node within
* the given context
**/
MBool FunctionCall::matches(Node* node, Node* context, ContextState* cs)
{
MBool result = MB_FALSE;
ExprResult* exprResult = evaluate(node, cs);
if (exprResult->getResultType() == ExprResult::NODESET) {
NodeSet* nodes = (NodeSet*)exprResult;
result = (nodes->contains(node));
}
delete exprResult;
return result;
} //-- matches
/**
* Evaluates the given Expression and converts it's result to a String.
* The value is appended to the given destination String
**/
void FunctionCall::evaluateToString(Expr* expr, Node* context,
ContextState* cs, String& dest)
{
if (!expr)
return;
ExprResult* exprResult = expr->evaluate(context, cs);
exprResult->stringValue(dest);
delete exprResult;
} //-- evaluateToString
/**
* Evaluates the given Expression and converts it's result to a number.
**/
double FunctionCall::evaluateToNumber(Expr* expr, Node* context,
ContextState* cs)
{
double result = Double::NaN;
if (!expr)
return result;
ExprResult* exprResult = expr->evaluate(context, cs);
result = exprResult->numberValue();
delete exprResult;
return result;
} //-- evaluateToNumber
/*
* Evaluates the given Expression and converts its result to a NodeSet.
* If the result is not a NodeSet NULL is returned.
*/
NodeSet* FunctionCall::evaluateToNodeSet(Expr* aExpr,
Node* aContext,
ContextState* aCs)
{
NS_ASSERTION(aExpr, "Missing expression to evaluate");
ExprResult* exprResult = aExpr->evaluate(aContext, aCs);
if (!exprResult)
return 0;
if (exprResult->getResultType() != ExprResult::NODESET) {
String err("NodeSet expected as argument");
aCs->recieveError(err);
delete exprResult;
return 0;
}
NodeSet* nodes = (NodeSet*)exprResult;
aCs->sortByDocumentOrder(nodes);
return nodes;
}
/**
* Called to check number of parameters
**/
MBool FunctionCall::requireParams (int paramCountMin,
int paramCountMax,
ContextState* cs)
{
int argc = params.getLength();
if ((argc < paramCountMin) || (argc > paramCountMax)) {
String err(INVALID_PARAM_COUNT);
toString(err);
cs->recieveError(err);
return MB_FALSE;
}
return MB_TRUE;
} //-- requireParams
/**
* Called to check number of parameters
**/
MBool FunctionCall::requireParams(int paramCountMin, ContextState* cs)
{
int argc = params.getLength();
if (argc < paramCountMin) {
String err(INVALID_PARAM_COUNT);
toString(err);
cs->recieveError(err);
return MB_FALSE;
}
return MB_TRUE;
} //-- requireParams
/**
* 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 FunctionCall::toString(String& dest)
{
dest.append(this->name);
dest.append('(');
//-- add parameters
ListIterator* iterator = params.iterator();
int argc = 0;
while (iterator->hasNext()) {
if (argc > 0)
dest.append(',');
Expr* expr = (Expr*)iterator->next();
expr->toString(dest);
++argc;
}
delete iterator;
dest.append(')');
} //-- toString

View File

@@ -1,353 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*
* Olivier Gerardin, ogerardin@vo.lu
* -- added number functions
*
* Marina Mechtcheriakova
* -- added support for lang function
*
*/
#ifndef TRANSFRMX_FUNCTIONLIB_H
#define TRANSFRMX_FUNCTIONLIB_H
#include "TxString.h"
#include "primitives.h"
#include "ExprResult.h"
#include "Expr.h"
class XPathNames {
public:
//-- Function Names
static const String BOOLEAN_FN;
static const String CONCAT_FN;
static const String CONTAINS_FN;
static const String COUNT_FN ;
static const String FALSE_FN;
static const String ID_FN;
static const String LANG_FN;
static const String LAST_FN;
static const String LOCAL_NAME_FN;
static const String NAME_FN;
static const String NAMESPACE_URI_FN;
static const String NORMALIZE_SPACE_FN;
static const String NOT_FN;
static const String POSITION_FN;
static const String STARTS_WITH_FN;
static const String STRING_FN;
static const String STRING_LENGTH_FN;
static const String SUBSTRING_FN;
static const String SUBSTRING_AFTER_FN;
static const String SUBSTRING_BEFORE_FN;
static const String SUM_FN;
static const String TRANSLATE_FN;
static const String TRUE_FN;
// OG+
static const String NUMBER_FN;
static const String ROUND_FN;
static const String CEILING_FN;
static const String FLOOR_FN;
// OG-
//-- internal XSL processor functions
static const String ERROR_FN;
}; //-- XPathNames
/**
* The following are definitions for the XPath functions
*
* <PRE>
* Modifications:
* 20000418: Keith Visco
* -- added ExtensionFunctionCall
*
* 19990805: Keith Visco
* - added NodeSetFunctionCall
* - moved position() function into NodeSetFunctionCall
* - removed PositionFunctionCall
* 19990806: Larry Fitzpatrick
* - changed constant short declarations for BooleanFunctionCall
* with enumerations
* 19990806: Keith Visco
* - added StringFunctionCall
* - stated using Larry's enum suggestion instead of using static const shorts,
* as you can see, I am a Java developer! ;-)
* </PRE>
*/
/**
* Represents the Set of boolean functions
**/
class BooleanFunctionCall : public FunctionCall {
public:
enum booleanFunctions { TX_BOOLEAN = 1, TX_FALSE, TX_LANG, TX_NOT, TX_TRUE };
/**
* Creates a BooleanFunctionCall of the given type
**/
BooleanFunctionCall(short type);
/**
* 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
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
private:
short type;
}; //-- BooleanFunctionCall
/**
* Internal Function created when there is an Error during parsing
* an Expression
**/
class ErrorFunctionCall : public FunctionCall {
public:
ErrorFunctionCall();
ErrorFunctionCall(const String& errorMsg);
/**
* 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
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
void setErrorMessage(String& errorMsg);
private:
String errorMessage;
}; //-- ErrorFunctionCall
/**
* Used for extension functions
**/
class ExtensionFunctionCall : public FunctionCall {
public:
static const String UNDEFINED_FUNCTION;
/**
* Creates a new ExtensionFunctionCall with the given function name
* @param name the name of the extension function
**/
ExtensionFunctionCall(const String& name);
/**
* Destructor for extension function call
**/
virtual ~ExtensionFunctionCall();
/**
* 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
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
private:
String fname;
FunctionCall* fnCall;
};
/**
* This class is used by ExtensionFunctionCall, to prevent deletion
* of the parameter expressions, by the resolved function call. The implementation
* for this class is in ExtensionFunctionCall.cpp
**/
class ExprWrapper : public Expr {
public:
/**
* Creates a new ExprWrapper for the given Expr
**/
ExprWrapper(Expr* expr);
/**
* Destructor for ExprWrapper
**/
virtual ~ExprWrapper();
/**
* 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
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
virtual void toString(String& str);
private:
Expr* expr;
}; //-- ExprWrapper
/*
* A representation of the XPath NodeSet funtions
*/
class NodeSetFunctionCall : public FunctionCall {
public:
enum NodeSetFunctions {
COUNT, // count()
ID, // id()
LAST, // last()
LOCAL_NAME, // local-name()
NAMESPACE_URI, // namespace-uri()
NAME, // name()
POSITION // position()
};
/*
* Creates a NodeSetFunctionCall of the given type
*/
NodeSetFunctionCall(NodeSetFunctions aType);
/*
* 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
*/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
private:
NodeSetFunctions mType;
};
/**
* Represents the XPath String Function Calls
**/
class StringFunctionCall : public FunctionCall {
public:
enum stringFunctions {
CONCAT = 1, //-- concat()
CONTAINS, //-- contains()
NORMALIZE_SPACE, //-- normalize-space()
STARTS_WITH, //-- starts-with()
STRING, //-- string()
STRING_LENGTH, //-- string-length()
SUBSTRING, //-- substring()
SUBSTRING_AFTER, //-- substring-after()
SUBSTRING_BEFORE, //-- substring-before()
TRANSLATE //-- translate()
};
/**
* Creates a String function of the given type
**/
StringFunctionCall(short type);
/**
* 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
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
private:
short type;
}; //-- StringFunctionCall
/*
* Represents the XPath Number Function Calls
*/
class NumberFunctionCall : public FunctionCall {
public:
enum NumberFunctions {
NUMBER, // number()
ROUND, // round()
FLOOR, // floor()
CEILING, // ceiling()
SUM // sum()
};
/*
* Creates a Number function of the given type
*/
NumberFunctionCall(NumberFunctions type);
/*
* 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
*/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
private:
NumberFunctions mType;
};
#endif

View File

@@ -1,322 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.
*
*/
/*
Implementation of an XPath LocationStep
*/
#include "Expr.h"
/**
* Creates a new LocationStep using the given NodeExpr and Axis Identifier
* @param nodeExpr the NodeExpr to use when matching Nodes
* @param axisIdentifier the Axis Identifier in which to search for nodes
**/
LocationStep::LocationStep(txNodeTest* aNodeTest,
LocationStepType aAxisIdentifier)
{
mNodeTest = aNodeTest;
mAxisIdentifier = aAxisIdentifier;
} //-- LocationStep
/**
* Destroys this LocationStep
* All predicates will be deleted
* The NodeExpr will be deleted
**/
LocationStep::~LocationStep() {
delete mNodeTest;
} //-- ~LocationStep
//-----------------------------/
//- Virtual methods from Expr -/
//-----------------------------/
/**
* 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 ProcessorState containing the stack information needed
* for evaluation
* @return the result of the evaluation
* @see Expr
**/
ExprResult* LocationStep::evaluate(Node* context, ContextState* cs) {
NodeSet* nodes = new NodeSet();
if (!context || !mNodeTest || !nodes)
return nodes;
Node* node = context;
switch (mAxisIdentifier) {
case ANCESTOR_AXIS :
node = context->getXPathParent();
//-- do not break here
case ANCESTOR_OR_SELF_AXIS :
while (node) {
if (mNodeTest->matches(node, cs)) {
nodes->add(node);
}
node = node->getXPathParent();
}
break;
case ATTRIBUTE_AXIS :
{
NamedNodeMap* atts = context->getAttributes();
if ( atts ) {
for ( PRUint32 i = 0; i < atts->getLength(); i++ ) {
Node* attr = atts->item(i);
if (mNodeTest->matches(attr, cs))
nodes->add(attr);
}
}
break;
}
case DESCENDANT_OR_SELF_AXIS :
if (mNodeTest->matches(context, cs))
nodes->add(context);
//-- do not break here
case DESCENDANT_AXIS :
fromDescendants(context, cs, nodes);
break;
case FOLLOWING_AXIS :
{
if ( node->getNodeType() == Node::ATTRIBUTE_NODE) {
node = node->getXPathParent();
fromDescendants(node, cs, nodes);
}
while (node && !node->getNextSibling()) {
node = node->getXPathParent();
}
while (node) {
node = node->getNextSibling();
if (mNodeTest->matches(node, cs))
nodes->add(node);
if (node->hasChildNodes())
fromDescendants(node, cs, nodes);
while (node && !node->getNextSibling()) {
node = node->getParentNode();
}
}
break;
}
case FOLLOWING_SIBLING_AXIS :
node = context->getNextSibling();
while (node) {
if (mNodeTest->matches(node, cs))
nodes->add(node);
node = node->getNextSibling();
}
break;
case NAMESPACE_AXIS : //-- not yet implemented
#if 0
// XXX DEBUG OUTPUT
cout << "namespace axis not yet implemented"<<endl;
#endif
break;
case PARENT_AXIS :
{
Node* parent = context->getXPathParent();
if (mNodeTest->matches(parent, cs))
nodes->add(parent);
break;
}
case PRECEDING_AXIS :
while (node && !node->getPreviousSibling()) {
node = node->getXPathParent();
}
while (node) {
node = node->getPreviousSibling();
if (node->hasChildNodes())
fromDescendantsRev(node, cs, nodes);
if (mNodeTest->matches(node, cs))
nodes->add(node);
while (node && !node->getPreviousSibling()) {
node = node->getParentNode();
}
}
break;
case PRECEDING_SIBLING_AXIS:
node = context->getPreviousSibling();
while (node) {
if (mNodeTest->matches(node, cs))
nodes->add(node);
node = node->getPreviousSibling();
}
break;
case SELF_AXIS :
if (mNodeTest->matches(context, cs))
nodes->add(context);
break;
default: //-- Children Axis
{
Node* tmpNode = context->getFirstChild();
while (tmpNode) {
if (mNodeTest->matches(tmpNode, cs))
nodes->add(tmpNode);
tmpNode = tmpNode->getNextSibling();
}
break;
}
} //-- switch
//-- apply predicates
evaluatePredicates(nodes, cs);
return nodes;
} //-- evaluate
/**
* Returns the default priority of this Pattern based on the given Node,
* context Node, and ContextState.
**/
double LocationStep::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
if (isEmpty())
return mNodeTest->getDefaultPriority();
return 0.5;
} //-- getDefaultPriority
void LocationStep::fromDescendants(Node* context, ContextState* cs, NodeSet* nodes) {
if (!context)
return;
Node* child = context->getFirstChild();
while (child) {
if (mNodeTest->matches(child, cs))
nodes->add(child);
//-- check childs descendants
if (child->hasChildNodes())
fromDescendants(child, cs, nodes);
child = child->getNextSibling();
}
} //-- fromDescendants
void LocationStep::fromDescendantsRev(Node* context, ContextState* cs, NodeSet* nodes) {
if (!context)
return;
Node* child = context->getLastChild();
while (child) {
//-- check childs descendants
if (child->hasChildNodes())
fromDescendantsRev(child, cs, nodes);
if (mNodeTest->matches(child, cs))
nodes->add(child);
child = child->getPreviousSibling();
}
} //-- fromDescendantsRev
/**
* Determines whether this Expr matches the given node within
* the given context
**/
MBool LocationStep::matches(Node* node, Node* context, ContextState* cs) {
if (!mNodeTest || !node)
return MB_FALSE;
if (!mNodeTest->matches(node, cs))
return MB_FALSE;
MBool result = MB_TRUE;
if (!isEmpty()) {
NodeSet* nodes = (NodeSet*)evaluate(node->getXPathParent(),cs);
result = nodes->contains(node);
delete nodes;
}
else if (mAxisIdentifier == CHILD_AXIS ) {
if (!node->getParentNode())
result = MB_FALSE;
}
return result;
} //-- matches
/**
* Creates a String representation of this Expr
* @param str the destination String to append to
* @see Expr
**/
void LocationStep::toString(String& str) {
switch (mAxisIdentifier) {
case ANCESTOR_AXIS :
str.append("ancestor::");
break;
case ANCESTOR_OR_SELF_AXIS :
str.append("ancestor-or-self::");
break;
case ATTRIBUTE_AXIS:
str.append("@");
break;
case DESCENDANT_AXIS:
str.append("descendant::");
break;
case DESCENDANT_OR_SELF_AXIS:
str.append("descendant-or-self::");
break;
case FOLLOWING_AXIS :
str.append("following::");
break;
case FOLLOWING_SIBLING_AXIS:
str.append("following-sibling::");
break;
case NAMESPACE_AXIS:
str.append("namespace::");
break;
case PARENT_AXIS :
str.append("parent::");
break;
case PRECEDING_AXIS :
str.append("preceding::");
break;
case PRECEDING_SIBLING_AXIS :
str.append("preceding-sibling::");
break;
case SELF_AXIS :
str.append("self::");
break;
default:
break;
}
if (mNodeTest)
mNodeTest->toString(str);
PredicateList::toString(str);
} //-- toString

View File

@@ -1,86 +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 Axel Hecht.
# Portions created by Axel Hecht are Copyright (C) Axel Hecht.
# All Rights Reserved.
#
# Contributor(s):
# Axel Hecht <axel@pike.org>
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifndef TX_EXE
MODULE = transformiix
REQUIRES = string \
xpcom \
dom \
layout \
content \
widget \
$(NULL)
endif
CPPSRCS = AdditiveExpr.cpp \
AttributeValueTemplate.cpp \
BooleanExpr.cpp \
BooleanFunctionCall.cpp \
BooleanResult.cpp \
ErrorFunctionCall.cpp \
Expr.cpp \
ExprLexer.cpp \
ExprLexerChars.cpp \
ExprParser.cpp \
ExtensionFunctionCall.cpp \
FilterExpr.cpp \
FunctionCall.cpp \
LocationStep.cpp \
MultiplicativeExpr.cpp \
NodeSet.cpp \
NodeSetFunctionCall.cpp \
NumberExpr.cpp \
NumberFunctionCall.cpp \
NumberResult.cpp \
PathExpr.cpp \
PredicateList.cpp \
RelationalExpr.cpp \
RootExpr.cpp \
StringExpr.cpp \
StringFunctionCall.cpp \
StringResult.cpp \
txNameTest.cpp \
txNodeTypeTest.cpp \
UnionExpr.cpp \
UnaryExpr.cpp \
VariableRefExpr.cpp \
XPathNames.cpp
ifndef TX_EXE
CPPSRCS += XPathProcessor.cpp \
nsNodeSet.cpp
endif
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../base -I$(srcdir)/../xml \
-I$(srcdir)/../xml/dom \
-I$(srcdir)/../xslt -I$(srcdir)/../xslt/util \
-I$(srcdir)/../xslt/functions \
-I$(srcdir)
libs:: $(OBJS)

View File

@@ -1,151 +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.
*
* NaN/Infinity code copied from the JS-library with permission from
* Netscape Communications Corporation: http://www.mozilla.org/js
* http://lxr.mozilla.org/seamonkey/source/js/src/jsinterp.c
*
*/
/**
* Represents a MultiplicativeExpr, an binary expression that
* performs a multiplicative operation between it's lvalue and rvalue:
* * : multiply
* mod : modulus
* div : divide
**/
#include "Expr.h"
#include <math.h>
/**
* Creates a new MultiplicativeExpr using the given operator
**/
MultiplicativeExpr::MultiplicativeExpr(Expr* leftExpr, Expr* rightExpr, short op) {
this->op = op;
this->leftExpr = leftExpr;
this->rightExpr = rightExpr;
} //-- MultiplicativeExpr
MultiplicativeExpr::~MultiplicativeExpr() {
delete leftExpr;
delete rightExpr;
} //-- ~MultiplicativeExpr
/**
* 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* MultiplicativeExpr::evaluate(Node* context, ContextState* cs) {
double rightDbl = Double::NaN;
ExprResult* exprRes = 0;
if ( rightExpr ) {
exprRes = rightExpr->evaluate(context, cs);
if ( exprRes ) rightDbl = exprRes->numberValue();
delete exprRes;
}
double leftDbl = Double::NaN;
if ( leftExpr ) {
exprRes = leftExpr->evaluate(context, cs);
if ( exprRes ) leftDbl = exprRes->numberValue();
delete exprRes;
}
double result = 0;
switch ( op ) {
case DIVIDE:
if (rightDbl == 0) {
#ifdef XP_PC
/* XXX MSVC miscompiles such that (NaN == 0) */
if (Double::isNaN(rightDbl))
result = Double::NaN;
else
#endif
if (leftDbl == 0 || Double::isNaN(leftDbl))
result = Double::NaN;
else if (Double::isNeg(leftDbl) ^ Double::isNeg(rightDbl))
result = Double::NEGATIVE_INFINITY;
else
result = Double::POSITIVE_INFINITY;
}
else
result = leftDbl / rightDbl;
break;
case MODULUS:
if (rightDbl == 0) {
result = Double::NaN;
}
else {
#ifdef XP_PC
/* Workaround MS fmod bug where 42 % (1/0) => NaN, not 42. */
if (!Double::isInfinite(leftDbl) && Double::isInfinite(rightDbl))
result = leftDbl;
else
#endif
result = fmod(leftDbl, rightDbl);
}
break;
default:
result = leftDbl * rightDbl;
break;
}
return new NumberResult(result);
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void MultiplicativeExpr::toString(String& str) {
if ( leftExpr ) leftExpr->toString(str);
else str.append("null");
switch ( op ) {
case DIVIDE:
str.append(" div ");
break;
case MODULUS:
str.append(" mod ");
break;
default:
str.append(" * ");
break;
}
if ( rightExpr ) rightExpr->toString(str);
else str.append("null");
} //-- toString

View File

@@ -1,356 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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
* -- moved initialization of DEFAULT_SIZE from NodeSet.h to here
*
* Olivier Gerardin, ogerardin@vo.lu
* -- fixed numberValue()
*
*/
#include "NodeSet.h"
#include "XMLDOMUtils.h"
#ifdef TX_EXE
#include <iostream.h>
#endif
/**
* NodeSet
* This class was ported from XSL:P.
**/
//-------------/
//- Constants -/
//-------------/
const int NodeSet::DEFAULT_SIZE = 25;
//----------------/
//- Constructors -/
//----------------/
/**
* Creates a new NodeSet with the default Size
**/
NodeSet::NodeSet() {
initialize(DEFAULT_SIZE);
} //-- NodeSet
/**
* Creates a new NodeSet with the default Size
**/
NodeSet::NodeSet(int size) {
initialize(size);
} //-- NodeSet
/**
* Creates a new NodeSet, copying the Node references from the source
* NodeSet
**/
NodeSet::NodeSet(const NodeSet& source) {
initialize(source.size());
source.copyInto(*this);
} //--NodeSet
/**
* Helper method for Constructors
**/
void NodeSet::initialize(int size) {
checkDuplicates = MB_TRUE;
elements = new Node*[size];
for ( int i = 0; i < size; i++ ) elements[i] = 0;
elementCount = 0;
bufferSize = size;
initialSize = size;
} //-- initialize
/**
* Destructor for NodeSet
**/
NodeSet::~NodeSet() {
delete [] elements;
} //-- ~NodeSet
/**
* Adds the specified Node to this NodeSet if it is not already
* contained within in this NodeSet.
* @param node the Node to add to the NodeSet
* @return true if the Node is added to the NodeSet
**/
MBool NodeSet::add(Node* node) {
if (node) {
if (checkDuplicates && contains(node)) return MB_FALSE;
if (elementCount == bufferSize) increaseSize();
elements[elementCount++] = node;
return MB_TRUE;
}
return MB_FALSE;
} //-- add
/**
* Adds the specified Node to the NodeSet at the specified index,
* as long as the Node is not already contained within the set
* @param node the Node to add to the NodeSet
* @return true if the Node is added to the NodeSet. If the index is
* out of bounds the Node will not be added to the set and false will be returned.
**/
MBool NodeSet::add(int index, Node* node)
{
if (!node || (index < 0) || (index > elementCount)) return MB_FALSE;
if (checkDuplicates && contains(node)) return MB_FALSE;
// make sure we have room to add the object
if (elementCount == bufferSize) increaseSize();
if (index == elementCount) {
elements[elementCount++] = node;
}
else {
shiftUp(index);
elements[index] = node;
++elementCount;
}
return MB_TRUE;
} //-- add
/**
* Removes all elements from the list
**/
void NodeSet::clear() {
for (int i = 0; i < elementCount; i++) {
elements[i] = 0;
}
elementCount = 0;
} //-- clear
/**
* Returns true if the specified Node is contained in the set.
* if the specfied Node is null, then if the NodeSet contains a null
* value, true will be returned.
* @param node the element to search the NodeSet for
* @return true if specified Node is contained in the NodeSet
**/
MBool NodeSet::contains(Node* node) {
return (MBool)(indexOf(node) >= 0);
} //-- contains
/**
* Copies the elements of this NodeSet, into the destination NodeSet
**/
void NodeSet::copyInto(NodeSet& dest) const {
for ( int i = 0; i < elementCount; i++ ) dest.add(elements[i]);
} //-- copyInto
/**
* Returns the Node at the specified position in this NodeSet.
* @param index the position of the Node to return
**/
Node* NodeSet::get(int index) {
if ((index < 0) || index >= elementCount) return 0;
return elements[index];
} //-- get
/**
* Returns true if duplicate checking is enabled, otherwise false.
*
* @return true if duplicate checking is enabled, otherwise false.
**/
MBool NodeSet::getDuplicateChecking() {
return checkDuplicates;
} //-- getDuplicateChecking
/**
* Returns the index of the specified Node,
* or -1 if the Node is not contained in the NodeSet
* @param node the Node to get the index for
**/
int NodeSet::indexOf(Node* node) {
for (int i = 0; i < elementCount; i++)
if (node == elements[i]) return i;
return -1;
} //-- indexOf
/**
* Returns true if there are no Nodes in the NodeSet.
* @return true if there are no Nodes in the NodeSet.
**/
MBool NodeSet::isEmpty() {
return (elementCount == 0) ? MB_TRUE : MB_FALSE;
} //-- isEmpty
/**
* Removes the Node at the specified index from the NodeSet
* @param index the position in the NodeSet to remove the Node from
* @return the Node that was removed from the list
**/
Node* NodeSet::remove(int index) {
if ((index < 0) || (index >= elementCount)) return 0;
Node* node = elements[index];
shiftDown(index+1);
--elementCount;
return node;
} //-- remove
/**
* Removes the the specified Node from the NodeSet
* @param node the Node to remove from the NodeSet
* @return true if the Node was removed from the list
**/
MBool NodeSet::remove(Node* node) {
int index = indexOf(node);
if (index > -1) {
remove(index);
}
else return MB_FALSE;
return MB_TRUE;
} //-- remove
/**
* Enables or disables checking for duplicates. By default
* the #add method will check for duplicate nodes. This should
* only be disabled when no possibility of duplicates could occur.
*
* @param checkDuplicates an MBool indicating, when true, to perform duplicate checking,
* otherwise duplicate checking is disabled.
**/
void NodeSet::setDuplicateChecking(MBool checkDuplicates) {
this->checkDuplicates = checkDuplicates;
} //-- setDuplicateChecking
/**
* Returns the number of elements in the NodeSet
* @return the number of elements in the NodeSet
**/
int NodeSet::size() const{
return elementCount;
} //-- size
/**
* Creates a String representation of this NodeSet
* @param str the destination string to append the String representation to.
**/
void NodeSet::toString(String& str) {
str.append("#NodeSet");
} //-- toString
//-------------------/
//- Private Methods -/
//-------------------/
/**
* increase the NodeSet capacity by a factor of its initial size
**/
void NodeSet::increaseSize() {
bufferSize += bufferSize;
Node** tmpNodes = elements;
elements = new Node*[bufferSize];
int i=0;
for (i=0;i < elementCount; i++) elements[i] = tmpNodes[i];
for (;i<bufferSize;i++)elements[i] = 0;
delete [] tmpNodes;
} //-- increaseSize
/**
* Shifts all elements at the specified index to down by 1
**/
void NodeSet::shiftDown(int index) {
if ((index <= 0) || (index > elementCount)) return;
//-- from Java
//-- System.arraycopy(elements, index, elements, index - 1, elementCount - index);
for (int i = index; i < elementCount; i++) {
elements[i-1] = elements[i];
}
elements[elementCount-1] = 0;
} //-- shiftDown
/**
* Shifts all elements at the specified index up by 1
**/
void NodeSet::shiftUp(int index) {
if (index == elementCount) return;
if (elementCount == bufferSize) increaseSize();
//-- from Java
//-- System.arraycopy(elements, index, elements, index + 1, elementCount - index);
for (int i = elementCount; i > index; i--) {
elements[i] = elements[i-1];
}
} //-- shiftUp
//------------------------------------/
//- Virtual Methods from: ExprResult -/
//------------------------------------/
/**
* Returns the type of ExprResult represented
* @return the type of ExprResult represented
**/
short NodeSet::getResultType() {
return ExprResult::NODESET;
} //-- getResultType
/**
* Converts this ExprResult to a Boolean (MBool) value
* @return the Boolean value
**/
MBool NodeSet::booleanValue() {
return (MBool) (size() > 0);
} //- booleanValue
/**
* Converts this ExprResult to a Number (double) value
* @return the Number value
**/
double NodeSet::numberValue() {
// OG+
// As per the XPath spec, the number value of a node-set is the number value
// of its string value.
String str;
stringValue(str);
return Double::toDouble(str);
// OG-
} //-- numberValue
/**
* Creates a String representation of this ExprResult
* @param str the destination string to append the String representation to.
**/
void NodeSet::stringValue(String& str) {
if ( size()>0) {
// XXX Sort by document order here
XMLDOMUtils::getNodeValue(get(0), &str);
}
} //-- stringValue

View File

@@ -1,242 +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
* -- moved initialization of DEFAULT_SIZE to NodeSet.cpp
*
*/
/**
* NodeSet
**/
#ifndef TRANSFRMX_NODESET_H
#define TRANSFRMX_NODESET_H
#include "dom.h"
#include "ExprResult.h"
class NodeSet : public ExprResult
{
public:
//----------------/
//- Constructors -/
//----------------/
/**
* Creates a new NodeSet with the default Size
**/
NodeSet();
/**
* Creates a new NodeSet with the specified Size
**/
NodeSet(int size);
/**
* Creates a new NodeSet using the given NodeSet
**/
NodeSet(const NodeSet& source);
/**
* Destructor for NodeSet, will not delete Node References
**/
virtual ~NodeSet();
/**
* Adds the specified Node to this NodeSet if it is not already
* contained within in this NodeSet.
* @param node the Node to add to the NodeSet
* @return true if the Node is added to the NodeSet
**/
MBool add(Node* node);
/**
* Adds the specified Node to the NodeSet at the specified index,
* as long as the Node is not already contained within the set
* @param node the Node to add to the NodeSet
* @return true if the Node is added to the NodeSet
* @exception IndexOutOfBoundsException
**/
MBool add(int index, Node* node);
/**
* Removes all elements from the list
**/
void clear();
/**
* Returns true if the specified Node is contained in the set.
* if the specfied Node is null, then if the NodeSet contains a null
* value, true will be returned.
* @param node the element to search the NodeSet for
* @return true if specified Node is contained in the NodeSet
**/
MBool contains(Node* node);
/**
* Copies the elements of this NodeSet, into the destination NodeSet
**/
void copyInto(NodeSet& dest) const;
/**
* Returns the Node at the specified position in this NodeSet.
* @param index the position of the Node to return
* @exception IndexOutOfBoundsException
**/
Node* get(int index);
/**
* Returns true if duplicate checking is enabled, otherwise false.
*
* @return true if duplicate checking is enabled, otherwise false.
**/
MBool getDuplicateChecking();
/**
* Returns the index of the specified Node,
* or -1 if the Node is not contained in the NodeSet
* @param node the Node to get the index for
**/
int indexOf(Node* node);
/**
* Returns true if there are no Nodes in the NodeSet.
* @return true if there are no Nodes in the NodeSet.
**/
MBool isEmpty();
/**
* Removes the Node at the specified index from the NodeSet
* @param index the position in the NodeSet to remove the Node from
* @return the Node that was removed from the list
**/
Node* remove(int index);
/**
* Removes the the specified Node from the NodeSet
* @param node the Node to remove from the NodeSet
* @return true if the Node was removed from the list
**/
MBool remove(Node* node);
/**
* Enables or disables checking for duplicates. By default
* the #add method will check for duplicate nodes. This should
* only be disabled when no possibility of duplicates could occur.
*
* @param checkDuplicates an MBool indicating, when true, to perform duplicate checking,
* otherwise duplicate checking is disabled.
**/
void setDuplicateChecking(MBool checkDuplicates);
/**
* Returns the number of elements in the NodeSet
* @return the number of elements in the NodeSet
**/
int size() const;
/**
* Creates a String representation of this NodeSet
* @param str the destination string to append the String representation to.
**/
void toString(String& str);
//------------------------------------/
//- Virtual Methods from: ExprResult -/
//------------------------------------/
/**
* Returns the type of ExprResult represented
* @return the type of ExprResult represented
**/
virtual short getResultType();
/**
* Converts this ExprResult to a Boolean (MBool) value
* @return the Boolean value
**/
virtual MBool booleanValue();
/**
* Converts this ExprResult to a Number (double) value
* @return the Number value
**/
virtual double numberValue();
/**
* Creates a String representation of this ExprResult
* @param str the destination string to append the String representation to.
**/
virtual void stringValue(String& str);
private:
//-------------------/
//- Private Members -/
//-------------------/
static const int DEFAULT_SIZE;
Node** elements;
int initialSize;
int bufferSize;
MBool checkDuplicates;
/**
* The next available location in the elements array
**/
int elementCount;
//-------------------/
//- Private Methods -/
//-------------------/
/**
* Helper method for constructors
**/
void initialize(int size);
/**
* increase the NodeSet capacity by a factor of its initial size
**/
void increaseSize();
/**
* Shifts all elements at the specified index to down by 1
**/
void shiftDown(int index);
/**
* Shifts all elements at the specified index up by 1
**/
void shiftUp(int index);
}; //-- NodeSet
#endif

View File

@@ -1,235 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*
* Marina Mechtcheriakova, mmarina@mindspring.com
* -- changed some behavoir to be more compliant with spec
*
*/
/*
* NodeSetFunctionCall
* A representation of the XPath NodeSet funtions
*/
#include "FunctionLib.h"
#include "XMLDOMUtils.h"
#include "Tokenizer.h"
#include "txAtom.h"
/*
* Creates a NodeSetFunctionCall of the given type
*/
NodeSetFunctionCall::NodeSetFunctionCall(NodeSetFunctions aType)
{
mType = aType;
switch (aType) {
case COUNT:
name = XPathNames::COUNT_FN;
break;
case ID:
name = XPathNames::ID_FN;
break;
case LAST:
name = XPathNames::LAST_FN;
break;
case LOCAL_NAME:
name = XPathNames::LOCAL_NAME_FN;
break;
case NAME:
name = XPathNames::NAME_FN;
break;
case NAMESPACE_URI:
name = XPathNames::NAMESPACE_URI_FN;
break;
case POSITION:
name = XPathNames::POSITION_FN;
break;
}
}
/*
* 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* NodeSetFunctionCall::evaluate(Node* aContext, ContextState* aCs) {
ListIterator iter(&params);
switch (mType) {
case COUNT:
{
if (!requireParams(1, 1, aCs))
return new StringResult("error");
NodeSet* nodes;
nodes = evaluateToNodeSet((Expr*)iter.next(), aContext, aCs);
if (!nodes)
return new StringResult("error");
double count = nodes->size();
delete nodes;
return new NumberResult(count);
}
case ID:
{
if (!requireParams(1, 1, aCs))
return new StringResult("error");
ExprResult* exprResult;
exprResult = ((Expr*)iter.next())->evaluate(aContext, aCs);
if (!exprResult)
return new StringResult("error");
NodeSet* resultSet = new NodeSet();
if (!resultSet) {
// XXX ErrorReport: out of memory
return 0;
}
Document* contextDoc;
if (aContext->getNodeType() == Node::DOCUMENT_NODE)
contextDoc = (Document*)aContext;
else
contextDoc = aContext->getOwnerDocument();
if (exprResult->getResultType() == ExprResult::NODESET) {
NodeSet* nodes = (NodeSet*)exprResult;
int i;
for (i = 0; i < nodes->size(); i++) {
String idList, id;
XMLDOMUtils::getNodeValue(nodes->get(i), &idList);
txTokenizer tokenizer(idList);
while (tokenizer.hasMoreTokens()) {
tokenizer.nextToken(id);
resultSet->add(contextDoc->getElementById(id));
}
}
}
else {
String idList, id;
exprResult->stringValue(idList);
txTokenizer tokenizer(idList);
while (tokenizer.hasMoreTokens()) {
tokenizer.nextToken(id);
resultSet->add(contextDoc->getElementById(id));
}
}
delete exprResult;
return resultSet;
}
case LAST:
{
if (!requireParams(0, 0, aCs))
return new StringResult("error");
NodeSet* contextNodeSet = (NodeSet*)aCs->getNodeSetStack()->peek();
if (!contextNodeSet) {
String err("Internal error");
aCs->recieveError(err);
return new StringResult("error");
}
return new NumberResult(contextNodeSet->size());
}
case LOCAL_NAME:
case NAME:
case NAMESPACE_URI:
{
if (!requireParams(0, 1, aCs))
return new StringResult("error");
Node* node = 0;
// Check for optional arg
if (iter.hasNext()) {
NodeSet* nodes;
nodes = evaluateToNodeSet((Expr*)iter.next(), aContext, aCs);
if (!nodes)
return new StringResult("error");
if (nodes->isEmpty()) {
delete nodes;
return new StringResult();
}
node = nodes->get(0);
delete nodes;
}
else {
node = aContext;
}
switch (mType) {
case LOCAL_NAME:
{
String localName;
txAtom* localNameAtom;
node->getLocalName(&localNameAtom);
if (localNameAtom) {
// Node has a localName
TX_GET_ATOM_STRING(localNameAtom, localName);
TX_RELEASE_ATOM(localNameAtom);
}
return new StringResult(localName);
}
case NAMESPACE_URI:
{
return new StringResult(node->getNamespaceURI());
}
case NAME:
{
switch (node->getNodeType()) {
case Node::ATTRIBUTE_NODE:
case Node::ELEMENT_NODE:
case Node::PROCESSING_INSTRUCTION_NODE:
// XXX Namespace: namespaces have a name
return new StringResult(node->getNodeName());
default:
break;
}
return new StringResult();
}
}
}
case POSITION:
{
if (!requireParams(0, 0, aCs))
return new StringResult("error");
NodeSet* contextNodeSet = (NodeSet*)aCs->getNodeSetStack()->peek();
if (!contextNodeSet) {
String err("Internal error");
aCs->recieveError(err);
return new StringResult("error");
}
return new NumberResult(contextNodeSet->indexOf(aContext) + 1);
}
}
String err("Internal error");
aCs->recieveError(err);
return new StringResult("error");
}

View File

@@ -1,59 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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"
//--------------/
//- NumberExpr -/
//--------------/
NumberExpr::NumberExpr(double dbl) {
_value = dbl;
} //-- NumberExpr
/**
* 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* NumberExpr::evaluate(Node* context, ContextState* cs) {
return new NumberResult(_value);
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void NumberExpr::toString(String& str) {
Double::toString(_value, str);
} //-- toString

View File

@@ -1,147 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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):
*
* Olivier Gerardin, ogerardin@vo.lu
* -- original author.
*
* Nisheeth Ranjan, nisheeth@netscape.com
* -- implemented rint function, which was not available on Windows.
*
*/
/*
* NumberFunctionCall
* A representation of the XPath Number funtions
*/
#include "FunctionLib.h"
#include "XMLDOMUtils.h"
#include <math.h>
/*
* Creates a NumberFunctionCall of the given type
*/
NumberFunctionCall::NumberFunctionCall(NumberFunctions aType) {
mType = aType;
switch (mType) {
case ROUND:
name = XPathNames::ROUND_FN;
break;
case CEILING:
name = XPathNames::CEILING_FN;
break;
case FLOOR:
name = XPathNames::FLOOR_FN;
break;
case SUM:
name = XPathNames::SUM_FN;
break;
case NUMBER:
name = XPathNames::NUMBER_FN;
break;
}
}
/*
* 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* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
ListIterator iter(&params);
if (mType == NUMBER) {
if (!requireParams(0, 1, cs))
return new StringResult("error");
}
else {
if (!requireParams(1, 1, cs))
return new StringResult("error");
}
switch (mType) {
case CEILING:
{
double dbl = evaluateToNumber((Expr*)iter.next(), context, cs);
if (Double::isNaN(dbl) || Double::isInfinite(dbl))
return new NumberResult(dbl);
if (Double::isNeg(dbl) && dbl > -1)
return new NumberResult(0 * dbl);
return new NumberResult(ceil(dbl));
}
case FLOOR:
{
double dbl = evaluateToNumber((Expr*)iter.next(), context, cs);
if (Double::isNaN(dbl) ||
Double::isInfinite(dbl) ||
(dbl == 0 && Double::isNeg(dbl)))
return new NumberResult(dbl);
return new NumberResult(floor(dbl));
}
case ROUND:
{
double dbl = evaluateToNumber((Expr*)iter.next(), context, cs);
if (Double::isNaN(dbl) || Double::isInfinite(dbl))
return new NumberResult(dbl);
if (Double::isNeg(dbl) && dbl >= -0.5)
return new NumberResult(0 * dbl);
return new NumberResult(floor(dbl + 0.5));
}
case SUM:
{
NodeSet* nodes;
nodes = evaluateToNodeSet((Expr*)iter.next(), context, cs);
if (!nodes)
return new StringResult("error");
double res = 0;
int i;
for (i = 0; i < nodes->size(); i++) {
String resultStr;
XMLDOMUtils::getNodeValue(nodes->get(i), &resultStr);
res += Double::toDouble(resultStr);
}
delete nodes;
return new NumberResult(res);
}
case NUMBER:
{
if (iter.hasNext())
return new NumberResult(
evaluateToNumber((Expr*)iter.next(), context, cs));
String resultStr;
XMLDOMUtils::getNodeValue(context, &resultStr);
return new NumberResult(Double::toDouble(resultStr));
}
}
return new StringResult("error");
}

View File

@@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*
*/
/**
* NumberResult
* Represents the a number as the result of evaluating an Expr
**/
#include "ExprResult.h"
/**
* Default Constructor
**/
NumberResult::NumberResult() {
value = 0.0;
} //-- NumberResult
/**
* Creates a new NumberResult with the value of the given double parameter
* @param dbl the double to use for initialization of this NumberResult's value
**/
NumberResult::NumberResult(double dbl) {
this->value = dbl;
} //-- NumberResult
/*
* Virtual Methods from ExprResult
*/
short NumberResult::getResultType() {
return ExprResult::NUMBER;
} //-- getResultType
void NumberResult::stringValue(String& str) {
Double::toString(value, str);
} //-- stringValue
MBool NumberResult::booleanValue() {
// OG+
// As per the XPath spec, the boolean value of a number is true if and only if
// it is neither positive 0 nor negative 0 nor NaN
return (MBool)(value != 0.0 && !Double::isNaN(value));
// OG-
} //-- booleanValue
double NumberResult::numberValue() {
return this->value;
} //-- numberValue

View File

@@ -1,297 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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.
*
* Bob Miller, kbob@oblix.com
* -- plugged core leak.
*
* Marina Mechtcheriakova, mmarina@mindspring.com
* -- fixed bug in PathExpr::matches
* - foo//bar would not match properly if there was more than
* one node in the NodeSet (nodes) on the final iteration
*
*/
#include "Expr.h"
#include "XMLUtils.h"
//------------/
//- PathExpr -/
//------------/
/**
* Creates a new PathExpr
**/
PathExpr::PathExpr()
{
//-- do nothing
}
/**
* Destructor, will delete all Expressions
**/
PathExpr::~PathExpr()
{
ListIterator* iter = expressions.iterator();
while (iter->hasNext()) {
iter->next();
PathExprItem* pxi = (PathExprItem*)iter->remove();
delete pxi->expr;
delete pxi;
}
delete iter;
} //-- ~PathExpr
/**
* Adds the Expr to this PathExpr
* @param expr the Expr to add to this PathExpr
**/
void PathExpr::addExpr(Expr* expr, PathOperator pathOp)
{
NS_ASSERTION(expressions.getLength() > 0 || pathOp == RELATIVE_OP,
"First step has to be relative in PathExpr");
if (expr) {
PathExprItem* pxi = new PathExprItem;
if (!pxi) {
// XXX ErrorReport: out of memory
NS_ASSERTION(0, "out of memory");
return;
}
pxi->expr = expr;
pxi->pathOp = pathOp;
expressions.add(pxi);
}
} //-- addPattenExpr
//-----------------------------/
//- Virtual methods from Expr -/
//-----------------------------/
/**
* 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* PathExpr::evaluate(Node* context, ContextState* cs)
{
//-- add selectExpr functionality here
if (!context || (expressions.getLength() == 0))
return new NodeSet(0);
NodeSet* nodes = new NodeSet();
if (!nodes) {
// XXX ErrorReport: out of memory
NS_ASSERTION(0, "out of memory");
return 0;
}
nodes->add(context);
ListIterator iter(&expressions);
PathExprItem* pxi;
while ((pxi = (PathExprItem*)iter.next())) {
NodeSet* tmpNodes = 0;
for (int i = 0; i < nodes->size(); i++) {
Node* node = nodes->get(i);
NodeSet* resNodes;
if (pxi->pathOp == DESCENDANT_OP) {
resNodes = new NodeSet;
evalDescendants(pxi->expr, node, cs, resNodes);
}
else {
ExprResult *res = pxi->expr->evaluate(node, cs);
if (!res || (res->getResultType() != ExprResult::NODESET)) {
//XXX ErrorReport: report nonnodeset error
delete res;
res = new NodeSet;
}
resNodes = (NodeSet*)res;
}
if (tmpNodes) {
resNodes->copyInto(*tmpNodes);
delete resNodes;
}
else
tmpNodes = resNodes;
}
delete nodes;
nodes = tmpNodes;
if (!nodes || (nodes->size() == 0)) break;
}
return nodes;
} //-- evaluate
/**
* Selects from the descendants of the context node
* all nodes that match the Expr
* -- this will be moving to a Utility class
**/
void PathExpr::evalDescendants (Expr* expr, Node* context,
ContextState* cs, NodeSet* resNodes)
{
ExprResult *res = expr->evaluate(context, cs);
if (!res || (res->getResultType() != ExprResult::NODESET)) {
//XXX ErrorReport: report nonnodeset error
}
else
((NodeSet*)res)->copyInto(*resNodes);
delete res;
MBool filterWS = cs->isStripSpaceAllowed(context);
Node* child = context->getFirstChild();
while (child) {
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();
}
} //-- evalDescendants
/**
* Returns the default priority of this Pattern based on the given Node,
* context Node, and ContextState.
**/
double PathExpr::getDefaultPriority(Node* node, Node* context,
ContextState* cs)
{
int size = expressions.getLength();
if (size > 1)
return 0.5;
return ((PathExprItem*)expressions.get(0))->
expr->getDefaultPriority(node, context, cs);
} //-- getDefaultPriority
/**
* Determines whether this Expr matches the given node within
* the given context
**/
MBool PathExpr::matches(Node* node, Node* context, ContextState* cs)
{
/*
* The idea is to split up a path into blocks separated by descendant
* operators. For example "foo/bar//baz/bop//ying/yang" is split up into
* three blocks. The "ying/yang" block is handled by the first while-loop
* and the "foo/bar" and "baz/bop" blocks are handled by the second
* while-loop.
* A block is considered matched when we find a list of ancestors that
* match the block. If there are more than one list of ancestors that
* match a block we only need to find the one furthermost down in the
* tree.
*/
if (!node || (expressions.getLength() == 0))
return MB_FALSE;
ListIterator iter(&expressions);
iter.resetToEnd();
PathExprItem* pxi;
PathOperator pathOp = RELATIVE_OP;
while (pathOp == RELATIVE_OP) {
pxi = (PathExprItem*)iter.previous();
if (!pxi)
return MB_TRUE; // We've stepped through the entire list
if (!node || !pxi->expr->matches(node, 0, cs))
return MB_FALSE;
node = node->getXPathParent();
pathOp = pxi->pathOp;
}
// We have at least one DESCENDANT_OP
Node* blockStart = node;
ListIterator blockIter(iter);
while ((pxi = (PathExprItem*)iter.previous())) {
if (!node)
return MB_FALSE; // There are more steps in the current block
// then ancestors of the tested node
if (!pxi->expr->matches(node, 0, cs)) {
// Didn't match. We restart at beginning of block using a new
// start node
iter = blockIter;
blockStart = blockStart->getXPathParent();
node = blockStart;
}
else {
node = node->getXPathParent();
if (pxi->pathOp == DESCENDANT_OP) {
// We've matched an entire block. Set new start iter and start node
blockIter = iter;
blockStart = node;
}
}
}
return MB_TRUE;
} //-- matches
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void PathExpr::toString(String& dest)
{
ListIterator iter(&expressions);
PathExprItem* pxi = (PathExprItem*)iter.next();
if (pxi) {
NS_ASSERTION(pxi->pathOp == RELATIVE_OP,
"First step should be relative");
pxi->expr->toString(dest);
}
while ((pxi = (PathExprItem*)iter.next())) {
switch (pxi->pathOp) {
case DESCENDANT_OP:
dest.append("//");
break;
case RELATIVE_OP:
dest.append('/');
break;
}
pxi->expr->toString(dest);
}
} //-- toString

View File

@@ -1,129 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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"
/*
* Represents an ordered list of Predicates,
* for use with Step and Filter Expressions
*/
PredicateList::PredicateList()
{
} // PredicateList
/*
* Destructor, will delete all Expressions in the list
*/
PredicateList::~PredicateList()
{
txListIterator iter(&predicates);
while (iter.hasNext()) {
iter.next();
Expr* expr = (Expr*)iter.remove();
delete expr;
}
} // ~PredicateList
/*
* Adds the given Expr to the list
* @param expr the Expr to add to the list
*/
void PredicateList::add(Expr* expr)
{
predicates.add(expr);
} // add
void PredicateList::evaluatePredicates(NodeSet* nodes, ContextState* cs)
{
NS_ASSERTION(nodes, "called evaluatePredicates with NULL NodeSet");
if (!nodes)
return;
cs->getNodeSetStack()->push(nodes);
NodeSet newNodes;
// optimize; set DuplicateChecking to MB_FALSE,
// restore original state later
// we only work with |Node|s already in the NodeSet, so they
// have been checked already, no need to check again in here.
MBool ndsCheckDupl = nodes->getDuplicateChecking();
nodes->setDuplicateChecking(MB_FALSE);
newNodes.setDuplicateChecking(MB_FALSE);
txListIterator iter(&predicates);
while (iter.hasNext()) {
Expr* expr = (Expr*)iter.next();
/*
* add nodes to newNodes that match the expression
* or, if the result is a number, add the node with the right
* position
*/
newNodes.clear();
int nIdx;
for (nIdx = 0; nIdx < nodes->size(); nIdx++) {
Node* node = nodes->get(nIdx);
ExprResult* exprResult = expr->evaluate(node, cs);
if (!exprResult)
break;
switch(exprResult->getResultType()) {
case ExprResult::NUMBER :
// handle default, [position() == numberValue()]
if ((double)(nIdx+1) == exprResult->numberValue())
newNodes.add(node);
break;
default:
if (exprResult->booleanValue())
newNodes.add(node);
break;
}
delete exprResult;
}
// Move new NodeSet to the current one
nodes->clear();
newNodes.copyInto(*nodes);
}
cs->getNodeSetStack()->pop();
// restore DuplicateChecking of NodeSet
nodes->setDuplicateChecking(ndsCheckDupl);
} // evaluatePredicates
/*
* returns true if this predicate list is empty
*/
MBool PredicateList::isEmpty()
{
return (MBool)(predicates.getLength() == 0);
} // isEmpty
void PredicateList::toString(String& dest)
{
txListIterator iter(&predicates);
while (iter.hasNext()) {
Expr* expr = (Expr*) iter.next();
dest.append("[");
expr->toString(dest);
dest.append("]");
}
} // toString

View File

@@ -1,255 +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.
*
* NaN/Infinity code copied from the JS-library with permission from
* Netscape Communications Corporation: http://www.mozilla.org/js
* http://lxr.mozilla.org/seamonkey/source/js/src/jsinterp.c
*
*/
#include "Expr.h"
#include "XMLDOMUtils.h"
//------------------/
//- RelationalExpr -/
//------------------/
RelationalExpr::RelationalExpr(Expr* leftExpr, Expr* rightExpr, short op) {
this->op = op;
this->leftExpr = leftExpr;
this->rightExpr = rightExpr;
} //-- RelationalExpr
RelationalExpr::~RelationalExpr() {
delete leftExpr;
delete rightExpr;
} //-- ~RelationalExpr
/**
* Compares the two ExprResults based on XPath 1.0 Recommendation (section 3.4)
**/
MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
short ltype = left->getResultType();
short rtype = right->getResultType();
MBool result = MB_FALSE;
//-- handle case for just Left NodeSet or Both NodeSets
if (ltype == ExprResult::NODESET) {
NodeSet* nodeSet = (NodeSet*)left;
for ( int i = 0; i < nodeSet->size(); i++) {
String str;
Node* node = nodeSet->get(i);
XMLDOMUtils::getNodeValue(node, &str);
StringResult strResult(str);
result = compareResults(&strResult, right);
if ( result ) break;
}
}
//-- handle case for Just Right NodeSet
else if ( rtype == ExprResult::NODESET) {
NodeSet* nodeSet = (NodeSet*)right;
for ( int i = 0; i < nodeSet->size(); i++) {
String str;
Node* node = nodeSet->get(i);
XMLDOMUtils::getNodeValue(node, &str);
StringResult strResult(str);
result = compareResults(left, &strResult);
if ( result ) break;
}
}
//-- neither NodeSet
else {
if ( op == NOT_EQUAL) {
if ((ltype == ExprResult::BOOLEAN)
|| (rtype == ExprResult::BOOLEAN)) {
result = (left->booleanValue() != right->booleanValue());
}
else if ((ltype == ExprResult::NUMBER) ||
(rtype == ExprResult::NUMBER)) {
double lval = left->numberValue();
double rval = right->numberValue();
#ifdef XP_PC
if (Double::isNaN(lval) || Double::isNaN(rval))
result = MB_TRUE;
else
result = (lval != rval);
#else
result = (lval != rval);
#endif
}
else {
String lStr;
left->stringValue(lStr);
String rStr;
right->stringValue(rStr);
result = !lStr.isEqual(rStr);
}
}
else if ( op == EQUAL) {
if ((ltype == ExprResult::BOOLEAN)
|| (rtype == ExprResult::BOOLEAN)) {
result = (left->booleanValue() == right->booleanValue());
}
else if ((ltype == ExprResult::NUMBER) ||
(rtype == ExprResult::NUMBER)) {
double lval = left->numberValue();
double rval = right->numberValue();
#ifdef XP_PC
if (Double::isNaN(lval) || Double::isNaN(rval))
result = MB_FALSE;
else
result = (lval == rval);
#else
result = (lval == rval);
#endif
}
else {
String lStr;
left->stringValue(lStr);
String rStr;
right->stringValue(rStr);
result = lStr.isEqual(rStr);
}
}
else {
double leftDbl = left->numberValue();
double rightDbl = right->numberValue();
switch( op ) {
case LESS_THAN:
#ifdef XP_PC
if (Double::isNaN(leftDbl) || Double::isNaN(rightDbl))
result = MB_FALSE;
else
result = (leftDbl < rightDbl);
#else
result = (leftDbl < rightDbl);
#endif
break;
case LESS_OR_EQUAL:
#ifdef XP_PC
if (Double::isNaN(leftDbl) || Double::isNaN(rightDbl))
result = MB_FALSE;
else
result = (leftDbl <= rightDbl);
#else
result = (leftDbl <= rightDbl);
#endif
break;
case GREATER_THAN :
#ifdef XP_PC
if (Double::isNaN(leftDbl) || Double::isNaN(rightDbl))
result = MB_FALSE;
else
result = (leftDbl > rightDbl);
#else
result = (leftDbl > rightDbl);
#endif
break;
case GREATER_OR_EQUAL:
#ifdef XP_PC
if (Double::isNaN(leftDbl) || Double::isNaN(rightDbl))
result = MB_FALSE;
else
result = (leftDbl >= rightDbl);
#else
result = (leftDbl >= rightDbl);
#endif
break;
}
}
}
return result;
} //-- compareResult
/**
* 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* RelationalExpr::evaluate(Node* context, ContextState* cs) {
//-- get result of left expression
ExprResult* lResult = 0;
if ( leftExpr ) lResult = leftExpr->evaluate(context, cs);
else return new BooleanResult();
//-- get result of right expr
ExprResult* rResult = 0;
if ( rightExpr ) rResult = rightExpr->evaluate(context, cs);
else {
delete lResult;
return new BooleanResult();
}
BooleanResult* boolResult = new BooleanResult(compareResults(lResult, rResult));
delete lResult;
delete rResult;
return boolResult;
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void RelationalExpr::toString(String& str) {
if ( leftExpr ) leftExpr->toString(str);
else str.append("null");
switch ( op ) {
case NOT_EQUAL:
str.append("!=");
break;
case LESS_THAN:
str.append("<");
break;
case LESS_OR_EQUAL:
str.append("<=");
break;
case GREATER_THAN :
str.append(">");
break;
case GREATER_OR_EQUAL:
str.append(">=");
break;
default:
str.append("=");
break;
}
if ( rightExpr ) rightExpr->toString(str);
else str.append("null");
} //-- toString

View File

@@ -1,89 +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"
/**
* Creates a new RootExpr
* @param aSerialize should this RootExpr be serialized
*/
RootExpr::RootExpr(MBool aSerialize) {
mSerialize = aSerialize;
}
/**
* 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* RootExpr::evaluate(Node* context, ContextState* cs) {
NodeSet* nodeSet = new NodeSet();
if (!nodeSet) {
// XXX ErrorReport: out of memory
NS_ASSERTION(0, "out of memory");
return 0;
}
if (!context)
return nodeSet;
if (context->getNodeType() != Node::DOCUMENT_NODE)
nodeSet->add(context->getOwnerDocument());
else
nodeSet->add(context);
return nodeSet;
} //-- evaluate
/**
* Returns the default priority of this Pattern based on the given Node,
* context Node, and ContextState.
**/
double RootExpr::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
return 0.5;
} //-- getDefaultPriority
/**
* Determines whether this NodeExpr matches the given node within
* the given context
**/
MBool RootExpr::matches(Node* node, Node* context, ContextState* cs) {
return node && (node->getNodeType() == Node::DOCUMENT_NODE);
} //-- matches
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void RootExpr::toString(String& dest) {
if (mSerialize)
dest.append('/');
} //-- toString

View File

@@ -1,67 +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"
/**
* StringExpr
**/
/**
* Creates a new StringExpr
**/
StringExpr::StringExpr(const String& value) {
//-- copy value
this->value.append(value);
} //-- StringExpr
/**
* 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* StringExpr::evaluate(Node* context, ContextState* cs) {
return new StringResult(value);
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void StringExpr::toString(String& str) {
UNICODE_CHAR ch = '\'';
if (value.indexOf(ch) != NOT_FOUND)
ch = '\"';
str.append(ch);
str.append(value);
str.append(ch);
} //-- toString

View File

@@ -1,289 +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.
*
*/
/**
* StringFunctionCall
* A representation of the XPath String funtions
**/
#include "FunctionLib.h"
#include "XMLUtils.h"
#include "XMLDOMUtils.h"
#include <math.h>
/**
* Creates a StringFunctionCall of the given type
**/
StringFunctionCall::StringFunctionCall(short type) : FunctionCall() {
this->type = type;
switch ( type ) {
case CONCAT:
name = XPathNames::CONCAT_FN;
break;
case CONTAINS:
name = XPathNames::CONTAINS_FN;
break;
case STARTS_WITH:
name = XPathNames::STARTS_WITH_FN;
break;
case STRING_LENGTH:
name = XPathNames::STRING_LENGTH_FN;
break;
case SUBSTRING:
name = XPathNames::SUBSTRING_FN;
break;
case SUBSTRING_AFTER:
name = XPathNames::SUBSTRING_AFTER_FN;
break;
case SUBSTRING_BEFORE:
name = XPathNames::SUBSTRING_BEFORE_FN;
break;
case TRANSLATE:
name = XPathNames::TRANSLATE_FN;
break;
default:
name = XPathNames::STRING_FN;
break;
}
} //-- StringFunctionCall
/**
* 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* StringFunctionCall::evaluate(Node* context, ContextState* cs) {
ListIterator* iter = params.iterator();
PRInt32 argc = params.getLength();
String err;
ExprResult* result = 0;
switch ( type ) {
case CONCAT :
if ( requireParams(2, cs) ) {
String resultStr;
while(iter->hasNext()) {
evaluateToString((Expr*)iter->next(),context, cs, resultStr);
}
result = new StringResult(resultStr);
}
else result = new StringResult("");
break;
case CONTAINS :
if ( requireParams(2, 2, cs) ) {
String arg1, arg2;
evaluateToString((Expr*)iter->next(),context, cs, arg1);
evaluateToString((Expr*)iter->next(),context, cs, arg2);
result = new BooleanResult((MBool)(arg1.indexOf(arg2) >= 0));
}
else result = new BooleanResult(MB_FALSE);
break;
case NORMALIZE_SPACE:
if ( requireParams(0, 1, cs) ) {
String resultStr;
if ( argc == 1)
evaluateToString((Expr*)iter->next(),context, cs, resultStr);
else
XMLDOMUtils::getNodeValue(context, &resultStr);
// Leading & Trailing Whitespace
resultStr.trim();
MBool hasSpace = MB_FALSE;
PRInt32 dest=0;
String normed(resultStr.length());
UNICODE_CHAR current;
for (PRInt32 src=0; src<resultStr.length(); src++) {
current=resultStr.charAt(src);
if (current==' ' || current=='\n' ||
current=='\t' || current=='\r') {
if (!hasSpace) {
normed.replace(dest,' ');
dest++;
hasSpace=MB_TRUE;
}
}
else {
normed.replace(dest,current);
dest++;
hasSpace=MB_FALSE;
}
}
result = new StringResult(normed);
}
else result = new StringResult("");
break;
case STARTS_WITH :
if ( requireParams(2, 2, cs) ) {
String arg1, arg2;
evaluateToString((Expr*)iter->next(),context, cs, arg1);
evaluateToString((Expr*)iter->next(),context, cs, arg2);
result = new BooleanResult((MBool)(arg1.indexOf(arg2) == 0));
}
else result = new BooleanResult(MB_FALSE);
break;
case STRING_LENGTH:
if ( requireParams(0, 1, cs) ) {
String resultStr;
if ( argc == 1) {
evaluateToString((Expr*)iter->next(),context, cs, resultStr);
}
else XMLDOMUtils::getNodeValue(context, &resultStr);
result = new NumberResult( (double) resultStr.length());
}
else result = new NumberResult(0.0);
break;
case SUBSTRING:
if ( requireParams(2, 3, cs) ) {
String src;
evaluateToString((Expr*)iter->next(),context, cs, src);
double dbl = evaluateToNumber((Expr*)iter->next(), context, cs);
//-- check for NaN
if ( Double::isNaN(dbl)) {
result = new StringResult("");
break;
}
//-- check for -Infinity
MBool startsNegInf = (dbl==Double::NEGATIVE_INFINITY);
PRInt32 startIdx = startsNegInf?0:(PRInt32)floor(dbl+.5);
PRInt32 endIdx = src.length()+1;
if ( argc == 3) {
dbl = evaluateToNumber((Expr*)iter->next(),context, cs);
if (startsNegInf) {
result = new StringResult("");
break;
}
if (dbl == Double::POSITIVE_INFINITY) ; //already complete
else if ( Double::isNaN(dbl) ||
dbl == Double::NEGATIVE_INFINITY ||
dbl < 0 )
endIdx = 0;
else endIdx = startIdx+(PRInt32)floor(dbl+.5);
}
String resultStr;
//-- strings are indexed starting at 1 for XSL
//-- adjust to a 0-based index
endIdx--;
if (startIdx<1){
startIdx = 0;
} else {
startIdx--;
}
src.subString(startIdx,endIdx,resultStr);
result = new StringResult(resultStr);
}
else result = new StringResult("");
break;
case SUBSTRING_AFTER:
if ( requireParams(2, 2, cs) ) {
String arg1, arg2;
evaluateToString((Expr*)iter->next(),context, cs, arg1);
evaluateToString((Expr*)iter->next(),context, cs, arg2);
PRInt32 idx = arg1.indexOf(arg2);
if ((idx >= 0)&&(idx<arg1.length())) {
PRInt32 len = arg2.length();
arg2.clear();
arg1.subString(idx+len,arg2);
result = new StringResult(arg2);
break;
}
}
result = new StringResult("");
break;
case SUBSTRING_BEFORE:
if ( requireParams(2, 2, cs) ) {
String arg1, arg2;
evaluateToString((Expr*)iter->next(),context, cs, arg1);
evaluateToString((Expr*)iter->next(),context, cs, arg2);
PRInt32 idx = arg1.indexOf(arg2);
if ((idx >= 0)&&(idx<arg1.length())) {
arg2.clear();
arg1.subString(0,idx,arg2);
result = new StringResult(arg2);
break;
}
}
result = new StringResult("");
break;
case TRANSLATE:
if ( requireParams(3, 3, cs) ) {
String src;
evaluateToString((Expr*)iter->next(),context, cs, src);
if (src.isEmpty()) {
result = new StringResult("");
break;
}
String oldChars, newChars;
evaluateToString((Expr*)iter->next(),context, cs, oldChars);
evaluateToString((Expr*)iter->next(),context, cs, newChars);
PRInt32 size = src.length();
UNICODE_CHAR* chars = src.toUnicode(new UNICODE_CHAR[size]);
src.clear();
PRInt32 i;
for (i = 0; i < size; i++) {
PRInt32 idx = oldChars.indexOf(chars[i]);
if (idx >= 0) {
if (idx < newChars.length())
src.append(newChars.charAt(idx));
}
else {
src.append(chars[i]);
}
}
delete chars;
result = new StringResult(src);
}
else
result = new StringResult("");
break;
default : //-- string( object? )
if ( requireParams(0, 1, cs) ) {
String resultStr;
if (iter->hasNext()) {
evaluateToString((Expr*)iter->next(),context, cs, resultStr);
}
else {
XMLDOMUtils::getNodeValue(context, &resultStr);
if ( cs->isStripSpaceAllowed(context) &&
XMLUtils::shouldStripTextnode(resultStr))
resultStr = "";
}
result = new StringResult(resultStr);
}
else result = new StringResult("");
break;
}
delete iter;
return result;
} //-- evaluate

View File

@@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*
*/
/**
* StringResult
* Represents a String as a Result of evaluating an Expr
**/
#include "ExprResult.h"
/**
* Default Constructor
**/
StringResult::StringResult() {
} //-- StringResult
/**
* Creates a new StringResult with the value of the given String parameter
* @param str the String to use for initialization of this StringResult's value
**/
StringResult::StringResult(const String& str) {
//-- copy str
this->value = str;
} //-- StringResult
/**
* Creates a new StringResult with the value of the given String parameter
* @param str the String to use for initialization of this StringResult's value
**/
StringResult::StringResult(const char* str) {
//-- copy str
this->value = str;
} //-- StringResult
/*
* Virtual Methods from ExprResult
*/
short StringResult::getResultType() {
return ExprResult::STRING;
} //-- getResultType
void StringResult::stringValue(String& str) {
str.append(this->value);
} //-- stringValue
MBool StringResult::booleanValue() {
return !value.isEmpty();
} //-- booleanValue
double StringResult::numberValue() {
return Double::toDouble(value);
} //-- numberValue

View File

@@ -1,76 +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 Initial Developer of the Original Code is Jonas Sicking.
* Portions created by Jonas Sicking are Copyright (C) 2001, Jonas Sicking.
* All rights reserved.
*
* Contributor(s):
* Jonas Sicking, sicking@bigfoot.com
* -- original author.
*
* NaN/Infinity code copied from the JS-library with permission from
* Netscape Communications Corporation: http://www.mozilla.org/js
* http://lxr.mozilla.org/seamonkey/source/js/src/jsinterp.c
*
*/
#include "Expr.h"
UnaryExpr::UnaryExpr(Expr* expr)
{
this->expr = expr;
}
UnaryExpr::~UnaryExpr()
{
delete expr;
}
/*
* 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* UnaryExpr::evaluate(Node* context, ContextState* cs)
{
ExprResult* exprRes = expr->evaluate(context, cs);
double value = exprRes->numberValue();
delete exprRes;
#ifdef HPUX
/*
* Negation of a zero doesn't produce a negative
* zero on HPUX. Perform the operation by multiplying with
* -1.
*/
return new NumberResult(-1 * value);
#else
return new NumberResult(-value);
#endif
}
/*
* Returns the String representation of this Expr.
* @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 Expr.
*/
void UnaryExpr::toString(String& str)
{
if (!expr)
return;
str.append('-');
expr->toString(str);
}

View File

@@ -1,154 +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"
//-------------/
//- UnionExpr -/
//-------------/
/**
* Creates a new UnionExpr
**/
UnionExpr::UnionExpr() {
//-- do nothing
}
/**
* Destructor, will delete all Path Expressions
**/
UnionExpr::~UnionExpr() {
ListIterator* iter = expressions.iterator();
while (iter->hasNext()) {
iter->next();
delete (Expr*)iter->remove();
}
delete iter;
} //-- ~UnionExpr
/**
* Adds the Expr to this UnionExpr
* @param expr the Expr to add to this UnionExpr
**/
void UnionExpr::addExpr(Expr* expr) {
if (expr)
expressions.add(expr);
} //-- addExpr
//-----------------------------/
//- Virtual methods from Expr -/
//-----------------------------/
/**
* 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* UnionExpr::evaluate(Node* context, ContextState* cs) {
if (!context || (expressions.getLength() == 0))
return new NodeSet(0);
NodeSet* nodes = new NodeSet();
txListIterator iter(&expressions);
while (iter.hasNext()) {
Expr* expr = (Expr*)iter.next();
ExprResult* exprResult = expr->evaluate(context, cs);
if (exprResult &&
exprResult->getResultType() == ExprResult::NODESET) {
((NodeSet*)exprResult)->copyInto(*nodes);
}
delete exprResult;
}
return nodes;
} //-- evaluate
/**
* Returns the default priority of this Pattern based on the given Node,
* context Node, and ContextState.
**/
double UnionExpr::getDefaultPriority(Node* node, Node* context,
ContextState* cs)
{
//-- find highest priority
double priority = Double::NEGATIVE_INFINITY;
ListIterator iter(&expressions);
while (iter.hasNext()) {
Expr* expr = (Expr*)iter.next();
double tmpPriority = expr->getDefaultPriority(node, context, cs);
if (tmpPriority > priority && expr->matches(node, context, cs))
priority = tmpPriority;
}
return priority;
} //-- getDefaultPriority
/**
* Determines whether this UnionExpr matches the given node within
* the given context
**/
MBool UnionExpr::matches(Node* node, Node* context, ContextState* cs) {
ListIterator* iter = expressions.iterator();
while (iter->hasNext()) {
Expr* expr = (Expr*)iter->next();
if (expr->matches(node, context, cs)) {
delete iter;
return MB_TRUE;
}
}
delete iter;
return MB_FALSE;
} //-- matches
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void UnionExpr::toString(String& dest) {
ListIterator* iter = expressions.iterator();
short count = 0;
while (iter->hasNext()) {
//-- set operator
if (count > 0)
dest.append(" | ");
((Expr*)iter->next())->toString(dest);
++count;
}
delete iter;
} //-- toString

View File

@@ -1,99 +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"
//-------------------/
//- VariableRefExpr -/
//-------------------/
/**
* Creates a VariableRefExpr with the given variable name
**/
VariableRefExpr::VariableRefExpr(const String& name) {
this->name = name;
} //-- VariableRefExpr
/**
* 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* VariableRefExpr::evaluate(Node* context, ContextState* cs) {
ExprResult* exprResult = cs->getVariable(name);
//-- make copy to prevent deletetion
//-- I know, I should add a #copy method to ExprResult, I will
ExprResult* copyOfResult = 0;
if ( exprResult ) {
switch ( exprResult->getResultType() ) {
//-- BooleanResult
case ExprResult::BOOLEAN :
copyOfResult = new BooleanResult(exprResult->booleanValue());
break;
//-- NodeSet
case ExprResult::NODESET :
{
NodeSet* src = (NodeSet*)exprResult;
NodeSet* dest = new NodeSet(src->size());
for ( int i = 0; i < src->size(); i++)
dest->add(src->get(i));
copyOfResult = dest;
break;
}
//-- NumberResult
case ExprResult::NUMBER :
copyOfResult = new NumberResult(exprResult->numberValue());
break;
//-- StringResult
default:
String tmp;
exprResult->stringValue(tmp);
StringResult* strResult = new StringResult(tmp);
copyOfResult = strResult;
break;
}
}
else copyOfResult = new StringResult();
return copyOfResult;
} //-- evaluate
/**
* Returns the String representation of this Expr.
* @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 Expr.
**/
void VariableRefExpr::toString(String& str) {
str.append('$');
str.append(name);
} //-- toString

View File

@@ -1,69 +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.
*
* Marina Mechtcheriakova, mmarina@mindspring.com
* -- added LANG_FN
*
*/
/**
* XPath names
**/
#include "FunctionLib.h"
//-- Function Names
const String XPathNames::BOOLEAN_FN = "boolean";
const String XPathNames::CONCAT_FN = "concat";
const String XPathNames::CONTAINS_FN = "contains";
const String XPathNames::COUNT_FN = "count";
const String XPathNames::FALSE_FN = "false";
const String XPathNames::ID_FN = "id";
const String XPathNames::LAST_FN = "last";
const String XPathNames::LOCAL_NAME_FN = "local-name";
const String XPathNames::NAME_FN = "name";
const String XPathNames::NAMESPACE_URI_FN = "namespace-uri";
const String XPathNames::NORMALIZE_SPACE_FN = "normalize-space";
const String XPathNames::NOT_FN = "not";
const String XPathNames::POSITION_FN = "position";
const String XPathNames::STARTS_WITH_FN = "starts-with";
const String XPathNames::STRING_FN = "string";
const String XPathNames::STRING_LENGTH_FN = "string-length";
const String XPathNames::SUBSTRING_FN = "substring";
const String XPathNames::SUBSTRING_AFTER_FN = "substring-after";
const String XPathNames::SUBSTRING_BEFORE_FN = "substring-before";
const String XPathNames::SUM_FN = "sum";
const String XPathNames::TRANSLATE_FN = "translate";
const String XPathNames::TRUE_FN = "true";
// OG+
const String XPathNames::NUMBER_FN = "number";
const String XPathNames::ROUND_FN = "round";
const String XPathNames::CEILING_FN = "ceiling";
const String XPathNames::FLOOR_FN = "floor";
// OG-
//Marina M. boolean function lang
const String XPathNames::LANG_FN = "lang";
//-- internal XSL processor functions
const String XPathNames::ERROR_FN = "error";

View File

@@ -1,110 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "XPathProcessor.h"
#include "dom.h"
#include "ProcessorState.h"
#include "Expr.h"
#include "nsNodeSet.h"
#include "nsIDOMClassInfo.h"
// QueryInterface implementation for XPathProcessor
NS_INTERFACE_MAP_BEGIN(XPathProcessor)
NS_INTERFACE_MAP_ENTRY(nsIXPathNodeSelector)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(XPathProcessor)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(XPathProcessor)
NS_IMPL_RELEASE(XPathProcessor)
/*
* Creates a new XPathProcessor
*/
XPathProcessor::XPathProcessor()
{
NS_INIT_ISUPPORTS();
}
/*
* Default destructor
*/
XPathProcessor::~XPathProcessor()
{
}
/* nsIDOMNodeList selectNodes (in nsIDOMNode aContextNode, in DOMString aPattern); */
NS_IMETHODIMP XPathProcessor::SelectNodes(nsIDOMNode *aContextNode,
const nsAReadableString & aPattern,
nsIDOMNodeList **_retval)
{
String pattern(PromiseFlatString(aPattern).get());
nsCOMPtr<nsIDOMDocument> aOwnerDOMDocument;
aContextNode->GetOwnerDocument(getter_AddRefs(aOwnerDOMDocument));
nsCOMPtr<nsIDocument> aOwnerDocument = do_QueryInterface(aOwnerDOMDocument);
Document* aDocument = new Document(aOwnerDOMDocument);
Node* aNode = aDocument->createWrapper(aContextNode);
ProcessorState* aProcessorState = new ProcessorState();
ExprParser aParser;
Expr* aExpression = aParser.createExpr(pattern);
ExprResult* exprResult = aExpression->evaluate(aNode, aProcessorState);
nsNodeSet* resultSet;
if (exprResult->getResultType() == ExprResult::NODESET) {
resultSet = new nsNodeSet((NodeSet*)exprResult);
}
else {
// Return an empty nodeset
resultSet = new nsNodeSet(nsnull);
}
*_retval = resultSet;
NS_ADDREF(*_retval);
delete aProcessorState;
delete exprResult;
delete aExpression;
delete aDocument;
return NS_OK;
}

View File

@@ -1,75 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef XPathProcessor_h__
#define XPathProcessor_h__
#include "nsIXPathNodeSelector.h"
/* e4172588-1dd1-11b2-bf09-ec309437245a */
#define TRANSFORMIIX_XPATH_PROCESSOR_CID \
{ 0xe4172588, 0x1dd1, 0x11b2, {0xbf, 0x09, 0xec, 0x30, 0x94, 0x37, 0x24, 0x5a} }
#define TRANSFORMIIX_XPATH_PROCESSOR_CONTRACTID \
"@mozilla.org/xpath-nodeselector;1"
/**
* A class for processing an XPath query
**/
class XPathProcessor : public nsIXPathNodeSelector
{
public:
/**
* Creates a new XPathProcessor
**/
XPathProcessor();
/**
* Default destructor for XPathProcessor
**/
virtual ~XPathProcessor();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIXPathNodeSelector interface
NS_DECL_NSIXPATHNODESELECTOR
};
#endif

View File

@@ -1,90 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
MODULE = transformiix
REQUIRES = string \
xpcom \
dom \
widget \
content \
$(NULL)
include <$(DEPTH)/config/config.mak>
!if defined(TX_EXE)
DEFINES=$(DEFINES) -DTX_EXE
!endif
CPP_OBJS= \
.\$(OBJDIR)\AdditiveExpr.obj \
.\$(OBJDIR)\AttributeValueTemplate.obj \
.\$(OBJDIR)\BooleanExpr.obj \
.\$(OBJDIR)\BooleanFunctionCall.obj \
.\$(OBJDIR)\BooleanResult.obj \
.\$(OBJDIR)\ErrorFunctionCall.obj \
.\$(OBJDIR)\Expr.obj \
.\$(OBJDIR)\ExprLexer.obj \
.\$(OBJDIR)\ExprLexerChars.obj \
.\$(OBJDIR)\ExprParser.obj \
.\$(OBJDIR)\ExtensionFunctionCall.obj \
.\$(OBJDIR)\FilterExpr.obj \
.\$(OBJDIR)\FunctionCall.obj \
.\$(OBJDIR)\LocationStep.obj \
.\$(OBJDIR)\MultiplicativeExpr.obj \
.\$(OBJDIR)\NodeSet.obj \
.\$(OBJDIR)\NodeSetFunctionCall.obj \
.\$(OBJDIR)\NumberExpr.obj \
.\$(OBJDIR)\NumberFunctionCall.obj \
.\$(OBJDIR)\NumberResult.obj \
.\$(OBJDIR)\PathExpr.obj \
.\$(OBJDIR)\PredicateList.obj \
.\$(OBJDIR)\RelationalExpr.obj \
.\$(OBJDIR)\RootExpr.obj \
.\$(OBJDIR)\StringExpr.obj \
.\$(OBJDIR)\StringFunctionCall.obj \
.\$(OBJDIR)\StringResult.obj \
.\$(OBJDIR)\txNameTest.obj \
.\$(OBJDIR)\txNodeTypeTest.obj \
.\$(OBJDIR)\UnionExpr.obj \
.\$(OBJDIR)\UnaryExpr.obj \
.\$(OBJDIR)\VariableRefExpr.obj \
.\$(OBJDIR)\XPathNames.obj \
!if !defined(TX_EXE)
.\$(OBJDIR)\nsNodeSet.obj \
.\$(OBJDIR)\XPathProcessor.obj \
!endif
$(NULL)
EXPORTS = \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom \
-I..\base -I..\xml -I..\xml\dom -I..\xslt \
-I..\xslt\functions -I..\xslt\util
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(OBJDIR) $(CPP_OBJS)

View File

@@ -1,85 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsNodeSet.h"
#include "nsIDOMClassInfo.h"
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
// QueryInterface implementation for nsNodeSet
NS_INTERFACE_MAP_BEGIN(nsNodeSet)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(NodeSet)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsNodeSet)
NS_IMPL_RELEASE(nsNodeSet)
nsNodeSet::nsNodeSet(NodeSet* aNodeSet) {
NS_INIT_ISUPPORTS();
mScriptObject = nsnull;
if (aNodeSet) {
for (int i=0; i < aNodeSet->size(); i++) {
mNodes.AppendElement(aNodeSet->get(i)->getNSObj());
}
}
}
nsNodeSet::~nsNodeSet() {
}
NS_IMETHODIMP
nsNodeSet::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
*aReturn = nsnull;
mNodes.QueryElementAt(aIndex, NS_GET_IID(nsIDOMNode), (void**)aReturn);
return NS_OK;
}
NS_IMETHODIMP
nsNodeSet::GetLength(PRUint32* aLength)
{
mNodes.Count(aLength);
return NS_OK;
}

View File

@@ -1,71 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
*
*
* 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 NPL, 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 NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_NS_NODESET_H
#define TRANSFRMX_NS_NODESET_H
#include "NodeSet.h"
#include "nsIDOMNodeList.h"
#include "nsSupportsArray.h"
class nsNodeSet : public nsIDOMNodeList
{
public:
/**
* Creates a new Mozilla NodeSet from a Transformiix NodeSet
**/
nsNodeSet(NodeSet* aNodeSet);
/**
* Default destructor for nsNodeSet
**/
virtual ~nsNodeSet();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDocumentTransformer interface
NS_DECL_NSIDOMNODELIST
private:
void* mScriptObject;
nsSupportsArray mNodes;
};
#endif

View File

@@ -1,113 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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"
#include "txAtoms.h"
txNameTest::txNameTest(String& aName, Node::NodeType aNodeType)
:mNodeType(aNodeType)
{
int idx = aName.indexOf(':');
if (idx >= 0) {
aName.subString(0, idx, mPrefix);
String localName;
aName.subString(idx+1, localName);
mLocalName = TX_GET_ATOM(localName);
}
else {
mLocalName = TX_GET_ATOM(aName);
}
}
txNameTest::~txNameTest()
{
TX_IF_RELEASE_ATOM(mLocalName);
}
/*
* Determines whether this txNodeTest matches the given node
*/
MBool txNameTest::matches(Node* aNode, ContextState* aCs)
{
if (!aNode || aNode->getNodeType() != mNodeType)
return MB_FALSE;
// Totally wild?
if (mLocalName == txXPathAtoms::_asterix && mPrefix.isEmpty())
return MB_TRUE;
// Compare namespaces
if (mPrefix.isEmpty()) {
if (aNode->getNamespaceID() != kNameSpaceID_None)
return MB_FALSE;
}
else {
String nsURI;
aCs->getNameSpaceURIFromPrefix(mPrefix, nsURI);
if(!aNode->getNamespaceURI().isEqual(nsURI))
return MB_FALSE;
}
// Name wild?
if (mLocalName == txXPathAtoms::_asterix)
return MB_TRUE;
// Compare local-names
txAtom* localName;
aNode->getLocalName(&localName);
MBool result = localName == mLocalName;
TX_IF_RELEASE_ATOM(localName);
return result;
}
/*
* Returns the default priority of this txNodeTest
*/
double txNameTest::getDefaultPriority()
{
if (mLocalName == txXPathAtoms::_asterix) {
if (mPrefix.isEmpty())
return -0.5;
return -0.25;
}
return 0;
}
/*
* Returns the String representation of this txNodeTest.
* @param aDest the String to use when creating the string representation.
* The string representation will be appended to the string.
*/
void txNameTest::toString(String& aDest)
{
if (!mPrefix.isEmpty()) {
aDest.append(mPrefix);
aDest.append(':');
}
String localName;
TX_GET_ATOM_STRING(mLocalName, localName);
aDest.append(localName);
}

View File

@@ -1,119 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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"
#include "txAtom.h"
/*
* Creates a new txNodeTypeTest of the given type
*/
txNodeTypeTest::txNodeTypeTest(NodeType aNodeType)
{
mNodeType = aNodeType;
mNodeName = 0;
}
txNodeTypeTest::~txNodeTypeTest()
{
TX_IF_RELEASE_ATOM(mNodeName);
}
void txNodeTypeTest::setNodeName(const String& aName)
{
mNodeName = TX_GET_ATOM(aName);
}
/*
* Determines whether this txNodeTest matches the given node
*/
MBool txNodeTypeTest::matches(Node* aNode, ContextState* aCs)
{
if (!aNode)
return MB_FALSE;
switch (mNodeType) {
case COMMENT_TYPE:
return aNode->getNodeType() == Node::COMMENT_NODE;
case TEXT_TYPE:
return (aNode->getNodeType() == Node::TEXT_NODE ||
aNode->getNodeType() == Node::CDATA_SECTION_NODE) &&
!aCs->isStripSpaceAllowed(aNode);
case PI_TYPE:
if (aNode->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
txAtom* localName;
MBool result;
result = !mNodeName ||
(aNode->getLocalName(&localName) &&
localName == mNodeName);
TX_IF_RELEASE_ATOM(localName);
return result;
}
return MB_FALSE;
case NODE_TYPE:
return (aNode->getNodeType() != Node::TEXT_NODE &&
aNode->getNodeType() != Node::CDATA_SECTION_NODE) ||
!aCs->isStripSpaceAllowed(aNode);
}
return MB_TRUE;
}
/*
* Returns the default priority of this txNodeTest
*/
double txNodeTypeTest::getDefaultPriority()
{
return mNodeName ? 0 : -0.5;
}
/*
* Returns the String representation of this txNodeTest.
* @param aDest the String to use when creating the string representation.
* The string representation will be appended to the string.
*/
void txNodeTypeTest::toString(String& aDest)
{
switch (mNodeType) {
case COMMENT_TYPE:
aDest.append("comment()");
break;
case TEXT_TYPE:
aDest.append("text()");
break;
case PI_TYPE:
aDest.append("processing-instruction(");
if (mNodeName) {
String str;
TX_GET_ATOM_STRING(mNodeName, str);
aDest.append('\'');
aDest.append(str);
aDest.append('\'');
}
aDest.append(')');
break;
case NODE_TYPE:
aDest.append("node()");
break;
}
}

View File

@@ -1,81 +0,0 @@
/* -*- Mode: C++; 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 TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Jonas Sicking.
* Portions created by the Initial Developer are Copyright (C) 2001
* Jonas Sicking. All Rights Reserved.
*
* Contributor(s):
* Jonas Sicking <sicking@bigfoot.com>
*
* 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 ***** */
TX_ATOM(_asterix, "*");
TX_ATOM(boolean, "boolean");
TX_ATOM(ceiling, "ceiling");
TX_ATOM(concat, "concat");
TX_ATOM(contains, "contains");
TX_ATOM(count, "count");
TX_ATOM(_false, "false");
TX_ATOM(floor, "floor");
TX_ATOM(id, "id");
TX_ATOM(lang, "lang");
TX_ATOM(last, "last");
TX_ATOM(localName, "local-name");
TX_ATOM(name, "name");
TX_ATOM(namespaceUri, "namespace-uri");
TX_ATOM(normalizeSpace, "normalize-space");
TX_ATOM(_not, "not");
TX_ATOM(number, "number");
TX_ATOM(position, "position");
TX_ATOM(round, "round");
TX_ATOM(startsWith, "starts-with");
TX_ATOM(string, "string");
TX_ATOM(stringLength, "string-length");
TX_ATOM(substring, "substring");
TX_ATOM(substringAfter, "substring-after");
TX_ATOM(substringBefore, "substring-before");
TX_ATOM(sum, "sum");
TX_ATOM(translate, "translate");
TX_ATOM(_true, "true");
// XPath Axes
TX_ATOM(ancestor, "ancestor");
TX_ATOM(ancestorOrSelf, "ancestor-or-self");
TX_ATOM(attribute, "attribute");
TX_ATOM(child, "child");
TX_ATOM(descendant, "descendant");
TX_ATOM(descendantOrSelf, "descendant-or-self");
TX_ATOM(following, "following");
TX_ATOM(followingSibling, "following-sibling");
TX_ATOM(_namespace, "namespace");
TX_ATOM(parent, "parent");
TX_ATOM(preceding, "preceding");
TX_ATOM(precedingSibling, "preceding-sibling");
TX_ATOM(self, "self");

View File

@@ -0,0 +1,39 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (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/NPL/
#
# 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 Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,30 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (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/NPL/
#
# 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 Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH=..
DIRS= public res src
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,33 @@
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/NC-rdf#">
<RDF:Bag ID="NC:SoftwareUpdateRoot">
<RDF:li>
<RDF:Bag ID="NC:NewSoftwareToday" NC:title="New Software">
<RDF:li>
<RDF:Description ID="AimUpdate344">
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
<NC:title>AOL AIM</NC:title>
<NC:description>An Instant Message Client</NC:description>
<NC:version>3.4.1.12</NC:version>
<NC:registryKey>/AOL/AIM/</NC:registryKey>
<NC:url>http://home.netscape.com/index.html</NC:url>
</RDF:Description>
</RDF:li>
<RDF:li>
<RDF:Description ID="PGPPlugin345">
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
<NC:title>PGP Plugin For Mozilla</NC:title>
<NC:description>A high grade encryption plugin</NC:description>
<NC:version>1.1.2.0</NC:version>
<NC:registryKey>/PGP/ROCKS/</NC:registryKey>
<NC:url>http://home.netscape.com/index.html</NC:url>
</RDF:Description>
</RDF:li>
</RDF:Bag>
</RDF:li>
</RDF:Bag>
</RDF:RDF>

View File

@@ -0,0 +1,57 @@
window {
display: block;
}
tree {
display: table;
background-color: #FFFFFF;
border: none;
border-spacing: 0px;
width: 100%;
}
treecol {
display: table-column;
width: 200px;
}
treeitem {
display: table-row;
}
treehead {
display: table-header-group;
}
treebody {
display: table-row-group;
}
treecell {
display: table-cell;
font-family: Verdana, Sans-Serif;
font-size: 8pt;
}
treecell[selectedcell] {
background-color: yellow;
}
treehead treeitem treecell {
background-color: #c0c0c0;
border: outset 1px;
border-color: white #707070 #707070 white;
padding-left: 4px;
}
treeitem[type="http://home.netscape.com/NC-rdf#SoftwarePackage"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/SoftwareUpdatePackage.gif");
}
treeitem[type="http://home.netscape.com/NC-rdf#Folder"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/bookmark-folder-closed.gif");
treeitem[type="http://home.netscape.com/NC-rdf#Folder"][open="true"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/bookmark-folder-open.gif");
}

View File

@@ -0,0 +1,123 @@
// the rdf service
var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService();
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
function getAttr(registry,service,attr_name)
{
var attr = registry.GetTarget(service,
RDF.GetResource('http://home.netscape.com/NC-rdf#' + attr_name),
true);
if (attr)
attr = attr.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (attr)
attr = attr.Value;
return attr;
}
function Init()
{
// this is the main rdf file.
var mainRegistry = RDF.GetDataSource('resource://res/rdf/SoftwareUpdates.rdf');
var mainContainer = Components.classes['component://netscape/rdf/container'].createInstance();
mainContainer = mainContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
mainContainer.Init(mainRegistry, RDF.GetResource('NC:SoftwareUpdateDataSources'));
// Now enumerate all of the softwareupdate datasources.
var mainEnumerator = mainContainer.GetElements();
while (mainEnumerator.HasMoreElements())
{
var aDistributor = mainEnumerator.GetNext();
aDistributor = aDistributor.QueryInterface(Components.interfaces.nsIRDFResource);
var distributorContainer = Components.classes['component://netscape/rdf/container'].createInstance();
distributorContainer = distributorContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
var distributorRegistry = RDF.GetDataSource(aDistributor.Value);
var distributorResource = RDF.GetResource('NC:SoftwareUpdateRoot');
distributorContainer.Init(distributorRegistry, distributorResource);
// Now enumerate all of the distributorContainer's packages.
var distributorEnumerator = distributorContainer.GetElements();
while (distributorEnumerator.HasMoreElements())
{
var aPackage = distributorEnumerator.GetNext();
aPackage = aPackage.QueryInterface(Components.interfaces.nsIRDFResource);
// remove any that we do not want.
if (getAttr(distributorRegistry, aPackage, 'title') == "AOL AIM")
{
//distributorContainer.RemoveElement(aPackage, true);
}
}
var tree = document.getElementById('tree');
// Add it to the tree control's composite datasource.
tree.database.AddDataSource(distributorRegistry);
}
// Install all of the stylesheets in the softwareupdate Registry into the
// panel.
// TODO
// XXX hack to force the tree to rebuild
var treebody = document.getElementById('NC:SoftwareUpdateRoot');
treebody.setAttribute('id', 'NC:SoftwareUpdateRoot');
}
function OpenURL(event, node)
{
if (node.getAttribute('type') == "http://home.netscape.com/NC-rdf#SoftwarePackage")
{
url = node.getAttribute('url');
/*window.open(url,'bookmarks');*/
var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore)
{
toolkitCore = new ToolkitCore();
if (toolkitCore)
{
toolkitCore.Init("ToolkitCore");
}
}
if (toolkitCore)
{
toolkitCore.ShowWindow(url,window);
}
dump("OpenURL(" + url + ")\n");
return true;
}
return false;
}
// To get around "window.onload" not working in viewer.
function Boot()
{
var tree = document.getElementById('tree');
if (tree == null) {
setTimeout(Boot, 0);
}
else {
Init();
}
}
setTimeout('Boot()', 0);

View File

@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-stylesheet href="resource:/res/rdf/sidebar.css" type="text/css"?>
<?xml-stylesheet href="resource:/res/rdf/SoftwareUpdate.css" type="text/css"?>
<window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<html:script src="SoftwareUpdate.js"/>
<tree id="tree"
flex="100%"
datasources="rdf:softwareupdates"
ondblclick="return OpenURL(event, event.target.parentNode);">
<treecol rdf:resource="http://home.netscape.com/NC-rdf#title" />
<treecol rdf:resource="http://home.netscape.com/NC-rdf#description" />
<treecol rdf:resource="http://home.netscape.com/NC-rdf#version" />
<treehead>
<treeitem>
<treecell>Title</treecell>
<treecell>Description</treecell>
<treecell>Version</treecell>
</treeitem>
</treehead>
<treebody id="NC:SoftwareUpdateRoot" rdf:containment="http://home.netscape.com/NC-rdf#child" />
</tree>
</window>

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

View File

@@ -0,0 +1,7 @@
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/softwareupdate-schema#">
<RDF:Bag ID="NC:SoftwareUpdateDataSources">
<RDF:li resource="resource:/res/rdf/SoftwareUpdate-Source-1.rdf" />
</RDF:Bag>
</RDF:RDF>

View File

@@ -0,0 +1,6 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
nsISoftwareUpdate.h
nsSoftwareUpdateIIDs.h

View File

@@ -0,0 +1,47 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (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/NPL/
#
# 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 Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
XPIDLSRCS = nsIXPInstallProgress.idl
EXPORTS = \
nsIDOMInstallTriggerGlobal.h \
nsIDOMInstallVersion.h \
nsSoftwareUpdateIIDs.h \
nsISoftwareUpdate.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,113 @@
interface Install
{
/* IID: { 0x18c2f988, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int BAD_PACKAGE_NAME = -200;
const int UNEXPECTED_ERROR = -201;
const int ACCESS_DENIED = -202;
const int TOO_MANY_CERTIFICATES = -203; /* Installer file must have 1 certificate */
const int NO_INSTALLER_CERTIFICATE = -204; /* Installer file must have a certificate */
const int NO_CERTIFICATE = -205; /* Extracted file is not signed */
const int NO_MATCHING_CERTIFICATE = -206; /* Extracted file does not match installer certificate */
const int UNKNOWN_JAR_FILE = -207; /* JAR file has not been opened */
const int INVALID_ARGUMENTS = -208; /* Bad arguments to a function */
const int ILLEGAL_RELATIVE_PATH = -209; /* Illegal relative path */
const int USER_CANCELLED = -210; /* User cancelled */
const int INSTALL_NOT_STARTED = -211;
const int SILENT_MODE_DENIED = -212;
const int NO_SUCH_COMPONENT = -213; /* no such component in the registry. */
const int FILE_DOES_NOT_EXIST = -214; /* File cannot be deleted as it does not exist */
const int FILE_READ_ONLY = -215; /* File cannot be deleted as it is read only. */
const int FILE_IS_DIRECTORY = -216; /* File cannot be deleted as it is a directory */
const int NETWORK_FILE_IS_IN_USE = -217; /* File on the network is in-use */
const int APPLE_SINGLE_ERR = -218; /* error in AppleSingle unpacking */
const int INVALID_PATH_ERR = -219; /* GetFolder() did not like the folderID */
const int PATCH_BAD_DIFF = -220; /* error in GDIFF patch */
const int PATCH_BAD_CHECKSUM_TARGET = -221; /* source file doesn't checksum */
const int PATCH_BAD_CHECKSUM_RESULT = -222; /* final patched file fails checksum */
const int UNINSTALL_FAILED = -223; /* error while uninstalling a package */
const int GESTALT_UNKNOWN_ERR = -5550;
const int GESTALT_INVALID_ARGUMENT = -5551;
const int SUCCESS = 0;
const int REBOOT_NEEDED = 999;
/* install types */
const int LIMITED_INSTALL = 0;
const int FULL_INSTALL = 1;
const int NO_STATUS_DLG = 2;
const int NO_FINALIZE_DLG = 4;
// these should not be public...
/* message IDs*/
const int SU_INSTALL_FILE_UNEXPECTED_MSG_ID = 0;
const int SU_DETAILS_REPLACE_FILE_MSG_ID = 1;
const int SU_DETAILS_INSTALL_FILE_MSG_ID = 2;
//////////////////////////
readonly attribute wstring UserPackageName;
readonly attribute wstring RegPackageName;
void Install();
void AbortInstall();
long AddDirectory( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring subdir,
in boolean forceMode );
long AddSubcomponent( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring targetName,
in boolean forceMode );
long DeleteComponent( in wstring registryName);
long DeleteFile( in InstallFolder folder,
in wstring relativeFileName );
long DiskSpaceAvailable( in InstallFolder folder );
long Execute(in wstring jarSource, in wstring args);
long FinalizeInstall();
long Gestalt (in wstring selector);
InstallFolder GetComponentFolder( in wstring regName,
in wstring subdirectory);
InstallFolder GetFolder(in wstring targetFolder,
in wstring subdirectory);
long GetLastError();
long GetWinProfile(in InstallFolder folder, in wstring file);
long GetWinRegistry();
long Patch( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring targetName );
void ResetError();
void SetPackageFolder( in InstallFolder folder );
long StartInstall( in wstring userPackageName,
in wstring packageName,
in wstring version,
in long flags );
long Uninstall( in wstring packageName);
};

View File

@@ -0,0 +1,24 @@
interface InstallTriggerGlobal
{
/* IID: { 0x18c2f987, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int MAJOR_DIFF = 4;
const int MINOR_DIFF = 3;
const int REL_DIFF = 2;
const int BLD_DIFF = 1;
const int EQUAL = 0;
boolean UpdateEnabled ();
long StartSoftwareUpdate(in wstring URL);
long ConditionalSoftwareUpdate( in wstring URL,
in wstring regName,
in long diffLevel,
in wstring version,
in long mode);
long CompareVersion( in wstring regName, in wstring version );
};

View File

@@ -0,0 +1,34 @@
interface InstallVersion
{
/* IID: { 0x18c2f986, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int EQUAL = 0;
const int BLD_DIFF = 1;
const int BLD_DIFF_MINUS = -1;
const int REL_DIFF = 2;
const int REL_DIFF_MINUS = -2;
const int MINOR_DIFF = 3;
const int MINOR_DIFF_MINUS = -3;
const int MAJOR_DIFF = 4;
const int MAJOR_DIFF_MINUS = -4;
attribute int major;
attribute int minor;
attribute int release;
attribute int build;
void InstallVersion();
void init(in wstring versionString);
/*
void init(in int major, in int minor, in int release, in int build);
*/
wstring toString();
/* int compareTo(in wstring version);
int compareTo(in int major, in int minor, in int release, in int build);
*/
int compareTo(in InstallVersion versionObject);
};

View File

@@ -0,0 +1,36 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (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/NPL/
#
# 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 Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
MODULE=xpinstall
DEPTH=..\..
EXPORTS= nsIDOMInstallTriggerGlobal.h \
nsIDOMInstallVersion.h \
nsSoftwareUpdateIIDs.h \
nsISoftwareUpdate.h
XPIDLSRCS = .\nsIXPInstallProgress.idl
include <$(DEPTH)\config\config.mak>
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1 @@
#error

View File

@@ -0,0 +1,96 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMInstallTriggerGlobal_h__
#define nsIDOMInstallTriggerGlobal_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#define NS_IDOMINSTALLTRIGGERGLOBAL_IID \
{ 0x18c2f987, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
class nsIDOMInstallTriggerGlobal : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLTRIGGERGLOBAL_IID; return iid; }
enum {
MAJOR_DIFF = 4,
MINOR_DIFF = 3,
REL_DIFF = 2,
BLD_DIFF = 1,
EQUAL = 0
};
NS_IMETHOD UpdateEnabled(PRBool* aReturn)=0;
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)=0;
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
};
#define NS_DECL_IDOMINSTALLTRIGGERGLOBAL \
NS_IMETHOD UpdateEnabled(PRBool* aReturn); \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn); \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
#define NS_FORWARD_IDOMINSTALLTRIGGERGLOBAL(_to) \
NS_IMETHOD UpdateEnabled(PRBool* aReturn) { return _to##UpdateEnabled(aReturn); } \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aFlags, aReturn); } \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, nsIDOMInstallVersion* aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aMajor, aMinor, aRelease, aBuild, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
extern nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallTriggerGlobal_h__

View File

@@ -0,0 +1,107 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMInstallVersion_h__
#define nsIDOMInstallVersion_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMInstallVersion;
#define NS_IDOMINSTALLVERSION_IID \
{ 0x18c2f986, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
class nsIDOMInstallVersion : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLVERSION_IID; return iid; }
enum {
EQUAL = 0,
BLD_DIFF = 1,
BLD_DIFF_MINUS = -1,
REL_DIFF = 2,
REL_DIFF_MINUS = -2,
MINOR_DIFF = 3,
MINOR_DIFF_MINUS = -3,
MAJOR_DIFF = 4,
MAJOR_DIFF_MINUS = -4
};
NS_IMETHOD GetMajor(PRInt32* aMajor)=0;
NS_IMETHOD SetMajor(PRInt32 aMajor)=0;
NS_IMETHOD GetMinor(PRInt32* aMinor)=0;
NS_IMETHOD SetMinor(PRInt32 aMinor)=0;
NS_IMETHOD GetRelease(PRInt32* aRelease)=0;
NS_IMETHOD SetRelease(PRInt32 aRelease)=0;
NS_IMETHOD GetBuild(PRInt32* aBuild)=0;
NS_IMETHOD SetBuild(PRInt32 aBuild)=0;
NS_IMETHOD Init(const nsString& aVersionString)=0;
NS_IMETHOD ToString(nsString& aReturn)=0;
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
};
#define NS_DECL_IDOMINSTALLVERSION \
NS_IMETHOD GetMajor(PRInt32* aMajor); \
NS_IMETHOD SetMajor(PRInt32 aMajor); \
NS_IMETHOD GetMinor(PRInt32* aMinor); \
NS_IMETHOD SetMinor(PRInt32 aMinor); \
NS_IMETHOD GetRelease(PRInt32* aRelease); \
NS_IMETHOD SetRelease(PRInt32 aRelease); \
NS_IMETHOD GetBuild(PRInt32* aBuild); \
NS_IMETHOD SetBuild(PRInt32 aBuild); \
NS_IMETHOD Init(const nsString& aVersionString); \
NS_IMETHOD ToString(nsString& aReturn); \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn); \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn); \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
#define NS_FORWARD_IDOMINSTALLVERSION(_to) \
NS_IMETHOD GetMajor(PRInt32* aMajor) { return _to##GetMajor(aMajor); } \
NS_IMETHOD SetMajor(PRInt32 aMajor) { return _to##SetMajor(aMajor); } \
NS_IMETHOD GetMinor(PRInt32* aMinor) { return _to##GetMinor(aMinor); } \
NS_IMETHOD SetMinor(PRInt32 aMinor) { return _to##SetMinor(aMinor); } \
NS_IMETHOD GetRelease(PRInt32* aRelease) { return _to##GetRelease(aRelease); } \
NS_IMETHOD SetRelease(PRInt32 aRelease) { return _to##SetRelease(aRelease); } \
NS_IMETHOD GetBuild(PRInt32* aBuild) { return _to##GetBuild(aBuild); } \
NS_IMETHOD SetBuild(PRInt32 aBuild) { return _to##SetBuild(aBuild); } \
NS_IMETHOD Init(const nsString& aVersionString) { return _to##Init(aVersionString); } \
NS_IMETHOD ToString(nsString& aReturn) { return _to##ToString(aReturn); } \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn) { return _to##CompareTo(aVersionObject, aReturn); } \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn) { return _to##CompareTo(aString, aReturn); } \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn); } \
extern nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallVersion_h__

View File

@@ -0,0 +1,85 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsISoftwareUpdate_h__
#define nsISoftwareUpdate_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsString.h"
#include "nsIXPInstallProgress.h"
#define NS_IXPINSTALLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/xpinstall"
#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component"
#define NS_ISOFTWAREUPDATE_IID \
{ 0x18c2f992, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}\
}
class nsISoftwareUpdate : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID)
NS_IMETHOD InstallJar(const nsString& fromURL,
const nsString& localFile,
long flags) = 0;
NS_IMETHOD RegisterNotifier(nsIXPInstallProgress *notifier) = 0;
NS_IMETHOD InstallPending(void) = 0;
/* FIX: these should be in a private interface */
NS_IMETHOD InstallJarCallBack() = 0;
NS_IMETHOD GetTopLevelNotifier(nsIXPInstallProgress **notifier) = 0;
};
class nsSoftwareUpdateFactory : public nsIFactory
{
public:
nsSoftwareUpdateFactory();
virtual ~nsSoftwareUpdateFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif // nsISoftwareUpdate_h__

View File

@@ -0,0 +1,30 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
[uuid(eea90d40-b059-11d2-915e-c12b696c9333)]
interface nsIXPInstallProgress : nsISupports
{
void BeforeJavascriptEvaluation();
void AfterJavascriptEvaluation();
void InstallStarted([const] in string UIPackageName);
void ItemScheduled([const] in string message );
void InstallFinalization([const] in string message, in long itemNum, in long totNum );
void InstallAborted();
};

View File

@@ -0,0 +1,93 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsIXPInstallProgressNotifier_h__
#define nsIXPInstallProgressNotifier_h__
class nsIXPInstallProgressNotifier
{
public:
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : BeforeJavascriptEvaluation
// Description : This will be called when prior to the install script being evaluate
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void BeforeJavascriptEvaluation(void) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : AfterJavascriptEvaluation
// Description : This will be called after the install script has being evaluated
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void AfterJavascriptEvaluation(void) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallStarted
// Description : This will be called when StartInstall has been called
// Return type : void
// Argument : char* UIPackageName - User Package Name
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallStarted(const char* UIPackageName) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : ItemScheduled
// Description : This will be called when items are being scheduled
// Return type : Any value returned other than zero, will be treated as an error and the script will be aborted
// Argument : The message that should be displayed to the user
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual long ItemScheduled( const char* message ) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallFinalization
// Description : This will be called when the installation is in its Finalize stage
// Return type : void
// Argument : char* message - The message that should be displayed to the user
// Argument : long itemNum - This is the current item number
// Argument : long totNum - This is the total number of items
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallFinalization( const char* message, long itemNum, long totNum ) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallAborted
// Description : This will be called when the install is aborted
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallAborted(void) = 0;
};
#endif

View File

@@ -0,0 +1,64 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsSoftwareUpdateIIDs_h___
#define nsSoftwareUpdateIIDs_h___
#define NS_SoftwareUpdate_CID \
{ /* 18c2f989-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f989, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstall_CID \
{ /* 18c2f98b-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98b, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallTrigger_CID \
{ /* 18c2f98d-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98d, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallVersion_CID \
{ /* 18c2f98f-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98f, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#endif /* nsSoftwareUpdateIIDs_h___ */

View File

@@ -0,0 +1,3 @@
progress.xul
progress.css
progress.html

View File

@@ -0,0 +1,34 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk
EXPORT_RESOURCE_XPINSTALL = \
$(srcdir)/progress.xul \
$(srcdir)/progress.html \
$(srcdir)/progress.css \
$(NULL)
install::
$(INSTALL) $(EXPORT_RESOURCE_XPINSTALL) $(DIST)/bin/res/xpinstall

View File

@@ -0,0 +1,31 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
IGNORE_MANIFEST=1
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) progress.xul $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.css $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.html $(DIST)\bin\res\xpinstall
clobber::
rm -f $(DIST)\res\xpinstall\progress.xul
rm -f $(DIST)\res\xpinstall\progress.css
rm -f $(DIST)\res\xpinstall\progress.html

View File

@@ -0,0 +1,3 @@
TD {
font: 10pt sans-serif;
}

View File

@@ -0,0 +1,16 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#C0C0C0" style="overflow:visible; margin: 0px; color-background: rgb(192,192,192);">
<center>
<table BORDER COLS=5 WIDTH="99%" style="color-background:rgb(192,192,192);">
<tr>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="10%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="81%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
</tr>
</table>
</center>
</body>
</html>

View File

@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<?xml-stylesheet href="../samples/xul.css" type="text/css"?>
<?xml-stylesheet href="progress.css" type="text/css"?>
<!DOCTYPE window
[
<!ENTITY downloadWindow.title "XPInstall Progress">
<!ENTITY status "Status:">
<!ENTITY cancelButtonTitle "Cancel">
]
>
<window xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="XPInstall Progress"
width="425"
height="225">
<data>
<broadcaster id="data.canceled" type="string" value="false"/>
</data>
<html:script>
function cancelInstall()
{
var cancelData = document.getElementById("data.canceled");
cancelData.setAttribute( "value", "true");
}
</html:script>
<html:center>
<html:table style="width:100%;">
<html:tr>
<html:td align="center">
<html:input id="dialog.uiPackageName" readonly="" style="background-color:lightgray;width:300px;"/>
</html:td>
</html:tr>
<html:tr>
<html:td nowrap="" style="border: 1px rgb(192,192,192);" align="center">
<html:input id="dialog.currentAction" readonly="" style="background-color:lightgray;width:450px;"/>
</html:td>
</html:tr>
<html:tr>
<html:td align="center" width="15%" nowrap="" style="border: 1px rgb(192,192,192);">
<progressmeter id="dialog.progress" mode="undetermined" style="width:300px;height:16px;">
</progressmeter>
</html:td>
</html:tr>
<html:tr>
<html:td align="center" width="3%" nowrap="" style="border: 1px rgb(192,192,192);">
<html:button onclick="cancelInstall()" height="12">
&cancelButtonTitle;
</html:button>
</html:td>
</html:tr>
</html:table>
</html:center>
</window>

View File

@@ -0,0 +1,61 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (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/NPL/
#
# 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 Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
LIBRARY_NAME = xpinstall
IS_COMPONENT = 1
REQUIRES = dom js netlib raptor xpcom
CPPSRCS = \
nsSoftwareUpdate.cpp \
nsInstall.cpp \
nsInstallDelete.cpp \
nsInstallExecute.cpp \
nsInstallFile.cpp \
nsInstallFolder.cpp \
nsInstallPatch.cpp \
nsInstallUninstall.cpp \
nsInstallTrigger.cpp \
nsInstallResources.cpp \
nsJSInstall.cpp \
nsJSInstallTriggerGlobal.cpp\
nsSoftwareUpdateRun.cpp \
nsSoftwareUpdateStream.cpp \
nsTopProgressNotifier.cpp \
nsLoggingProgressNotifier \
ScheduledTasks.cpp \
nsInstallFileOpItem.cpp \
$(NULL)
INCLUDES += -I$(srcdir)/../public
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,233 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef SU_PAS_H
#define SU_PAS_H
#include <Errors.h>
#include <Types.h>
#include <Files.h>
#include <Script.h>
#include <Resources.h>
typedef struct PASHeader /* header portion of Patchable AppleSingle */
{
UInt32 magicNum; /* internal file type tag = 0x00244200*/
UInt32 versionNum; /* format version: 1 = 0x00010000 */
UInt8 filler[16]; /* filler */
UInt16 numEntries; /* number of entries which follow */
} PASHeader ;
typedef struct PASEntry /* one Patchable AppleSingle entry descriptor */
{
UInt32 entryID; /* entry type: see list, 0 invalid */
UInt32 entryOffset; /* offset, in bytes, from beginning */
/* of file to this entry's data */
UInt32 entryLength; /* length of data in octets */
} PASEntry;
typedef struct PASMiscInfo
{
short fileHasResFork;
short fileResAttrs;
OSType fileType;
OSType fileCreator;
UInt32 fileFlags;
} PASMiscInfo;
typedef struct PASResFork
{
short NumberOfTypes;
} PASResFork;
typedef struct PASResource
{
short attr;
short attrID;
OSType attrType;
Str255 attrName;
unsigned long length;
} PASResource;
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
#define kCreator 'MOSS'
#define kType 'PASf'
#define PAS_BUFFER_SIZE (1024*512)
#define PAS_MAGIC_NUM (0x00244200)
#define PAS_VERSION (0x00010000)
enum
{
ePas_Data = 1,
ePas_Misc,
ePas_Resource
};
#ifdef __cplusplus
extern "C" {
#endif
/* Prototypes */
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec);
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec);
#ifdef __cplusplus
}
#endif
#endif /* SU_PAS_H */

View File

@@ -0,0 +1,380 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nscore.h"
#include "NSReg.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsInstall.h" // for error codes
#include "prmem.h"
#include "ScheduledTasks.h"
#ifdef _WINDOWS
#include <sys/stat.h>
#include <windows.h>
BOOL WIN32_IsMoveFileExBroken()
{
/* the NT option MOVEFILE_DELAY_UNTIL_REBOOT is broken on
* Windows NT 3.51 Service Pack 4 and NT 4.0 before Service Pack 2
*/
BOOL broken = FALSE;
OSVERSIONINFO osinfo;
// they *all* appear broken--better to have one way that works.
return TRUE;
osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osinfo) && osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if ( osinfo.dwMajorVersion == 3 && osinfo.dwMinorVersion == 51 )
{
if ( 0 == stricmp(osinfo.szCSDVersion,"Service Pack 4"))
{
broken = TRUE;
}
}
else if ( osinfo.dwMajorVersion == 4 )
{
if (osinfo.szCSDVersion[0] == '\0' ||
(0 == stricmp(osinfo.szCSDVersion,"Service Pack 1")))
{
broken = TRUE;
}
}
}
return broken;
}
PRInt32 DoWindowsReplaceExistingFileStuff(const char* currentName, const char* finalName)
{
PRInt32 err = 0;
char* final = strdup(finalName);
char* current = strdup(currentName);
/* couldn't delete, probably in use. Schedule for later */
DWORD dwVersion, dwWindowsMajorVersion;
/* Get OS version info */
dwVersion = GetVersion();
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
/* Get build numbers for Windows NT or Win32s */
if (dwVersion < 0x80000000) // Windows NT
{
/* On Windows NT */
if ( WIN32_IsMoveFileExBroken() )
{
/* the MOVEFILE_DELAY_UNTIL_REBOOT option doesn't work on
* NT 3.51 SP4 or on NT 4.0 until SP2
*/
struct stat statbuf;
PRBool nameFound = PR_FALSE;
char tmpname[_MAX_PATH];
strncpy( tmpname, finalName, _MAX_PATH );
int len = strlen(tmpname);
while (!nameFound && len < _MAX_PATH )
{
tmpname[len-1] = '~';
tmpname[len] = '\0';
if ( stat(tmpname, &statbuf) != 0 )
nameFound = TRUE;
else
len++;
}
if ( nameFound )
{
if ( MoveFile( finalName, tmpname ) )
{
if ( MoveFile( currentName, finalName ) )
{
DeleteFileNowOrSchedule(nsFileSpec(tmpname));
}
else
{
/* 2nd move failed, put old file back */
MoveFile( tmpname, finalName );
}
}
else
{
/* non-executable in use; schedule for later */
return -1; // let the start registry stuff do our work!
}
}
}
else if ( MoveFileEx(currentName, finalName, MOVEFILE_DELAY_UNTIL_REBOOT) )
{
err = 0;
}
}
else // Windows 95 or Win16
{
/*
* Place an entry in the WININIT.INI file in the Windows directory
* to delete finalName and rename currentName to be finalName at reboot
*/
int strlen;
char Src[_MAX_PATH]; // 8.3 name
char Dest[_MAX_PATH]; // 8.3 name
strlen = GetShortPathName( (LPCTSTR)currentName, (LPTSTR)Src, (DWORD)sizeof(Src) );
if ( strlen > 0 )
{
free(current);
current = strdup(Src);
}
strlen = GetShortPathName( (LPCTSTR) finalName, (LPTSTR) Dest, (DWORD) sizeof(Dest));
if ( strlen > 0 )
{
free(final);
final = strdup(Dest);
}
/* NOTE: use OEM filenames! Even though it looks like a Windows
* .INI file, WININIT.INI is processed under DOS
*/
AnsiToOem( final, final );
AnsiToOem( current, current );
if ( WritePrivateProfileString( "Rename", final, current, "WININIT.INI" ) )
err = 0;
}
free(final);
free(current);
return err;
}
#endif
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename)
{
REGERR result = 0;
filename.Delete(false);
if (filename.Exists())
{
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) )
{
// FIX should be using nsPersistentFileDescriptor!!!
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)filename.GetNativePathCString(), REGTYPE_ENTRY_FILE, nsnull, 0);
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
}
return result;
}
/* tmp file is the bad one that we want to replace with target. */
REGERR ReplaceFileNowOrSchedule(nsFileSpec& replacementFile, nsFileSpec& doomedFile )
{
REGERR result = 0;
if(replacementFile == doomedFile)
{
/* do not have to do anything */
return result;
}
doomedFile.Delete(false);
if (! doomedFile.Exists() )
{
// Now that we have move the existing file, we can move the mExtracedFile into place.
nsFileSpec parentofFinalFile;
doomedFile.GetParent(parentofFinalFile);
result = replacementFile.Move(parentofFinalFile);
if ( NS_SUCCEEDED(result) )
{
char* leafName = doomedFile.GetLeafName();
replacementFile.Rename(leafName);
nsCRT::free(leafName);
}
}
else
{
#ifdef _WINDOWS
if (DoWindowsReplaceExistingFileStuff(replacementFile.GetNativePathCString(), doomedFile.GetNativePathCString()) == 0)
return 0;
#endif
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey);
if ( result == REGERR_OK )
{
char* replacementFileName = (char*)(const char*)replacementFile.GetNativePathCString();
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)doomedFile.GetNativePathCString(), REGTYPE_ENTRY_FILE, replacementFileName, strlen(replacementFileName));
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
}
return result;
}
void DeleteScheduledFiles(void);
void ReplaceScheduledFiles(void);
extern "C" void PerformScheduledTasks(void *data)
{
DeleteScheduledFiles();
ReplaceScheduledFiles();
}
void DeleteScheduledFiles(void)
{
HREG reg;
if (REGERR_OK == NR_RegOpen("", &reg))
{
RKEY key;
REGENUM state;
/* perform scheduled file deletions and replacements (PC only) */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY,&key))
{
char buf[MAXREGNAMELEN];
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, buf, sizeof(buf), NULL ))
{
nsFileSpec doomedFile(buf);
doomedFile.Delete(PR_FALSE);
if (! doomedFile.Exists())
{
NR_RegDeleteEntry( reg, key, buf );
}
}
/* delete list node if empty */
if (REGERR_NOMORE == NR_RegEnumEntries( reg, key, &state, buf, sizeof(buf), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
}
}
NR_RegClose(reg);
}
}
void ReplaceScheduledFiles(void)
{
HREG reg;
if (REGERR_OK == NR_RegOpen("", &reg))
{
RKEY key;
REGENUM state;
/* replace files if any listed */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &key))
{
char tmpfile[MAXREGNAMELEN];
char target[MAXREGNAMELEN];
state = 0;
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
{
nsFileSpec replaceFile(tmpfile);
if (! replaceFile.Exists() )
{
NR_RegDeleteEntry( reg, key, tmpfile );
}
else if ( REGERR_OK != NR_RegGetEntryString( reg, key, tmpfile, target, sizeof(target) ) )
{
/* can't read target filename, corruption? */
NR_RegDeleteEntry( reg, key, tmpfile );
}
else
{
nsFileSpec targetFile(target);
targetFile.Delete(PR_FALSE);
if (!targetFile.Exists())
{
nsFileSpec parentofTarget;
targetFile.GetParent(parentofTarget);
nsresult result = replaceFile.Move(parentofTarget);
if ( NS_SUCCEEDED(result) )
{
char* leafName = targetFile.GetLeafName();
replaceFile.Rename(leafName);
nsCRT::free(leafName);
NR_RegDeleteEntry( reg, key, tmpfile );
}
}
}
}
/* delete list node if empty */
if (REGERR_NOMORE == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
}
}
NR_RegClose(reg);
}
}

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __SCHEDULEDTASKS_H__
#define __SCHEDULEDTASKS_H__
#include "NSReg.h"
#include "nsFileSpec.h"
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename);
REGERR ReplaceFileNowOrSchedule(nsFileSpec& tmpfile, nsFileSpec& target );
extern "C" void PerformScheduledTasks(void *data);
#endif

View File

@@ -0,0 +1,135 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*--------------------------------------------------------------
* GDIFF.H
*
* Constants used in processing the GDIFF format
*--------------------------------------------------------------*/
#include "prio.h"
#include "nsFileSpec.h"
#define GDIFF_MAGIC "\xD1\xFF\xD1\xFF"
#define GDIFF_MAGIC_LEN 4
#define GDIFF_VER 5
#define GDIFF_EOF "\0"
#define GDIFF_VER_POS 4
#define GDIFF_CS_POS 5
#define GDIFF_CSLEN_POS 6
#define GDIFF_HEADERSIZE 7
#define GDIFF_APPDATALEN 4
#define GDIFF_CS_NONE 0
#define GDIFF_CS_MD5 1
#define GDIFF_CS_SHA 2
#define GDIFF_CS_CRC32 32
#define CRC32_LEN 4
/*--------------------------------------
* GDIFF opcodes
*------------------------------------*/
#define ENDDIFF 0
#define ADD8MAX 246
#define ADD16 247
#define ADD32 248
#define COPY16BYTE 249
#define COPY16SHORT 250
#define COPY16LONG 251
#define COPY32BYTE 252
#define COPY32SHORT 253
#define COPY32LONG 254
#define COPY64 255
/* instruction sizes */
#define ADD16SIZE 2
#define ADD32SIZE 4
#define COPY16BYTESIZE 3
#define COPY16SHORTSIZE 4
#define COPY16LONGSIZE 6
#define COPY32BYTESIZE 5
#define COPY32SHORTSIZE 6
#define COPY32LONGSIZE 8
#define COPY64SIZE 12
/*--------------------------------------
* error codes
*------------------------------------*/
#define GDIFF_OK 0
#define GDIFF_ERR_UNKNOWN -1
#define GDIFF_ERR_ARGS -2
#define GDIFF_ERR_ACCESS -3
#define GDIFF_ERR_MEM -4
#define GDIFF_ERR_HEADER -5
#define GDIFF_ERR_BADDIFF -6
#define GDIFF_ERR_OPCODE -7
#define GDIFF_ERR_OLDFILE -8
#define GDIFF_ERR_CHKSUMTYPE -9
#define GDIFF_ERR_CHECKSUM -10
#define GDIFF_ERR_CHECKSUM_TARGET -11
#define GDIFF_ERR_CHECKSUM_RESULT -12
/*--------------------------------------
* types
*------------------------------------*/
#ifndef AIX
#ifdef OSF1
#include <sys/types.h>
#else
typedef unsigned char uchar;
#endif
#endif
typedef struct _diffdata {
PRFileDesc* fSrc;
PRFileDesc* fOut;
PRFileDesc* fDiff;
uint8 checksumType;
uint8 checksumLength;
uchar* oldChecksum;
uchar* newChecksum;
PRBool bMacAppleSingle;
PRBool bWin32BoundImage;
uchar* databuf;
uint32 bufsize;
} DIFFDATA;
typedef DIFFDATA* pDIFFDATA;
/*--------------------------------------
* miscellaneous
*------------------------------------*/
#define APPFLAG_W32BOUND "autoinstall:Win32PE"
#define APPFLAG_APPLESINGLE "autoinstall:AppleSingle"
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

View File

@@ -0,0 +1,111 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (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/NPL/
#
# 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 Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH=..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
MODULE=xpinstall
DLL=.\$(OBJDIR)\$(MODULE).dll
DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LINCS= \
-I$(PUBLIC)\xpinstall \
-I$(PUBLIC)\jar \
-I$(PUBLIC)\libreg \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\pref \
-I$(PUBLIC)\rdf \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\nspr2 \
-I$(PUBLIC)\zlib \
-I$(PUBLIC)\xpfe\components \
$(NULL)
LLIBS = \
$(DIST)\lib\jar50.lib \
$(DIST)\lib\libreg32.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\js3250.lib \
$(DIST)\lib\jsdombase_s.lib \
$(DIST)\lib\jsdomevents_s.lib \
$(DIST)\lib\zlib.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR) \
$(NULL)
OBJS = \
.\$(OBJDIR)\nsInstall.obj \
.\$(OBJDIR)\nsInstallTrigger.obj \
.\$(OBJDIR)\nsInstallVersion.obj \
.\$(OBJDIR)\nsInstallFolder.obj \
.\$(OBJDIR)\nsJSInstall.obj \
.\$(OBJDIR)\nsJSInstallTriggerGlobal.obj \
.\$(OBJDIR)\nsJSInstallVersion.obj \
.\$(OBJDIR)\nsSoftwareUpdate.obj \
.\$(OBJDIR)\nsSoftwareUpdateRun.obj \
.\$(OBJDIR)\nsSoftwareUpdateStream.obj \
.\$(OBJDIR)\nsInstallFile.obj \
.\$(OBJDIR)\nsInstallDelete.obj \
.\$(OBJDIR)\nsInstallExecute.obj \
.\$(OBJDIR)\nsInstallPatch.obj \
.\$(OBJDIR)\nsInstallUninstall.obj \
.\$(OBJDIR)\nsInstallResources.obj \
.\$(OBJDIR)\nsTopProgressNotifier.obj \
.\$(OBJDIR)\nsLoggingProgressNotifier.obj\
.\$(OBJDIR)\ScheduledTasks.obj \
.\$(OBJDIR)\nsWinReg.obj \
.\$(OBJDIR)\nsJSWinReg.obj \
.\$(OBJDIR)\nsWinRegItem.obj \
.\$(OBJDIR)\nsWinRegValue.obj \
.\$(OBJDIR)\nsWinProfile.obj \
.\$(OBJDIR)\nsJSWinProfile.obj \
.\$(OBJDIR)\nsWinProfileItem.obj \
.\$(OBJDIR)\nsInstallProgressDialog.obj \
.\$(OBJDIR)\nsInstallFileOpItem.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components
clobber::
rm -f $(DIST)\lib\$(MODULE).lib
rm -f $(DIST)\bin\components\$(MODULE).dll

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,265 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALL_H__
#define __NS_INSTALL_H__
#include "nscore.h"
#include "nsISupports.h"
#include "jsapi.h"
#include "plevent.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsVector.h"
#include "nsHashtable.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstallVersion.h"
#include "nsIXPInstallProgress.h"
class nsInstallInfo
{
public:
nsInstallInfo(const nsString& fromURL, const nsString& localFile, long flags);
nsInstallInfo(nsVector* fromURL, nsVector* localFiles, long flags);
virtual ~nsInstallInfo();
nsString& GetFromURL(PRUint32 index = 0);
nsString& GetLocalFile(PRUint32 index = 0);
void GetArguments(nsString& args, PRUint32 index = 0);
long GetFlags();
PRBool IsMultipleTrigger();
static void DeleteVector(nsVector* vector);
private:
PRBool mMultipleTrigger;
nsresult mError;
long mFlags;
nsVector *mFromURLs;
nsVector *mLocalFiles;
};
class nsInstall
{
friend class nsWinReg;
friend class nsWinProfile;
public:
enum
{
BAD_PACKAGE_NAME = -200,
UNEXPECTED_ERROR = -201,
ACCESS_DENIED = -202,
TOO_MANY_CERTIFICATES = -203,
NO_INSTALLER_CERTIFICATE = -204,
NO_CERTIFICATE = -205,
NO_MATCHING_CERTIFICATE = -206,
UNKNOWN_JAR_FILE = -207,
INVALID_ARGUMENTS = -208,
ILLEGAL_RELATIVE_PATH = -209,
USER_CANCELLED = -210,
INSTALL_NOT_STARTED = -211,
SILENT_MODE_DENIED = -212,
NO_SUCH_COMPONENT = -213,
FILE_DOES_NOT_EXIST = -214,
FILE_READ_ONLY = -215,
FILE_IS_DIRECTORY = -216,
NETWORK_FILE_IS_IN_USE = -217,
APPLE_SINGLE_ERR = -218,
INVALID_PATH_ERR = -219,
PATCH_BAD_DIFF = -220,
PATCH_BAD_CHECKSUM_TARGET = -221,
PATCH_BAD_CHECKSUM_RESULT = -222,
UNINSTALL_FAILED = -223,
GESTALT_UNKNOWN_ERR = -5550,
GESTALT_INVALID_ARGUMENT = -5551,
SUCCESS = 0,
REBOOT_NEEDED = 999,
LIMITED_INSTALL = 0,
FULL_INSTALL = 1,
NO_STATUS_DLG = 2,
NO_FINALIZE_DLG = 4,
INSTALL_FILE_UNEXPECTED_MSG_ID = 0,
DETAILS_REPLACE_FILE_MSG_ID = 1,
DETAILS_INSTALL_FILE_MSG_ID = 2
};
nsInstall();
virtual ~nsInstall();
PRInt32 SetScriptObject(void* aScriptObject);
PRInt32 SaveWinRegPrototype(void* aScriptObject);
PRInt32 SaveWinProfilePrototype(void* aScriptObject);
JSObject* RetrieveWinRegPrototype(void);
JSObject* RetrieveWinProfilePrototype(void);
PRInt32 GetUserPackageName(nsString& aUserPackageName);
PRInt32 GetRegPackageName(nsString& aRegPackageName);
PRInt32 AbortInstall();
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn);
PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn);
PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt32* aReturn);
PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn);
PRInt32 Execute(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 FinalizeInstall(PRInt32* aReturn);
PRInt32 Gestalt(const nsString& aSelector, PRInt32* aReturn);
PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder);
PRInt32 GetComponentFolder(const nsString& aComponentName, nsString** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsString** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, nsString** aFolder);
PRInt32 GetLastError(PRInt32* aReturn);
PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn);
PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 ResetError();
PRInt32 SetPackageFolder(const nsString& aFolder);
PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn);
PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn);
PRInt32 FileOpDirCreate(nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpDirGetParent(nsFileSpec& aTarget, nsFileSpec* aReturn);
PRInt32 FileOpDirRemove(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpDirRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileCopy(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileDelete(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileExists(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileExecute(nsFileSpec& aTarget, nsString& aParams, PRInt32* aReturn);
PRInt32 FileOpFileGetNativeVersion(nsFileSpec& aTarget, nsString* aReturn);
PRInt32 FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileGetModDate(nsFileSpec& aTarget, nsFileSpec::TimeStamp* aReturn);
PRInt32 FileOpFileGetSize(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileIsDirectory(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileIsFile(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileModDateChanged(nsFileSpec& aTarget, nsFileSpec::TimeStamp& aOldStamp, PRBool* aReturn);
PRInt32 FileOpFileMove(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileWinShortcutCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileMacAliasCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileUnixLinkCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedName, nsFileSpec** aRealName);
void AddPatch(nsHashKey *aKey, nsFileSpec* fileName);
void GetPatch(nsHashKey *aKey, nsFileSpec* fileName);
void GetJarFileLocation(nsString& aFile);
void SetJarFileLocation(const nsString& aFile);
void GetInstallArguments(nsString& args);
void SetInstallArguments(const nsString& args);
private:
JSObject* mScriptObject;
JSObject* mWinRegObject;
JSObject* mWinProfileObject;
nsString mJarFileLocation;
void* mJarFileData;
nsString mInstallArguments;
PRBool mUserCancelled;
PRBool mUninstallPackage;
PRBool mRegisterPackage;
nsString mRegistryPackageName; /* Name of the package we are installing */
nsString mUIName; /* User-readable package name */
nsInstallVersion* mVersionInfo; /* Component version info */
nsVector* mInstalledFiles;
nsHashtable* mPatchList;
nsIXPInstallProgress *mNotifier;
PRInt32 mLastError;
void ParseFlags(int flags);
PRInt32 SanityCheck(void);
void GetTime(nsString &aString);
PRInt32 GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName );
PRInt32 GetQualifiedPackageName( const nsString& name, nsString& qualifiedName );
void CurrentUserNode(nsString& userRegNode);
PRBool BadRegName(const nsString& regName);
PRInt32 SaveError(PRInt32 errcode);
void CleanUp();
PRInt32 OpenJARFile(void);
void CloseJARFile(void);
PRInt32 ExtractDirEntries(const nsString& directory, nsVector *paths);
PRInt32 ScheduleForInstall(nsInstallObject* ob);
};
#endif

View File

@@ -0,0 +1,235 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "prmem.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstallDelete.h"
#include "nsInstallResources.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((folderSpec == "null") || (inInstall == NULL))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mDeleteStatus = DELETE_FILE;
mFinalFile = nsnull;
mRegistryName = "";
mFinalFile = new nsFileSpec(folderSpec);
*mFinalFile += inPartialPath;
*error = ProcessInstallDelete();
}
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
const nsString& inComponentName,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if (inInstall == NULL)
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mDeleteStatus = DELETE_COMPONENT;
mFinalFile = nsnull;
mRegistryName = inComponentName;
*error = ProcessInstallDelete();
}
nsInstallDelete::~nsInstallDelete()
{
if (mFinalFile == nsnull)
delete mFinalFile;
}
PRInt32 nsInstallDelete::Prepare()
{
// no set-up necessary
return nsInstall::SUCCESS;
}
PRInt32 nsInstallDelete::Complete()
{
PRInt32 err = nsInstall::SUCCESS;
if (mInstall == NULL)
return nsInstall::INVALID_ARGUMENTS;
if (mDeleteStatus == DELETE_COMPONENT)
{
char* temp = mRegistryName.ToNewCString();
err = VR_Remove(temp);
delete [] temp;
}
if ((mDeleteStatus == DELETE_FILE) || (err == REGERR_OK))
{
err = NativeComplete();
}
else
{
err = nsInstall::UNEXPECTED_ERROR;
}
return err;
}
void nsInstallDelete::Abort()
{
}
char* nsInstallDelete::toString()
{
char* buffer = new char[1024];
if (mDeleteStatus == DELETE_COMPONENT)
{
sprintf( buffer, nsInstallResources::GetDeleteComponentString(), nsAutoCString(mRegistryName));
}
else
{
if (mFinalFile)
sprintf( buffer, nsInstallResources::GetDeleteFileString(), mFinalFile->GetCString());
}
return buffer;
}
PRBool
nsInstallDelete::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallDelete::RegisterPackageNode()
{
return PR_FALSE;
}
PRInt32 nsInstallDelete::ProcessInstallDelete()
{
PRInt32 err;
char* tempCString = nsnull;
if (mDeleteStatus == DELETE_COMPONENT)
{
/* Check if the component is in the registry */
tempCString = mRegistryName.ToNewCString();
err = VR_InRegistry( tempCString );
if (err != REGERR_OK)
{
return err;
}
else
{
char* tempRegistryString;
tempRegistryString = (char*)PR_Calloc(MAXREGPATHLEN, sizeof(char));
err = VR_GetPath( tempCString , MAXREGPATHLEN, tempRegistryString);
if (err == REGERR_OK)
{
if (mFinalFile)
delete mFinalFile;
mFinalFile = new nsFileSpec(tempRegistryString);
}
PR_FREEIF(tempRegistryString);
}
}
if(tempCString)
delete [] tempCString;
if (mFinalFile->Exists())
{
if (mFinalFile->IsFile())
{
err = nsInstall::SUCCESS;
}
else
{
err = nsInstall::FILE_IS_DIRECTORY;
}
}
else
{
err = nsInstall::FILE_DOES_NOT_EXIST;
}
return err;
}
PRInt32 nsInstallDelete::NativeComplete()
{
if (mFinalFile->Exists())
{
if (mFinalFile->IsFile())
{
return DeleteFileNowOrSchedule(*mFinalFile);
}
else
{
return nsInstall::FILE_IS_DIRECTORY;
}
}
return nsInstall::FILE_DOES_NOT_EXIST;
}

View File

@@ -0,0 +1,78 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallDelete_h__
#define nsInstallDelete_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#define DELETE_COMPONENT 1
#define DELETE_FILE 2
class nsInstallDelete : public nsInstallObject
{
public:
nsInstallDelete( nsInstall* inInstall,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error);
nsInstallDelete( nsInstall* inInstall,
const nsString& ,
PRInt32 *error);
virtual ~nsInstallDelete();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsFileSpec* mFinalFile;
nsString mRegistryName;
PRInt32 mDeleteStatus;
PRInt32 ProcessInstallDelete();
PRInt32 NativeComplete();
};
#endif /* nsInstallDelete_h__ */

View File

@@ -0,0 +1,136 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "prmem.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "nsInstallExecute.h"
#include "nsInstallResources.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
nsInstallExecute:: nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((inInstall == nsnull) || (inJarLocation == "null"))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mJarLocation = inJarLocation;
mArgs = inArgs;
mExecutableFile = nsnull;
}
nsInstallExecute::~nsInstallExecute()
{
if (mExecutableFile)
delete mExecutableFile;
}
PRInt32 nsInstallExecute::Prepare()
{
if (mInstall == NULL || mJarLocation == "null")
return nsInstall::INVALID_ARGUMENTS;
return mInstall->ExtractFileFromJar(mJarLocation, nsnull, &mExecutableFile);
}
PRInt32 nsInstallExecute::Complete()
{
if (mExecutableFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
nsFileSpec app( *mExecutableFile);
if (!app.Exists())
{
return nsInstall::INVALID_ARGUMENTS;
}
PRInt32 result = app.Execute( mArgs );
DeleteFileNowOrSchedule( app );
return result;
}
void nsInstallExecute::Abort()
{
/* Get the names */
if (mExecutableFile == nsnull)
return;
DeleteFileNowOrSchedule(*mExecutableFile);
}
char* nsInstallExecute::toString()
{
char* buffer = new char[1024];
// if the FileSpec is NULL, just us the in jar file name.
if (mExecutableFile == nsnull)
{
char *tempString = mJarLocation.ToNewCString();
sprintf( buffer, nsInstallResources::GetExecuteString(), tempString);
delete [] tempString;
}
else
{
sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString());
}
return buffer;
}
PRBool
nsInstallExecute::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallExecute::RegisterPackageNode()
{
return PR_FALSE;
}

View File

@@ -0,0 +1,73 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallExecute_h__
#define nsInstallExecute_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
class nsInstallExecute : public nsInstallObject
{
public:
nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
PRInt32 *error);
virtual ~nsInstallExecute();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsString mJarLocation; // Location in the JAR
nsString mArgs; // command line arguments
nsFileSpec *mExecutableFile; // temporary file location
PRInt32 NativeComplete(void);
void NativeAbort(void);
};
#endif /* nsInstallExecute_h__ */

View File

@@ -0,0 +1,366 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstallFile.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
#include "nsInstallResources.h"
/* Public Methods */
/* Constructor
inInstall - softUpdate object we belong to
inComponentName - full path of the registry component
inVInfo - full version info
inJarLocation - location inside the JAR file
inFinalFileSpec - final location on disk
*/
nsInstallFile::nsInstallFile(nsInstall* inInstall,
const nsString& inComponentName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
PRInt32 *error)
: nsInstallObject(inInstall)
{
mVersionRegistryName = nsnull;
mJarLocation = nsnull;
mExtracedFile = nsnull;
mFinalFile = nsnull;
mVersionInfo = nsnull;
mUpgradeFile = PR_FALSE;
if ((folderSpec == "null") || (inInstall == NULL))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
/* Check for existence of the newer version */
PRBool versionNewer = PR_FALSE; // Is this a newer version
char* qualifiedRegNameString = inComponentName.ToNewCString();
if ( (forceInstall == PR_FALSE ) && (inVInfo != "") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) )
{
nsInstallVersion *newVersion = new nsInstallVersion();
newVersion->Init(inVInfo);
VERSION versionStruct;
VR_GetVersion( qualifiedRegNameString, &versionStruct );
nsInstallVersion* oldVersion = new nsInstallVersion();
oldVersion->Init(versionStruct.major,
versionStruct.minor,
versionStruct.release,
versionStruct.build);
PRInt32 areTheyEqual;
newVersion->CompareTo(oldVersion, &areTheyEqual);
delete oldVersion;
delete newVersion;
if (areTheyEqual == nsIDOMInstallVersion::MAJOR_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::MINOR_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::REL_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::BLD_DIFF_MINUS )
{
// the file to be installed is OLDER than what is on disk. Return error
delete qualifiedRegNameString;
*error = areTheyEqual;
return;
}
}
delete qualifiedRegNameString;
mFinalFile = new nsFileSpec(folderSpec);
*mFinalFile += inPartialPath;
mReplaceFile = mFinalFile->Exists();
if (mReplaceFile == PR_FALSE)
{
nsFileSpec parent;
mFinalFile->GetParent(parent);
nsFileSpec makeDirs(parent.GetCString(), PR_TRUE);
}
mForceInstall = forceInstall;
mVersionRegistryName = new nsString(inComponentName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = new nsString(inVInfo);
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// determine Child status
if ( regPackageName == "" )
{
// in the "current communicator package" absolute pathnames (start
// with slash) indicate shared files -- all others are children
mChildFile = ( mVersionRegistryName->CharAt(0) != '/' );
}
else
{
// there is no "starts with" api in nsString. LAME!
nsString startsWith;
mVersionRegistryName->Left(startsWith, regPackageName.Length());
if (startsWith.Equals(regPackageName))
{
mChildFile = true;
}
else
{
mChildFile = false;
}
}
}
nsInstallFile::~nsInstallFile()
{
if (mVersionRegistryName)
delete mVersionRegistryName;
if (mJarLocation)
delete mJarLocation;
if (mExtracedFile)
delete mExtracedFile;
if (mFinalFile)
delete mFinalFile;
if (mVersionInfo)
delete mVersionInfo;
}
/* Prepare
* Extracts file out of the JAR archive
*/
PRInt32 nsInstallFile::Prepare()
{
if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull )
return nsInstall::INVALID_ARGUMENTS;
return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, &mExtracedFile);
}
/* Complete
* Completes the install:
* - move the downloaded file to the final location
* - updates the registry
*/
PRInt32 nsInstallFile::Complete()
{
PRInt32 err;
if (mInstall == nsnull || mVersionRegistryName == nsnull || mFinalFile == nsnull )
{
return nsInstall::INVALID_ARGUMENTS;
}
err = CompleteFileMove();
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
{
err = RegisterInVersionRegistry();
}
return err;
}
void nsInstallFile::Abort()
{
if (mExtracedFile != nsnull)
mExtracedFile->Delete(PR_FALSE);
}
char* nsInstallFile::toString()
{
char* buffer = new char[1024];
if (mFinalFile == nsnull)
{
sprintf( buffer, nsInstallResources::GetInstallFileString(), nsnull);
}
else if (mReplaceFile)
{
// we are replacing this file.
sprintf( buffer, nsInstallResources::GetReplaceFileString(), mFinalFile->GetCString());
}
else
{
sprintf( buffer, nsInstallResources::GetInstallFileString(), mFinalFile->GetCString());
}
return buffer;
}
PRInt32 nsInstallFile::CompleteFileMove()
{
int result = 0;
if (mExtracedFile == nsnull)
{
return -1;
}
if ( *mExtracedFile == *mFinalFile )
{
/* No need to rename, they are the same */
result = 0;
}
else
{
result = ReplaceFileNowOrSchedule(*mExtracedFile, *mFinalFile );
}
return result;
}
PRInt32
nsInstallFile::RegisterInVersionRegistry()
{
int refCount;
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// Register file and log for Uninstall
if (!mChildFile)
{
int found;
if (regPackageName != "")
{
found = VR_UninstallFileExistsInList( (char*)(const char*)nsAutoCString(regPackageName) ,
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
}
else
{
found = VR_UninstallFileExistsInList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
}
if (found != REGERR_OK)
mUpgradeFile = PR_FALSE;
else
mUpgradeFile = PR_TRUE;
}
else if (REGERR_OK == VR_InRegistry( (char*)(const char*)nsAutoCString(*mVersionRegistryName)))
{
mUpgradeFile = PR_TRUE;
}
else
{
mUpgradeFile = PR_FALSE;
}
if ( REGERR_OK != VR_GetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), &refCount ))
{
refCount = 0;
}
VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName),
(char*)(const char*)mFinalFile->GetNativePathCString(), // DO NOT CHANGE THIS.
(char*)(const char*)nsAutoCString(*mVersionInfo),
PR_FALSE );
if (mUpgradeFile)
{
if (refCount == 0)
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
else
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount ); //FIX?? what should the ref count be/
}
else
{
if (refCount != 0)
{
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount + 1 );
}
else
{
if (mReplaceFile)
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 2 );
else
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
}
}
if ( !mChildFile && !mUpgradeFile )
{
if (regPackageName != "")
{
VR_UninstallAddFileToList( (char*)(const char*)nsAutoCString(regPackageName),
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
}
else
{
VR_UninstallAddFileToList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
}
}
return nsInstall::SUCCESS;
}
/* CanUninstall
* InstallFile() installs files which can be uninstalled,
* hence this function returns true.
*/
PRBool
nsInstallFile::CanUninstall()
{
return TRUE;
}
/* RegisterPackageNode
* InstallFile() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsInstallFile::RegisterPackageNode()
{
return TRUE;
}

View File

@@ -0,0 +1,93 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallFile_h__
#define nsInstallFile_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallVersion.h"
class nsInstallFile : public nsInstallObject
{
public:
/*************************************************************
* Public Methods
*
* Constructor
* inSoftUpdate - softUpdate object we belong to
* inComponentName - full path of the registry component
* inVInfo - full version info
* inJarLocation - location inside the JAR file
* inFinalFileSpec - final location on disk
*************************************************************/
nsInstallFile( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
PRInt32 *error);
virtual ~nsInstallFile();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsString* mVersionInfo; /* Version info for this file*/
nsString* mJarLocation; /* Location in the JAR */
nsFileSpec* mExtracedFile; /* temporary file location */
nsFileSpec* mFinalFile; /* final file destination */
nsString* mVersionRegistryName; /* full version path */
PRBool mForceInstall; /* whether install is forced */
PRBool mReplaceFile; /* whether file exists */
PRBool mChildFile; /* whether file is a child */
PRBool mUpgradeFile; /* whether file is an upgrade */
PRInt32 CompleteFileMove();
PRInt32 RegisterInVersionRegistry();
};
#endif /* nsInstallFile_h__ */

View File

@@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallFileOpEnums_h__
#define nsInstallFileOpEnums_h__
typedef enum nsInstallFileOpEnums {
NS_FOP_DIR_CREATE = 0,
NS_FOP_DIR_REMOVE = 1,
NS_FOP_DIR_RENAME = 2,
NS_FOP_FILE_COPY = 3,
NS_FOP_FILE_DELETE = 4,
NS_FOP_FILE_EXECUTE = 5,
NS_FOP_FILE_MOVE = 6,
NS_FOP_FILE_RENAME = 7,
NS_FOP_WIN_SHORTCUT_CREATE = 8,
NS_FOP_MAC_ALIAS_CREATE = 9,
NS_FOP_UNIX_LINK_CREATE = 10,
NS_FOP_FILE_SET_STAT = 11
} nsInstallFileOpEnums;
#endif /* nsInstallFileOpEnums_h__ */

View File

@@ -0,0 +1,316 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nspr.h"
#include "nsInstall.h"
#include "nsInstallFileOpEnums.h"
#include "nsInstallFileOpItem.h"
/* Public Methods */
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32 aFlags,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = aFlags;
mSrc = nsnull;
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aSrc,
nsFileSpec& aTarget,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = new nsFileSpec(aSrc);
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = nsnull;
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
nsString& aParams,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = nsnull;
mParams = new nsString(aParams);
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::~nsInstallFileOpItem()
{
if(mSrc)
delete mSrc;
if(mTarget)
delete mTarget;
}
PRInt32 nsInstallFileOpItem::Complete()
{
PRInt32 aReturn = NS_OK;
switch(mCommand)
{
case NS_FOP_DIR_CREATE:
NativeFileOpDirCreate(mTarget);
break;
case NS_FOP_DIR_REMOVE:
NativeFileOpDirRemove(mTarget, mFlags);
break;
case NS_FOP_DIR_RENAME:
NativeFileOpDirRename(mSrc, mTarget);
break;
case NS_FOP_FILE_COPY:
NativeFileOpFileCopy(mSrc, mTarget);
break;
case NS_FOP_FILE_DELETE:
NativeFileOpFileDelete(mTarget, mFlags);
break;
case NS_FOP_FILE_EXECUTE:
NativeFileOpFileExecute(mTarget, mParams);
break;
case NS_FOP_FILE_MOVE:
NativeFileOpFileMove(mSrc, mTarget);
break;
case NS_FOP_FILE_RENAME:
NativeFileOpFileRename(mSrc, mTarget);
break;
case NS_FOP_WIN_SHORTCUT_CREATE:
NativeFileOpWinShortcutCreate();
break;
case NS_FOP_MAC_ALIAS_CREATE:
NativeFileOpMacAliasCreate();
break;
case NS_FOP_UNIX_LINK_CREATE:
NativeFileOpUnixLinkCreate();
break;
}
return aReturn;
}
float nsInstallFileOpItem::GetInstallOrder()
{
return 3;
}
char* nsInstallFileOpItem::toString()
{
nsString result;
char* resultCString;
switch(mCommand)
{
case NS_FOP_FILE_COPY:
result = "Copy file: ";
result.Append(mSrc->GetNativePathCString());
result.Append(" to ");
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_DELETE:
result = "Delete file: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_MOVE:
result = "Move file: ";
result.Append(mSrc->GetNativePathCString());
result.Append(" to ");
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_RENAME:
result = "Rename file: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_DIR_CREATE:
result = "Create Folder: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_DIR_REMOVE:
result = "Remove Folder: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_WIN_SHORTCUT_CREATE:
break;
case NS_FOP_MAC_ALIAS_CREATE:
break;
case NS_FOP_UNIX_LINK_CREATE:
break;
case NS_FOP_FILE_SET_STAT:
result = "Set file stat: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
default:
result = "Unkown file operation command!";
resultCString = result.ToNewCString();
break;
}
return resultCString;
}
PRInt32 nsInstallFileOpItem::Prepare()
{
return NULL;
}
void nsInstallFileOpItem::Abort()
{
}
/* Private Methods */
/* CanUninstall
* InstallFileOpItem() does not install any files which can be uninstalled,
* hence this function returns false.
*/
PRBool
nsInstallFileOpItem::CanUninstall()
{
return FALSE;
}
/* RegisterPackageNode
* InstallFileOpItem() does notinstall files which need to be registered,
* hence this function returns false.
*/
PRBool
nsInstallFileOpItem::RegisterPackageNode()
{
return FALSE;
}
//
// File operation functions begin here
//
PRInt32
nsInstallFileOpItem::NativeFileOpDirCreate(nsFileSpec* aTarget)
{
aTarget->CreateDirectory();
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags)
{
aTarget->Delete(aFlags);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Rename(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Copy(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags)
{
aTarget->Delete(aFlags);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams)
{
aTarget->Execute(*aParams);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Move(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Rename(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpWinShortcutCreate()
{
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpMacAliasCreate()
{
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpUnixLinkCreate()
{
return NS_OK;
}

View File

@@ -0,0 +1,111 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallFileOpItem_h__
#define nsInstallFileOpItem_h__
#include "prtypes.h"
#include "nsFileSpec.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
class nsInstallFileOpItem : public nsInstallObject
{
public:
/* Public Fields */
/* Public Methods */
// used by:
// FileOpFileDelete()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32 aFlags,
PRInt32* aReturn);
// used by:
// FileOpDirRemove()
// FileOpDirRename()
// FileOpFileCopy()
// FileOpFileMove()
// FileOpFileRename()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsFileSpec& aSrc,
nsFileSpec& aTarget,
PRInt32* aReturn);
// used by:
// FileOpDirCreate()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32* aReturn);
// used by:
// FileOpFileExecute()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
nsString& aParams,
PRInt32* aReturn);
~nsInstallFileOpItem();
PRInt32 Prepare(void);
PRInt32 Complete();
char* toString();
void Abort();
float GetInstallOrder();
/* should these be protected? */
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsInstall* mIObj; // initiating Install object
nsFileSpec* mSrc;
nsFileSpec* mTarget;
nsString* mParams;
long mFStat;
PRInt32 mFlags;
PRInt32 mCommand;
/* Private Methods */
PRInt32 NativeFileOpDirCreate(nsFileSpec* aTarget);
PRInt32 NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags);
PRInt32 NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags);
PRInt32 NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams);
PRInt32 NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpWinShortcutCreate();
PRInt32 NativeFileOpMacAliasCreate();
PRInt32 NativeFileOpUnixLinkCreate();
};
#endif /* nsInstallFileOpItem_h__ */

View File

@@ -0,0 +1,336 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nscore.h"
#include "prtypes.h"
#include "nsRepository.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
#include "nsFileLocations.h"
#include "nsIFileLocator.h"
struct DirectoryTable
{
char * directoryName; /* The formal directory name */
PRInt32 folderEnum; /* Directory ID */
};
struct DirectoryTable DirectoryTable[] =
{
{"Plugins", 100 },
{"Program", 101 },
{"Communicator", 102 },
{"User Pick", 103 },
{"Temporary", 104 },
{"Installed", 105 },
{"Current User", 106 },
{"Preferences", 107 },
{"OS Drive", 108 },
{"file:///", 109 },
{"Components", 110 },
{"Chrome", 111 },
{"Win System", 200 },
{"Windows", 201 },
{"Mac System", 300 },
{"Mac Desktop", 301 },
{"Mac Trash", 302 },
{"Mac Startup", 303 },
{"Mac Shutdown", 304 },
{"Mac Apple Menu", 305 },
{"Mac Control Panel", 306 },
{"Mac Extension", 307 },
{"Mac Fonts", 308 },
{"Mac Preferences", 309 },
{"Mac Documents", 310 },
{"Unix Local", 400 },
{"Unix Lib", 401 },
{"", -1 }
};
nsInstallFolder::nsInstallFolder(const nsString& aFolderID)
{
mFileSpec = nsnull;
SetDirectoryPath( aFolderID, "");
}
nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath)
{
mFileSpec = nsnull;
/*
aFolderID can be either a Folder enum in which case we merely pass it to SetDirectoryPath, or
it can be a Directory. If it is the later, it must already exist and of course be a directory
not a file.
*/
nsFileSpec dirCheck(aFolderID);
if ( (dirCheck.Error() == NS_OK) && (dirCheck.IsDirectory()) && (dirCheck.Exists()))
{
nsString tempString = aFolderID;
tempString += aRelativePath;
mFileSpec = new nsFileSpec(tempString);
// make sure that the directory is created.
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
}
else
{
SetDirectoryPath( aFolderID, aRelativePath);
}
}
nsInstallFolder::~nsInstallFolder()
{
if (mFileSpec != nsnull)
delete mFileSpec;
}
void
nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath)
{
aDirectoryPath = "";
if (mFileSpec != nsnull)
{
// We want the a NATIVE path.
aDirectoryPath.SetString(mFileSpec->GetCString());
}
}
void
nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath)
{
if ( aFolderID.EqualsIgnoreCase("User Pick") )
{
PickDefaultDirectory();
return;
}
else if ( aFolderID.EqualsIgnoreCase("Installed") )
{
mFileSpec = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path.
return;
}
else
{
PRInt32 folderDirSpecID = MapNameToEnum(aFolderID);
switch (folderDirSpecID)
{
case 100: /////////////////////////////////////////////////////////// Plugins
SetAppShellDirectory(nsSpecialFileSpec::App_PluginsDirectory );
break;
case 101: /////////////////////////////////////////////////////////// Program
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
break;
case 102: /////////////////////////////////////////////////////////// Communicator
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
break;
case 103: /////////////////////////////////////////////////////////// User Pick
// we should never be here.
mFileSpec = nsnull;
break;
case 104: /////////////////////////////////////////////////////////// Temporary
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_TemporaryDirectory ));
break;
case 105: /////////////////////////////////////////////////////////// Installed
// we should never be here.
mFileSpec = nsnull;
break;
case 106: /////////////////////////////////////////////////////////// Current User
SetAppShellDirectory(nsSpecialFileSpec::App_UserProfileDirectory50 );
break;
case 107: /////////////////////////////////////////////////////////// Preferences
SetAppShellDirectory(nsSpecialFileSpec::App_PrefsDirectory50 );
break;
case 108: /////////////////////////////////////////////////////////// OS Drive
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_DriveDirectory ));
break;
case 109: /////////////////////////////////////////////////////////// File URL
{
nsString tempFileURLString = aFolderID;
tempFileURLString += aRelativePath;
mFileSpec = new nsFileSpec( nsFileURL(tempFileURLString) );
}
break;
case 110: /////////////////////////////////////////////////////////// Components
SetAppShellDirectory(nsSpecialFileSpec::App_ComponentsDirectory );
break;
case 111: /////////////////////////////////////////////////////////// Chrome
SetAppShellDirectory(nsSpecialFileSpec::App_ChromeDirectory );
break;
case 200: /////////////////////////////////////////////////////////// Win System
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_SystemDirectory ));
break;
case 201: /////////////////////////////////////////////////////////// Windows
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_WindowsDirectory ));
break;
case 300: /////////////////////////////////////////////////////////// Mac System
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_SystemDirectory ));
break;
case 301: /////////////////////////////////////////////////////////// Mac Desktop
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DesktopDirectory ));
break;
case 302: /////////////////////////////////////////////////////////// Mac Trash
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_TrashDirectory ));
break;
case 303: /////////////////////////////////////////////////////////// Mac Startup
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
break;
case 304: /////////////////////////////////////////////////////////// Mac Shutdown
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
break;
case 305: /////////////////////////////////////////////////////////// Mac Apple Menu
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_AppleMenuDirectory ));
break;
case 306: /////////////////////////////////////////////////////////// Mac Control Panel
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ControlPanelDirectory ));
break;
case 307: /////////////////////////////////////////////////////////// Mac Extension
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ExtensionDirectory ));
break;
case 308: /////////////////////////////////////////////////////////// Mac Fonts
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_FontsDirectory ));
break;
case 309: /////////////////////////////////////////////////////////// Mac Preferences
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_PreferencesDirectory ));
break;
case 310: /////////////////////////////////////////////////////////// Mac Documents
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DocumentsDirectory ));
break;
case 400: /////////////////////////////////////////////////////////// Unix Local
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LocalDirectory ));
break;
case 401: /////////////////////////////////////////////////////////// Unix Lib
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LibDirectory ));
break;
case -1:
default:
mFileSpec = nsnull;
return;
}
#ifndef XP_MAC
if (aRelativePath.Length() > 0)
{
nsString tempPath(aRelativePath);
if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\')
tempPath += '/';
*mFileSpec += tempPath;
}
#endif
// make sure that the directory is created.
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
}
}
void nsInstallFolder::PickDefaultDirectory()
{
//FIX: Need to put up a dialog here and set mFileSpec
return;
}
/* MapNameToEnum
* maps name from the directory table to its enum */
PRInt32
nsInstallFolder::MapNameToEnum(const nsString& name)
{
int i = 0;
if ( name == "null")
return -1;
while ( DirectoryTable[i].directoryName[0] != 0 )
{
if ( name.EqualsIgnoreCase(DirectoryTable[i].directoryName) )
return DirectoryTable[i].folderEnum;
i++;
}
return -1;
}
static NS_DEFINE_IID(kFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_IID(kFileLocatorCID, NS_FILELOCATOR_CID);
void
nsInstallFolder::SetAppShellDirectory(PRUint32 value)
{
nsIFileLocator * appShellLocator;
nsresult rv = nsComponentManager::CreateInstance(kFileLocatorCID,
nsnull,
kFileLocatorIID,
(void**) &appShellLocator);
if ( NS_SUCCEEDED(rv) )
{
mFileSpec = new nsFileSpec();
appShellLocator->GetFileLocation(value, mFileSpec);
NS_RELEASE(appShellLocator);
}
}

View File

@@ -0,0 +1,58 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALLFOLDER_H__
#define __NS_INSTALLFOLDER_H__
#include "nscore.h"
#include "prtypes.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
class nsInstallFolder
{
public:
nsInstallFolder(const nsString& aFolderID);
nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath);
virtual ~nsInstallFolder();
void GetDirectoryPath(nsString& aDirectoryPath);
private:
nsFileSpec* mFileSpec;
void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath);
void PickDefaultDirectory();
PRInt32 MapNameToEnum(const nsString& name);
void SetAppShellDirectory(PRUint32 value);
};
#endif

View File

@@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallObject_h__
#define nsInstallObject_h__
#include "prtypes.h"
class nsInstall;
class nsInstallObject
{
public:
/* Public Methods */
nsInstallObject(nsInstall* inInstall) {mInstall = inInstall; }
/* Override with your set-up action */
virtual PRInt32 Prepare() = 0;
/* Override with your Completion action */
virtual PRInt32 Complete() = 0;
/* Override with an explanatory string for the progress dialog */
virtual char* toString() = 0;
/* Override with your clean-up function */
virtual void Abort() = 0;
/* should these be protected? */
virtual PRBool CanUninstall() = 0;
virtual PRBool RegisterPackageNode() = 0;
protected:
nsInstall* mInstall;
};
#endif /* nsInstallObject_h__ */

View File

@@ -0,0 +1,986 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFileSpec.h"
#include "prmem.h"
#include "nsInstall.h"
#include "nsInstallPatch.h"
#include "nsInstallResources.h"
#include "nsIDOMInstallVersion.h"
#include "zlib.h"
#include "gdiff.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "plstr.h"
#include "xp_file.h" /* for XP_PlatformFileToURL */
#ifdef XP_MAC
#include "PatchableAppleSingle.h"
#endif
#define BUFSIZE 32768
#define OPSIZE 1
#define MAXCMDSIZE 12
#define SRCFILE 0
#define OUTFILE 1
#define getshort(s) (uint16)( ((uchar)*(s) << 8) + ((uchar)*((s)+1)) )
#define getlong(s) \
(uint32)( ((uchar)*(s) << 24) + ((uchar)*((s)+1) << 16 ) + \
((uchar)*((s)+2) << 8) + ((uchar)*((s)+3)) )
static int32 gdiff_parseHeader( pDIFFDATA dd );
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
static int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum );
static int32 gdiff_ApplyPatch( pDIFFDATA dd );
static int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length );
static int32 gdiff_add( pDIFFDATA dd, uint32 count );
static int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count );
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
PRInt32 *error)
: nsInstallObject(inInstall)
{
char tempTargetFile[MAXREGPATHLEN];
char* tempVersionString = inVRName.ToNewCString();
PRInt32 err = VR_GetPath(tempVersionString, MAXREGPATHLEN, tempTargetFile );
delete [] tempVersionString;
if (err != REGERR_OK)
{
*error = nsInstall::NO_SUCH_COMPONENT;
return;
}
nsString folderSpec(tempTargetFile);
mPatchFile = nsnull;
mTargetFile = nsnull;
mPatchedFile = nsnull;
mRegistryName = new nsString(inVRName);
mJarLocation = new nsString(inJarLocation);
mTargetFile = new nsFileSpec(folderSpec);
mVersionInfo = new nsInstallVersion();
mVersionInfo->Init(inVInfo);
}
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((inInstall == nsnull) || (inVRName == "null") || (inJarLocation == "null"))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mPatchFile = nsnull;
mTargetFile = nsnull;
mPatchedFile = nsnull;
mRegistryName = new nsString(inVRName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = new nsInstallVersion();
mVersionInfo->Init(inVInfo);
mTargetFile = new nsFileSpec(folderSpec);
if(inPartialPath != "null")
*mTargetFile += inPartialPath;
}
nsInstallPatch::~nsInstallPatch()
{
if (mVersionInfo)
delete mVersionInfo;
if (mTargetFile)
delete mTargetFile;
if (mJarLocation)
delete mJarLocation;
if (mRegistryName)
delete mRegistryName;
if (mPatchedFile)
delete mPatchedFile;
if (mPatchFile)
delete mPatchFile;
}
PRInt32 nsInstallPatch::Prepare()
{
PRInt32 err;
PRBool deleteOldSrc;
if (mTargetFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
if (mTargetFile->Exists())
{
if (mTargetFile->IsFile())
{
err = nsInstall::SUCCESS;
}
else
{
err = nsInstall::FILE_IS_DIRECTORY;
}
}
else
{
err = nsInstall::FILE_DOES_NOT_EXIST;
}
if (err != nsInstall::SUCCESS)
{
return err;
}
err = mInstall->ExtractFileFromJar(*mJarLocation, mTargetFile, &mPatchFile);
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull)
{
deleteOldSrc = PR_TRUE;
}
else
{
fileName = mTargetFile;
deleteOldSrc = PR_FALSE;
}
err = NativePatch( *fileName, // the file to patch
*mPatchFile, // the patch that was extracted from the jarfile
&mPatchedFile); // the new patched file
if (err != nsInstall::SUCCESS)
{
return err;
}
PR_ASSERT(mPatchedFile != nsnull);
mInstall->AddPatch(&ikey, mPatchedFile );
if ( deleteOldSrc )
{
DeleteFileNowOrSchedule(*fileName );
}
return err;
}
PRInt32 nsInstallPatch::Complete()
{
if ((mInstall == nsnull) || (mVersionInfo == nsnull) || (mPatchedFile == nsnull) || (mTargetFile == nsnull))
{
return nsInstall::INVALID_ARGUMENTS;
}
PRInt32 err = nsInstall::SUCCESS;
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
// the patch has not been superceded--do final replacement
err = ReplaceFileNowOrSchedule( *mTargetFile, *mPatchedFile);
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
{
nsString tempVersionString;
mVersionInfo->ToString(tempVersionString);
char* tempRegName = mRegistryName->ToNewCString();
char* tempVersion = tempVersionString.ToNewCString();
err = VR_Install( tempRegName,
(char*) (const char *) nsNSPRPath(*mTargetFile),
tempVersion,
PR_FALSE );
delete [] tempRegName;
delete [] tempVersion;
}
else
{
err = nsInstall::UNEXPECTED_ERROR;
}
}
else
{
// nothing -- old intermediate patched file was
// deleted by a superceding patch
}
return err;
}
void nsInstallPatch::Abort()
{
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
DeleteFileNowOrSchedule( *mPatchedFile );
}
}
char* nsInstallPatch::toString()
{
char* buffer = new char[1024];
// FIX! sprintf( buffer, nsInstallResources::GetPatchFileString(), mPatchedFile->GetCString());
return buffer;
}
PRBool
nsInstallPatch::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallPatch::RegisterPackageNode()
{
return PR_FALSE;
}
PRInt32
nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchFile, nsFileSpec **newFile)
{
DIFFDATA *dd;
PRInt32 status = GDIFF_ERR_MEM;
char *tmpurl = NULL;
char *realfile = PL_strdup(nsNSPRPath(sourceFile)); // needs to be sourceFile!!!
nsFileSpec outFileSpec = sourceFile;
dd = (DIFFDATA *)PR_Calloc( 1, sizeof(DIFFDATA));
if (dd != NULL)
{
dd->databuf = (uchar*)PR_Malloc(BUFSIZE);
if (dd->databuf == NULL)
{
status = GDIFF_ERR_MEM;
goto cleanup;
}
dd->bufsize = BUFSIZE;
// validate patch header & check for special instructions
dd->fDiff = PR_Open (nsNSPRPath(patchFile), PR_RDONLY, 0666);
if (dd->fDiff != NULL)
{
status = gdiff_parseHeader(dd);
} else {
status = GDIFF_ERR_ACCESS;
}
#ifdef dono
#ifdef WIN32
/* unbind Win32 images */
if ( dd->bWin32BoundImage && status == GDIFF_OK ) {
tmpurl = WH_TempName( xpURL, NULL );
if ( tmpurl != NULL ) {
if (su_unbind( srcfile, srctype, tmpurl, xpURL ))
{
PL_strfree(realfile);
realfile = tmpurl;
realtype = xpURL;
}
}
else
status = GDIFF_ERR_MEM;
}
#endif
#endif
#ifdef XP_MAC
if ( dd->bMacAppleSingle && status == GDIFF_OK )
{
// create a tmp file, so that we can AppleSingle the src file
nsSpecialSystemDirectory tempMacFile(nsSpecialSystemDirectory::OS_TemporaryDirectory);
nsString srcName = sourceFile.GetLeafName();
tempMacFile.SetLeafName(srcName);
tempMacFile.MakeUnique();
// Encode!
// Encode src file, and put into temp file
FSSpec sourceSpec = sourceFile.GetFSSpec();
FSSpec tempSpec = tempMacFile.GetFSSpec();
status = PAS_EncodeFile(&sourceSpec, &tempSpec);
if (status == noErr)
{
// set
PL_strfree(realfile);
realfile = PL_strdup(nsNSPRPath(tempMacFile));
}
}
#endif
if (status != NS_OK)
goto cleanup;
// make a unique file at the same location of our source file (FILENAME-ptch.EXT)
nsString patchFileName = "-ptch";
nsString newFileName = sourceFile.GetLeafName();
PRInt32 index;
if ((index = newFileName.RFind(".")) > 0)
{
nsString extention;
nsString fileName;
newFileName.Right(extention, (newFileName.Length() - index) );
newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index)));
newFileName = fileName + patchFileName + extention;
} else {
newFileName += patchFileName;
}
outFileSpec.SetLeafName(newFileName); //????
outFileSpec.MakeUnique();
char *outFile = PL_strdup(nsNSPRPath(outFileSpec));
// apply patch to the source file
dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666);
dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666);
if (dd->fSrc != NULL && dd->fOut != NULL)
{
status = gdiff_validateFile (dd, SRCFILE);
// specify why diff failed
if (status == GDIFF_ERR_CHECKSUM)
status = GDIFF_ERR_CHECKSUM_TARGET;
if (status == GDIFF_OK)
status = gdiff_ApplyPatch(dd);
if (status == GDIFF_OK)
status = gdiff_validateFile (dd, OUTFILE);
if (status == GDIFF_ERR_CHECKSUM)
status = GDIFF_ERR_CHECKSUM_RESULT;
if (status == GDIFF_OK)
{
*newFile = &outFileSpec;
if ( outFile != nsnull)
PL_strfree( outFile );
}
} else {
status = GDIFF_ERR_ACCESS;
}
}
#ifdef XP_MAC
if ( dd->bMacAppleSingle && status == GDIFF_OK )
{
// create another file, so that we can decode somewhere
nsFileSpec anotherName = outFileSpec;
anotherName.MakeUnique();
// Close the out file so that we can read it
PR_Close( dd->fOut );
dd->fOut = NULL;
FSSpec outSpec = outFileSpec.GetFSSpec();
FSSpec anotherSpec = anotherName.GetFSSpec();
status = PAS_DecodeFile(&outSpec, &anotherSpec);
if (status != noErr)
{
goto cleanup;
}
nsFileSpec parent;
outFileSpec.GetParent(parent);
outFileSpec.Delete(PR_FALSE);
anotherName.Copy(parent);
*newFile = &anotherName;
}
#endif
cleanup:
if ( dd != NULL )
{
if ( dd->fSrc != nsnull )
PR_Close( dd->fSrc );
if ( dd->fDiff != nsnull )
PR_Close( dd->fDiff );
if ( dd->fOut != nsnull )
{
PR_Close( dd->fOut );
}
if ( status != GDIFF_OK )
//XP_FileRemove( outfile, outtype );
newFile = NULL;
PR_FREEIF( dd->databuf );
PR_FREEIF( dd->oldChecksum );
PR_FREEIF( dd->newChecksum );
PR_DELETE(dd);
}
if ( tmpurl != NULL ) {
//XP_FileRemove( tmpurl, xpURL );
tmpurl = NULL;
PR_DELETE( tmpurl );
}
/* lets map any GDIFF error to nice SU errors */
switch (status)
{
case GDIFF_OK:
break;
case GDIFF_ERR_HEADER:
case GDIFF_ERR_BADDIFF:
case GDIFF_ERR_OPCODE:
case GDIFF_ERR_CHKSUMTYPE:
status = nsInstall::PATCH_BAD_DIFF;
break;
case GDIFF_ERR_CHECKSUM_TARGET:
status = nsInstall::PATCH_BAD_CHECKSUM_TARGET;
break;
case GDIFF_ERR_CHECKSUM_RESULT:
status = nsInstall::PATCH_BAD_CHECKSUM_RESULT;
break;
case GDIFF_ERR_OLDFILE:
case GDIFF_ERR_ACCESS:
case GDIFF_ERR_MEM:
case GDIFF_ERR_UNKNOWN:
default:
status = nsInstall::UNEXPECTED_ERROR;
break;
}
return status;
// return -1; //old return value
}
void*
nsInstallPatch::HashFilePath(const nsFilePath& aPath)
{
PRUint32 rv = 0;
char* cPath = PL_strdup(nsNSPRPath(aPath));
if(cPath != nsnull)
{
char ch;
char* filePath = PL_strdup(cPath);
PRUint32 cnt=0;
while ((ch = *filePath++) != 0)
{
// FYI: rv = rv*37 + ch
rv = ((rv << 5) + (rv << 2) + rv) + ch;
cnt++;
}
for (PRUint32 i=0; i<=cnt; i++)
*filePath--;
PL_strfree(filePath);
}
PL_strfree(cPath);
return (void*)rv;
}
/*---------------------------------------------------------
* gdiff_parseHeader()
*
* reads and validates the GDIFF header info
*---------------------------------------------------------
*/
static
int32 gdiff_parseHeader( pDIFFDATA dd )
{
int32 err = GDIFF_OK;
uint8 cslen;
uint8 oldcslen;
uint8 newcslen;
uint32 nRead;
uchar header[GDIFF_HEADERSIZE];
/* Read the fixed-size part of the header */
nRead = PR_Read (dd->fDiff, header, GDIFF_HEADERSIZE);
if ( nRead != GDIFF_HEADERSIZE ||
memcmp( header, GDIFF_MAGIC, GDIFF_MAGIC_LEN ) != 0 ||
header[GDIFF_VER_POS] != GDIFF_VER )
{
err = GDIFF_ERR_HEADER;
}
else
{
/* get the checksum information */
dd->checksumType = header[GDIFF_CS_POS];
cslen = header[GDIFF_CSLEN_POS];
if ( cslen > 0 )
{
oldcslen = cslen / 2;
newcslen = cslen - oldcslen;
PR_ASSERT( newcslen == oldcslen );
dd->checksumLength = oldcslen;
dd->oldChecksum = (uchar*)PR_MALLOC(oldcslen);
dd->newChecksum = (uchar*)PR_MALLOC(newcslen);
if ( dd->oldChecksum != NULL && dd->newChecksum != NULL )
{
nRead = PR_Read (dd->fDiff, dd->oldChecksum, oldcslen);
if ( nRead == oldcslen )
{
nRead = PR_Read (dd->fDiff, dd->newChecksum, newcslen);
if ( nRead != newcslen ) {
err = GDIFF_ERR_HEADER;
}
}
else {
err = GDIFF_ERR_HEADER;
}
}
else {
err = GDIFF_ERR_MEM;
}
}
/* get application data, if any */
if ( err == GDIFF_OK )
{
uint32 appdataSize;
uchar *buf;
uchar lenbuf[GDIFF_APPDATALEN];
nRead = PR_Read(dd->fDiff, lenbuf, GDIFF_APPDATALEN);
if ( nRead == GDIFF_APPDATALEN )
{
appdataSize = getlong(lenbuf);
if ( appdataSize > 0 )
{
buf = (uchar *)PR_MALLOC( appdataSize );
if ( buf != NULL )
{
nRead = PR_Read (dd->fDiff, buf, appdataSize);
if ( nRead == appdataSize )
{
if ( 0 == memcmp( buf, APPFLAG_W32BOUND, appdataSize ) )
dd->bWin32BoundImage = TRUE;
if ( 0 == memcmp( buf, APPFLAG_APPLESINGLE, appdataSize ) )
dd->bMacAppleSingle = TRUE;
}
else {
err = GDIFF_ERR_HEADER;
}
PR_DELETE( buf );
}
else {
err = GDIFF_ERR_MEM;
}
}
}
else {
err = GDIFF_ERR_HEADER;
}
}
}
return (err);
}
/*---------------------------------------------------------
* gdiff_validateFile()
*
* computes the checksum of the file and compares it to
* the value stored in the GDIFF header
*---------------------------------------------------------
*/
static
int32 gdiff_validateFile( pDIFFDATA dd, int file )
{
int32 result;
PRFileDesc* fh;
uchar* chksum;
/* which file are we dealing with? */
if ( file == SRCFILE ) {
fh = dd->fSrc;
chksum = dd->oldChecksum;
}
else { /* OUTFILE */
fh = dd->fOut;
chksum = dd->newChecksum;
}
/* make sure file's at beginning */
PR_Seek( fh, 0, PR_SEEK_SET );
/* calculate appropriate checksum */
switch (dd->checksumType)
{
case GDIFF_CS_NONE:
result = GDIFF_OK;
break;
case GDIFF_CS_CRC32:
if ( dd->checksumLength == CRC32_LEN )
result = gdiff_valCRC32( dd, fh, getlong(chksum) );
else
result = GDIFF_ERR_HEADER;
break;
case GDIFF_CS_MD5:
case GDIFF_CS_SHA:
default:
/* unsupported checksum type */
result = GDIFF_ERR_CHKSUMTYPE;
break;
}
/* reset file position to beginning and return status */
PR_Seek( fh, 0, PR_SEEK_SET );
return (result);
}
/*---------------------------------------------------------
* gdiff_valCRC32()
*
* computes the checksum of the file and compares it to
* the passed in checksum. Assumes file is positioned at
* beginning.
*---------------------------------------------------------
*/
static
int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum )
{
uint32 crc;
uint32 nRead;
crc = crc32(0L, Z_NULL, 0);
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
while ( nRead > 0 )
{
crc = crc32( crc, dd->databuf, nRead );
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
}
if ( crc == chksum )
return GDIFF_OK;
else
return GDIFF_ERR_CHECKSUM;
}
/*---------------------------------------------------------
* gdiff_ApplyPatch()
*
* Combines patch data with source file to produce the
* new target file. Assumes all three files have been
* opened, GDIFF header read, and all other setup complete
*
* The GDIFF patch is processed sequentially which random
* access is neccessary for the source file.
*---------------------------------------------------------
*/
static
int32 gdiff_ApplyPatch( pDIFFDATA dd )
{
int32 err;
XP_Bool done;
uint32 position;
uint32 count;
uchar opcode;
uchar cmdbuf[MAXCMDSIZE];
done = FALSE;
while ( !done ) {
err = gdiff_getdiff( dd, &opcode, OPSIZE );
if ( err != GDIFF_OK )
break;
switch (opcode)
{
case ENDDIFF:
done = TRUE;
break;
case ADD16:
err = gdiff_getdiff( dd, cmdbuf, ADD16SIZE );
if ( err == GDIFF_OK ) {
err = gdiff_add( dd, getshort( cmdbuf ) );
}
break;
case ADD32:
err = gdiff_getdiff( dd, cmdbuf, ADD32SIZE );
if ( err == GDIFF_OK ) {
err = gdiff_add( dd, getlong( cmdbuf ) );
}
break;
case COPY16BYTE:
err = gdiff_getdiff( dd, cmdbuf, COPY16BYTESIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = *(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY16SHORT:
err = gdiff_getdiff( dd, cmdbuf, COPY16SHORTSIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = getshort(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY16LONG:
err = gdiff_getdiff( dd, cmdbuf, COPY16LONGSIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = getlong(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32BYTE:
err = gdiff_getdiff( dd, cmdbuf, COPY32BYTESIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = *(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32SHORT:
err = gdiff_getdiff( dd, cmdbuf, COPY32SHORTSIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = getshort(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32LONG:
err = gdiff_getdiff( dd, cmdbuf, COPY32LONGSIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = getlong(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY64:
/* we don't support 64-bit file positioning yet */
err = GDIFF_ERR_OPCODE;
break;
default:
err = gdiff_add( dd, opcode );
break;
}
if ( err != GDIFF_OK )
done = TRUE;
}
/* return status */
return (err);
}
/*---------------------------------------------------------
* gdiff_getdiff()
*
* reads the next "length" bytes of the diff into "buffer"
*
* XXX: need a diff buffer to optimize reads!
*---------------------------------------------------------
*/
static
int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length )
{
uint32 bytesRead;
bytesRead = PR_Read (dd->fDiff, buffer, length);
if ( bytesRead != length )
return GDIFF_ERR_BADDIFF;
return GDIFF_OK;
}
/*---------------------------------------------------------
* gdiff_add()
*
* append "count" bytes from diff file to new file
*---------------------------------------------------------
*/
static
int32 gdiff_add( pDIFFDATA dd, uint32 count )
{
int32 err = GDIFF_OK;
uint32 nRead;
uint32 chunksize;
while ( count > 0 ) {
chunksize = ( count > dd->bufsize) ? dd->bufsize : count;
nRead = PR_Read (dd->fDiff, dd->databuf, chunksize);
if ( nRead != chunksize ) {
err = GDIFF_ERR_BADDIFF;
break;
}
PR_Write (dd->fOut, dd->databuf, chunksize);
count -= chunksize;
}
return (err);
}
/*---------------------------------------------------------
* gdiff_copy()
*
* copy "count" bytes from "position" in source file
*---------------------------------------------------------
*/
static
int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count )
{
int32 err = GDIFF_OK;
uint32 nRead;
uint32 chunksize;
PR_Seek (dd->fSrc, position, PR_SEEK_SET);
while ( count > 0 ) {
chunksize = (count > dd->bufsize) ? dd->bufsize : count;
nRead = PR_Read (dd->fSrc, dd->databuf, chunksize);
if ( nRead != chunksize ) {
err = GDIFF_ERR_OLDFILE;
break;
}
PR_Write (dd->fOut, dd->databuf, chunksize);
count -= chunksize;
}
return (err);
}

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallPatch_h__
#define nsInstallPatch_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nsInstallVersion.h"
class nsInstallPatch : public nsInstallObject
{
public:
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error);
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
PRInt32 *error);
virtual ~nsInstallPatch();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsInstallVersion *mVersionInfo;
nsFileSpec *mTargetFile;
nsFileSpec *mPatchFile;
nsFileSpec *mPatchedFile;
nsString *mJarLocation;
nsString *mRegistryName;
PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile);
void* HashFilePath(const nsFilePath& aPath);
};
#endif /* nsInstallPatch_h__ */

View File

@@ -0,0 +1,343 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#include "nsIXPInstallProgress.h"
#include "nsInstallProgressDialog.h"
#include "nsIAppShellComponentImpl.h"
#include "nsIServiceManager.h"
#include "nsIDocumentViewer.h"
#include "nsIContent.h"
#include "nsINameSpaceManager.h"
#include "nsIContentViewer.h"
#include "nsIDOMElement.h"
#include "nsINetService.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID( kAppShellServiceCID, NS_APPSHELL_SERVICE_CID );
static NS_DEFINE_IID( kNetServiceCID, NS_NETSERVICE_CID );
// Utility to set element attribute.
static nsresult setAttribute( nsIDOMXULDocument *doc,
const char *id,
const char *name,
const nsString &value ) {
nsresult rv = NS_OK;
if ( doc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
if ( elem ) {
// Set the text attribute.
rv = elem->SetAttribute( name, value );
if ( NS_SUCCEEDED( rv ) ) {
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
// Utility to get element attribute.
static nsresult getAttribute( nsIDOMXULDocument *doc,
const char *id,
const char *name,
nsString &value ) {
nsresult rv = NS_OK;
if ( doc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
if ( elem ) {
// Set the text attribute.
rv = elem->GetAttribute( name, value );
if ( NS_SUCCEEDED( rv ) ) {
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
nsInstallProgressDialog::nsInstallProgressDialog()
{
NS_INIT_REFCNT();
mWindow = nsnull;
mDocument = nsnull;
}
nsInstallProgressDialog::~nsInstallProgressDialog()
{
}
NS_IMPL_ADDREF( nsInstallProgressDialog );
NS_IMPL_RELEASE( nsInstallProgressDialog );
NS_IMETHODIMP
nsInstallProgressDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if (aIID.Equals(nsIXPInstallProgress::GetIID())) {
*aInstancePtr = (void*) ((nsInstallProgressDialog*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIXULWindowCallbacks::GetIID())) {
*aInstancePtr = (void*) ((nsIXULWindowCallbacks*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) (nsISupports*)((nsIXPInstallProgress*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsInstallProgressDialog::BeforeJavascriptEvaluation()
{
nsresult rv = NS_OK;
// Get app shell service.
nsIAppShellService *appShell;
rv = nsServiceManager::GetService( kAppShellServiceCID,
nsIAppShellService::GetIID(),
(nsISupports**)&appShell );
if ( NS_SUCCEEDED( rv ) )
{
// Open "progress" dialog.
nsIURL *url;
rv = NS_NewURL( &url, "resource:/res/xpinstall/progress.xul" );
if ( NS_SUCCEEDED(rv) )
{
nsIWebShellWindow *newWindow;
rv = appShell->CreateTopLevelWindow( nsnull,
url,
PR_TRUE,
newWindow,
nsnull,
this, // callbacks??
0,
0 );
if ( NS_SUCCEEDED( rv ) )
{
mWindow = newWindow;
NS_RELEASE( newWindow );
if (mWindow != nsnull)
mWindow->Show(PR_TRUE);
}
else
{
DEBUG_PRINTF( PR_STDOUT, "Error creating progress dialog, rv=0x%X\n", (int)rv );
}
NS_RELEASE( url );
}
nsServiceManager::ReleaseService( kAppShellServiceCID, appShell );
}
else
{
DEBUG_PRINTF( PR_STDOUT, "Unable to get app shell service, rv=0x%X\n", (int)rv );
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::AfterJavascriptEvaluation()
{
if (mWindow)
{
mWindow->Close();
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallStarted(const char *UIPackageName)
{
setAttribute( mDocument, "dialog.uiPackageName", "value", nsString(UIPackageName) );
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::ItemScheduled(const char *message)
{
PRInt32 maxChars = 40;
nsString theMessage(message);
PRInt32 len = theMessage.Length();
if (len > maxChars)
{
PRInt32 offset = (len/2) - ((len - maxChars)/2);
PRInt32 count = (len - maxChars);
theMessage.Cut(offset, count);
theMessage.Insert(nsString("..."), offset);
}
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
nsString aValue;
getAttribute( mDocument, "data.canceled", "value", aValue );
if (aValue.EqualsIgnoreCase("true"))
return -1;
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum)
{
PRInt32 maxChars = 40;
nsString theMessage(message);
PRInt32 len = theMessage.Length();
if (len > maxChars)
{
PRInt32 offset = (len/2) - ((len - maxChars)/2);
PRInt32 count = (len - maxChars);
theMessage.Cut(offset, count);
theMessage.Insert(nsString("..."), offset);
}
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
nsresult rv = NS_OK;
char buf[16];
PR_snprintf( buf, sizeof buf, "%lu", totNum );
setAttribute( mDocument, "dialog.progress", "max", buf );
if (totNum != 0)
{
PR_snprintf( buf, sizeof buf, "%lu", ((totNum-itemNum)/totNum) );
}
else
{
PR_snprintf( buf, sizeof buf, "%lu", 0 );
}
setAttribute( mDocument, "dialog.progress", "value", buf );
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallAborted()
{
return NS_OK;
}
// Do startup stuff from C++ side.
NS_IMETHODIMP
nsInstallProgressDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell)
{
nsresult rv = NS_OK;
// Get content viewer from the web shell.
nsCOMPtr<nsIContentViewer> contentViewer;
rv = aWebShell ? aWebShell->GetContentViewer(getter_AddRefs(contentViewer))
: NS_ERROR_NULL_POINTER;
if ( contentViewer ) {
// Up-cast to a document viewer.
nsCOMPtr<nsIDocumentViewer> docViewer( do_QueryInterface( contentViewer, &rv ) );
if ( docViewer ) {
// Get the document from the doc viewer.
nsCOMPtr<nsIDocument> document;
rv = docViewer->GetDocument(*getter_AddRefs(document));
if ( document ) {
// Upcast to XUL document.
mDocument = do_QueryInterface( document, &rv );
if ( ! mDocument )
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDOMXULDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDocumentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetContentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
return rv;
}

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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/NPL/
*
* 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __nsInstallProgressDialog_h__
#define __nsInstallProgressDialog_h__
#include "nsIXPInstallProgress.h"
#include "nsISupports.h"
#include "nsISupportsUtils.h"
#include "nsCOMPtr.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsIXULWindowCallbacks.h"
#include "nsIDocument.h"
#include "nsIDOMXULDocument.h"
class nsInstallProgressDialog : public nsIXPInstallProgress, public nsIXULWindowCallbacks
{
public:
nsInstallProgressDialog();
virtual ~nsInstallProgressDialog();
NS_DECL_ISUPPORTS
NS_IMETHOD BeforeJavascriptEvaluation();
NS_IMETHOD AfterJavascriptEvaluation();
NS_IMETHOD InstallStarted(const char *UIPackageName);
NS_IMETHOD ItemScheduled(const char *message);
NS_IMETHOD InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum);
NS_IMETHOD InstallAborted();
// Declare implementations of nsIXULWindowCallbacks interface functions.
NS_IMETHOD ConstructBeforeJavaScript(nsIWebShell *aWebShell);
NS_IMETHOD ConstructAfterJavaScript(nsIWebShell *aWebShell) { return NS_OK; }
private:
nsCOMPtr<nsIDOMXULDocument> mDocument;
nsCOMPtr<nsIWebShellWindow> mWindow;
};
#endif

Some files were not shown because too many files have changed in this diff Show More