Convert CR-LF line endings to LF to fix bustage.

This commit is contained in:
dbaron%dbaron.org 2005-01-28 00:48:32 +00:00
parent 4b1b4e1951
commit ffc102ed81
9 changed files with 500 additions and 500 deletions

View File

@ -194,96 +194,96 @@ XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString instanceId;
evaluateToString((Expr*)iter.next(), aContext, instanceId);
evaluateToString((Expr*)iter.next(), aContext, instanceId);
// here document is the XForms document
nsCOMPtr<nsIDOMDocument> document;
rv = mResolverNode->GetOwnerDocument(getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, rv);
// here document is the XForms document
nsCOMPtr<nsIDOMDocument> document;
rv = mResolverNode->GetOwnerDocument(getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(document, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMElement> instEle;
rv = document->GetElementById(instanceId, getter_AddRefs(instEle));
PRBool foundInstance = PR_FALSE;
nsAutoString localname, namespaceURI;
if (instEle) {
instEle->GetLocalName(localname);
instEle->GetNamespaceURI(namespaceURI);
if (localname.EqualsLiteral("instance") &&
nsCOMPtr<nsIDOMElement> instEle;
rv = document->GetElementById(instanceId, getter_AddRefs(instEle));
PRBool foundInstance = PR_FALSE;
nsAutoString localname, namespaceURI;
if (instEle) {
instEle->GetLocalName(localname);
instEle->GetNamespaceURI(namespaceURI);
if (localname.EqualsLiteral("instance") &&
namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
foundInstance = PR_TRUE;
}
foundInstance = PR_TRUE;
}
}
if (!foundInstance) {
// We didn't find an instance element with the given id. Return the
// empty result set.
*aResult = resultSet;
NS_ADDREF(*aResult);
return NS_OK;
}
// Make sure that this element is contained in the same
// model as the context node of the expression as per
// the XForms 1.0 spec.
// first step is to get the contextNode passed in to
// the evaluation
nsCOMPtr<nsIDOMNode> xfContextNode;
rv = txXPathNativeNode::getNode(aContext->getContextNode(),
if (!foundInstance) {
// We didn't find an instance element with the given id. Return the
// empty result set.
*aResult = resultSet;
NS_ADDREF(*aResult);
return NS_OK;
}
// Make sure that this element is contained in the same
// model as the context node of the expression as per
// the XForms 1.0 spec.
// first step is to get the contextNode passed in to
// the evaluation
nsCOMPtr<nsIDOMNode> xfContextNode;
rv = txXPathNativeNode::getNode(aContext->getContextNode(),
getter_AddRefs(xfContextNode));
NS_ENSURE_SUCCESS(rv, rv);
// now see if the node we found (instEle) and the
// context node for the evaluation (xfContextNode) link
// back to the same model.
nsCOMPtr<nsIXFormsUtilityService>xformsService =
do_GetService("@mozilla.org/xforms-utility-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> instNode, modelInstance;
instNode = do_QueryInterface(instEle);
rv = xformsService->GetModelFromNode(instNode,
NS_ENSURE_SUCCESS(rv, rv);
// now see if the node we found (instEle) and the
// context node for the evaluation (xfContextNode) link
// back to the same model.
nsCOMPtr<nsIXFormsUtilityService>xformsService =
do_GetService("@mozilla.org/xforms-utility-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> instNode, modelInstance;
instNode = do_QueryInterface(instEle);
rv = xformsService->GetModelFromNode(instNode,
getter_AddRefs(modelInstance));
NS_ENSURE_SUCCESS(rv, rv);
PRBool modelContainsNode = PR_FALSE;
rv = xformsService->IsNodeAssocWithModel(xfContextNode,
modelInstance,
&modelContainsNode);
NS_ENSURE_SUCCESS(rv, rv);
if (modelContainsNode) {
// ok, we've found an instance node with the proper id
// that fulfills the requirement of being from the
// same model as the context node. Now we need to
// return a 'node-set containing just the root
// element node of the referenced instance data'.
// Wonderful.
nsCOMPtr<nsIDOMNode> instanceRoot;
rv = xformsService->GetInstanceDocumentRoot(
instanceId,
modelInstance,
getter_AddRefs(instanceRoot));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_SUCCESS(rv, rv);
PRBool modelContainsNode = PR_FALSE;
rv = xformsService->IsNodeAssocWithModel(xfContextNode,
modelInstance,
&modelContainsNode);
NS_ENSURE_SUCCESS(rv, rv);
if (modelContainsNode) {
// ok, we've found an instance node with the proper id
// that fulfills the requirement of being from the
// same model as the context node. Now we need to
// return a 'node-set containing just the root
// element node of the referenced instance data'.
// Wonderful.
nsCOMPtr<nsIDOMNode> instanceRoot;
rv = xformsService->GetInstanceDocumentRoot(
instanceId,
modelInstance,
getter_AddRefs(instanceRoot));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(instanceRoot, NS_ERROR_NULL_POINTER);
nsAutoPtr<txXPathNode> txNode(txXPathNativeNode::createXPathNode(instanceRoot));
if (txNode) {
resultSet->add(*txNode);
}
}
// XXX where we need to do the work
// if (walker.moveToElementById(instanceId)) {
// resultSet->add(walker.getCurrentPosition());
// }
nsAutoPtr<txXPathNode> txNode(txXPathNativeNode::createXPathNode(instanceRoot));
if (txNode) {
resultSet->add(*txNode);
}
}
// XXX where we need to do the work
// if (walker.moveToElementById(instanceId)) {
// resultSet->add(walker.getCurrentPosition());
// }
*aResult = resultSet;
NS_ADDREF(*aResult);
@ -292,9 +292,9 @@ XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
}
case MAX:
{
if (!requireParams(1, 1, aContext))
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
if (!requireParams(1, 1, aContext))
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
nsRefPtr<txNodeSet> nodes;
nsresult rv = evaluateToNodeSet((Expr*)iter.next(), aContext,
getter_AddRefs(nodes));
@ -307,11 +307,11 @@ XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
nsAutoString resultStr;
txXPathNodeUtils::appendNodeValue(nodes->get(i), resultStr);
test = Double::toDouble(resultStr);
if (Double::isNaN(test)) {
if (Double::isNaN(test)) {
res = Double::NaN;
break;
}
if (test > res || i == 0) {
if (test > res || i == 0) {
res = test;
}
}
@ -320,9 +320,9 @@ XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
}
case MIN:
{
if (!requireParams(1, 1, aContext))
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
if (!requireParams(1, 1, aContext))
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
nsRefPtr<txNodeSet> nodes;
nsresult rv = evaluateToNodeSet((Expr*)iter.next(), aContext,
getter_AddRefs(nodes));
@ -355,16 +355,16 @@ XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
}
case NOW:
{
if (!requireParams(0, 0, aContext))
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
if (!requireParams(0, 0, aContext))
return NS_ERROR_XPATH_BAD_ARGUMENT_COUNT;
PRExplodedTime time;
char ctime[60];
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &time);
int gmtoffsethour = time.tm_params.tp_gmt_offset < 0 ?
-1*time.tm_params.tp_gmt_offset / 3600 :
time.tm_params.tp_gmt_offset / 3600;
int gmtoffsethour = time.tm_params.tp_gmt_offset < 0 ?
-1*time.tm_params.tp_gmt_offset / 3600 :
time.tm_params.tp_gmt_offset / 3600;
int remainder = time.tm_params.tp_gmt_offset%3600;
int gmtoffsetminute = remainder ? remainder/60 : 00;

View File

@ -35,56 +35,56 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIXFormsUtilityService_h
#define nsIXFormsUtilityService_h
#include "nsISupports.h"
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
class nsIDOMNode; /* forward declaration */
class nsIXFormsModelElement; /* forward declaration */
/* starting interface: nsIXFormsUtilityService */
#define NS_IXFORMSUTILITYSERVICE_IID_STR "4a744a59-8771-4065-959d-b8de3dad81da"
#define NS_IXFORMSUTILITYSERVICE_IID \
{0x4a744a59, 0x8771, 0x4065, \
{ 0x95, 0x9d, 0xb8, 0xde, 0x3d, 0xad, 0x81, 0xda }}
#define NS_XFORMS_UTILITY_CONTRACTID "@mozilla.org/xforms-utility-service;1"
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSIXFORMSUTILITYSERVICE \
NS_IMETHOD GetModelFromNode(nsIDOMNode *node, nsIDOMNode **_retval); \
NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval); \
NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval); \
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval);
/**
* Private interface implemented by the nsXFormsUtilityService in XForms extension.
* Defining it here to prevent XPath requiring XForms extension.
*/
class NS_NO_VTABLE nsIXFormsUtilityService : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXFORMSUTILITYSERVICE_IID)
/**
* Function to get the corresponding model element from a xforms node or
* a xforms instance data node.
*/
/* nsIDOMNode getModelFromNode (in nsIDOMNode node); */
NS_IMETHOD GetModelFromNode(nsIDOMNode *node, nsIDOMNode **_retval) = 0;
/**
* Function to see if the given node is associated with the given model.
#ifndef nsIXFormsUtilityService_h
#define nsIXFormsUtilityService_h
#include "nsISupports.h"
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
class nsIDOMNode; /* forward declaration */
class nsIXFormsModelElement; /* forward declaration */
/* starting interface: nsIXFormsUtilityService */
#define NS_IXFORMSUTILITYSERVICE_IID_STR "4a744a59-8771-4065-959d-b8de3dad81da"
#define NS_IXFORMSUTILITYSERVICE_IID \
{0x4a744a59, 0x8771, 0x4065, \
{ 0x95, 0x9d, 0xb8, 0xde, 0x3d, 0xad, 0x81, 0xda }}
#define NS_XFORMS_UTILITY_CONTRACTID "@mozilla.org/xforms-utility-service;1"
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSIXFORMSUTILITYSERVICE \
NS_IMETHOD GetModelFromNode(nsIDOMNode *node, nsIDOMNode **_retval); \
NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval); \
NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval); \
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval);
/**
* Private interface implemented by the nsXFormsUtilityService in XForms extension.
* Defining it here to prevent XPath requiring XForms extension.
*/
class NS_NO_VTABLE nsIXFormsUtilityService : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXFORMSUTILITYSERVICE_IID)
/**
* Function to get the corresponding model element from a xforms node or
* a xforms instance data node.
*/
/* nsIDOMNode getModelFromNode (in nsIDOMNode node); */
NS_IMETHOD GetModelFromNode(nsIDOMNode *node, nsIDOMNode **_retval) = 0;
/**
* Function to see if the given node is associated with the given model.
* Right now this function is only called by XPath in the case of the
* instance() function.
* The provided node can be an instance node from an instance
@ -95,30 +95,30 @@ class NS_NO_VTABLE nsIXFormsUtilityService : public nsISupports {
* Form controls are associated with model elements either explicitly through
* single-node binding or implicitly (if model cannot by calculated, it
* will use the first model element encountered in the document). The model
* can also be inherited from a containing element like xforms:group or
* xforms:repeat.
*/
/* PRBool isNodeAssocWithModel (in nsIDOMNode aNode, in nsIDOMNode aModel); */
NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval) = 0;
/**
* Function to get the instance document root for the instance element with
* the given id. The instance element must be associated with the given
* model.
*/
/* nsIDOMNode getInstanceDocumentRoot (in DOMString aID, in nsIDOMNode aModelNode); */
NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval) = 0;
/**
* Function to ensure that aValue is of the schema type aType. Will basically
* be a forwarder to the nsISchemaValidator function of the same name.
*/
/* boolean validateString (in AString aValue, in AString aType, in AString aNamespace); */
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval) = 0;
};
* can also be inherited from a containing element like xforms:group or
* xforms:repeat.
*/
/* PRBool isNodeAssocWithModel (in nsIDOMNode aNode, in nsIDOMNode aModel); */
NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval) = 0;
#define NS_ERROR_XFORMS_CALCUATION_EXCEPTION \
/**
* Function to get the instance document root for the instance element with
* the given id. The instance element must be associated with the given
* model.
*/
/* nsIDOMNode getInstanceDocumentRoot (in DOMString aID, in nsIDOMNode aModelNode); */
NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval) = 0;
/**
* Function to ensure that aValue is of the schema type aType. Will basically
* be a forwarder to the nsISchemaValidator function of the same name.
*/
/* boolean validateString (in AString aValue, in AString aType, in AString aNamespace); */
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval) = 0;
};
#define NS_ERROR_XFORMS_CALCUATION_EXCEPTION \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3001)
#endif /* nsIXFormsUtilityService_h */
#endif /* nsIXFormsUtilityService_h */

View File

@ -35,21 +35,21 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIXFormsXPathEvaluator_h
#define nsIXFormsXPathEvaluator_h
#include "nsISupports.h"
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
class nsIDOMNode; /* forward declaration */
class nsIDOMXPathExpression; /* forward declaration */
/* starting interface: nsIXFormsXPathEvaluator */
#ifndef nsIXFormsXPathEvaluator_h
#define nsIXFormsXPathEvaluator_h
#include "nsISupports.h"
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
class nsIDOMNode; /* forward declaration */
class nsIDOMXPathExpression; /* forward declaration */
/* starting interface: nsIXFormsXPathEvaluator */
#define NS_XFORMS_XPATH_EVALUATOR_CONTRACTID "@mozilla.org/dom/xforms-xpath-evaluator;1"
/* a7e127c6-31ff-40b4-8780-15d6938b33d3 */
#define TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_CID \
@ -58,40 +58,40 @@ class nsIDOMXPathExpression; /* forward declaration */
/* 60050a4a-4c99-4bad-8c47-3b9b96caf2b4 */
#define TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_IID \
{ 0x60050a4a, 0x4c99, 0x4bad, { 0x8c, 0x47, 0x3b, 0x9b, 0x96, 0xca, 0xf2, 0xb4 } }
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSIXFORMXPATHEVALUATOR \
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSIXFORMXPATHEVALUATOR \
NS_IMETHOD CreateExpression(const nsAString & aExpression, nsIDOMNode *aResolverNode,nsIDOMXPathExpression **aResult); \
NS_IMETHOD Evaluate(const nsAString & aExpression, nsIDOMNode *aContextNode, nsIDOMNode *aResolverNode, PRUint16 aType, nsISupports *aInResult, nsISupports **aResult);
/**
* Private interface implemented by the nsXFormsXPathEvaluator in Transformiix
* and will move to the XForms extension when XPath is made extensible. We
/**
* Private interface implemented by the nsXFormsXPathEvaluator in Transformiix
* and will move to the XForms extension when XPath is made extensible. We
* are using this interface instead of nsIDOMXPathEvaluator since we can
* don't really need all of that overhead. For example, this interface uses
* a resolver node from the xforms document rather than forcing XForms to
* create a namespace resolver node prior to creating the expression or
* running an evaluation.
*/
class NS_NO_VTABLE nsIXFormsXPathEvaluator : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_IID)
/**
* Function to create a nsIDOMXPathExpression from the provided expression
* string. aResolverNode is the xforms node that the expression is
*/
class NS_NO_VTABLE nsIXFormsXPathEvaluator : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(TRANSFORMIIX_XFORMS_XPATH_EVALUATOR_IID)
/**
* Function to create a nsIDOMXPathExpression from the provided expression
* string. aResolverNode is the xforms node that the expression is
* associated with.
*/
*/
NS_IMETHOD CreateExpression(const nsAString & aExpression, nsIDOMNode *aResolverNode, nsIDOMXPathExpression **aResult) = 0;
/**
* Function to evaluate the given expression. aResolverNode is the xforms
/**
* Function to evaluate the given expression. aResolverNode is the xforms
* node that the expression is associated with. The other parameters are as
* required by DOM's XPathEvaluator.
*/
*/
NS_IMETHOD Evaluate(const nsAString & aExpression, nsIDOMNode *aContextNode, nsIDOMNode *aResolverNode, PRUint16 aType, nsISupports *aInResult, nsISupports **aResult) = 0;
};
#endif /* nsIXFormsXPathEvaluator_h */
};
#endif /* nsIXFormsXPathEvaluator_h */

View File

@ -155,18 +155,18 @@ nsresult nsXFormsXPathEvaluator::XFormsParseContextImpl::resolveNamespacePrefix
nsVoidableString ns;
nsresult rv;
// begin - taken directly from nsXPathNSResolver::LookupNamespaceURI
if (prefix.EqualsLiteral("xml")) {
ns.AssignLiteral("http://www.w3.org/XML/1998/namespace");
if (prefix.EqualsLiteral("xml")) {
ns.AssignLiteral("http://www.w3.org/XML/1998/namespace");
rv = NS_OK;
}
}
else {
nsCOMPtr<nsIDOM3Node> dom3Node = do_QueryInterface(mResolverNode);
NS_ASSERTION(dom3Node, "Need a node to resolve namespaces.");
nsCOMPtr<nsIDOM3Node> dom3Node = do_QueryInterface(mResolverNode);
NS_ASSERTION(dom3Node, "Need a node to resolve namespaces.");
if( dom3Node ) {
rv = dom3Node->LookupNamespaceURI(prefix, ns);
rv = dom3Node->LookupNamespaceURI(prefix, ns);
}
else {
SetDOMStringToNull(ns);
SetDOMStringToNull(ns);
rv = NS_OK;
}
}
@ -263,11 +263,11 @@ PRBool nsXFormsXPathEvaluator::XFormsParseContextImpl::caseInsensitiveNameTests(
return PR_FALSE;
}
PRBool nsXFormsXPathEvaluator::XFormsParseContextImpl::fcp()
{
return PR_FALSE;
}
PRBool nsXFormsXPathEvaluator::XFormsParseContextImpl::fcp()
{
return PR_FALSE;
}
void
nsXFormsXPathEvaluator::XFormsParseContextImpl::SetErrorOffset(PRUint32 aOffset)
{

View File

@ -88,7 +88,7 @@ private:
nsresult resolveFunctionCall(nsIAtom* aName, PRInt32 aID,
FunctionCall*& aFunction);
PRBool caseInsensitiveNameTests();
PRBool fcp();
PRBool fcp();
void SetErrorOffset(PRUint32 aOffset);
private:

View File

@ -1,13 +1,13 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<!-- list all the packages being supplied by this jar -->
<RDF:Seq about="urn:mozilla:package:root">
<RDF:li resource="urn:mozilla:package:xforms"/>
</RDF:Seq>
<!-- package information -->
<RDF:Description about="urn:mozilla:package:xforms"
chrome:name="xforms"/>
</RDF:RDF>
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<!-- list all the packages being supplied by this jar -->
<RDF:Seq about="urn:mozilla:package:root">
<RDF:li resource="urn:mozilla:package:xforms"/>
</RDF:Seq>
<!-- package information -->
<RDF:Description about="urn:mozilla:package:xforms"
chrome:name="xforms"/>
</RDF:RDF>

View File

@ -1,3 +1,3 @@
xforms.jar:
content/xforms/contents.rdf
* content/xforms/xforms.css
xforms.jar:
content/xforms/contents.rdf
* content/xforms/xforms.css

View File

@ -1,87 +1,87 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla XForms support.
*
* The Initial Developer of the Original Code is
* IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Aaron Reed <aaronr@us.ibm.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 ***** */
#include "nsXFormsUtilityService.h"
#include "nsXFormsUtils.h"
#include "nsIXTFElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsString.h"
#include "nsIDOMDocument.h"
#include "nsIXFormsModelElement.h"
#include "nsIDOMNodeList.h"
#include "nsIInstanceElementPrivate.h"
NS_IMPL_ISUPPORTS1(nsXFormsUtilityService, nsIXFormsUtilityService)
NS_IMETHODIMP
nsXFormsUtilityService::GetModelFromNode(nsIDOMNode *aNode,
nsIDOMNode **aModel)
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
NS_ASSERTION(aModel, "no return buffer, we'll crash soon");
*aModel = nsnull;
nsAutoString namespaceURI;
aNode->GetNamespaceURI(namespaceURI);
// If the node is in the XForms namespace and XTF based, then it should
// be able to be handled by GetModel. Otherwise it is probably an instance
// node in a instance document.
if (!namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(element);
nsCOMPtr<nsIDOMNode> modelElement = do_QueryInterface(modelPriv);
if( modelElement ) {
NS_IF_ADDREF(*aModel = modelElement);
}
// No model found
NS_ENSURE_TRUE(*aModel, NS_ERROR_FAILURE);
return NS_OK;
}
/**
* Function to see if the given node is associated with the given model.
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla XForms support.
*
* The Initial Developer of the Original Code is
* IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Aaron Reed <aaronr@us.ibm.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 ***** */
#include "nsXFormsUtilityService.h"
#include "nsXFormsUtils.h"
#include "nsIXTFElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsString.h"
#include "nsIDOMDocument.h"
#include "nsIXFormsModelElement.h"
#include "nsIDOMNodeList.h"
#include "nsIInstanceElementPrivate.h"
NS_IMPL_ISUPPORTS1(nsXFormsUtilityService, nsIXFormsUtilityService)
NS_IMETHODIMP
nsXFormsUtilityService::GetModelFromNode(nsIDOMNode *aNode,
nsIDOMNode **aModel)
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
NS_ASSERTION(aModel, "no return buffer, we'll crash soon");
*aModel = nsnull;
nsAutoString namespaceURI;
aNode->GetNamespaceURI(namespaceURI);
// If the node is in the XForms namespace and XTF based, then it should
// be able to be handled by GetModel. Otherwise it is probably an instance
// node in a instance document.
if (!namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(element);
nsCOMPtr<nsIDOMNode> modelElement = do_QueryInterface(modelPriv);
if( modelElement ) {
NS_IF_ADDREF(*aModel = modelElement);
}
// No model found
NS_ENSURE_TRUE(*aModel, NS_ERROR_FAILURE);
return NS_OK;
}
/**
* Function to see if the given node is associated with the given model.
* Right now this function is only called by XPath in the case of the
* instance() function.
* The provided node can be an instance node from an instance
@ -92,134 +92,134 @@ nsXFormsUtilityService::GetModelFromNode(nsIDOMNode *aNode,
* Form controls are associated with model elements either explicitly through
* single-node binding or implicitly (if model cannot by calculated, it
* will use the first model element encountered in the document). The model
* can also be inherited from a containing element like xforms:group or
* xforms:repeat.
*/
NS_IMETHODIMP
nsXFormsUtilityService::IsNodeAssocWithModel( nsIDOMNode *aNode,
nsIDOMNode *aModel,
PRBool *aModelAssocWithNode)
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
nsAutoString namespaceURI;
aNode->GetNamespaceURI(namespaceURI);
// If the node is in the XForms namespace and XTF based, then it should
// be able to be handled by GetModel. Otherwise it is probably an instance
// node in a instance document.
if (namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(element);
nsCOMPtr<nsIDOMNode> modelNode = do_QueryInterface(modelPriv);
if (modelNode && (modelNode == aModel)) {
*aModelAssocWithNode = PR_TRUE;
}
else {
*aModelAssocWithNode = PR_FALSE;
}
}
else {
// We are assuming that if the node coming in isn't a proper XForms element,
// then it is an instance element in an instance doc. Now we just have
// to determine if the given model contains this instance document.
nsCOMPtr<nsIDOMDocument> document;
aNode->GetOwnerDocument(getter_AddRefs(document));
*aModelAssocWithNode = PR_FALSE;
// Guess that we'd better make sure that it is a model
nsCOMPtr<nsIXFormsModelElement> modelEle = do_QueryInterface(aModel);
if (modelEle) {
// OK, we know that this is a model element. So now we have to go
// instance element by instance element and find the associated
// document. If it is equal to the document that contains aNode,
// then aNode is associated with this aModel element and we can return
// true.
nsCOMPtr<nsIDOMNodeList> children;
aModel->GetChildNodes(getter_AddRefs(children));
if (!children)
return NS_OK;
PRUint32 childCount = 0;
children->GetLength(&childCount);
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIInstanceElementPrivate> instElement;
nsCOMPtr<nsIDOMDocument> instDocument;
for (PRUint32 i = 0; i < childCount; ++i) {
children->Item(i, getter_AddRefs(node));
NS_ASSERTION(node, "incorrect NodeList length?");
instElement = do_QueryInterface(node);
if (!instElement)
continue;
instElement->GetDocument(getter_AddRefs(instDocument));
if (instDocument) {
if (instDocument == document) {
*aModelAssocWithNode = PR_TRUE;
break;
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsUtilityService::GetInstanceDocumentRoot(const nsAString& aID,
nsIDOMNode *aModelNode,
nsIDOMNode **aInstanceRoot)
{
nsresult rv = NS_ERROR_FAILURE;
NS_ASSERTION(aInstanceRoot, "no return buffer, we'll crash soon");
*aInstanceRoot = nsnull;
if (aID.IsEmpty()) {
return rv;
}
nsCOMPtr<nsIXFormsModelElement> modelElement = do_QueryInterface(aModelNode);
nsCOMPtr<nsIDOMDocument> doc;
rv = modelElement->GetInstanceDocument(aID, getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> element;
rv = doc->GetDocumentElement(getter_AddRefs(element));
NS_ENSURE_SUCCESS(rv, rv);
if (element) {
NS_IF_ADDREF(*aInstanceRoot = element);
}
return rv;
}
/* Gotta do this via the service since we don't want transformiix to require
* any of the new extensions, like schema-validation
*/
NS_IMETHODIMP
nsXFormsUtilityService::ValidateString(const nsAString & aValue,
const nsAString & aType,
const nsAString & aNamespace,
PRBool *aResult)
{
// XXX TODO This function needs to call the XForms validator layer from
// bug 274083 when it goes into the build.
#if 0
nsresult rv = NS_ERROR_FAILURE;
nsXFormsSchemaValidator *validator = new nsXFormsSchemaValidator();
*aResult = validator->ValidateString(aValue, aType, aNamespace);
return rv;
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
* can also be inherited from a containing element like xforms:group or
* xforms:repeat.
*/
NS_IMETHODIMP
nsXFormsUtilityService::IsNodeAssocWithModel( nsIDOMNode *aNode,
nsIDOMNode *aModel,
PRBool *aModelAssocWithNode)
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
nsAutoString namespaceURI;
aNode->GetNamespaceURI(namespaceURI);
// If the node is in the XForms namespace and XTF based, then it should
// be able to be handled by GetModel. Otherwise it is probably an instance
// node in a instance document.
if (namespaceURI.EqualsLiteral(NS_NAMESPACE_XFORMS)) {
nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(element);
nsCOMPtr<nsIDOMNode> modelNode = do_QueryInterface(modelPriv);
if (modelNode && (modelNode == aModel)) {
*aModelAssocWithNode = PR_TRUE;
}
else {
*aModelAssocWithNode = PR_FALSE;
}
}
else {
// We are assuming that if the node coming in isn't a proper XForms element,
// then it is an instance element in an instance doc. Now we just have
// to determine if the given model contains this instance document.
nsCOMPtr<nsIDOMDocument> document;
aNode->GetOwnerDocument(getter_AddRefs(document));
*aModelAssocWithNode = PR_FALSE;
// Guess that we'd better make sure that it is a model
nsCOMPtr<nsIXFormsModelElement> modelEle = do_QueryInterface(aModel);
if (modelEle) {
// OK, we know that this is a model element. So now we have to go
// instance element by instance element and find the associated
// document. If it is equal to the document that contains aNode,
// then aNode is associated with this aModel element and we can return
// true.
nsCOMPtr<nsIDOMNodeList> children;
aModel->GetChildNodes(getter_AddRefs(children));
if (!children)
return NS_OK;
PRUint32 childCount = 0;
children->GetLength(&childCount);
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIInstanceElementPrivate> instElement;
nsCOMPtr<nsIDOMDocument> instDocument;
for (PRUint32 i = 0; i < childCount; ++i) {
children->Item(i, getter_AddRefs(node));
NS_ASSERTION(node, "incorrect NodeList length?");
instElement = do_QueryInterface(node);
if (!instElement)
continue;
instElement->GetDocument(getter_AddRefs(instDocument));
if (instDocument) {
if (instDocument == document) {
*aModelAssocWithNode = PR_TRUE;
break;
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsUtilityService::GetInstanceDocumentRoot(const nsAString& aID,
nsIDOMNode *aModelNode,
nsIDOMNode **aInstanceRoot)
{
nsresult rv = NS_ERROR_FAILURE;
NS_ASSERTION(aInstanceRoot, "no return buffer, we'll crash soon");
*aInstanceRoot = nsnull;
if (aID.IsEmpty()) {
return rv;
}
nsCOMPtr<nsIXFormsModelElement> modelElement = do_QueryInterface(aModelNode);
nsCOMPtr<nsIDOMDocument> doc;
rv = modelElement->GetInstanceDocument(aID, getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> element;
rv = doc->GetDocumentElement(getter_AddRefs(element));
NS_ENSURE_SUCCESS(rv, rv);
if (element) {
NS_IF_ADDREF(*aInstanceRoot = element);
}
return rv;
}
/* Gotta do this via the service since we don't want transformiix to require
* any of the new extensions, like schema-validation
*/
NS_IMETHODIMP
nsXFormsUtilityService::ValidateString(const nsAString & aValue,
const nsAString & aType,
const nsAString & aNamespace,
PRBool *aResult)
{
// XXX TODO This function needs to call the XForms validator layer from
// bug 274083 when it goes into the build.
#if 0
nsresult rv = NS_ERROR_FAILURE;
nsXFormsSchemaValidator *validator = new nsXFormsSchemaValidator();
*aResult = validator->ValidateString(aValue, aType, aNamespace);
return rv;
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -1,47 +1,47 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla XForms support.
*
* The Initial Developer of the Original Code is
* IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Aaron Reed <aaronr@us.ibm.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 ***** */
#include "nsIXFormsUtilityService.h"
class nsXFormsUtilityService : public nsIXFormsUtilityService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXFORMSUTILITYSERVICE
};
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla XForms support.
*
* The Initial Developer of the Original Code is
* IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Aaron Reed <aaronr@us.ibm.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 ***** */
#include "nsIXFormsUtilityService.h"
class nsXFormsUtilityService : public nsIXFormsUtilityService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXFORMSUTILITYSERVICE
};