Fix for bug 96647 (Change the way output is constructed in Transformiix). r=sicking, Pike, sr=jst.

This commit is contained in:
peterv%netscape.com 2002-01-24 13:38:51 +00:00
Родитель b876d6cabd
Коммит 6df18a080b
96 изменённых файлов: 5228 добавлений и 2036 удалений

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

@ -20,7 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
* Peter Van der Beken <peterv@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -41,6 +41,7 @@
#include "nsAppShellCIDs.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMEventReceiver.h"
#include "nsIEventQueueService.h"
@ -297,7 +298,9 @@ nsSyncLoader::LoadDocument(nsIURI* documentURI, nsIDocument *aLoader, nsIDOMDocu
return rv;
}
if (mLoadSuccess) {
nsCOMPtr<nsIDOMElement> documentElement;
DOMDocument->GetDocumentElement(getter_AddRefs(documentElement));
if (mLoadSuccess && documentElement) {
*_retval = DOMDocument;
NS_ADDREF(*_retval);
}

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

@ -432,7 +432,10 @@ nsXMLContentSink::Observe(nsISupports *aSubject, const char *aTopic, const PRUni
mDocument = resultDoc;
NS_ADDREF(mDocument);
mDocument->SetRootContent(content);
nsCOMPtr<nsIContent> root;
mDocument->GetRootContent(getter_AddRefs(root));
if (!root)
mDocument->SetRootContent(content);
// Reset the observer on the transform mediator
mXSLTransformMediator->SetTransformObserver(nsnull);

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

@ -124,10 +124,14 @@ LOBJS =../source/base/ArrayList.$(OBJ_SUFFIX) \
../source/xml/XMLDOMUtils.$(OBJ_SUFFIX) \
../source/xml/parser/XMLParser.$(OBJ_SUFFIX) \
../source/xml/parser/nsSyncLoader.$(OBJ_SUFFIX) \
../source/xslt/OutputFormat.$(OBJ_SUFFIX) \
../source/xslt/txOutputFormat.$(OBJ_SUFFIX) \
../source/xslt/Names.$(OBJ_SUFFIX) \
../source/xslt/Numbering.$(OBJ_SUFFIX) \
../source/xslt/ProcessorState.$(OBJ_SUFFIX) \
../source/xslt/txMozillaTextOutput.$(OBJ_SUFFIX) \
../source/xslt/txMozillaXMLOutput.$(OBJ_SUFFIX) \
../source/xslt/txRtfHandler.$(OBJ_SUFFIX) \
../source/xslt/txTextHandler.$(OBJ_SUFFIX) \
../source/xslt/VariableBinding.$(OBJ_SUFFIX) \
../source/xslt/XSLTProcessor.$(OBJ_SUFFIX) \
../source/xslt/functions/CurrentFunctionCall.$(OBJ_SUFFIX) \
@ -155,8 +159,7 @@ include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../source/xslt -I$(srcdir)/../source/base \
-I$(srcdir)/../source/net \
-I$(srcdir)/../source/xml -I$(srcdir)/../source/xml/dom \
-I$(srcdir)/../source/xml/parser \
-I$(srcdir)/../source/xml/printer -I$(srcdir)/../source/xpath \
-I$(srcdir)/../source/xml/parser -I$(srcdir)/../source/xpath \
-I$(srcdir)/../source/xslt/util -I$(srcdir)/../source/xslt/functions
_T_VERSION = $(shell date +%Y%m%d%H)

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

@ -96,10 +96,11 @@ PR_STATIC_CALLBACK(void)
Shutdown(nsIModule* aSelf)
{
NS_PRECONDITION(gInitialized, "module not initialized");
if (! gInitialized)
if (!gInitialized)
return;
gInitialized = PR_FALSE;
txXMLAtoms::shutdown();
txXPathAtoms::shutdown();
txXSLTAtoms::shutdown();

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

@ -107,10 +107,14 @@ CPP_OBJS= \
..\source\xml\$(OBJDIR)\XMLDOMUtils.obj \
..\source\xml\parser\$(OBJDIR)\nsSyncLoader.obj \
..\source\xml\parser\$(OBJDIR)\XMLParser.obj \
..\source\xslt\$(OBJDIR)\OutputFormat.obj \
..\source\xslt\$(OBJDIR)\txOutputFormat.obj \
..\source\xslt\$(OBJDIR)\Names.obj \
..\source\xslt\$(OBJDIR)\Numbering.obj \
..\source\xslt\$(OBJDIR)\ProcessorState.obj \
..\source\xslt\$(OBJDIR)\txMozillaTextOutput.obj \
..\source\xslt\$(OBJDIR)\txMozillaXMLOutput.obj \
..\source\xslt\$(OBJDIR)\txRtfHandler.obj \
..\source\xslt\$(OBJDIR)\txTextHandler.obj \
..\source\xslt\$(OBJDIR)\VariableBinding.obj \
..\source\xslt\$(OBJDIR)\XSLTProcessor.obj \
..\source\xslt\functions\$(OBJDIR)\CurrentFunctionCall.obj \

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

@ -1079,13 +1079,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>OutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringList.cpp</PATH>
@ -1520,13 +1513,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -1555,13 +1541,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>JavaScriptDebug.shlb</PATH>
@ -1576,13 +1555,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>TxObjectWrapper.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XSLTProcessorModule.cpp</PATH>
@ -1632,6 +1604,41 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaTextOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaXMLOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txRtfHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txTextHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txFormatNumberFunctionCall.cpp</PATH>
@ -1641,7 +1648,28 @@
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStaticDebug.o</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Library</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txOutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
@ -1725,11 +1753,6 @@
<PATH>ExprLexer.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>OutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringList.cpp</PATH>
@ -2055,11 +2078,6 @@
<PATH>nsSyncLoader.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -2080,11 +2098,6 @@
<PATH>FunctionAvailableFnCall.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>JavaScriptDebug.shlb</PATH>
@ -2095,11 +2108,6 @@
<PATH>Map.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>TxObjectWrapper.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XSLTProcessorModule.cpp</PATH>
@ -2135,6 +2143,31 @@
<PATH>txXPathResultComparator.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaTextOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaXMLOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txRtfHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txTextHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txFormatNumberFunctionCall.cpp</PATH>
@ -2142,7 +2175,22 @@
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStaticDebug.o</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txOutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
@ -3145,13 +3193,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>OutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringList.cpp</PATH>
@ -3614,13 +3655,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -3649,13 +3683,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>JavaScript.shlb</PATH>
@ -3670,13 +3697,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>TxObjectWrapper.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>XSLTProcessorModule.cpp</PATH>
@ -3726,6 +3746,41 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaTextOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaXMLOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txRtfHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txTextHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txFormatNumberFunctionCall.cpp</PATH>
@ -3735,7 +3790,28 @@
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStatic.o</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Library</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>txOutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
@ -3799,11 +3875,6 @@
<PATH>ExprLexer.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>OutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>StringList.cpp</PATH>
@ -4149,11 +4220,6 @@
<PATH>nsSyncLoader.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>CurrentFunctionCall.cpp</PATH>
@ -4174,11 +4240,6 @@
<PATH>FunctionAvailableFnCall.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>JavaScript.shlb</PATH>
@ -4189,11 +4250,6 @@
<PATH>Map.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>TxObjectWrapper.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>XSLTProcessorModule.cpp</PATH>
@ -4229,6 +4285,31 @@
<PATH>txXPathResultComparator.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaTextOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaXMLOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txRtfHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txTextHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txFormatNumberFunctionCall.cpp</PATH>
@ -4236,7 +4317,22 @@
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txAtoms.cpp</PATH>
<PATH>XPathProcessor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsNodeSet.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStatic.o</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>txOutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
@ -4317,12 +4413,6 @@
<PATH>txAtoms.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>TxObjectWrapper.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>net</NAME>
<FILEREF>
@ -4469,8 +4559,6 @@
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>util</NAME>
</GROUP>
</GROUP>
<GROUP><NAME>xpath</NAME>
<FILEREF>
@ -4712,13 +4800,37 @@
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>OutputFormat.cpp</PATH>
<PATH>ProcessorState.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>ProcessorState.cpp</PATH>
<PATH>txMozillaTextOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>txMozillaXMLOutput.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>txOutputFormat.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>txRtfHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>txTextHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
@ -4857,6 +4969,12 @@
<PATH>JavaScript.shlb</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiix.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStatic.o</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>Debug</NAME>
<FILEREF>
@ -4889,6 +5007,12 @@
<PATH>JavaScriptDebug.shlb</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>transformiixDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStaticDebug.o</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
</GROUP>
<GROUP><NAME>System Libraries</NAME>

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

@ -1,29 +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 Peter Van der Beken are Copyright (C) 2000
* Peter Van der Beken. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peter.vanderbeken@pandora.be
* -- original author.
*
*/
#include "MacSharedPrefix.h"
#define HAVE_RINT 1

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

@ -1,29 +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 Peter Van der Beken are Copyright (C) 2000
* Peter Van der Beken. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peter.vanderbeken@pandora.be
* -- original author.
*
*/
#include "MacSharedPrefix_debug.h"
#define HAVE_RINT 1

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

@ -1,47 +0,0 @@
/* -*- Mode: C++; 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.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.
*
*/
#include "nsISupports.idl"
#include "domstubs.idl"
%{C++
#include "nsString.h"
%}
/**
* The nsIXPathNodeSelector can be used to query a DOM tree using XPath.
*/
[scriptable, uuid(f70c3f08-1dd1-11b2-b582-db02dfacb173)]
interface nsIXPathNodeSelector : nsISupports
{
/**
* Return a nodelist that is the result of an XPath query of the tree
* fragment starting with the context node.
*
* @param aContextNode The context node for the query.
* @param aPattern The pattern for the query.
*
* @returns The result of the XPath query.
*/
nsIDOMNodeList selectNodes(in nsIDOMNode aContextNode,
in DOMString aPattern);
};
%{ C++
extern nsresult
NS_NewXPathNodeSelector(nsIXPathNodeSelector** aNodeSelector);
%}

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

@ -130,8 +130,6 @@ double Double::toDouble(const String& aSrc)
PRInt32 len = aSrc.length();
MBool digitFound = MB_FALSE;
double sign = 1.0;
// leading whitespace
while (idx < len &&
(aSrc.charAt(idx) == ' ' ||

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

@ -836,12 +836,31 @@ PRInt32 String::indexOf(const String& data, PRInt32 offset) const
//
MBool String::isEqual(const String& data) const
{
if (this == &data)
return MB_TRUE;
else if (strLength != data.length())
if (strLength != data.length())
return MB_FALSE;
else
return isEqual(strBuffer, data.toUnicode(), data.length());
return isEqual(strBuffer, data.toUnicode(), data.length());
}
MBool String::isEqualIgnoreCase(const String& data) const
{
if (strLength != data.length())
return MB_FALSE;
const UNICODE_CHAR* otherBuffer = data.strBuffer;
UNICODE_CHAR thisChar, otherChar;
PRInt32 compLoop = 0;
while (compLoop < strLength) {
thisChar = strBuffer[compLoop];
if ((thisChar >= 'A') && (thisChar <= 'Z'))
thisChar += 32;
otherChar = otherBuffer[compLoop];
if ((otherChar >= 'A') && (otherChar <= 'Z'))
otherChar += 32;
if (thisChar != otherChar)
return MB_FALSE;
++compLoop;
}
return MB_TRUE;
}
/**
@ -940,13 +959,12 @@ String& String::subString(PRInt32 start, String& dest) const
String& String::subString(PRInt32 start, PRInt32 end, String& dest) const
{
PRInt32 srcLoop;
PRInt32 destLoop = 0;
start = start < 0? 0 : start;
end = end > strLength? strLength : end;
start = start < 0 ? 0 : start;
end = end > strLength ? strLength : end;
dest.clear();
if ((start < end))
if (start < end)
{
dest.ensureCapacity(end - start);
for (srcLoop=start;srcLoop<end;srcLoop++)

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

@ -121,9 +121,7 @@ class String : public TxObject
virtual MBool isEqual(const String& data) const; //Check equality between
//strings
#ifndef TX_EXE
virtual MBool isEqualIgnoreCase(const String& data) const;
#endif
//Returns index of last occurrence of data
virtual PRInt32 lastIndexOf(UNICODE_CHAR data) const;

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

@ -82,6 +82,11 @@ public:
aString = mString;
return MB_TRUE;
}
friend ostream& operator << (ostream& aOutput, const txAtom& aSource)
{
aOutput << aSource.mString;
return aOutput;
}
private:
String mString;
};

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

@ -48,18 +48,14 @@ XML_ATOMS;
#define TX_ATOM(_name, _value) txAtom* txXSLTAtoms::_name = 0
#include "txXSLTAtomList.h"
#undef TX_ATOM
#ifndef TX_EXE
#define TX_ATOM(_name, _value) txAtom* txHTMLAtoms::_name = 0
#include "txHTMLAtomList.h"
#undef TX_ATOM
#endif
static PRUint32 gXMLRefCnt = 0;
static PRUint32 gXPathRefCnt = 0;
static PRUint32 gXSLTRefCnt = 0;
#ifndef TX_EXE
static PRUint32 gHTMLRefCnt = 0;
#endif
#ifdef TX_EXE
#define TX_ATOM(_name, _value) \
@ -99,7 +95,6 @@ MBool txXSLTAtoms::init()
return MB_TRUE;
}
#ifndef TX_EXE
MBool txHTMLAtoms::init()
{
if (0 == gHTMLRefCnt++) {
@ -108,7 +103,6 @@ MBool txHTMLAtoms::init()
}
return MB_TRUE;
}
#endif
#undef TX_ATOM
@ -142,7 +136,6 @@ void txXSLTAtoms::shutdown()
}
}
#ifndef TX_EXE
void txHTMLAtoms::shutdown()
{
NS_ASSERTION(gHTMLRefCnt != 0, "bad release atoms");
@ -151,6 +144,5 @@ void txHTMLAtoms::shutdown()
#include "txHTMLAtomList.h"
}
}
#endif
#undef TX_ATOM

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

@ -51,6 +51,7 @@
*/
#define XML_ATOMS \
TX_ATOM(_empty, ""); \
TX_ATOM(base, "base"); \
TX_ATOM(lang, "lang"); \
TX_ATOM(space, "space"); \
@ -83,7 +84,6 @@ public:
#include "txXSLTAtomList.h"
};
#ifndef TX_EXE
class txHTMLAtoms
{
public:
@ -91,7 +91,6 @@ public:
static void shutdown();
#include "txHTMLAtomList.h"
};
#endif
#undef TX_ATOM

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

@ -82,17 +82,13 @@
<HEAD>
<TITLE>TransforMiiX Test Cases</TITLE>
<SCRIPT Language="JavaScript">
<xsl:text>
// This is a test for properly printing SCRIPT elements
// currently there is a bug, so use xsl:text as a wrapper as I
// have done here
function foo() {
var x = 1;
var y = 2;
return (x &lt; y);
}
//
</xsl:text>
</SCRIPT>
</HEAD>
<BODY BGColor="#FFFFFF" Text="#000000">

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

@ -101,13 +101,15 @@ OBJS =../base/ArrayList.$(OBJ_SUFFIX) \
../xml/parser/xmlrole.$(OBJ_SUFFIX) \
../xml/parser/xmlparse.$(OBJ_SUFFIX) \
../xml/parser/xmltok.$(OBJ_SUFFIX) \
../xml/printer/XMLPrinter.$(OBJ_SUFFIX) \
../xml/printer/HTMLPrinter.$(OBJ_SUFFIX) \
../xml/printer/TEXTPrinter.$(OBJ_SUFFIX) \
../xslt/OutputFormat.$(OBJ_SUFFIX) \
../xslt/txOutputFormat.$(OBJ_SUFFIX) \
../xslt/Names.$(OBJ_SUFFIX) \
../xslt/Numbering.$(OBJ_SUFFIX) \
../xslt/ProcessorState.$(OBJ_SUFFIX) \
../xslt/txHTMLOutput.$(OBJ_SUFFIX) \
../xslt/txRtfHandler.$(OBJ_SUFFIX) \
../xslt/txTextHandler.$(OBJ_SUFFIX) \
../xslt/txTextOutput.$(OBJ_SUFFIX) \
../xslt/txXMLOutput.$(OBJ_SUFFIX) \
../xslt/VariableBinding.$(OBJ_SUFFIX) \
../xslt/XSLTProcessor.$(OBJ_SUFFIX) \
../xslt/functions/CurrentFunctionCall.$(OBJ_SUFFIX) \
@ -128,5 +130,5 @@ include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../xslt -I$(srcdir)/../base -I$(srcdir)/../net \
-I$(srcdir)/../xml -I$(srcdir)/../xml/dom \
-I$(srcdir)/../xml/parser -I$(srcdir)/../xml/parser/xmlparse \
-I$(srcdir)/../xml/printer -I$(srcdir)/../xpath -I$(srcdir)/../xslt/util \
-I$(srcdir)/../xpath -I$(srcdir)/../xslt/util \
-I$(srcdir)/../xslt/functions

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

@ -95,13 +95,15 @@ CPP_OBJS= \
../xml/$(OBJDIR)/XMLUtils.obj \
../xml/$(OBJDIR)/XMLDOMUtils.obj \
../xml/parser/$(OBJDIR)/XMLParser.obj \
../xml/printer/$(OBJDIR)/XMLPrinter.obj \
../xml/printer/$(OBJDIR)/HTMLPrinter.obj \
../xml/printer/$(OBJDIR)/TEXTPrinter.obj \
../xslt/$(OBJDIR)/OutputFormat.obj \
../xslt/$(OBJDIR)/txOutputFormat.obj \
../xslt/$(OBJDIR)/Names.obj \
../xslt/$(OBJDIR)/Numbering.obj \
../xslt/$(OBJDIR)/ProcessorState.obj \
../xslt/$(OBJDIR)/txHTMLOutput.obj \
../xslt/$(OBJDIR)/txRtfHandler.obj \
../xslt/$(OBJDIR)/txTextHandler.obj \
../xslt/$(OBJDIR)/txTextOutput.obj \
../xslt/$(OBJDIR)/txXMLOutput.obj \
../xslt/$(OBJDIR)/VariableBinding.obj \
../xslt/$(OBJDIR)/XSLTProcessor.obj \
../xslt/functions/$(OBJDIR)/CurrentFunctionCall.obj \
@ -122,8 +124,7 @@ EXPORTS = \
$(NULL)
LINCS=-I../xslt -I../base -I../net \
-I../xml -I../xml/dom \
-I../xml/printer -I../xpath -I../xslt/util \
-I../xml -I../xml/dom -I../xpath -I../xslt/util \
-I../xslt/functions -I../xml/parser
LCFLAGS = \

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

@ -38,9 +38,6 @@ REQUIRES = string \
endif
DIRS = dom parser
ifdef TX_EXE
DIRS += printer
endif
CPPSRCS = XMLDOMUtils.cpp XMLUtils.cpp

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

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

@ -23,192 +23,64 @@
*
*/
/**
* XMLDOMUtils
**/
#include "XMLDOMUtils.h"
#include "txAtom.h"
/**
* Copies the given Node, using the owner Document to create all
* necessary new Node(s)
**/
Node* XMLDOMUtils::copyNode(Node* node, Document* owner, NamespaceResolver* resolver) {
void XMLDOMUtils::getNodeValue(Node* aNode, String& aResult)
{
if (!aNode)
return;
if ( !node ) return 0;
unsigned short nodeType = aNode->getNodeType();
short nodeType = node->getNodeType();
//-- make sure owner exists if we are copying nodes other than
//-- document nodes
if (nodeType != Node::DOCUMENT_NODE && !owner) return 0;
Node* newNode = 0;
PRUint32 i = 0;
switch ( nodeType ) {
case Node::ATTRIBUTE_NODE :
{
Attr* attr = (Attr*)node;
Attr* newAttr = owner->createAttribute(attr->getName());
newAttr->setValue(attr->getValue());
newNode = newAttr;
break;
}
case Node::DOCUMENT_NODE :
{
Document* doc = (Document*)node;
Document* newDoc = new Document();
if (!newDoc)
break;
#ifndef TX_EXE
owner->addWrapper(newDoc);
#endif
NodeList* nl = doc->getChildNodes();
for (i = 0; i < nl->getLength(); i++) {
newDoc->appendChild(copyNode(nl->item(i), newDoc, resolver));
}
newNode = newDoc;
break;
}
case Node::DOCUMENT_FRAGMENT_NODE :
{
newNode = owner->createDocumentFragment();
Node* tmpNode = node->getFirstChild();
while (tmpNode) {
newNode->appendChild(copyNode(tmpNode, owner, resolver));
tmpNode = tmpNode->getNextSibling();
}
break;
}
case Node::ELEMENT_NODE :
{
Element* element = (Element*)node;
#ifndef TX_EXE
String name, nameSpaceURI;
name = element->getNodeName();
resolver->getResultNameSpaceURI(name, nameSpaceURI);
Element* newElement = owner->createElementNS(nameSpaceURI, name);
#else
Element* newElement = owner->createElement(element->getNodeName());
#endif
//-- copy atts
NamedNodeMap* attList = element->getAttributes();
if ( attList ) {
for ( i = 0; i < attList->getLength(); i++ ) {
Attr* attr = (Attr*) attList->item(i);
#ifndef TX_EXE
resolver->getResultNameSpaceURI(attr->getName(), nameSpaceURI);
newElement->setAttributeNS(nameSpaceURI, attr->getName(), attr->getValue());
#else
newElement->setAttribute(attr->getName(), attr->getValue());
#endif
}
}
//-- copy children
Node* tmpNode = element->getFirstChild();
while (tmpNode) {
newElement->appendChild(copyNode(tmpNode, owner, resolver));
tmpNode = tmpNode->getNextSibling();
}
newNode = newElement;
break;
}
case Node::TEXT_NODE :
newNode = owner->createTextNode(((Text*)node)->getData());
break;
case Node::CDATA_SECTION_NODE :
newNode = owner->createCDATASection(((CDATASection*)node)->getData());
break;
case Node::PROCESSING_INSTRUCTION_NODE:
{
ProcessingInstruction* pi = (ProcessingInstruction*)node;
newNode = owner->createProcessingInstruction(pi->getTarget(), pi->getData());
break;
}
switch (nodeType) {
case Node::ATTRIBUTE_NODE:
case Node::CDATA_SECTION_NODE:
case Node::COMMENT_NODE:
newNode = owner->createComment(((Comment*)node)->getData());
break;
default:
break;
} //-- switch
return newNode;
} //-- copyNode
void XMLDOMUtils::getNodeValue(Node* node, String* target) {
if (!node) return;
int nodeType = node->getNodeType();
switch ( nodeType ) {
case Node::ATTRIBUTE_NODE :
target->append( ((Attr*)node)->getValue() );
break;
case Node::DOCUMENT_NODE :
getNodeValue( ((Document*)node)->getDocumentElement(), target);
break;
case Node::DOCUMENT_FRAGMENT_NODE :
case Node::ELEMENT_NODE :
case Node::PROCESSING_INSTRUCTION_NODE:
case Node::TEXT_NODE:
{
Node* tmpNode = node->getFirstChild();
aResult.append(aNode->getNodeValue());
break;
}
case Node::DOCUMENT_NODE:
{
getNodeValue(((Document*)aNode)->getDocumentElement(),
aResult);
break;
}
case Node::DOCUMENT_FRAGMENT_NODE:
case Node::ELEMENT_NODE:
{
Node* tmpNode = aNode->getFirstChild();
while (tmpNode) {
nodeType = tmpNode->getNodeType();
if (nodeType == Node::TEXT_NODE ||
nodeType == Node::ELEMENT_NODE ||
nodeType == Node::CDATA_SECTION_NODE) {
getNodeValue(tmpNode,target);
};
if ((nodeType == Node::TEXT_NODE) ||
(nodeType == Node::CDATA_SECTION_NODE))
aResult.append(tmpNode->getNodeValue());
else if (nodeType == Node::ELEMENT_NODE)
getNodeValue(tmpNode, aResult);
tmpNode = tmpNode->getNextSibling();
}
break;
}
case Node::TEXT_NODE :
case Node::CDATA_SECTION_NODE :
target->append ( ((Text*)node)->getData() );
break;
case Node::COMMENT_NODE :
case Node::PROCESSING_INSTRUCTION_NODE :
target->append ( node->getNodeValue() );
break;
}
}
} //-- switch
} //-- getNodeValue
/**
* Resolves the namespace for the given prefix. The namespace is put
* into the dest argument.
*
* @return true if the namespace was found
**/
MBool XMLDOMUtils::getNameSpace
(const String& prefix, Element* element, String& dest)
MBool XMLDOMUtils::getNamespaceURI(const String& aPrefix,
Element* aElement,
String& aResult)
{
String attName("xmlns");
if (!prefix.isEmpty()) {
attName.append(':');
attName.append(prefix);
}
dest.clear();
Element* elem = element;
while( elem ) {
NamedNodeMap* atts = elem->getAttributes();
if ( atts ) {
Node* attr = atts->getNamedItem(attName);
if (attr) {
dest.append(attr->getNodeValue());
return MB_TRUE;
}
}
Node* node = elem->getParentNode();
if ((!node) || (node->getNodeType() != Node::ELEMENT_NODE)) break;
elem = (Element*) node;
}
return MB_FALSE;
} //-- getNameSpace
txAtom* prefix = TX_GET_ATOM(aPrefix);
if (!prefix)
return MB_FALSE;
PRInt32 namespaceID = aElement->lookupNamespaceID(prefix);
TX_RELEASE_ATOM(prefix);
if (namespaceID == kNameSpaceID_Unknown)
return MB_FALSE;
Document* document = aElement->getOwnerDocument();
if (!document)
return MB_FALSE;
document->namespaceIDToURI(namespaceID, aResult);
return MB_TRUE;
}

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

@ -23,39 +23,31 @@
*
*/
#ifndef TRANSFRMX_XMLDOMUTILS_H
#define TRANSFRMX_XMLDOMUTILS_H
#include "dom.h"
#include "NamespaceResolver.h"
#include "baseutils.h"
/**
/*
* A utility class for use with XML DOM implementations
**/
class XMLDOMUtils {
*/
class XMLDOMUtils
{
public:
/*
* Appends the value of the given node to aResult.
*/
static void getNodeValue(Node* aNode, String& aResult);
/**
* Copies the given Node, using the owner Document to create all
* necessary new Node(s)
**/
static Node* copyNode(Node* node, Document* owner, NamespaceResolver* resolver);
/**
* Appends the value of the given Node to the target String
**/
static void getNodeValue(Node* node, String* target);
/**
* Returns the Namespace associated with the given prefix
**/
static MBool getNameSpace(const String& prefix, Element* element, String& dest);
}; //-- XMLDOMUtils
/*
* Looks up the namespace URI associated with the given prefix.
*
* @return true if the namespace URI was found
*/
static MBool getNamespaceURI(const String& aPrefix,
Element* aElement,
String& aResult);
};
#endif

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

@ -25,19 +25,30 @@
*
*/
/**
* An XML utility class
**/
/*
* XML utility classes
*/
#include "XMLUtils.h"
txExpandedName::txExpandedName(PRInt32 aNsID,
txAtom* aLocalName) : mNamespaceID(aNsID),
mLocalName(aLocalName)
{
if (mLocalName)
TX_ADDREF_ATOM(mLocalName);
}
txExpandedName::~txExpandedName()
{
TX_IF_RELEASE_ATOM(mLocalName);
}
//------------------------------/
//- Implementation of XMLUtils -/
//------------------------------/
const String XMLUtils::XMLNS = "xmlns";
void XMLUtils::getNameSpace(const String& src, String& dest) {
void XMLUtils::getPrefix(const String& src, String& dest) {
//-- anything preceding ':' is the namespace part of the name
int idx = src.indexOf(':');
@ -50,7 +61,7 @@ void XMLUtils::getNameSpace(const String& src, String& dest) {
}
else dest.append("");
} //-- getNameSpace
}
void XMLUtils::getLocalPart(const String& src, String& dest) {
@ -135,49 +146,6 @@ MBool XMLUtils::isWhitespace(const String& text) {
return MB_TRUE;
} //-- isWhitespace
/**
* Normalizes the value of an XML attribute
**/
void XMLUtils::normalizeAttributeValue(String& attValue) {
PRInt32 size = attValue.length();
//-- make copy of chars
UNICODE_CHAR* chars = new UNICODE_CHAR[size];
attValue.toUnicode(chars);
//-- clear attValue
attValue.clear();
PRInt32 cc = 0;
MBool addSpace = MB_FALSE;
while ( cc < size) {
UNICODE_CHAR ch = chars[cc++];
switch (ch) {
case ' ':
if (!attValue.isEmpty())
addSpace = MB_TRUE;
break;
case '\r':
break;
case '\n':
attValue.append("&#xA;");
break;
case '\'':
attValue.append("&apos;");
break;
case '\"':
attValue.append("&quot;");
break;
default:
if ( addSpace) {
attValue.append(' ');
addSpace = MB_FALSE;
}
attValue.append(ch);
break;
}
}
delete chars;
} //-- normalizeAttributeValue
/**
* Normalizes the value of a XML processing instruction
**/
@ -230,4 +198,3 @@ MBool XMLUtils::shouldStripTextnode (const String& data){
}
return toStrip;
} //-- shouldStripTextnode

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

@ -30,16 +30,39 @@
#ifndef MITRE_XMLUTILS_H
#define MITRE_XMLUTILS_H
#include "TxString.h"
#include "baseutils.h"
#include "txAtom.h"
class String;
class txExpandedName {
public:
txExpandedName(PRInt32 aNsID, txAtom* aLocalName);
~txExpandedName();
MBool
operator == (const txExpandedName& rhs)
{
return ((mNamespaceID == rhs.mNamespaceID) &&
(mLocalName == rhs.mLocalName));
}
MBool
operator != (const txExpandedName& rhs)
{
return ((mNamespaceID != rhs.mNamespaceID) ||
(mLocalName != rhs.mLocalName));
}
PRInt32 mNamespaceID;
txAtom* mLocalName;
};
class XMLUtils {
public:
static const String XMLNS;
static void getNameSpace(const String& src, String& dest);
static void getPrefix(const String& src, String& dest);
static void getLocalPart(const String& src, String& dest);
@ -53,11 +76,6 @@ public:
**/
static MBool isWhitespace(const String& text);
/**
* Normalizes the value of an XML attribute
**/
static void normalizeAttributeValue(String& attValue);
/**
* Normalizes the value of a XML processingInstruction
**/

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

@ -62,7 +62,9 @@ Document::Document() : Node(0, 0)
ownerDocument = this;
wrapperHashTable = new nsObjectHashtable(nsnull, nsnull,
DeleteWrapper, nsnull);
#ifdef DEBUG
bInHashTableDeletion = PR_FALSE;
#endif
nsCOMPtr<nsIDocument> doc(do_QueryInterface(document));
NS_ASSERTION(doc,"document doesn't implement nsIDocument");
if (doc) {
@ -83,7 +85,9 @@ Document::Document(nsIDOMDocument* aDocument) : Node(aDocument, 0)
ownerDocument = this;
wrapperHashTable = new nsObjectHashtable(nsnull, nsnull,
DeleteWrapper, nsnull);
#ifdef DEBUG
bInHashTableDeletion = PR_FALSE;
#endif
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDocument));
NS_ASSERTION(doc,"document doesn't implement nsIDocument");
if (doc) {
@ -99,21 +103,12 @@ Document::Document(nsIDOMDocument* aDocument) : Node(aDocument, 0)
Document::~Document()
{
removeWrapper(this);
#ifdef DEBUG
bInHashTableDeletion = PR_TRUE;
#endif
delete wrapperHashTable;
}
/**
* Flags wether the document is deleting the wrapper hash table and the objects
* that it contains.
*
* @return flags wether the document is deleting the wrapper hash table
*/
PRBool Document::inHashTableDeletion()
{
return bInHashTableDeletion;
}
/**
* Call nsIDOMDocument::GetDocumentElement to get the document's
* DocumentElement.
@ -288,7 +283,7 @@ Attr* Document::createAttribute(const String& aName)
* @return the Attribute
*/
Attr* Document::createAttributeNS(const String& aNamespaceURI,
const String& aName)
const String& aName)
{
NSI_FROM_TX_NULL_CHECK(Document)
nsCOMPtr<nsIDOMAttr> attr;
@ -641,3 +636,20 @@ TxObject* Document::removeWrapper(MozillaObjectWrapper* aObject)
nsISupportsKey key(aObject->getNSObj());
return (TxObject*)wrapperHashTable->Remove(&key);
}
PRInt32 Document::namespaceURIToID(const String& aNamespaceURI)
{
PRInt32 namesspaceID = kNameSpaceID_Unknown;
if (nsNSManager)
nsNSManager->RegisterNameSpace(aNamespaceURI.getConstNSString(),
namesspaceID);
return namesspaceID;
}
void Document::namespaceIDToURI(PRInt32 aNamespaceID, String& aNamespaceURI)
{
if (nsNSManager)
nsNSManager->GetNameSpaceURI(aNamespaceID,
aNamespaceURI.getNSString());
return;
}

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

@ -467,6 +467,9 @@ PRInt32 Node::lookupNamespaceID(txAtom* aPrefix)
elem = do_QueryInterface(nsNode);
}
if (!aPrefix || aPrefix == txXMLAtoms::_empty)
aPrefix = txXMLAtoms::xmlns;
while (elem) {
nsAutoString uri;
rv = elem->GetAttr(kNameSpaceID_XMLNS, aPrefix, uri);
@ -485,6 +488,11 @@ PRInt32 Node::lookupNamespaceID(txAtom* aPrefix)
rv = temp->GetParent(*getter_AddRefs(elem));
NS_ENSURE_SUCCESS(rv, kNameSpaceID_Unknown);
}
if (aPrefix == txXMLAtoms::xmlns)
// No default namespace
return kNameSpaceID_None;
// Error, namespace not found
return kNameSpaceID_Unknown;
}

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

@ -1,92 +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 Peter Van der Beken are Copyright (C) 2000
* Peter Van der Beken. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peter.vanderbeken@pandora.be
* -- original author.
*
*/
/* Base class of all the wrapper classes. Takes care of addref'ing and
releasing the Mozilla objects.
*/
#include "mozilladom.h"
MOZ_DECL_CTOR_COUNTER(MozillaObjectWrapper)
/**
* Construct a wrapper with the specified Mozilla object and document owner.
*
* @param aNsObject the Mozilla object you want to wrap
* @param aOwner the document that owns this object
*/
MozillaObjectWrapper::MozillaObjectWrapper(nsISupports* aNsObject,
Document* aOwner)
{
MOZ_COUNT_CTOR(MozillaObjectWrapper);
nsObject = aNsObject;
ownerDocument = aOwner;
if (ownerDocument)
ownerDocument->addWrapper(this);
}
/**
* Destructor
*/
MozillaObjectWrapper::~MozillaObjectWrapper()
{
MOZ_COUNT_DTOR(MozillaObjectWrapper);
if (ownerDocument && (ownerDocument != this) &&
!ownerDocument->inHashTableDeletion())
ownerDocument->removeWrapper(getNSObj());
}
/**
* Wrap a different Mozilla object with this wrapper.
*
* @param aNsObject the Mozilla object you want to wrap
*/
void MozillaObjectWrapper::setNSObj(nsISupports* aNsObject)
{
nsObject = aNsObject;
}
/**
* Wrap a different Mozilla object with this wrapper and set document owner.
*
* @param aNsObject the Mozilla object you want to wrap
*/
void MozillaObjectWrapper::setNSObj(nsISupports* aNsObject, Document* aOwner)
{
nsObject = aNsObject;
ownerDocument = aOwner;
if (ownerDocument && (ownerDocument != this))
ownerDocument->addWrapper(this);
}
/**
* Get the Mozilla object wrapped with this wrapper.
*
* @return the Mozilla object wrapped with this wrapper
*/
nsISupports* MozillaObjectWrapper::getNSObj() const
{
return nsObject;
};

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

@ -72,7 +72,6 @@
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMText.h"
#include "nsINameSpaceManager.h"
#include "txAtom.h"
#ifndef NULL
@ -331,8 +330,6 @@ class Document : public Node
Document(nsIDOMDocument* aDocument);
~Document();
PRBool inHashTableDeletion();
Element* getDocumentElement();
DocumentType* getDoctype();
DOMImplementation* getImplementation();
@ -401,9 +398,16 @@ class Document : public Node
Element* getElementById(const String aID);
private:
PRBool bInHashTableDeletion;
PRInt32 namespaceURIToID(const String& aNamespaceURI);
void namespaceIDToURI(PRInt32 aNamespaceID, String& aNamespaceURI);
#ifdef DEBUG
protected:
PRBool bInHashTableDeletion;
friend class MozillaObjectWrapper;
#endif
private:
nsObjectHashtable *wrapperHashTable;
nsCOMPtr<nsINameSpaceManager> nsNSManager;
@ -421,8 +425,9 @@ class Element : public Node
const String& getTagName();
const String& getAttribute(const String& aName);
void setAttribute(const String& aName, const String& aValue);
void setAttributeNS(const String& aNamespaceURI, const String& aName,
const String& aValue);
void setAttributeNS(const String& aNamespaceURI,
const String& aName,
const String& aValue);
void removeAttribute(const String& aName);
Attr* getAttributeNode(const String& aName);
Attr* setAttributeNode(Attr* aNewAttr);

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

@ -27,6 +27,7 @@
#include "dom.h"
#include "txAtoms.h"
#include "XMLUtils.h"
//
//Construct an Attribute object using the specified name and document owner
@ -46,7 +47,7 @@ Attr::Attr(const String& name, Document* owner):
}
else {
String tmp;
nodeName.subString(idx+1, tmp);
nodeName.subString(idx + 1, tmp);
mLocalName = TX_GET_ATOM(tmp);
// namespace handling has to be handled late, the attribute must
// be added to the tree to resolve the prefix, unless it's
@ -64,6 +65,22 @@ Attr::Attr(const String& name, Document* owner):
}
}
Attr::Attr(const String& aNamespaceURI,
const String& aName,
Document* aOwner) :
NodeDefinition(Node::ATTRIBUTE_NODE, aName, NULL_STRING, aOwner)
{
if (aNamespaceURI.isEmpty())
mNamespaceID = kNameSpaceID_None;
else
mNamespaceID = txNamespaceManager::getNamespaceID(aNamespaceURI);
specified = MB_TRUE;
String localPart;
XMLUtils::getLocalPart(nodeName, localPart);
mLocalName = TX_GET_ATOM(localPart);
}
//
//Release the mLocalName
//

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

@ -207,6 +207,12 @@ Element* Document::createElement(const String& tagName)
return new Element(tagName, this);
}
Element* Document::createElementNS(const String& aNamespaceURI,
const String& aTagName)
{
return new Element(aNamespaceURI, aTagName, this);
}
//
//Construct an attribute with the specified name
//
@ -215,6 +221,12 @@ Attr* Document::createAttribute(const String& name)
return new Attr(name, this);
}
Attr* Document::createAttributeNS(const String& aNamespaceURI,
const String& aName)
{
return new Attr(aNamespaceURI, aName, this);
}
//
//Construct a text node with the given data
//
@ -271,5 +283,16 @@ Element* Document::getElementById(const String aID)
String Document::getBaseURI()
{
return documentBaseURI;
return documentBaseURI;
}
PRInt32 Document::namespaceURIToID(const String& aNamespaceURI)
{
return txNamespaceManager::getNamespaceID(aNamespaceURI);
}
void Document::namespaceIDToURI(PRInt32 aNamespaceID, String& aNamespaceURI)
{
aNamespaceURI = txNamespaceManager::getNamespaceURI(aNamespaceID);
return;
}

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

@ -27,6 +27,7 @@
#include "dom.h"
#include "txAtoms.h"
#include "XMLUtils.h"
//
//Construct a new element with the specified tagName and Document owner.
@ -50,6 +51,18 @@ Element::Element(const String& tagName, Document* owner) :
}
}
Element::Element(const String& aNamespaceURI,
const String& aTagName,
Document* aOwner) :
NodeDefinition(Node::ELEMENT_NODE, aTagName, NULL_STRING, aOwner)
{
Element(aTagName, aOwner);
if (aNamespaceURI.isEmpty())
mNamespaceID = kNameSpaceID_None;
else
mNamespaceID = txNamespaceManager::getNamespaceID(aNamespaceURI);
}
//
// This element is being destroyed, so destroy all attributes stored
// in the mAttributes NamedNodeMap.
@ -171,19 +184,58 @@ const String& Element::getAttribute(const String& name)
//
void Element::setAttribute(const String& name, const String& value)
{
Attr* tempAttribute;
// Check to see if an attribute with this name already exists. If it does
// overwrite its value, if not, add it.
Attr* tempAttribute = getAttributeNode(name);
if (tempAttribute) {
tempAttribute->setNodeValue(value);
}
else {
tempAttribute = getOwnerDocument()->createAttribute(name);
tempAttribute->setNodeValue(value);
tempAttribute->ownerElement = this;
mAttributes.append(tempAttribute);
}
}
//Check to see if an attribute with this name already exists. If it does
//over write its value, if not, add it.
tempAttribute = getAttributeNode(name);
if (tempAttribute)
tempAttribute->setNodeValue(value);
else
{
tempAttribute = getOwnerDocument()->createAttribute(name);
tempAttribute->setNodeValue(value);
mAttributes.setNamedItem(tempAttribute);
void Element::setAttributeNS(const String& aNamespaceURI,
const String& aName,
const String& aValue)
{
// Check to see if an attribute with this name already exists. If it does
// overwrite its value, if not, add it.
PRInt32 namespaceID = txNamespaceManager::getNamespaceID(aNamespaceURI);
String localPart;
XMLUtils::getLocalPart(aName, localPart);
txAtom* localName = TX_GET_ATOM(localPart);
Attr* foundNode = 0;
AttrMap::ListItem* item = mAttributes.firstItem;
while (item) {
foundNode = (Attr*)item->node;
txAtom* attrName;
if (foundNode->getLocalName(&attrName) &&
namespaceID == foundNode->getNamespaceID() &&
localName == attrName) {
TX_IF_RELEASE_ATOM(attrName);
break;
}
TX_IF_RELEASE_ATOM(attrName);
foundNode = 0;
item = item->next;
}
TX_IF_RELEASE_ATOM(localName);
if (foundNode) {
foundNode->setNodeValue(aValue);
}
else {
Attr* temp = getOwnerDocument()->createAttributeNS(aNamespaceURI,
aName);
temp->setNodeValue(aValue);
temp->ownerElement = this;
mAttributes.append(temp);
}
}
//

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

@ -46,7 +46,8 @@ CPPSRCS = Attr.cpp \
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../../../base -I$(srcdir)/../../../net \
-I$(srcdir)/../../../xpath -I$(srcdir)/../../../xslt
INCLUDES += -I$(srcdir)/../.. -I$(srcdir)/../../../base \
-I$(srcdir)/../../../net -I$(srcdir)/../../../xpath \
-I$(srcdir)/../../../xslt
libs:: $(OBJS)

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

@ -89,11 +89,6 @@ const String& NodeDefinition::getNodeName() const
return nodeName;
}
const String& NodeDefinition::getNodeValue() const
{
return nodeValue;
}
const String& NodeDefinition::getNodeValue()
{
return nodeValue;
@ -395,9 +390,17 @@ PRInt32 NodeDefinition::lookupNamespaceID(txAtom* aPrefix)
node = node->getXPathParent();
String name("xmlns:");
String prefixString;
TX_GET_ATOM_STRING(aPrefix, prefixString);
name.append(prefixString);
if (aPrefix && (aPrefix != txXMLAtoms::_empty)) {
// We have a prefix, search for xmlns:prefix attributes.
String prefixString;
TX_GET_ATOM_STRING(aPrefix, prefixString);
name.append(prefixString);
}
else {
// No prefix, look up the default namespace by searching for xmlns
// attributes. Remove the trailing :, set length to 5 (xmlns).
name.setLength(5);
}
Attr* xmlns;
while (node && node->getNodeType() == Node::ELEMENT_NODE) {
String nsURI;
@ -411,6 +414,8 @@ PRInt32 NodeDefinition::lookupNamespaceID(txAtom* aPrefix)
}
node = node->getXPathParent();
}
if (!aPrefix || (aPrefix == txXMLAtoms::_empty))
return kNameSpaceID_None;
return kNameSpaceID_Unknown;
}

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

@ -125,7 +125,6 @@ class Node : public TxObject
//Read functions
virtual const String& getNodeName() const = 0;
virtual const String& getNodeValue() const = 0;
virtual const String& getNodeValue() = 0;
virtual unsigned short getNodeType() const = 0;
virtual Node* getParentNode() const = 0;
@ -267,7 +266,6 @@ class NodeDefinition : public Node, public NodeList
//Read functions
const String& getNodeName() const;
virtual const String& getNodeValue() const;
virtual const String& getNodeValue();
unsigned short getNodeType() const;
Node* getParentNode() const;
@ -394,11 +392,20 @@ class Document : public NodeDefinition
Node* removeChild(Node* oldChild);
// Introduced in DOM Level 2
Element* createElementNS(const String& aNamespaceURI,
const String& aTagName);
Attr* createAttributeNS(const String& aNamespaceURI,
const String& aName);
Element* getElementById(const String aID);
//Override to return documentBaseURI
String getBaseURI();
PRInt32 namespaceURIToID(const String& aNamespaceURI);
void namespaceIDToURI(PRInt32 aNamespaceID, String& aNamespaceURI);
private:
Element* documentElement;
DocumentType* doctype;
@ -416,6 +423,8 @@ class Element : public NodeDefinition
{
public:
Element(const String& tagName, Document* owner);
Element(const String& aNamespaceURI, const String& aTagName,
Document* aOwner);
virtual ~Element();
//Override insertBefore to limit Elements to having only certain nodes as
@ -426,6 +435,9 @@ class Element : public NodeDefinition
NamedNodeMap* getAttributes();
const String& getAttribute(const String& name);
void setAttribute(const String& name, const String& value);
void setAttributeNS(const String& aNamespaceURI,
const String& aName,
const String& aValue);
void removeAttribute(const String& name);
Attr* getAttributeNode(const String& name);
Attr* setAttributeNode(Attr* newAttr);
@ -452,10 +464,13 @@ class Element : public NodeDefinition
//
class Attr : public NodeDefinition
{
// AttrMap needs to be friend to be able to update the ownerElement
// These need to be friend to be able to update the ownerElement
friend class AttrMap;
friend class Element;
public:
Attr(const String& name, Document* owner);
Attr(const String& aNamespaceURI, const String& aName,
Document* aOwner);
virtual ~Attr();
const String& getName() const;

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

@ -47,7 +47,7 @@ CPP_OBJS= \
EXPORTS = \
$(NULL)
LINCS=-I..\..\..\base -I..\..\..\net \
LINCS=-I..\.. -I..\..\..\base -I..\..\..\net \
-I..\..\..\xpath -I..\..\..\xslt
LCFLAGS = \

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

@ -33,7 +33,6 @@ DIRS=dom parser
!if defined(TX_EXE)
DEFINES=$(DEFINES) -DTX_EXE
DIRS = $(DIRS) printer
!endif
CPP_OBJS= \

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

@ -53,8 +53,8 @@ include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../../base -I$(srcdir)/../../net -I$(srcdir)/../dom
ifdef TX_EXE
INCLUDES += -I$(srcdir)/xmlparse
COMPILE_CFLAGS += -DXML_UNICODE -I$(srcdir)/xmltok
INCLUDES += -I$(srcdir)/xmlparse -I$(srcdir)/xmltok
COMPILE_CFLAGS += -DXML_UNICODE
endif
libs:: $(OBJS)

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

@ -211,7 +211,6 @@ void commentHandler(void* userData, const XML_Char* s)
{
ParserState* ps = (ParserState*)userData;
String data((UNICODE_CHAR*)s);
Node* prevSib = ps->currentNode->getLastChild();
ps->currentNode->appendChild(ps->document->createComment(data));
} //-- commentHandler

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

@ -20,7 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
* Peter Van der Beken <peterv@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -41,6 +41,7 @@
#include "nsAppShellCIDs.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMEventReceiver.h"
#include "nsIEventQueueService.h"
@ -297,7 +298,9 @@ nsSyncLoader::LoadDocument(nsIURI* documentURI, nsIDocument *aLoader, nsIDOMDocu
return rv;
}
if (mLoadSuccess) {
nsCOMPtr<nsIDOMElement> documentElement;
DOMDocument->GetDocumentElement(getter_AddRefs(documentElement));
if (mLoadSuccess && documentElement) {
*_retval = DOMDocument;
NS_ADDREF(*_retval);
}

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

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

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

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

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

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

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

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

@ -132,8 +132,8 @@ MBool AttributeExpr::matches(Node* node, Node* context, ContextState* cs) {
String nsForNode;
Node* parent = node->getXPathParent();
if (parent)
XMLDOMUtils::getNameSpace(prefixForNode, (Element*)parent,
nsForNode);
XMLDOMUtils::getNamespaceURI(prefixForNode, (Element*)parent,
nsForNode);
String nsForTest;
if (!prefix.isEmpty())
cs->getNameSpaceURIFromPrefix(prefix, nsForTest);

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

@ -27,7 +27,7 @@
*/
#include "FunctionLib.h"
#include "Names.h"
#include "txAtoms.h"
/**
* Creates a default BooleanFunctionCall, which always evaluates to False
@ -82,7 +82,8 @@ ExprResult* BooleanFunctionCall::evaluate(Node* context, ContextState* cs) {
if ( requireParams(1,1,cs) ) {
String arg1, lang;
evaluateToString((Expr*)iter->next(),context, cs, arg1);
lang = ((Element*)context)->getAttribute(XML_LANG_ATTR);
((Element*)context)->getAttr(txXMLAtoms::lang,
kNameSpaceID_XML, lang);
arg1.toUpperCase(); // case-insensitive comparison
lang.toUpperCase();
result = (MBool)(lang.indexOf(arg1) == 0);

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

@ -119,7 +119,7 @@ MBool ElementExpr::matches(Node* node, Node* context, ContextState* cs) {
String prefix2;
if (idx > 0) nodeName.subString(0, idx, prefix2);
// use source tree to aquire namespace for node
XMLDOMUtils::getNameSpace(prefix2, (Element*) node, nsURI2);
XMLDOMUtils::getNamespaceURI(prefix2, (Element*) node, nsURI2);
if (!nsURI.isEqual(nsURI2)) return MB_FALSE;
}

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

@ -43,7 +43,6 @@
#include "baseutils.h"
#include "TxObject.h"
#include "primitives.h"
#include "NamespaceResolver.h"
/*
XPath class definitions.
@ -60,7 +59,7 @@ typedef class Expr PatternExpr;
/**
* The expression context and state class used when evaluating XPath Expressions.
**/
class ContextState : public NamespaceResolver, public ErrorObserver {
class ContextState : public ErrorObserver {
public:
@ -95,6 +94,12 @@ public:
**/
virtual void sortByDocumentOrder(NodeSet* nodes) = 0;
/**
* Returns the namespace URI for the given namespace prefix, this method should
* only be called for determining a namespace declared within the context
* (ie. the stylesheet)
**/
virtual void getNameSpaceURIFromPrefix(const String& aPrefix, String& aNamespaceURI) = 0;
}; //-- ContextState

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

@ -46,11 +46,11 @@ public:
//-- ResultTypes
enum ResultType {
NODESET = 1,
TREE_FRAGMENT = 0,
NUMBER,
STRING,
BOOLEAN,
TREE_FRAGMENT,
NUMBER
NODESET
};
virtual ~ExprResult() {};

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

@ -79,12 +79,9 @@ endif
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../base -I$(srcdir)/../xml \
-I$(srcdir)/../xml/dom \
INCLUDES += -I$(srcdir) -I$(srcdir)/../base \
-I$(srcdir)/../xml -I$(srcdir)/../xml/dom \
-I$(srcdir)/../xslt -I$(srcdir)/../xslt/util \
-I$(srcdir)/../xslt/functions
ifndef TX_EXE
INCLUDES += -I$(srcdir)
endif
libs:: $(OBJS)

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

@ -351,6 +351,6 @@ double NodeSet::numberValue() {
void NodeSet::stringValue(String& str) {
if ( size()>0) {
// XXX Sort by document order here
XMLDOMUtils::getNodeValue(get(0), &str);
XMLDOMUtils::getNodeValue(get(0), str);
}
} //-- stringValue

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

@ -239,4 +239,6 @@ private:
}; //-- NodeSet
typedef NodeSet txResultTreeFragment;
#endif

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

@ -119,7 +119,7 @@ ExprResult* NodeSetFunctionCall::evaluate(Node* aContext, ContextState* aCs) {
int i;
for (i = 0; i < nodes->size(); i++) {
String idList, id;
XMLDOMUtils::getNodeValue(nodes->get(i), &idList);
XMLDOMUtils::getNodeValue(nodes->get(i), idList);
txTokenizer tokenizer(idList);
while (tokenizer.hasMoreTokens()) {
tokenizer.nextToken(id);
@ -211,6 +211,10 @@ ExprResult* NodeSetFunctionCall::evaluate(Node* aContext, ContextState* aCs) {
}
return new StringResult();
}
default:
{
break;
}
}
}
case POSITION:

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

@ -125,7 +125,7 @@ ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
int i;
for (i = 0; i < nodes->size(); i++) {
String resultStr;
XMLDOMUtils::getNodeValue(nodes->get(i), &resultStr);
XMLDOMUtils::getNodeValue(nodes->get(i), resultStr);
res += Double::toDouble(resultStr);
}
delete nodes;
@ -139,7 +139,7 @@ ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
evaluateToNumber((Expr*)iter.next(), context, cs));
String resultStr;
XMLDOMUtils::getNodeValue(context, &resultStr);
XMLDOMUtils::getNodeValue(context, resultStr);
return new NumberResult(Double::toDouble(resultStr));
}
}

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

@ -62,7 +62,7 @@ MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
for ( int i = 0; i < nodeSet->size(); i++) {
String str;
Node* node = nodeSet->get(i);
XMLDOMUtils::getNodeValue(node, &str);
XMLDOMUtils::getNodeValue(node, str);
StringResult strResult(str);
result = compareResults(&strResult, right);
if ( result ) break;
@ -74,7 +74,7 @@ MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
for ( int i = 0; i < nodeSet->size(); i++) {
String str;
Node* node = nodeSet->get(i);
XMLDOMUtils::getNodeValue(node, &str);
XMLDOMUtils::getNodeValue(node, str);
StringResult strResult(str);
result = compareResults(left, &strResult);
if ( result ) break;

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

@ -108,7 +108,7 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) {
if ( argc == 1)
evaluateToString((Expr*)iter->next(),context, cs, resultStr);
else
XMLDOMUtils::getNodeValue(context, &resultStr);
XMLDOMUtils::getNodeValue(context, resultStr);
// Leading & Trailing Whitespace
resultStr.trim();
MBool hasSpace = MB_FALSE;
@ -150,7 +150,7 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) {
if ( argc == 1) {
evaluateToString((Expr*)iter->next(),context, cs, resultStr);
}
else XMLDOMUtils::getNodeValue(context, &resultStr);
else XMLDOMUtils::getNodeValue(context, resultStr);
result = new NumberResult( (double) resultStr.length());
}
else result = new NumberResult(0.0);
@ -273,7 +273,7 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) {
evaluateToString((Expr*)iter->next(),context, cs, resultStr);
}
else {
XMLDOMUtils::getNodeValue(context, &resultStr);
XMLDOMUtils::getNodeValue(context, resultStr);
if ( cs->isStripSpaceAllowed(context) &&
XMLUtils::shouldStripTextnode(resultStr))
resultStr = "";

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

@ -82,10 +82,10 @@ ExprResult* UnionExpr::evaluate(Node* context, ContextState* cs) {
Expr* expr = (Expr*)iter.next();
ExprResult* exprResult = expr->evaluate(context, cs);
if (exprResult &&
exprResult->getResultType() == ExprResult::NODESET) {
exprResult->getResultType() == ExprResult::NODESET) {
((NodeSet*)exprResult)->copyInto(*nodes);
}
delete exprResult;
delete exprResult;
}
return nodes;

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

@ -38,16 +38,28 @@ REQUIRES = string \
content_xsl \
widget \
necko \
unicharutil \
$(NULL)
endif
CPPSRCS = Names.cpp \
Numbering.cpp \
OutputFormat.cpp \
txOutputFormat.cpp \
ProcessorState.cpp \
txRtfHandler.cpp \
txTextHandler.cpp \
VariableBinding.cpp \
XSLTProcessor.cpp
ifdef TX_EXE
CPPSRCS += txHTMLOutput.cpp \
txTextOutput.cpp \
txXMLOutput.cpp
else
CPPSRCS += txMozillaTextOutput.cpp \
txMozillaXMLOutput.cpp
endif
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir) -I$(srcdir)/../base -I$(srcdir)/../net \

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

@ -71,59 +71,22 @@ const String PROC_INST = "processing-instruction";
const String PRESERVE_SPACE = "preserve-space";
const String SORT = "sort";
const String STRIP_SPACE = "strip-space";
const String STYLESHEET = "stylesheet";
const String TEMPLATE = "template";
const String TEXT = "text";
const String TRANSFORM = "transform";
const String VALUE_OF = "value-of";
const String VARIABLE = "variable";
const String WHEN = "when";
const String WITH_PARAM = "with-param";
//-- Attributes
const String CASE_ORDER_ATTR = "case-order";
const String CDATA_ELEMENTS_ATTR = "cdata-section-elements";
const String COUNT_ATTR = "count";
const String DATA_TYPE_ATTR = "data-type";
const String DECIMAL_SEPARATOR_ATTR = "decimal-separator";
const String DEFAULT_SPACE_ATTR = "default-space";
const String DIGIT_ATTR = "digit";
const String DOCTYPE_PUBLIC_ATTR = "doctype-public";
const String DOCTYPE_SYSTEM_ATTR = "doctype-system";
const String ELEMENTS_ATTR = "elements";
const String ENCODING_ATTR = "encoding";
const String EXPR_ATTR = "expr";
const String FORMAT_ATTR = "format";
const String FROM_ATTR = "from";
const String GROUPING_SEPARATOR_ATTR = "grouping-separator";
const String HREF_ATTR = "href";
const String INDENT_ATTR = "indent";
const String INFINITY_ATTR = "infinity";
const String LANG_ATTR = "lang";
const String LEVEL_ATTR = "level";
const String MATCH_ATTR = "match";
const String METHOD_ATTR = "method";
const String MEDIA_TYPE_ATTR = "media-type";
const String MINUS_SIGN_ATTR = "minus-sign";
const String MODE_ATTR = "mode";
const String NAME_ATTR = "name";
const String NAMESPACE_ATTR = "namespace";
const String NAN_ATTR = "NaN";
const String OMIT_XMLDECL_ATTR = "omit-xml-declaration";
const String ORDER_ATTR = "order";
const String PATTERN_SEPARATOR_ATTR = "pattern-separator";
const String PER_MILLE_ATTR = "per-mille";
const String PERCENT_ATTR = "percent";
const String PRIORITY_ATTR = "priority";
const String SELECT_ATTR = "select";
const String STANDALONE = "standalone";
const String TEST_ATTR = "test";
const String USE_ATTR = "use";
const String USE_ATTRIBUTE_SETS_ATTR = "use-attribute-sets";
const String VALUE_ATTR = "value";
const String VERSION_ATTR = "version";
const String XML_LANG_ATTR = "xml:lang";
const String ZERO_DIGIT_ATTR = "zero-digit";
//-- Attribute Values
const String ANY_VALUE = "any";
@ -141,9 +104,6 @@ const String UPPER_FIRST_VALUE = "upper-first";
const String YES_VALUE = "yes";
//-- Stylesheet attributes
const String INDENT_RESULT_ATTR = "indent-result";
const String RESULT_NS_ATTR = "result-ns";
const String ANCESTOR_AXIS = "ancestor";
const String ANCESTOR_OR_SELF_AXIS = "ancestor-or-self";
const String ATTRIBUTE_AXIS = "attribute";

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

@ -68,11 +68,9 @@ extern const String PARAM;
extern const String PROC_INST;
extern const String PRESERVE_SPACE;
extern const String STRIP_SPACE;
extern const String STYLESHEET;
extern const String SORT;
extern const String TEMPLATE;
extern const String TEXT;
extern const String TRANSFORM;
extern const String VALUE_OF;
extern const String VARIABLE;
extern const String WHEN;
@ -80,49 +78,14 @@ extern const String WITH_PARAM;
//-- Attributes
extern const String CASE_ORDER_ATTR;
extern const String CDATA_ELEMENTS;
extern const String COUNT_ATTR;
extern const String DATA_TYPE_ATTR;
extern const String DECIMAL_SEPARATOR_ATTR;
extern const String DEFAULT_SPACE_ATTR;
extern const String DIGIT_ATTR;
extern const String DOCTYPE_PUBLIC_ATTR;
extern const String DOCTYPE_SYSTEM_ATTR;
extern const String ELEMENTS_ATTR;
extern const String ENCODING_ATTR;
extern const String EXPR_ATTR;
extern const String FORMAT_ATTR;
extern const String FROM_ATTR;
extern const String GROUPING_SEPARATOR_ATTR;
extern const String HREF_ATTR;
extern const String INDENT_ATTR;
extern const String INFINITY_ATTR;
extern const String LANG_ATTR;
extern const String LEVEL_ATTR;
extern const String MATCH_ATTR;
extern const String MEDIA_TYPE_ATTR;
extern const String METHOD_ATTR;
extern const String MINUS_SIGN_ATTR;
extern const String MODE_ATTR;
extern const String NAME_ATTR;
extern const String NAMESPACE_ATTR;
extern const String NAN_ATTR;
extern const String OMIT_XMLDECL_ATTR;
extern const String ORDER_ATTR;
extern const String PATTERN_SEPARATOR_ATTR;
extern const String PER_MILLE_ATTR;
extern const String PERCENT_ATTR;
extern const String PRIORITY_ATTR;
extern const String SELECT_ATTR;
extern const String STANDALONE;
extern const String TEST_ATTR;
extern const String USE_ATTR;
extern const String USE_ATTRIBUTE_SETS_ATTR;
extern const String VALUE_ATTR;
extern const String VERSION_ATTR;
extern const String XML_LANG_ATTR;
extern const String ZERO_DIGIT_ATTR;
//-- Attribute Values
extern const String ANY_VALUE;
@ -140,9 +103,6 @@ extern const String UPPER_FIRST_VALUE;
extern const String YES_VALUE;
//-- Stylesheet attributes
extern const String INDENT_RESULT_ATTR;
extern const String RESULT_NS_ATTR;
extern const String ANCESTOR_AXIS;
extern const String ANCESTOR_OR_SELF_AXIS;
extern const String ATTRIBUTE_AXIS;

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

@ -30,6 +30,7 @@
#include "Numbering.h"
#include "Names.h"
#include "txAtoms.h"
void Numbering::doNumbering(Element* xslNumber, String& dest, Node* context,
ProcessorState* ps)
@ -40,7 +41,9 @@ void Numbering::doNumbering(Element* xslNumber, String& dest, Node* context,
int* counts = 0;
int nbrOfCounts = 0;
String valueAttr = xslNumber->getAttribute(VALUE_ATTR);
String valueAttr;
xslNumber->getAttr(txXSLTAtoms::value, kNameSpaceID_None,
valueAttr);
//-- check for expr
if (!valueAttr.isEmpty()) {
Expr* expr = ps->getExpr(xslNumber, ProcessorState::ValueAttr);
@ -57,7 +60,9 @@ void Numbering::doNumbering(Element* xslNumber, String& dest, Node* context,
//-- create count expression
String countAttr = xslNumber->getAttribute(COUNT_ATTR);
String countAttr;
xslNumber->getAttr(txXSLTAtoms::count, kNameSpaceID_None,
countAttr);
Pattern* countPattern;
MBool ownsPattern;
@ -103,8 +108,12 @@ void Numbering::doNumbering(Element* xslNumber, String& dest, Node* context,
NodeSet* nodes = 0;
int cnum = 0;
String level = xslNumber->getAttribute(LEVEL_ATTR);
String fromAttr = xslNumber->getAttribute(FROM_ATTR);
String level;
xslNumber->getAttr(txXSLTAtoms::level, kNameSpaceID_None,
level);
String fromAttr;
xslNumber->getAttr(txXSLTAtoms::from, kNameSpaceID_None,
fromAttr);
PatternExpr* from = 0;
if (MULTIPLE_VALUE.isEqual(level))

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

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

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

@ -43,30 +43,16 @@
#include "ExprResult.h"
#include "Names.h"
#include "XMLParser.h"
#ifndef TX_EXE
// #include "nslog.h"
// #define PRINTF NS_LOG_PRINTF(XPATH)
// #define FLUSH NS_LOG_FLUSH(XPATH)
#else
#include "TxLog.h"
#endif
//-------------/
//- Constants -/
//-------------/
const String ProcessorState::wrapperNSPrefix = "transformiix";
const String ProcessorState::wrapperName = "transformiix:result";
const String ProcessorState::wrapperNS = "http://www.mitre.org/TransforMiix";
#include "txAtoms.h"
/**
* Creates a new ProcessorState
**/
ProcessorState::ProcessorState()
ProcessorState::ProcessorState() : mXPathParseContext(0),
mSourceDocument(0),
xslDocument(0),
resultDocument(0)
{
mSourceDocument = 0;
xslDocument = 0;
resultDocument = 0;
mXPathParseContext = 0;
initialize();
} //-- ProcessorState
@ -77,22 +63,20 @@ ProcessorState::ProcessorState()
ProcessorState::ProcessorState(Document* aSourceDocument,
Document* aXslDocument,
Document* aResultDocument)
: mXPathParseContext(0),
mSourceDocument(aSourceDocument),
xslDocument(aXslDocument),
resultDocument(aResultDocument)
{
mSourceDocument = aSourceDocument;
xslDocument = aXslDocument;
resultDocument = aResultDocument;
mXPathParseContext = 0;
initialize();
} //-- ProcessorState
/**
* Destroys this ProcessorState
**/
ProcessorState::~ProcessorState() {
delete resultNodeStack;
while ( ! variableSets.empty() ) {
ProcessorState::~ProcessorState()
{
while (! variableSets.empty()) {
delete (NamedMap*) variableSets.pop();
}
@ -101,7 +85,7 @@ ProcessorState::~ProcessorState() {
while (iter.hasNext())
delete (ImportFrame*)iter.next();
// Make sure that xslDocument and mSourceDocument isn't deleted along with
// Make sure that xslDocument and mSourceDocument aren't deleted along with
// the rest of the documents in the loadedDocuments hash
if (xslDocument)
loadedDocuments.remove(xslDocument->getBaseURI());
@ -129,30 +113,31 @@ void ProcessorState::addAttributeSet(Element* aAttributeSet,
recieveError(err);
return;
}
//-- get attribute set, if already exists, then merge
// Get attribute set, if already exists, then merge
NodeSet* attSet = (NodeSet*)aImportFrame->mNamedAttributeSets.get(name);
if ( !attSet) {
if (!attSet) {
attSet = new NodeSet();
aImportFrame->mNamedAttributeSets.put(name, attSet);
}
//-- add xsl:attribute elements to attSet
// Add xsl:attribute elements to attSet
Node* node = aAttributeSet->getFirstChild();
while (node) {
if ( node->getNodeType() == Node::ELEMENT_NODE) {
String nodeName = node->getNodeName();
String ns;
XMLUtils::getNameSpace(nodeName, ns);
if ( !xsltNameSpace.isEqual(ns)) continue;
String localPart;
XMLUtils::getLocalPart(nodeName, localPart);
if ( ATTRIBUTE.isEqual(localPart) ) attSet->add(node);
if (node->getNodeType() == Node::ELEMENT_NODE) {
PRInt32 nsID = node->getNamespaceID();
if (nsID != kNameSpaceID_XSLT)
continue;
txAtom* nodeName;
if (!node->getLocalName(&nodeName) || !nodeName)
continue;
if (nodeName == txXSLTAtoms::attribute)
attSet->add(node);
TX_RELEASE_ATOM(nodeName);
}
node = node->getNextSibling();
}
} //-- addAttributeSet
}
/**
* Registers the given ErrorObserver with this ProcessorState
**/
@ -256,111 +241,6 @@ void ProcessorState::addLREStylesheet(Document* aStylesheet,
delete templ;
}
/**
* Adds the given node to the result tree
* @param node the Node to add to the result tree
**/
MBool ProcessorState::addToResultTree(Node* node) {
Node* current = resultNodeStack->peek();
#ifndef TX_EXE
String nameSpaceURI, name, localName;
#endif
switch (node->getNodeType()) {
case Node::ATTRIBUTE_NODE:
{
if (current->getNodeType() != Node::ELEMENT_NODE) return MB_FALSE;
Element* element = (Element*)current;
Attr* attr = (Attr*)node;
#ifndef TX_EXE
name = attr->getName();
getResultNameSpaceURI(name, nameSpaceURI);
// XXX HACK (pvdb) Workaround for BUG 51656 Html rendered as xhtml
if (getOutputFormat()->isHTMLOutput()) {
name.toLowerCase();
}
element->setAttributeNS(nameSpaceURI, name, attr->getValue());
#else
element->setAttribute(attr->getName(),attr->getValue());
#endif
delete node;
break;
}
case Node::ELEMENT_NODE:
//-- if current node is the document, make sure
//-- we don't already have a document element.
//-- if we do, create a wrapper element
if ( current == resultDocument ) {
Element* docElement = resultDocument->getDocumentElement();
if ( docElement ) {
String nodeName(wrapperName);
Element* wrapper = resultDocument->createElement(nodeName);
resultNodeStack->push(wrapper);
current->appendChild(wrapper);
current = wrapper;
}
#ifndef TX_EXE
else {
// Checking if we should set the output method to HTML
name = node->getNodeName();
XMLUtils::getLocalPart(name, localName);
if (localName.isEqualIgnoreCase(HTML)) {
setOutputMethod(HTML);
// XXX HACK (pvdb) Workaround for BUG 51656
// Html rendered as xhtml
name.toLowerCase();
}
}
#endif
}
current->appendChild(node);
break;
case Node::TEXT_NODE :
//-- if current node is the document, create wrapper element
if ( current == resultDocument &&
!XMLUtils::isWhitespace(node->getNodeValue())) {
String nodeName(wrapperName);
Element* wrapper = resultDocument->createElement(nodeName);
resultNodeStack->push(wrapper);
while (current->hasChildNodes()){
wrapper->appendChild(current->getFirstChild());
current->removeChild(current->getFirstChild());
}
current->appendChild(wrapper);
current = wrapper;
}
current->appendChild(node);
break;
case Node::PROCESSING_INSTRUCTION_NODE:
case Node::COMMENT_NODE :
current->appendChild(node);
break;
case Node::DOCUMENT_FRAGMENT_NODE:
{
current->appendChild(node);
delete node; //-- DOM Implementation does not clean up DocumentFragments
break;
}
//-- only add if not adding to document Node
default:
if (current != resultDocument) current->appendChild(node);
else return MB_FALSE;
break;
}
return MB_TRUE;
} //-- addToResultTree
/**
* Copies the node using the rules defined in the XSL specification
**/
Node* ProcessorState::copyNode(Node* node) {
return 0;
} //-- copyNode
/*
* Retrieve the document designated by the URI uri, using baseUri as base URI.
* Parses it as an XML document, and returns it. If a fragment identifier is
@ -493,7 +373,8 @@ Node* ProcessorState::findTemplate(Node* aNode,
if (templ->mTemplate->getNodeType() == Node::ELEMENT_NODE) {
Element* elem = (Element*)templ->mTemplate;
priorityAttr = elem->getAttribute(PRIORITY_ATTR);
elem->getAttr(txXSLTAtoms::priority, kNameSpaceID_None,
priorityAttr);
}
double tmpPriority;
@ -567,13 +448,6 @@ Node* ProcessorState::getCurrentNode() {
return currentNodeStack.peek();
} //-- setCurrentNode
/**
* Gets the default Namespace URI stack.
**/
Stack* ProcessorState::getDefaultNSURIStack() {
return &defaultNameSpaceURIStack;
} //-- getDefaultNSURIStack
Expr* ProcessorState::getExpr(Element* aElem, ExprAttr aAttr)
{
NS_ASSERTION(aElem, "missing element while getting expression");
@ -586,13 +460,16 @@ Expr* ProcessorState::getExpr(Element* aElem, ExprAttr aAttr)
String attr;
switch (aAttr) {
case SelectAttr:
attr = aElem->getAttribute(SELECT_ATTR);
aElem->getAttr(txXSLTAtoms::select, kNameSpaceID_None,
attr);
break;
case TestAttr:
attr = aElem->getAttribute(TEST_ATTR);
aElem->getAttr(txXSLTAtoms::test, kNameSpaceID_None,
attr);
break;
case ValueAttr:
attr = aElem->getAttribute(VALUE_ATTR);
aElem->getAttr(txXSLTAtoms::value, kNameSpaceID_None,
attr);
break;
}
@ -626,10 +503,12 @@ PatternExpr* ProcessorState::getPattern(Element* aElem, PatternAttr aAttr)
String attr;
switch (aAttr) {
case CountAttr:
attr = aElem->getAttribute(COUNT_ATTR);
aElem->getAttr(txXSLTAtoms::count, kNameSpaceID_None,
attr);
break;
case FromAttr:
attr = aElem->getAttribute(FROM_ATTR);
aElem->getAttr(txXSLTAtoms::from, kNameSpaceID_None,
attr);
break;
}
@ -668,89 +547,39 @@ Element* ProcessorState::getNamedTemplate(String& aName)
return 0;
}
/**
* Returns the namespace URI for the given name, this method should only be
* called for determining a namespace declared within the context (ie. the stylesheet)
**/
void ProcessorState::getNameSpaceURI(const String& name, String& nameSpaceURI) {
String prefix;
XMLUtils::getNameSpace(name, prefix);
getNameSpaceURIFromPrefix(prefix, nameSpaceURI);
} //-- getNameSpaceURI
/**
* Returns the namespace URI for the given namespace prefix, this method should
* only be called for determining a namespace declared within the context
* (ie. the stylesheet)
**/
void ProcessorState::getNameSpaceURIFromPrefix(const String& prefix, String& nameSpaceURI) {
void ProcessorState::getNameSpaceURIFromPrefix(const String& aPrefix,
String& aNamespaceURI)
{
if (mXPathParseContext)
XMLDOMUtils::getNameSpace(prefix, mXPathParseContext, nameSpaceURI);
} //-- getNameSpaceURI
XMLDOMUtils::getNamespaceURI(aPrefix, mXPathParseContext,
aNamespaceURI);
}
/**
* Returns the NodeStack which keeps track of where we are in the
* result tree
* @return the NodeStack which keeps track of where we are in the
* result tree
**/
NodeStack* ProcessorState::getNodeStack() {
return resultNodeStack;
} //-- getNodeStack
txOutputFormat* ProcessorState::getOutputFormat()
{
return &mOutputFormat;
}
/**
* Returns the OutputFormat which contains information on how
* to serialize the output. I will be removing this soon, when
* change to an event based printer, so that I can serialize
* as I go
**/
OutputFormat* ProcessorState::getOutputFormat() {
return &format;
} //-- getOutputFormat
Document* ProcessorState::getResultDocument() {
Document* ProcessorState::getResultDocument()
{
return resultDocument;
} //-- getResultDocument
}
/**
* Returns the namespace URI for the given name, this method should only be
* called for returning a namespace declared within in the result document.
**/
void ProcessorState::getResultNameSpaceURI(const String& name, String& nameSpaceURI) {
String prefix;
XMLUtils::getNameSpace(name, prefix);
if (prefix.isEmpty()) {
nameSpaceURI.clear();
nameSpaceURI.append(*(String*)defaultNameSpaceURIStack.peek());
}
else {
String* result = (String*)nameSpaceMap.get(prefix);
if (result) {
nameSpaceURI.clear();
nameSpaceURI.append(*result);
}
}
} //-- getResultNameSpaceURI
Stack* ProcessorState::getVariableSetStack() {
Stack* ProcessorState::getVariableSetStack()
{
return &variableSets;
} //-- getVariableSetStack
}
String& ProcessorState::getXSLNamespace() {
return xsltNameSpace;
} //-- getXSLNamespace
/**
/*
* Determines if the given XSL node allows Whitespace stripping
**/
*/
MBool ProcessorState::isXSLStripSpaceAllowed(Node* node) {
if ( !node ) return MB_FALSE;
return (MBool)(PRESERVE != getXMLSpaceMode(node));
if (!node)
return MB_FALSE;
return (MBool)(getXMLSpaceMode(node) != PRESERVE);
} //--isXSLStripSpaceAllowed
}
/**
* Removes and returns the current source node being processed, from the stack
@ -792,39 +621,6 @@ void ProcessorState::pushCurrentNode(Node* node) {
} //-- setCurrentNode
/**
* Sets a new default Namespace URI.
**/
void ProcessorState::setDefaultNameSpaceURIForResult(const String& nsURI) {
String* nsTempURIPointer = 0;
String* nsURIPointer = 0;
StringListIterator theIterator(&nameSpaceURIList);
while (theIterator.hasNext()) {
nsTempURIPointer = theIterator.next();
if (nsTempURIPointer->isEqual(nsURI)) {
nsURIPointer = nsTempURIPointer;
break;
}
}
if ( ! nsURIPointer ) {
nsURIPointer = new String(nsURI);
nameSpaceURIList.add(nsURIPointer);
}
defaultNameSpaceURIStack.push(nsURIPointer);
} //-- setDefaultNameSpaceURI
/**
* Sets the output method. Valid output method options are,
* "xml", "html", or "text".
**/
void ProcessorState::setOutputMethod(const String& method) {
format.setMethod(method);
if ( method.indexOf(HTML) == 0 ) {
setDefaultNameSpaceURIForResult(HTML_NS);
}
}
/*
* Adds the set of names to the Whitespace handling list.
* xsl:strip-space calls this with MB_TRUE, xsl:preserve-space
* with MB_FALSE
@ -859,9 +655,11 @@ void ProcessorState::shouldStripSpace(String& aNames,
/**
* Adds the supplied xsl:key to the set of keys
**/
MBool ProcessorState::addKey(Element* aKeyElem) {
String keyName = aKeyElem->getAttribute(NAME_ATTR);
if(!XMLUtils::isValidQName(keyName))
MBool ProcessorState::addKey(Element* aKeyElem)
{
String keyName;
aKeyElem->getAttr(txXSLTAtoms::name, kNameSpaceID_None, keyName);
if (!XMLUtils::isValidQName(keyName))
return MB_FALSE;
txXSLKey* xslKey = (txXSLKey*)xslKeys.get(keyName);
if (!xslKey) {
@ -907,61 +705,77 @@ MBool ProcessorState::addDecimalFormat(Element* element)
String attValue = element->getAttribute(NAME_ATTR);
String formatName = attValue;
attValue = element->getAttribute(DECIMAL_SEPARATOR_ATTR);
if (attValue.length() == 1)
format->mDecimalSeparator = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::decimalSeparator,
kNameSpaceID_None, attValue)) {
if (attValue.length() == 1)
format->mDecimalSeparator = attValue.charAt(0);
else
success = MB_FALSE;
}
attValue = element->getAttribute(GROUPING_SEPARATOR_ATTR);
if (attValue.length() == 1)
format->mGroupingSeparator = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::groupingSeparator,
kNameSpaceID_None, attValue)) {
if (attValue.length() == 1)
format->mGroupingSeparator = attValue.charAt(0);
else
success = MB_FALSE;
}
attValue = element->getAttribute(INFINITY_ATTR);
if (!attValue.isEmpty())
if (element->getAttr(txXSLTAtoms::infinity,
kNameSpaceID_None, attValue))
format->mInfinity=attValue;
attValue = element->getAttribute(MINUS_SIGN_ATTR);
if (attValue.length() == 1)
format->mMinusSign = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::minusSign,
kNameSpaceID_None, attValue)) {
if (attValue.length() == 1)
format->mMinusSign = attValue.charAt(0);
else
success = MB_FALSE;
}
attValue = element->getAttribute(NAN_ATTR);
if (!attValue.isEmpty())
if (element->getAttr(txXSLTAtoms::NaN, kNameSpaceID_None,
attValue))
format->mNaN=attValue;
attValue = element->getAttribute(PERCENT_ATTR);
if (attValue.length() == 1)
format->mPercent = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::percent, kNameSpaceID_None,
attValue)) {
if (attValue.length() == 1)
format->mPercent = attValue.charAt(0);
else
success = MB_FALSE;
}
attValue = element->getAttribute(PER_MILLE_ATTR);
if (attValue.length() == 1)
format->mPerMille = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::perMille,
kNameSpaceID_None, attValue)) {
if (attValue.length() == 1)
format->mPerMille = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
}
attValue = element->getAttribute(ZERO_DIGIT_ATTR);
if (attValue.length() == 1)
format->mZeroDigit = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::zeroDigit,
kNameSpaceID_None, attValue)) {
if (attValue.length() == 1)
format->mZeroDigit = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
}
attValue = element->getAttribute(DIGIT_ATTR);
if (attValue.length() == 1)
format->mDigit = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::digit, kNameSpaceID_None,
attValue)) {
if (attValue.length() == 1)
format->mDigit = attValue.charAt(0);
else
success = MB_FALSE;
}
attValue = element->getAttribute(PATTERN_SEPARATOR_ATTR);
if (attValue.length() == 1)
format->mPatternSeparator = attValue.charAt(0);
else if (!attValue.isEmpty())
success = MB_FALSE;
if (element->getAttr(txXSLTAtoms::patternSeparator,
kNameSpaceID_None, attValue)) {
if (attValue.length() == 1)
format->mPatternSeparator = attValue.charAt(0);
else
success = MB_FALSE;
}
if (!success) {
delete format;
@ -1025,9 +839,9 @@ ExprResult* ProcessorState::getVariable(String& name) {
StackIterator* iter = variableSets.iterator();
ExprResult* exprResult = 0;
while ( iter->hasNext() ) {
while (iter->hasNext()) {
NamedMap* map = (NamedMap*) iter->next();
if ( map->get(name)) {
if (map->get(name)) {
exprResult = ((VariableBinding*)map->get(name))->getValue();
break;
}
@ -1039,13 +853,13 @@ ExprResult* ProcessorState::getVariable(String& name) {
/**
* Determines if the given XML node allows Whitespace stripping
**/
MBool ProcessorState::isStripSpaceAllowed(Node* node) {
MBool ProcessorState::isStripSpaceAllowed(Node* node)
{
if (!node)
return MB_FALSE;
if ( !node ) return MB_FALSE;
switch ( node->getNodeType() ) {
case Node::ELEMENT_NODE :
switch (node->getNodeType()) {
case Node::ELEMENT_NODE:
{
// check Whitespace stipping handling list against given Node
ImportFrame* frame;
@ -1060,30 +874,31 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) {
return iNameTest->stripsSpace();
}
}
String method;
if (format.getMethod(method).isEqual("html")) {
if (mOutputFormat.mMethod == eHTMLOutput) {
String ucName = name;
ucName.toUpperCase();
if (ucName.isEqual("SCRIPT")) return MB_FALSE;
if (ucName.isEqual("SCRIPT"))
return MB_FALSE;
}
break;
}
case Node::TEXT_NODE:
case Node::CDATA_SECTION_NODE:
{
if (!XMLUtils::shouldStripTextnode(node->getNodeValue()))
return MB_FALSE;
return isStripSpaceAllowed(node->getParentNode());
}
case Node::DOCUMENT_NODE:
{
return MB_TRUE;
default:
break;
}
}
XMLSpaceMode mode = getXMLSpaceMode(node);
if (mode == DEFAULT) return (MBool)(defaultSpace == STRIP);
if (mode == DEFAULT)
return MB_FALSE;
return (MBool)(STRIP == mode);
} //--isStripSpaceAllowed
}
/**
* Notifies this Error observer of a new error, with default
@ -1098,7 +913,7 @@ void ProcessorState::recieveError(String& errorMessage) {
**/
void ProcessorState::recieveError(String& errorMessage, ErrorLevel level) {
ListIterator* iter = errorObservers.iterator();
while ( iter->hasNext()) {
while (iter->hasNext()) {
ErrorObserver* observer = (ErrorObserver*)iter->next();
observer->recieveError(errorMessage, level);
}
@ -1197,46 +1012,48 @@ void ProcessorState::sortByDocumentOrder(NodeSet* nodes) {
//- Private Methods -/
//-------------------/
/**
/*
* Returns the closest xml:space value for the given Text node
**/
ProcessorState::XMLSpaceMode ProcessorState::getXMLSpaceMode(Node* node) {
*/
ProcessorState::XMLSpaceMode ProcessorState::getXMLSpaceMode(Node* aNode)
{
NS_ASSERTION(aNode, "Calling getXMLSpaceMode with NULL node!");
if (!node) return DEFAULT; //-- we should never see this
Node* parent = node;
while ( parent ) {
switch ( parent->getNodeType() ) {
Node* parent = aNode;
while (parent) {
switch (parent->getNodeType()) {
case Node::ELEMENT_NODE:
{
String value = ((Element*)parent)->getAttribute(XML_SPACE);
if ( value.isEqual(PRESERVE_VALUE)) {
String value;
((Element*)parent)->getAttr(txXMLAtoms::space,
kNameSpaceID_XML, value);
if (value.isEqual(PRESERVE_VALUE))
return PRESERVE;
}
break;
}
case Node::TEXT_NODE:
case Node::CDATA_SECTION_NODE:
//-- we will only see this the first time through the loop
//-- if the argument node is a text node
{
// We will only see this the first time through the loop
// if the argument node is a text node.
break;
}
default:
{
return DEFAULT;
}
}
parent = parent->getParentNode();
}
return DEFAULT;
} //-- getXMLSpaceMode
}
/**
* Initializes this ProcessorState
**/
void ProcessorState::initialize() {
//-- initialize default-space
defaultSpace = PRESERVE;
//-- add global variable set
void ProcessorState::initialize()
{
// add global variable set
NamedMap* globalVars = new NamedMap();
globalVars->setObjectDeletion(MB_TRUE);
variableSets.push(globalVars);
@ -1247,84 +1064,25 @@ void ProcessorState::initialize() {
mExprHashes[ValueAttr].setOwnership(Map::eOwnsItems);
mPatternHashes[CountAttr].setOwnership(Map::eOwnsItems);
mPatternHashes[FromAttr].setOwnership(Map::eOwnsItems);
nameSpaceMap.setObjectDeletion(MB_TRUE);
//-- create NodeStack
resultNodeStack = new NodeStack();
resultNodeStack->push(this->resultDocument);
setDefaultNameSpaceURIForResult("");
//-- determine xsl properties
Element* element = NULL;
// determine xslt properties
if (mSourceDocument) {
loadedDocuments.put(mSourceDocument->getBaseURI(), mSourceDocument);
}
if (xslDocument) {
element = xslDocument->getDocumentElement();
loadedDocuments.put(xslDocument->getBaseURI(), xslDocument);
// XXX hackarond to get namespacehandling in a little better shape
// we won't need to do this once we resolve namespaces during parsing
mXPathParseContext = element;
mXPathParseContext = xslDocument->getDocumentElement();
}
if ( element ) {
//-- process namespace nodes
NamedNodeMap* atts = element->getAttributes();
if ( atts ) {
for (PRUint32 i = 0; i < atts->getLength(); i++) {
Attr* attr = (Attr*)atts->item(i);
String attName = attr->getName();
String attValue = attr->getValue();
if ( attName.indexOf(XMLUtils::XMLNS) == 0) {
String ns;
XMLUtils::getLocalPart(attName, ns);
// default namespace
if ( attName.isEqual(XMLUtils::XMLNS) ) {
//-- Is this correct?
setDefaultNameSpaceURIForResult(attValue);
}
// namespace declaration
else {
String ns;
XMLUtils::getLocalPart(attName, ns);
nameSpaceMap.put(ns, new String(attValue));
}
// check for XSL namespace
if ( attValue.indexOf(XSLT_NS) == 0) {
xsltNameSpace = ns;
}
}
else if ( attName.isEqual(DEFAULT_SPACE_ATTR) ) {
if ( attValue.isEqual(STRIP_VALUE) ) {
defaultSpace = STRIP;
}
}
else if ( attName.isEqual(RESULT_NS_ATTR) ) {
if (!attValue.isEmpty()) {
if ( attValue.indexOf(HTML_NS) == 0 ) {
setOutputMethod("html");
}
else setOutputMethod(attValue);
}
}
else if ( attName.isEqual(INDENT_RESULT_ATTR) ) {
if (!attValue.isEmpty()) {
format.setIndent(attValue.isEqual(YES_VALUE));
}
}
} //-- end for each att
} //-- end if atts are not null
}
//-- make sure all keys are deleted
// make sure all keys are deleted
xslKeys.setObjectDeletion(MB_TRUE);
//-- Make sure all loaded documents get deleted
// Make sure all loaded documents get deleted
loadedDocuments.setObjectDeletion(MB_TRUE);
//-- add predefined default decimal format
// add predefined default decimal format
defaultDecimalFormatSet = MB_FALSE;
decimalFormats.put("", new txDecimalFormat);
decimalFormats.setObjectDeletion(MB_TRUE);

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

@ -36,7 +36,7 @@
#include "ExprParser.h"
#include "Expr.h"
#include "StringList.h"
#include "OutputFormat.h"
#include "txOutputFormat.h"
#include "Map.h"
class txXSLKey;
@ -48,11 +48,6 @@ class txDecimalFormat;
class ProcessorState : public ContextState {
public:
static const String wrapperNSPrefix;
static const String wrapperName;
static const String wrapperNS;
/**
* Creates a new ProcessorState
**/
@ -92,6 +87,9 @@ public:
// Map of named attribute sets
NamedMap mNamedAttributeSets;
// Output format, as specified by the xsl:output elements
txOutputFormat mOutputFormat;
// ImportFrame which is the first one *not* imported by this frame
ImportFrame* mFirstNotImported;
@ -99,7 +97,6 @@ public:
// Namespace aliases (xsl:namespace-alias)
// Toplevel variables/parameters
// Output specifier (xsl:output)
};
// To be able to do some cleaning up in destructor
friend class ImportFrame;
@ -131,17 +128,6 @@ public:
*/
void addLREStylesheet(Document* aStylesheet, ImportFrame* aImportFrame);
/**
* Adds the given Node to the Result Tree
*
**/
MBool addToResultTree(Node* node);
/**
* Copies the node using the rules defined in the XSL specification
**/
Node* copyNode(Node* node);
/**
* Returns the AttributeSet associated with the given name
* or null if no AttributeSet is found
@ -153,11 +139,6 @@ public:
**/
Node* getCurrentNode();
/**
* Gets the default Namespace URI stack.
**/
Stack* getDefaultNSURIStack();
/*
* Returns the template associated with the given name, or
* null if not template is found
@ -178,10 +159,10 @@ public:
* change to an event based printer, so that I can serialize
* as I go
**/
OutputFormat* getOutputFormat();
txOutputFormat* getOutputFormat();
Stack* getVariableSetStack();
Stack* getVariableSetStack();
enum ExprAttr {
SelectAttr = 0,
@ -202,15 +183,6 @@ public:
**/
Document* getResultDocument();
/**
* Returns the namespace URI for the given name, this method should
* only be called to get a namespace declared within the result
* document.
**/
void getResultNameSpaceURI(const String& name, String& nameSpaceURI);
String& getXSLNamespace();
/**
* Retrieve the document designated by the URI uri, using baseUri as base URI.
* Parses it as an XML document, and returns it. If a fragment identifier is
@ -307,19 +279,7 @@ public:
**/
void pushCurrentNode(Node* node);
/**
* Sets a new default Namespace URI. This is used for the Result Tree
**/
void setDefaultNameSpaceURIForResult(const String& nsURI);
/**
* Sets the output method. Valid output method options are,
* "xml", "html", or "text".
**/
void setOutputMethod(const String& method);
/*
* Adds the set of names to the Whitespace stripping handling list.
* xsl:strip-space calls this with MB_TRUE, xsl:preserve-space
* with MB_FALSE
@ -399,23 +359,12 @@ public:
**/
virtual void sortByDocumentOrder(NodeSet* nodes);
//------------------------------------------/
//- Virtual Methods from NamespaceResolver -/
//------------------------------------------/
/**
* Returns the namespace URI for the given name, this method should
* only be called to get a namespace declared within the context (ie.
* the stylesheet).
**/
void getNameSpaceURI(const String& name, String& nameSpaceURI);
/**
* Returns the namespace URI for the given namespace prefix. This method
* should only be called to get a namespace declared within the
* context (ie. the stylesheet).
**/
void getNameSpaceURIFromPrefix(const String& prefix, String& nameSpaceURI);
void getNameSpaceURIFromPrefix(const String& aPrefix, String& aNamespaceURI);
private:
@ -431,49 +380,38 @@ private:
/**
* The list of ErrorObservers registered with this ProcessorState
**/
List errorObservers;
List errorObservers;
/**
* Stack of URIs for currently entered stylesheets
**/
Stack enteredStylesheets;
Stack enteredStylesheets;
/**
* List of import containers. Sorted by ascending import precedence
**/
txList mImportFrames;
/**
* Current stack of nodes, where we are in the result document tree
**/
NodeStack* resultNodeStack;
txList mImportFrames;
/**
* The output format used when serializing the result
**/
OutputFormat format;
/**
* Default whitespace stripping mode
**/
XMLSpaceMode defaultSpace;
txOutputFormat mOutputFormat;
/**
* The set of loaded documents. This includes both document() loaded
* documents and xsl:include/xsl:import'ed documents.
**/
NamedMap loadedDocuments;
NamedMap loadedDocuments;
/**
* The set of all available keys
**/
NamedMap xslKeys;
NamedMap xslKeys;
/*
* A list of all avalible decimalformats
*/
NamedMap decimalFormats;
NamedMap decimalFormats;
/*
* bool indicating if the default decimal format has been explicitly set
@ -505,16 +443,11 @@ private:
Document* resultDocument;
Stack variableSets;
ExprParser exprParser;
String xsltNameSpace;
NamedMap nameSpaceMap;
StringList nameSpaceURIList;
Stack defaultNameSpaceURIStack;
Stack xsltNameSpaces;
/**
* Returns the closest xml:space value for the given node
**/
XMLSpaceMode getXMLSpaceMode(Node* node);
XMLSpaceMode getXMLSpaceMode(Node* aNode);
/**
* Initializes the ProcessorState

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -37,7 +37,15 @@
#ifndef TX_EXE
#include "nsICSSStyleSheet.h"
#include "nsICSSLoaderObserver.h"
#include "nsIDocumentTransformer.h"
#include "nsIDOMHTMLScriptElement.h"
#include "nsIObserver.h"
#include "nsIScriptLoaderObserver.h"
#include "txMozillaTextOutput.h"
#include "txMozillaXMLOutput.h"
#endif
#include "dom.h"
@ -48,11 +56,12 @@
#include "TxString.h"
#include "ErrorObserver.h"
#include "List.h"
#include "txTextHandler.h"
#ifndef TX_EXE
/* bacd8ad0-552f-11d3-a9f7-000064657374 */
#define TRANSFORMIIX_XSLT_PROCESSOR_CID \
{ 0xbacd8ad0, 0x552f, 0x11d3, {0xa9, 0xf7, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
{ 0xbacd8ad0, 0x552f, 0x11d3, { 0xa9, 0xf7, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74 } }
#define TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID \
"@mozilla.org/document-transformer;1?type=text/xsl"
@ -73,7 +82,8 @@ MBool txShutdown();
**/
class XSLTProcessor
#ifndef TX_EXE
: public nsIDocumentTransformer
: public nsIDocumentTransformer,
public nsIScriptLoaderObserver
#endif
{
@ -81,8 +91,11 @@ public:
#ifndef TX_EXE
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDocumentTransformer interface
NS_DECL_NSIDOCUMENTTRANSFORMER
NS_DECL_NSISCRIPTLOADEROBSERVER
#endif
/**
@ -250,21 +263,6 @@ private:
MBool allowShadowing,
ProcessorState* ps);
#ifdef TX_EXE
/**
* Prints the given XML document to the given ostream and uses
* the properties specified in the OutputFormat.
* This method is used to print the result tree
* @param document the XML document to print
* @param format the OutputFormat specifying formatting info
* @param ostream the Stream to print to
**/
void print(Document& document, OutputFormat* format, ostream& out);
#endif
/**
* Processes the xsl:with-param elements of the given xsl action
**/
@ -274,21 +272,7 @@ private:
* Looks up the given XSLType with the given name
* The ProcessorState is used to get the current XSLT namespace
**/
short getElementType(const String& name, ProcessorState* ps);
/**
* Gets the Text value of the given DocumentFragment. The value is placed
* into the given destination String. If a non text node element is
* encountered and warningForNonTextNodes is turned on, the MB_FALSE
* will be returned, otherwise true is always returned.
* @param dfrag the document fragment to get the text from
* @param dest the destination string to place the text into.
* @param deep indicates to process non text nodes and recusively append
* their value. If this value is true, the allowOnlyTextNodes flag is ignored.
**/
MBool getText
(DocumentFragment* dfrag, String& dest, MBool deep, MBool allowOnlyTextNodes);
short getElementType(Element* aElement, ProcessorState* aPs);
/**
* Notifies all registered ErrorObservers of the given error
@ -316,12 +300,13 @@ private:
const String& mode,
ProcessorState* ps);
void processAction(Node* node, Node* xslAction, ProcessorState* ps);
void processAction(Node* aNode, Node* aXsltAction, ProcessorState* aPs);
/**
* Processes the attribute sets specified in the names argument
* Processes the attribute sets specified in the use-attribute-sets attribute
* of the element specified in aElement
**/
void processAttributeSets(const String& names, Node* node, ProcessorState* ps);
void processAttributeSets(Element* aElement, Node* node, ProcessorState* ps);
/**
* Processes the children of the specified element using the given context node
@ -375,23 +360,54 @@ private:
ExprResult* processVariable(Node* node, Element* xslVariable, ProcessorState* ps);
/**
* Performs the xsl:copy action as specified in the XSL Working Draft
**/
void xslCopy(Node* node, Element* action, ProcessorState* ps);
void startTransform(Node* aNode, ProcessorState* aPs);
/**
* Performs the xsl:copy-of action as specified in the XSLT Working Draft
**/
void xslCopyOf(ExprResult* exprResult, ProcessorState* ps);
MBool initializeHandlers(ProcessorState* aPs);
/*
* Performs the xsl:copy action as specified in the XSLT specification
*/
void xslCopy(Node* aNode, Element* aAction, ProcessorState* aPs);
/*
* Performs the xsl:copy-of action as specified in the XSLT specification
*/
void xslCopyOf(ExprResult* aExprResult, ProcessorState* aPs);
/*
* Copy a node. For document nodes, copy the children.
*/
void copyNode(Node* aNode, ProcessorState* aPs);
void startElement(ProcessorState* aPs, const String& aName, const PRInt32 aNsID);
void processChildrenAsValue(Node* aNode,
Element* aElement,
ProcessorState* aPs,
MBool aOnlyText,
String& aValue);
#ifdef TX_EXE
txStreamXMLEventHandler* mOutputHandler;
#else
txMozillaXMLEventHandler* mOutputHandler;
#endif
txXMLEventHandler* mResultHandler;
MBool mHaveDocumentElement;
Stack mAttributeSetStack;
#ifndef TX_EXE
void SignalTransformEnd();
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsIObserver> mObserver;
#endif
}; //-- XSLTProcessor
class XSLType : public TxObject {
public:
enum types {
APPLY_IMPORTS = 1,
APPLY_IMPORTS = 1,
APPLY_TEMPLATES,
ATTRIBUTE,
ATTRIBUTE_SET,
@ -408,6 +424,7 @@ public:
KEY,
FOR_EACH,
LITERAL,
MESSAGE,
NUMBER,
OTHERWISE,
OUTPUT,
@ -421,8 +438,7 @@ public:
VALUE_OF,
VARIABLE,
WHEN,
WITH_PARAM,
MESSAGE
WITH_PARAM
};
XSLType(const XSLType& xslType);

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

@ -105,7 +105,7 @@ ExprResult* DocumentFunctionCall::evaluate(Node* context, ContextState* cs)
for (i = 0; i < nodeSet1->size(); i++) {
Node* node = nodeSet1->get(i);
String uriStr;
XMLDOMUtils::getNodeValue(node, &uriStr);
XMLDOMUtils::getNodeValue(node, uriStr);
if (!baseURISet) {
// if the second argument wasn't specified, use
// the baseUri of node itself

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

@ -20,7 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
* Peter Van der Beken <peterv@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -74,7 +74,7 @@ ExprResult* ElementAvailableFunctionCall::evaluate(Node* context, ContextState*
exprResult->stringValue(property);
if (XMLUtils::isValidQName(property)) {
String prefix, propertyNsURI;
XMLUtils::getNameSpace(property, prefix);
XMLUtils::getPrefix(property, prefix);
if (!prefix.isEmpty()) {
cs->getNameSpaceURIFromPrefix(property, propertyNsURI);
}

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

@ -20,7 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken, peterv@netscape.com
* Peter Van der Beken <peterv@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -75,7 +75,7 @@ ExprResult* FunctionAvailableFunctionCall::evaluate(Node* context, ContextState*
exprResult->stringValue(property);
if (XMLUtils::isValidQName(property)) {
String prefix;
XMLUtils::getNameSpace(property, prefix);
XMLUtils::getPrefix(property, prefix);
if (prefix.isEmpty() &&
(property.isEqual(XPathNames::BOOLEAN_FN) ||
property.isEqual(XPathNames::CONCAT_FN) ||

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

@ -38,8 +38,9 @@ ExprResult* SystemPropertyFunctionCall::evaluate(Node* context, ContextState* cs
String property;
exprResult->stringValue(property);
if (XMLUtils::isValidQName(property)) {
String propertyNsURI;
cs->getNameSpaceURI(property, propertyNsURI);
String propertyNsURI, prefix;
XMLUtils::getLocalPart(property, prefix);
cs->getNameSpaceURIFromPrefix(prefix, propertyNsURI);
if (propertyNsURI.isEqual(XSLT_NS)) {
String localName;
XMLUtils::getLocalPart(property, localName);

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

@ -82,7 +82,7 @@ ExprResult* txKeyFunctionCall::evaluate(Node* aContext, ContextState* aCs)
NodeSet* nodeSet = (NodeSet*) exprResult;
for (int i=0; i<nodeSet->size(); i++) {
String val;
XMLDOMUtils::getNodeValue(nodeSet->get(i), &val);
XMLDOMUtils::getNodeValue(nodeSet->get(i), val);
key->getNodes(val,contextDoc)->copyInto(*res);
}
}
@ -238,7 +238,7 @@ void txXSLKey::testNode(Node* aNode, NamedMap* aMap)
NodeSet* res = (NodeSet*)exprResult;
for (int i=0; i<res->size(); i++) {
val.clear();
XMLDOMUtils::getNodeValue(res->get(i), &val);
XMLDOMUtils::getNodeValue(res->get(i), val);
nodeSet = (NodeSet*)aMap->get(val);
if (!nodeSet) {

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

@ -28,33 +28,48 @@ REQUIRES = string \
necko \
content_xsl \
content \
unicharutil \
$(NULL)
include <$(DEPTH)/config/config.mak>
DIRS=util functions
!if defined(TX_EXE)
!ifdef TX_EXE
DEFINES= $(DEFINES) -DTX_EXE
!endif
CPP_OBJS= \
.\$(OBJDIR)\Names.obj \
.\$(OBJDIR)\Numbering.obj \
.\$(OBJDIR)\OutputFormat.obj \
.\$(OBJDIR)\txOutputFormat.obj \
.\$(OBJDIR)\ProcessorState.obj \
.\$(OBJDIR)\txRtfHandler.obj \
.\$(OBJDIR)\txTextHandler.obj \
.\$(OBJDIR)\VariableBinding.obj \
.\$(OBJDIR)\XSLTProcessor.obj \
.\$(OBJDIR)\XSLTProcessor.obj
!ifdef TX_EXE
CPP_OBJS = $(CPP_OBJS) \
.\$(OBJDIR)\txHTMLOutput.obj \
.\$(OBJDIR)\txTextOutput.obj \
.\$(OBJDIR)\txXMLOutput.obj \
$(NULL)
!else
CPP_OBJS = $(CPP_OBJS) \
.\$(OBJDIR)\txMozillaTextOutput.obj \
.\$(OBJDIR)\txMozillaXMLOutput.obj \
$(NULL)
!endif
EXPORTS = \
$(NULL)
!ifndef TX_EXE
LINCS=-I$(PUBLIC)\xpcom -I..\xpath -I..\xml\dom -I..\xml\dom\mozImpl \
-I..\base -I ..\xml -I .\util -I ..\net -I..\xml\parser -I.\functions
!else
!ifdef TX_EXE
LINCS=-I. -I..\base -I..\net -I..\xml -I..\xml\dom -I..\xml\parser \
-I..\xml\parser\xmlparse -I..\xml\printer -I..\xpath -Iutil -Ifunctions
!else
LINCS=-I$(PUBLIC)\xpcom -I..\xpath -I..\xml\dom -I..\xml\dom\mozImpl \
-I..\base -I ..\xml -I .\util -I ..\net -I..\xml\parser -I.\functions
!endif
LCFLAGS = \

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

@ -36,12 +36,52 @@
*
* ***** END LICENSE BLOCK ***** */
TX_ATOM(area, "area");
TX_ATOM(base, "base");
TX_ATOM(basefont, "basefont");
TX_ATOM(br, "br");
TX_ATOM(button, "button");
TX_ATOM(checked, "checked");
TX_ATOM(col, "col");
TX_ATOM(compact, "compact");
TX_ATOM(declare, "declare");
TX_ATOM(defer, "defer");
TX_ATOM(dir, "dir");
TX_ATOM(disabled, "disabled");
TX_ATOM(dl, "dl");
TX_ATOM(frame, "frame");
TX_ATOM(headerDefaultStyle, "default-style");
TX_ATOM(head, "head");
TX_ATOM(hr, "hr");
TX_ATOM(img, "img");
TX_ATOM(input, "input");
TX_ATOM(isindex, "isindex");
TX_ATOM(ismap, "ismap");
TX_ATOM(li, "li");
TX_ATOM(link, "link");
TX_ATOM(media, "media");
TX_ATOM(menu, "menu");
TX_ATOM(meta, "meta");
TX_ATOM(multiple, "multiple");
TX_ATOM(noresize, "noresize");
TX_ATOM(noshade, "noshade");
TX_ATOM(nowrap, "nowrap");
TX_ATOM(object, "object");
TX_ATOM(ol, "ol");
TX_ATOM(optgroup, "optgroup");
TX_ATOM(option, "option");
TX_ATOM(p, "p");
TX_ATOM(param, "param");
TX_ATOM(readonly, "readonly");
TX_ATOM(script, "script");
TX_ATOM(select, "select");
TX_ATOM(selected, "selected");
TX_ATOM(src, "src");
TX_ATOM(style, "style");
TX_ATOM(table, "table");
TX_ATOM(td, "td");
TX_ATOM(textarea, "textarea");
TX_ATOM(th, "th");
TX_ATOM(title, "title");
TX_ATOM(type, "type");
TX_ATOM(ul, "ul");

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

@ -0,0 +1,328 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txHTMLOutput.h"
#include "txAtoms.h"
#include "txOutputFormat.h"
#include "XMLUtils.h"
txHTMLOutput::txHTMLOutput()
{
mUseEmptyElementShorthand = MB_FALSE;
mHTMLEmptyTags.setOwnership(Map::eOwnsNone);
mHTMLEmptyTags.put(txHTMLAtoms::area, txHTMLAtoms::area);
mHTMLEmptyTags.put(txHTMLAtoms::base, txHTMLAtoms::base);
mHTMLEmptyTags.put(txHTMLAtoms::basefont, txHTMLAtoms::basefont);
mHTMLEmptyTags.put(txHTMLAtoms::br, txHTMLAtoms::br);
mHTMLEmptyTags.put(txHTMLAtoms::col, txHTMLAtoms::col);
mHTMLEmptyTags.put(txHTMLAtoms::frame, txHTMLAtoms::frame);
mHTMLEmptyTags.put(txHTMLAtoms::hr, txHTMLAtoms::hr);
mHTMLEmptyTags.put(txHTMLAtoms::img, txHTMLAtoms::img);
mHTMLEmptyTags.put(txHTMLAtoms::input, txHTMLAtoms::input);
mHTMLEmptyTags.put(txHTMLAtoms::isindex, txHTMLAtoms::isindex);
mHTMLEmptyTags.put(txHTMLAtoms::link, txHTMLAtoms::link);
mHTMLEmptyTags.put(txHTMLAtoms::meta, txHTMLAtoms::meta);
mHTMLEmptyTags.put(txHTMLAtoms::param, txHTMLAtoms::param);
mHTMLEmptyAttributes.setOwnership(Map::eOwnsItems);
// checked
txList* elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::input);
mHTMLEmptyAttributes.put(txHTMLAtoms::checked, elementList);
// compact
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::dir);
elementList->add(txHTMLAtoms::dl);
elementList->add(txHTMLAtoms::menu);
elementList->add(txHTMLAtoms::ol);
elementList->add(txHTMLAtoms::ul);
mHTMLEmptyAttributes.put(txHTMLAtoms::compact, elementList);
// declare
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::object);
mHTMLEmptyAttributes.put(txHTMLAtoms::declare, elementList);
// defer
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::script);
mHTMLEmptyAttributes.put(txHTMLAtoms::defer, elementList);
// disabled
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::button);
elementList->add(txHTMLAtoms::input);
elementList->add(txHTMLAtoms::optgroup);
elementList->add(txHTMLAtoms::option);
elementList->add(txHTMLAtoms::select);
elementList->add(txHTMLAtoms::textarea);
mHTMLEmptyAttributes.put(txHTMLAtoms::disabled, elementList);
// ismap
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::img);
elementList->add(txHTMLAtoms::input);
mHTMLEmptyAttributes.put(txHTMLAtoms::ismap, elementList);
// multiple
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::select);
mHTMLEmptyAttributes.put(txHTMLAtoms::multiple, elementList);
// noresize
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::frame);
mHTMLEmptyAttributes.put(txHTMLAtoms::noresize, elementList);
// noshade
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::hr);
mHTMLEmptyAttributes.put(txHTMLAtoms::noshade, elementList);
// nowrap
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::td);
elementList->add(txHTMLAtoms::th);
mHTMLEmptyAttributes.put(txHTMLAtoms::nowrap, elementList);
// readonly
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::input);
elementList->add(txHTMLAtoms::textarea);
mHTMLEmptyAttributes.put(txHTMLAtoms::readonly, elementList);
// selected
elementList = new List;
if (!elementList)
return;
elementList->add(txHTMLAtoms::option);
mHTMLEmptyAttributes.put(txHTMLAtoms::selected, elementList);
}
txHTMLOutput::~txHTMLOutput()
{
}
void txHTMLOutput::attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue)
{
if (!mStartTagOpen)
// XXX Signal this? (can't add attributes after element closed)
return;
MBool shortHand = MB_FALSE;
if (aNsID == kNameSpaceID_None) {
String localPart;
XMLUtils::getLocalPart(aName, localPart);
shortHand = isShorthandAttribute(localPart);
if (shortHand && localPart.isEqualIgnoreCase(aValue)) {
txListIterator iter(&mAttributes);
txAttribute* setAtt = 0;
txAtom* localName = TX_GET_ATOM(localPart);
txExpandedName att(aNsID, localName);
while ((setAtt = (txAttribute*)iter.next())) {
if (setAtt->mName == att) {
setAtt->mShorthand = MB_TRUE;
break;
}
}
if (!setAtt) {
setAtt = new txAttribute(aNsID, localName, "");
setAtt->mShorthand = MB_TRUE;
mAttributes.add(setAtt);
}
TX_IF_RELEASE_ATOM(localName);
}
}
if (!shortHand)
txXMLOutput::attribute(aName, aNsID, aValue);
}
void txHTMLOutput::characters(const String& aData)
{
// Special-case script and style
txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek();
if (currentElement &&
(currentElement->mNamespaceID == kNameSpaceID_None) &&
((currentElement->mLocalName == txHTMLAtoms::script) ||
(currentElement->mLocalName == txHTMLAtoms::style))) {
closeStartTag(MB_FALSE);
printUTF8Chars(aData);
}
else {
txXMLOutput::characters(aData);
}
}
void txHTMLOutput::endElement(const String& aName,
const PRInt32 aNsID)
{
if ((aNsID == kNameSpaceID_None) && isShorthandElement(aName) &&
mStartTagOpen) {
MBool newLine = (mOutputFormat.mIndent == eTrue) &&
mAfterEndTag;
closeStartTag(MB_FALSE);
if (newLine)
*mOut << endl;
if (mOutputFormat.mIndent == eTrue)
mIndentLevel -= DEFAULT_INDENT;
mAfterEndTag = MB_TRUE;
}
else {
txXMLOutput::endElement(aName, aNsID);
}
delete (txExpandedName*)mCurrentElements.pop();
}
void txHTMLOutput::processingInstruction(const String& aTarget, const String& aData)
{
closeStartTag(MB_FALSE);
if (mOutputFormat.mIndent == eTrue) {
for (PRUint32 i = 0; i < mIndentLevel; i++)
*mOut << ' ';
}
*mOut << PI_START << aTarget << SPACE << aData << R_ANGLE_BRACKET;
if (mOutputFormat.mIndent == eTrue)
*mOut << endl;
}
void txHTMLOutput::startDocument()
{
// XXX Should be using mOutputFormat.getVersion
*mOut << DOCTYPE_START << "html " << PUBLIC;
*mOut << " \"-//W3C//DTD HTML 4.0 Transitional//EN\"";
*mOut << " \"http://www.w3.org/TR/REC-html40/loose.dtd\"";
*mOut << DOCTYPE_END << endl;
}
void txHTMLOutput::startElement(const String& aName,
const PRInt32 aNsID)
{
txXMLOutput::startElement(aName, aNsID);
txAtom* localAtom;
if (aNsID == kNameSpaceID_None) {
String localName(aName);
localName.toLowerCase();
localAtom = TX_GET_ATOM(localName);
}
else {
localAtom = TX_GET_ATOM(aName);
}
NS_ASSERTION(localAtom, "Can't get atom");
txExpandedName* currentElement = new txExpandedName(aNsID, localAtom);
TX_IF_RELEASE_ATOM(localAtom);
NS_ASSERTION(currentElement, "Can't create currentElement");
if (currentElement)
mCurrentElements.push(currentElement);
}
void txHTMLOutput::closeStartTag(MBool aUseEmptyElementShorthand)
{
txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek();
if (mStartTagOpen && currentElement &&
(currentElement->mNamespaceID == kNameSpaceID_None) &&
(currentElement->mLocalName == txHTMLAtoms::head)) {
txXMLOutput::closeStartTag(MB_FALSE);
if (mOutputFormat.mIndent == eTrue) {
*mOut << endl;
for (PRUint32 i = 0; i < mIndentLevel; i++)
*mOut << ' ';
}
*mOut << LT << "meta http-equiv=" << QUOTE << "Content-Type" << QUOTE;
*mOut << " content=" << QUOTE << mOutputFormat.mMediaType << ";";
*mOut << " charset=" << mOutputFormat.mEncoding << QUOTE << GT;
}
else {
txXMLOutput::closeStartTag(aUseEmptyElementShorthand);
}
}
MBool txHTMLOutput::isShorthandElement(const String& aName)
{
String localName;
XMLUtils::getLocalPart(aName, localName);
localName.toLowerCase();
txAtom* localAtom = TX_GET_ATOM(localName);
if (localAtom && mHTMLEmptyTags.get(localAtom))
return MB_TRUE;
return MB_FALSE;
}
MBool txHTMLOutput::isShorthandAttribute(const String& aLocalName)
{
String localName(aLocalName);
localName.toLowerCase();
txAtom* localAtom = TX_GET_ATOM(localName);
txList* elements = (txList*)mHTMLEmptyAttributes.get(localAtom);
if (localAtom && (elements)) {
txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek();
txListIterator iter(elements);
while (iter.hasNext()) {
if ((txAtom*)iter.next() == currentElement->mLocalName)
return MB_TRUE;
}
}
return MB_FALSE;
}

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

@ -0,0 +1,112 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_HTML_OUTPUT_H
#define TRANSFRMX_HTML_OUTPUT_H
#include "txXMLOutput.h"
#include "Map.h"
#include "Stack.h"
class txHTMLOutput : public txXMLOutput
{
public:
txHTMLOutput();
~txHTMLOutput();
/*
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue);
/*
* Signals to receive characters.
*
* @param aData the characters to receive
*/
void characters(const String& aData);
/*
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void endElement(const String& aName,
const PRInt32 aNsID);
/*
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
void processingInstruction(const String& aTarget,
const String& aData);
/*
* Signals the start of a document.
*/
void startDocument();
/*
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void startElement(const String& aName,
const PRInt32 aNsID);
private:
void closeStartTag(MBool aUseEmptyElementShorthand);
MBool isShorthandElement(const String& aName);
MBool isShorthandAttribute(const String& aLocalName);
Map mHTMLEmptyTags;
Map mHTMLEmptyAttributes;
Stack mCurrentElements;
};
#endif

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

@ -0,0 +1,220 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txMozillaTextOutput.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMText.h"
#include "TxString.h"
txMozillaTextOutput::txMozillaTextOutput()
{
}
txMozillaTextOutput::~txMozillaTextOutput()
{
}
void txMozillaTextOutput::attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue)
{
}
void txMozillaTextOutput::characters(const String& aData)
{
if (mTextNode)
mTextNode->AppendData(aData.getConstNSString());
}
void txMozillaTextOutput::comment(const String& aData)
{
}
void txMozillaTextOutput::disableStylesheetLoad()
{
}
void txMozillaTextOutput::endDocument()
{
}
void txMozillaTextOutput::endElement(const String& aName,
const PRInt32 aNsID)
{
}
nsresult txMozillaTextOutput::getRootContent(nsIContent** aReturn)
{
NS_ASSERTION(aReturn, "NULL pointer passed to getRootContent");
*aReturn = mRootContent;
NS_IF_ADDREF(*aReturn);
return NS_OK;
}
PRBool txMozillaTextOutput::isDone()
{
return PR_TRUE;
}
void txMozillaTextOutput::processingInstruction(const String& aTarget,
const String& aData)
{
}
void txMozillaTextOutput::removeScriptElement(nsIDOMHTMLScriptElement *aElement)
{
NS_NOTREACHED("No script elements in text output, so this is weird!");
}
void txMozillaTextOutput::setOutputDocument(nsIDOMDocument* aDocument)
{
NS_ASSERTION(aDocument, "Document can't be NULL!");
if (!aDocument)
return;
/*
* Create an XHTML document to hold the text.
*
* <html>
* <head />
* <body>
* <pre> * The text comes here * </pre>
* <body>
* </html>
*/
nsCOMPtr<nsIDOMElement> element, docElement;
nsCOMPtr<nsIDOMNode> parent, pre;
nsCOMPtr<nsIDOMText> textNode;
NS_NAMED_LITERAL_STRING(XHTML_NSURI, "http://www.w3.org/1999/xhtml");
aDocument->CreateElementNS(XHTML_NSURI,
NS_LITERAL_STRING("html"),
getter_AddRefs(docElement));
mRootContent = do_QueryInterface(docElement);
NS_ASSERTION(mRootContent, "Need root element");
if (!mRootContent)
return;
nsCOMPtr<nsIDocument> document = do_QueryInterface(aDocument);
NS_ASSERTION(document, "Need document");
nsresult rv = mRootContent->SetDocument(document, PR_FALSE, PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set the document");
if (NS_FAILED(rv))
return;
rv = document->SetRootContent(mRootContent);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set the root content");
if (NS_FAILED(rv))
return;
aDocument->CreateElementNS(XHTML_NSURI,
NS_LITERAL_STRING("head"),
getter_AddRefs(element));
NS_ASSERTION(element, "Failed to create head element");
if (!element)
return;
rv = docElement->AppendChild(element, getter_AddRefs(parent));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the head element");
if (NS_FAILED(rv))
return;
aDocument->CreateElementNS(XHTML_NSURI,
NS_LITERAL_STRING("body"),
getter_AddRefs(element));
NS_ASSERTION(element, "Failed to create body element");
if (!mRootContent)
return;
rv = docElement->AppendChild(element, getter_AddRefs(parent));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the body element");
if (NS_FAILED(rv))
return;
aDocument->CreateElementNS(XHTML_NSURI,
NS_LITERAL_STRING("pre"),
getter_AddRefs(element));
NS_ASSERTION(element, "Failed to create pre element");
if (!element)
return;
rv = parent->AppendChild(element, getter_AddRefs(pre));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the pre element");
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(pre);
htmlElement->SetId(NS_LITERAL_STRING("transformiixResult"));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the id");
aDocument->CreateTextNode(NS_LITERAL_STRING(""),
getter_AddRefs(textNode));
NS_ASSERTION(textNode, "Failed to create the text node");
if (!textNode)
return;
rv = pre->AppendChild(textNode, getter_AddRefs(parent));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to append the text node");
if (NS_FAILED(rv))
return;
mTextNode = textNode;
}
void txMozillaTextOutput::setOutputFormat(txOutputFormat* aOutputFormat)
{
mOutputFormat.reset();
mOutputFormat.merge(*aOutputFormat);
mOutputFormat.setFromDefaults();
}
void txMozillaTextOutput::startDocument()
{
}
void txMozillaTextOutput::startElement(const String& aName,
const PRInt32 aNsID)
{
}

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

@ -0,0 +1,162 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_MOZILLA_TEXT_OUTPUT_H
#define TRANSFRMX_MOZILLA_TEXT_OUTPUT_H
#include "txXMLEventHandler.h"
#include "nsIContent.h"
#include "nsIDOMCharacterData.h"
#include "nsCOMPtr.h"
#include "txOutputFormat.h"
class txMozillaTextOutput : public txMozillaXMLEventHandler
{
public:
txMozillaTextOutput();
virtual ~txMozillaTextOutput();
/*
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue);
/*
* Signals to receive characters.
*
* @param aData the characters to receive
*/
void characters(const String& aData);
/*
* Signals to receive data that should be treated as a comment.
*
* @param data the comment data to receive
*/
void comment(const String& aData);
/*
* Signals the end of a document. It is an error to call
* this method more than once.
*/
void endDocument();
/*
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void endElement(const String& aName,
const PRInt32 aNsID);
/*
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
void processingInstruction(const String& aTarget, const String& aData);
/*
* Signals the start of a document.
*/
void startDocument();
/*
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void startElement(const String& aName,
const PRInt32 aNsID);
/*
* Sets the output format.
*
* @param aOutputFormat the output format
*/
void setOutputFormat(txOutputFormat* aOutputFormat);
/*
* Disables loading of stylesheets.
*/
void disableStylesheetLoad();
/*
* Returns the root content of the result.
*
* @param aReturn the root content
*/
nsresult getRootContent(nsIContent** aReturn);
/*
* Returns PR_TRUE if the event handler has finished anything
* extra that had to happen after the transform has finished.
*/
PRBool isDone();
/*
* Removes a script element from the array of elements that are
* still loading.
*
* @param aReturn the script element to remove
*/
void removeScriptElement(nsIDOMHTMLScriptElement *aElement);
/*
* Sets the Mozilla output document.
*
* @param aDocument the Mozilla output document
*/
void setOutputDocument(nsIDOMDocument* aDocument);
private:
nsCOMPtr<nsIDOMCharacterData> mTextNode;
nsCOMPtr<nsIContent> mRootContent;
txOutputFormat mOutputFormat;
};
#endif

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

@ -0,0 +1,498 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txMozillaXMLOutput.h"
#include "nsIDocument.h"
#include "nsIDOMComment.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMText.h"
#include "nsIDOMHTMLTableSectionElem.h"
#include "nsIDOMHTMLScriptElement.h"
#include "nsIDOMNSDocument.h"
#include "nsUnicharUtils.h"
#include "txAtoms.h"
#define kXHTMLNameSpaceURI "http://www.w3.org/1999/xhtml"
#define kTXNameSpaceURI "http://www.mozilla.org/TransforMiix"
#define kTXWrapper "transformiix:result"
#define TX_ENSURE_CURRENTNODE \
NS_ASSERTION(mCurrentNode, "mCurrentNode is NULL"); \
if (!mCurrentNode) \
return
txMozillaXMLOutput::txMozillaXMLOutput() : mDisableStylesheetLoad(PR_FALSE)
{
}
txMozillaXMLOutput::~txMozillaXMLOutput()
{
}
void txMozillaXMLOutput::attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue)
{
if (!mParentNode)
// XXX Signal this? (can't add attributes after element closed)
return;
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mCurrentNode);
NS_ASSERTION(element, "No element to add the attribute to.");
if (!element)
// XXX Signal this? (no element to add attributes to)
return;
if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) {
// Outputting HTML as XHTML, lowercase attribute names
nsAutoString lowerName(aName.getConstNSString());
ToLowerCase(lowerName);
element->SetAttributeNS(NS_LITERAL_STRING(""), lowerName,
aValue.getConstNSString());
}
else {
nsAutoString nsURI;
mNameSpaceManager->GetNameSpaceURI(aNsID, nsURI);
element->SetAttributeNS(nsURI, aName.getConstNSString(),
aValue.getConstNSString());
}
}
void txMozillaXMLOutput::characters(const String& aData)
{
closePrevious(eCloseElement);
mText.Append(aData.getConstNSString());
}
void txMozillaXMLOutput::comment(const String& aData)
{
closePrevious(eCloseElement | eFlushText);
TX_ENSURE_CURRENTNODE;
nsCOMPtr<nsIDOMComment> comment;
nsresult rv = mDocument->CreateComment(aData.getConstNSString(),
getter_AddRefs(comment));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create comment");
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(comment);
nsCOMPtr<nsIDOMNode> resultNode;
rv = mCurrentNode->AppendChild(node, getter_AddRefs(resultNode));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append comment");
}
void txMozillaXMLOutput::disableStylesheetLoad()
{
mDisableStylesheetLoad = PR_TRUE;
}
void txMozillaXMLOutput::endDocument()
{
closePrevious(eCloseElement | eFlushText);
if (!mHaveTitle) {
nsCOMPtr<nsIDOMNSDocument> domDoc = do_QueryInterface(mDocument);
if (domDoc) {
domDoc->SetTitle(NS_LITERAL_STRING(""));
}
}
}
void txMozillaXMLOutput::endElement(const String& aName, const PRInt32 aNsID)
{
#ifdef DEBUG
nsAutoString nodeName;
mCurrentNode->GetNodeName(nodeName);
if (!nodeName.EqualsIgnoreCase(aName.getConstNSString()))
NS_ASSERTION(nodeName.EqualsIgnoreCase(aName.getConstNSString()),
"Unbalanced startElement and endElement calls!");
#endif
closePrevious(eCloseElement | eFlushText);
nsresult rv;
nsCOMPtr<nsIContent> currentContent = do_QueryInterface(mCurrentNode, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't QI to nsIContent");
if (!currentContent)
return;
nsCOMPtr<nsIAtom> atom;
currentContent->GetTag(*getter_AddRefs(atom));
PRBool isHTML = (mOutputFormat.mMethod == eHTMLOutput) &&
(aNsID == kNameSpaceID_None);
if (isHTML && (atom == txHTMLAtoms::table)) {
// Check if we have any table section.
nsCOMPtr<nsIDOMHTMLTableSectionElement> section;
nsCOMPtr<nsIContent> childContent;
PRInt32 count, i = 0;
currentContent->ChildCount(count);
while (!section && (i < count)) {
rv = currentContent->ChildAt(i, *getter_AddRefs(childContent));
NS_ASSERTION(NS_SUCCEEDED(rv), "Something went wrong while getting a child");
section = do_QueryInterface(childContent);
++i;
}
if (!section && (count > 0)) {
// If no section, wrap table's children in a tbody.
nsCOMPtr<nsIDOMElement> wrapper;
rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI),
NS_LITERAL_STRING("tbody"),
getter_AddRefs(wrapper));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create tbody element");
if (wrapper) {
nsCOMPtr<nsIDOMNode> resultNode;
wrapChildren(mCurrentNode, wrapper);
rv = mCurrentNode->AppendChild(wrapper, getter_AddRefs(resultNode));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append tbody element");
}
}
}
else if (isHTML || (aNsID == kNameSpaceID_HTML)) {
if (mScriptParent && (atom == txHTMLAtoms::script)) {
// Add this script element to the array of loading script elements.
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement = do_QueryInterface(mCurrentNode, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "Need script element");
mScriptElements.AppendElement(scriptElement);
// Add the script element to the tree.
nsCOMPtr<nsIDocument> document = do_QueryInterface(mScriptParent);
if (document && !mRootContent) {
mRootContent = do_QueryInterface(mCurrentNode);
mRootContent->SetDocument(document, PR_FALSE, PR_TRUE);
document->SetRootContent(mRootContent);
}
else {
nsCOMPtr<nsIDOMNode> resultNode;
rv = mScriptParent->AppendChild(mCurrentNode,
getter_AddRefs(resultNode));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append script element");
}
mScriptParent = nsnull;
}
else if (mStyleElement && (atom == txHTMLAtoms::style)) {
if (!mDisableStylesheetLoad) {
mStyleElement->SetEnableUpdates(PR_TRUE);
mStyleElement->UpdateStyleSheet(PR_TRUE, nsnull, -1);
}
mStyleElement = nsnull;
}
}
nsCOMPtr<nsIDOMNode> tempNode = mCurrentNode;
tempNode->GetParentNode(getter_AddRefs(mCurrentNode));
}
nsresult txMozillaXMLOutput::getRootContent(nsIContent** aReturn)
{
NS_ASSERTION(aReturn, "NULL pointer passed to getRootContent");
*aReturn = mRootContent;
NS_IF_ADDREF(*aReturn);
return NS_OK;
}
PRBool txMozillaXMLOutput::isDone()
{
PRUint32 scriptCount;
mScriptElements.Count(&scriptCount);
return (scriptCount == 0);
}
void txMozillaXMLOutput::processingInstruction(const String& aTarget, const String& aData)
{
if (mOutputFormat.mMethod == eHTMLOutput)
return;
closePrevious(eCloseElement | eFlushText);
TX_ENSURE_CURRENTNODE;
nsCOMPtr<nsIDOMProcessingInstruction> pi;
nsresult rv = mDocument->CreateProcessingInstruction(aTarget.getConstNSString(),
aData.getConstNSString(),
getter_AddRefs(pi));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create entity reference");
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pi);
nsCOMPtr<nsIDOMNode> resultNode;
mCurrentNode->AppendChild(node, getter_AddRefs(resultNode));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append entity reference");
}
void txMozillaXMLOutput::removeScriptElement(nsIDOMHTMLScriptElement *aElement)
{
PRInt32 index = mScriptElements.IndexOf(aElement);
if (index > -1)
mScriptElements.RemoveElementAt(index);
}
void txMozillaXMLOutput::setOutputDocument(nsIDOMDocument* aDocument)
{
NS_ASSERTION(aDocument, "Document can't be NULL!");
if (!aDocument)
return;
mDocument = aDocument;
mCurrentNode = mDocument;
mHaveTitle = PR_FALSE;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDocument);
doc->GetNameSpaceManager(*getter_AddRefs(mNameSpaceManager));
NS_ASSERTION(mNameSpaceManager, "Can't get namespace manager.");
}
void txMozillaXMLOutput::setOutputFormat(txOutputFormat* aOutputFormat)
{
mOutputFormat.reset();
mOutputFormat.merge(*aOutputFormat);
mOutputFormat.setFromDefaults();
}
void txMozillaXMLOutput::startDocument()
{
NS_ASSERTION(mDocument, "Document can't be NULL!");
}
void txMozillaXMLOutput::startElement(const String& aName,
const PRInt32 aNsID)
{
closePrevious(eCloseElement | eFlushText);
nsresult rv;
if (!mRootContent && !mOutputFormat.mSystemId.isEmpty()) {
// No root element yet, so add the doctype if necesary.
nsCOMPtr<nsIDOMDOMImplementation> implementation;
rv = mDocument->GetImplementation(getter_AddRefs(implementation));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't get DOMImplementation");
if (NS_SUCCEEDED(rv)) {
nsAutoString qName;
nsCOMPtr<nsIDOMDocumentType> documentType;
nsCOMPtr<nsIDOMNode> firstNode, node;
if (mOutputFormat.mMethod == eHTMLOutput)
qName.Assign(NS_LITERAL_STRING("html"));
else
qName.Assign(aName.getConstNSString());
rv = implementation->CreateDocumentType(qName,
mOutputFormat.mPublicId.getConstNSString(),
mOutputFormat.mSystemId.getConstNSString(),
getter_AddRefs(documentType));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create doctype");
mDocument->GetFirstChild(getter_AddRefs(firstNode));
rv = mDocument->InsertBefore(documentType, firstNode, getter_AddRefs(node));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't insert doctype");
}
}
nsCOMPtr<nsIDOMElement> element;
if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) {
// Outputting HTML as XHTML, lowercase element names
nsAutoString lowerName(aName.getConstNSString());
ToLowerCase(lowerName);
rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), lowerName,
getter_AddRefs(element));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create element");
startHTMLElement(element);
}
else {
nsAutoString nsURI;
mNameSpaceManager->GetNameSpaceURI(aNsID, nsURI);
rv = mDocument->CreateElementNS(nsURI, aName.getConstNSString(),
getter_AddRefs(element));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create element");
if (aNsID == kNameSpaceID_XHTML)
startHTMLElement(element);
}
if (element) {
mParentNode = mCurrentNode;
mCurrentNode = do_QueryInterface(element);
}
}
void txMozillaXMLOutput::closePrevious(PRInt8 aAction)
{
TX_ENSURE_CURRENTNODE;
nsresult rv;
PRInt32 namespaceID = kNameSpaceID_None;
nsCOMPtr<nsIContent> currentContent = do_QueryInterface(mCurrentNode, &rv);
if (currentContent)
currentContent->GetNameSpaceID(namespaceID);
PRBool isHTML = (namespaceID == kNameSpaceID_HTML) ||
((mOutputFormat.mMethod == eHTMLOutput) &&
(namespaceID == kNameSpaceID_None));
if ((aAction & eCloseElement) && mParentNode) {
nsCOMPtr<nsIDocument> document = do_QueryInterface(mParentNode);
nsCOMPtr<nsIDOMElement> currentElement = do_QueryInterface(mCurrentNode);
if (document && currentElement && mRootContent) {
// We already have a document element, but the XSLT spec allows this.
// As a workaround, create a wrapper object and use that as the
// document element.
nsCOMPtr<nsIDOMElement> wrapper;
rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kTXNameSpaceURI),
NS_LITERAL_STRING(kTXWrapper),
getter_AddRefs(wrapper));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create wrapper element");
wrapChildren(mParentNode, wrapper);
mParentNode = wrapper;
mRootContent = do_QueryInterface(wrapper);
mRootContent->SetDocument(document, PR_FALSE, PR_TRUE);
document->SetRootContent(mRootContent);
}
PRBool appendNode = PR_TRUE;
if (isHTML) {
nsCOMPtr<nsIAtom> atom;
currentContent->GetTag(*getter_AddRefs(atom));
if (atom == txHTMLAtoms::script) {
appendNode = PR_FALSE;
mScriptParent = mParentNode;
}
else if (atom == txHTMLAtoms::style) {
mStyleElement = do_QueryInterface(mCurrentNode);
if (mStyleElement) {
// XXX Trick nsCSSLoader into blocking/notifying us?
// We would need to implement nsIParser and
// pass ourselves as first parameter to
// InitStyleLinkElement. We would then be notified
// of stylesheet loads/load failures.
mStyleElement->InitStyleLinkElement(nsnull, PR_FALSE);
mStyleElement->SetEnableUpdates(PR_FALSE);
}
}
}
if (appendNode) {
if (document && !mRootContent) {
mRootContent = do_QueryInterface(mCurrentNode);
mRootContent->SetDocument(document, PR_FALSE, PR_TRUE);
document->SetRootContent(mRootContent);
}
else {
nsCOMPtr<nsIDOMNode> resultNode;
rv = mParentNode->AppendChild(mCurrentNode, getter_AddRefs(resultNode));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append node");
}
}
mParentNode = nsnull;
}
else if ((aAction & eFlushText) && !mText.IsEmpty()) {
nsCOMPtr<nsIDOMText> text;
rv = mDocument->CreateTextNode(mText, getter_AddRefs(text));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create text node");
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(text);
nsCOMPtr<nsIDOMNode> resultNode;
mCurrentNode->AppendChild(node, getter_AddRefs(resultNode));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't append text node");
if (currentContent && !mHaveTitle) {
nsCOMPtr<nsIAtom> atom;
currentContent->GetTag(*getter_AddRefs(atom));
if ((atom == txHTMLAtoms::title) && mTitleElement) {
// The first title wins
mHaveTitle = PR_TRUE;
nsCOMPtr<nsIDOMNSDocument> domDoc = do_QueryInterface(mDocument);
if (domDoc) {
mText.CompressWhitespace();
domDoc->SetTitle(mText);
}
mTitleElement = nsnull;
}
}
mText.Truncate();
}
}
void txMozillaXMLOutput::startHTMLElement(nsIDOMElement* aElement)
{
nsCOMPtr<nsIAtom> atom;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
content->GetTag(*getter_AddRefs(atom));
if ((atom == txHTMLAtoms::title) && !mHaveTitle) {
mTitleElement = aElement;
}
}
void txMozillaXMLOutput::wrapChildren(nsIDOMNode* aCurrentNode,
nsIDOMElement* aWrapper)
{
nsresult rv;
nsCOMPtr<nsIContent> currentContent;
currentContent = do_QueryInterface(mCurrentNode, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't QI to nsIContent");
if (!currentContent)
return;
PRInt32 count, i = 0;
nsCOMPtr<nsIDOMNode> child, resultNode;
nsCOMPtr<nsIContent> childContent;
currentContent->ChildCount(count);
for (i = 0; i < count; i++) {
rv = currentContent->ChildAt(0, *getter_AddRefs(childContent));
if (NS_SUCCEEDED(rv)) {
child = do_QueryInterface(childContent);
aCurrentNode->RemoveChild(child, getter_AddRefs(resultNode));
aWrapper->AppendChild(resultNode, getter_AddRefs(child));
}
}
}

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

@ -0,0 +1,189 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_MOZILLA_XML_OUTPUT_H
#define TRANSFRMX_MOZILLA_XML_OUTPUT_H
#include "txXMLEventHandler.h"
#include "nsIContent.h"
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsINameSpaceManager.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsString2.h"
#include "nsSupportsArray.h"
#include "txOutputFormat.h"
class txMozillaXMLOutput : public txMozillaXMLEventHandler
{
public:
txMozillaXMLOutput();
virtual ~txMozillaXMLOutput();
/*
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue);
/*
* Signals to receive characters.
*
* @param aData the characters to receive
*/
void characters(const String& aData);
/*
* Signals to receive data that should be treated as a comment.
*
* @param data the comment data to receive
*/
void comment(const String& aData);
/*
* Signals the end of a document. It is an error to call
* this method more than once.
*/
void endDocument();
/*
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void endElement(const String& aName,
const PRInt32 aNsID);
/*
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
void processingInstruction(const String& aTarget,
const String& aData);
/*
* Signals the start of a document.
*/
void startDocument();
/*
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void startElement(const String& aName,
const PRInt32 aNsID);
/*
* Sets the output format.
*
* @param aOutputFormat the output format
*/
void setOutputFormat(txOutputFormat* aOutputFormat);
/*
* Disables loading of stylesheets.
*/
void disableStylesheetLoad();
/*
* Returns the root content of the result.
*
* @param aReturn the root content
*/
nsresult getRootContent(nsIContent** aReturn);
/*
* Returns PR_TRUE if the event handler has finished anything
* extra that had to happen after the transform has finished.
*/
PRBool isDone();
/*
* Removes a script element from the array of elements that are
* still loading.
*
* @param aReturn the script element to remove
*/
void removeScriptElement(nsIDOMHTMLScriptElement *aElement);
/*
* Sets the Mozilla output document.
*
* @param aDocument the Mozilla output document
*/
void setOutputDocument(nsIDOMDocument* aDocument);
private:
void closePrevious(PRInt8 aAction);
void startHTMLElement(nsIDOMElement* aElement);
void wrapChildren(nsIDOMNode* aCurrentNode, nsIDOMElement* aWrapper);
nsCOMPtr<nsIDOMDocument> mDocument;
nsCOMPtr<nsIDOMNode> mCurrentNode;
nsCOMPtr<nsIDOMNode> mParentNode;
nsCOMPtr<nsIContent> mRootContent;
nsCOMPtr<nsIDOMNode> mScriptParent;
nsCOMPtr<nsIDOMElement> mTitleElement;
nsCOMPtr<nsIStyleSheetLinkingElement> mStyleElement;
nsCOMPtr<nsINameSpaceManager> mNameSpaceManager;
nsSupportsArray mScriptElements;
nsAutoString mText;
txOutputFormat mOutputFormat;
PRPackedBool mHaveTitle;
PRPackedBool mDisableStylesheetLoad;
enum txAction { eCloseElement = 1, eFlushText = 2 };
};
#endif

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

@ -0,0 +1,162 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txOutputFormat.h"
#include "XMLUtils.h"
txOutputFormat::txOutputFormat() : mMethod(eMethodNotSet),
mOmitXMLDeclaration(eNotSet),
mStandalone(eNotSet),
mIndent(eNotSet)
{
}
txOutputFormat::~txOutputFormat()
{
txListIterator iter(&mCDATASectionElements);
while (iter.hasNext())
delete (txExpandedName*)iter.next();
}
void txOutputFormat::reset()
{
mMethod = eMethodNotSet;
mVersion.clear();
if (mEncoding.isEmpty())
mOmitXMLDeclaration = eNotSet;
mStandalone = eNotSet;
mPublicId.clear();
mSystemId.clear();
txListIterator iter(&mCDATASectionElements);
while (iter.hasNext())
delete (txExpandedName*)iter.next();
mIndent = eNotSet;
mMediaType.clear();
}
void txOutputFormat::merge(txOutputFormat& aOutputFormat)
{
if (mMethod == eMethodNotSet)
mMethod = aOutputFormat.mMethod;
if (mVersion.isEmpty())
mVersion = aOutputFormat.mVersion;
if (mEncoding.isEmpty())
mEncoding = aOutputFormat.mEncoding;
if (mOmitXMLDeclaration == eNotSet)
mOmitXMLDeclaration = aOutputFormat.mOmitXMLDeclaration;
if (mStandalone == eNotSet)
mStandalone = aOutputFormat.mStandalone;
if (mPublicId.isEmpty())
mPublicId = aOutputFormat.mPublicId;
if (mSystemId.isEmpty())
mSystemId = aOutputFormat.mSystemId;
txListIterator iter(&aOutputFormat.mCDATASectionElements);
txExpandedName* qName;
while ((qName = (txExpandedName*)iter.next())) {
mCDATASectionElements.add(qName);
// XXX We need txList.clear()
iter.remove();
}
if (mIndent == eNotSet)
mIndent = aOutputFormat.mIndent;
if (mMediaType.isEmpty())
mMediaType = aOutputFormat.mMediaType;
}
void txOutputFormat::setFromDefaults()
{
if (mMethod == eMethodNotSet)
mMethod = eXMLOutput;
switch (mMethod) {
case eXMLOutput:
{
if (mVersion.isEmpty())
mVersion = "1.0";
if (mEncoding.isEmpty())
mEncoding = "UTF-8";
if (mOmitXMLDeclaration == eNotSet)
mOmitXMLDeclaration = eFalse;
if (mIndent == eNotSet)
mIndent = eFalse;
if (mMediaType.isEmpty())
mMediaType = "text/xml";
break;
}
case eHTMLOutput:
{
if (mVersion.isEmpty())
mVersion = "4.0";
if (mEncoding.isEmpty())
mEncoding = "UTF-8";
if (mIndent == eNotSet)
mIndent = eTrue;
if (mMediaType.isEmpty())
mMediaType = "text/html";
break;
}
case eTextOutput:
{
if (mEncoding.isEmpty())
mEncoding = "UTF-8";
if (mMediaType.isEmpty())
mMediaType = "text/plain";
break;
}
}
}

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

@ -0,0 +1,107 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_OUTPUTFORMAT_H
#define TRANSFRMX_OUTPUTFORMAT_H
#include "baseutils.h"
#include "List.h"
#include "TxString.h"
enum txOutputMethod {
eMethodNotSet,
eXMLOutput,
eHTMLOutput,
eTextOutput
};
enum txThreeState {
eNotSet,
eFalse,
eTrue
};
class txOutputFormat {
public:
txOutputFormat();
~txOutputFormat();
// "Unset" all values
void reset();
// Merges in the values of aOutputFormat, members that already
// have a value in this txOutputFormat will not be changed.
void merge(txOutputFormat& aOutputFormat);
// Sets members that have no value to their default value.
void setFromDefaults();
// The XSLT output method, which can be "xml", "html", or "text"
txOutputMethod mMethod;
// The xml version number that should be used when serializing
// xml documents
String mVersion;
// The XML character encoding that should be used when serializing
// xml documents
String mEncoding;
// Signals if we should output an XML declaration
txThreeState mOmitXMLDeclaration;
// Signals if we should output a standalone document declaration
txThreeState mStandalone;
// The public Id for creating a DOCTYPE
String mPublicId;
// The System Id for creating a DOCTYPE
String mSystemId;
// The elements whose text node children should be output as CDATA
txList mCDATASectionElements;
// Signals if output should be indented
txThreeState mIndent;
// The media type of the output
String mMediaType;
};
#endif

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

@ -0,0 +1,146 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txRtfHandler.h"
txRtfHandler::txRtfHandler(Document* aDocument,
txResultTreeFragment* aResultTreeFragment) :
mDocument(aDocument),
mResultTreeFragment(aResultTreeFragment)
{
NS_ASSERTION(mDocument, "We need a valid document");
if (!mDocument)
return;
NS_ASSERTION(mResultTreeFragment, "We need a valid result tree fragment");
if (!mResultTreeFragment)
return;
DocumentFragment* fragment = mDocument->createDocumentFragment();
NS_ASSERTION(fragment, "Out of memory creating a document fragmen");
// XXX ErrorReport: Out of memory
mResultTreeFragment->add(fragment);
mCurrentNode = fragment;
}
txRtfHandler::~txRtfHandler()
{
}
void txRtfHandler::attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue)
{
Element* element = (Element*)mCurrentNode;
NS_ASSERTION(element, "We need an element");
if (!element)
// XXX ErrorReport: Can't add attributes without element
return;
if (element->hasChildNodes())
// XXX ErrorReport: Can't add attributes after adding children
return;
String nsURI;
mDocument->namespaceIDToURI(aNsID, nsURI);
element->setAttributeNS(nsURI, aName, aValue);
}
void txRtfHandler::characters(const String& aData)
{
NS_ASSERTION(mCurrentNode, "We need a node");
if (!mCurrentNode)
return;
Text* text = mDocument->createTextNode(aData);
mCurrentNode->appendChild(text);
}
void txRtfHandler::comment(const String& aData)
{
NS_ASSERTION(mCurrentNode, "We need a node");
if (!mCurrentNode)
return;
Comment* comment = mDocument->createComment(aData);
mCurrentNode->appendChild(comment);
}
void txRtfHandler::endDocument()
{
}
void txRtfHandler::endElement(const String& aName,
const PRInt32 aNsID)
{
NS_ASSERTION(mCurrentNode, "We need a node");
if (!mCurrentNode)
return;
mCurrentNode = mCurrentNode->getParentNode();
}
void txRtfHandler::processingInstruction(const String& aTarget,
const String& aData)
{
NS_ASSERTION(mCurrentNode, "We need a node");
if (!mCurrentNode)
return;
ProcessingInstruction* pi;
pi = mDocument->createProcessingInstruction(aTarget, aData);
mCurrentNode->appendChild(pi);
}
void txRtfHandler::startDocument()
{
}
void txRtfHandler::startElement(const String& aName,
const PRInt32 aNsID)
{
NS_ASSERTION(mCurrentNode, "We need a node");
if (!mCurrentNode)
return;
String nsURI;
mDocument->namespaceIDToURI(aNsID, nsURI);
Element* element = mDocument->createElementNS(nsURI, aName);
mCurrentNode->appendChild(element);
mCurrentNode = element;
}

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

@ -0,0 +1,121 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_RTF_HANDLER_H
#define TRANSFRMX_RTF_HANDLER_H
#include "txXMLEventHandler.h"
#include "NodeSet.h"
class txRtfHandler : public txXMLEventHandler
{
public:
txRtfHandler(Document* aDocument,
txResultTreeFragment* aResultTreeFragment);
virtual ~txRtfHandler();
/**
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue);
/**
* Signals to receive characters.
*
* @param aData the characters to receive
*/
void characters(const String& aData);
/**
* Signals to receive data that should be treated as a comment.
*
* @param data the comment data to receive
*/
void comment(const String& aData);
/**
* Signals the end of a document. It is an error to call
* this method more than once.
*/
void endDocument();
/**
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void endElement(const String& aName,
const PRInt32 aNsID);
/**
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
void processingInstruction(const String& aTarget,
const String& aData);
/**
* Signals the start of a document.
*/
void startDocument();
/**
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void startElement(const String& aName,
const PRInt32 aNsID);
private:
Document* mDocument;
txResultTreeFragment* mResultTreeFragment;
Node* mCurrentNode;
};
#endif

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

@ -0,0 +1,93 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txTextHandler.h"
#include "TxString.h"
txTextHandler::txTextHandler(String& aValue, MBool aOnlyText) : mLevel(0),
mValue(aValue),
mOnlyText(aOnlyText)
{
}
txTextHandler::~txTextHandler()
{
}
void txTextHandler::attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue)
{
}
void txTextHandler::characters(const String& aData)
{
if (mLevel == 0)
mValue.append(aData);
}
void txTextHandler::comment(const String& aData)
{
}
void txTextHandler::endDocument()
{
}
void txTextHandler::endElement(const String& aName,
const PRInt32 aNsID)
{
if (mOnlyText)
--mLevel;
}
void txTextHandler::processingInstruction(const String& aTarget,
const String& aData)
{
}
void txTextHandler::startDocument()
{
}
void txTextHandler::startElement(const String& aName,
const PRInt32 aNsID)
{
if (mOnlyText)
++mLevel;
}

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

@ -0,0 +1,119 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_TEXT_HANDLER_H
#define TRANSFRMX_TEXT_HANDLER_H
#include "txXMLEventHandler.h"
class txTextHandler : public txXMLEventHandler
{
public:
txTextHandler(String& aValue, MBool aOnlyText);
virtual ~txTextHandler();
/*
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue);
/*
* Signals to receive characters.
*
* @param aData the characters to receive
*/
void characters(const String& aData);
/*
* Signals to receive data that should be treated as a comment.
*
* @param data the comment data to receive
*/
void comment(const String& aData);
/*
* Signals the end of a document. It is an error to call
* this method more than once.
*/
void endDocument();
/*
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void endElement(const String& aName,
const PRInt32 aNsID);
/*
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
void processingInstruction(const String& aTarget,
const String& aData);
/*
* Signals the start of a document.
*/
void startDocument();
/*
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void startElement(const String& aName,
const PRInt32 aNsID);
private:
PRUint32 mLevel;
String& mValue;
MBool mOnlyText;
};
#endif

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

@ -0,0 +1,109 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txTextOutput.h"
#include "TxString.h"
txTextOutput::txTextOutput()
{
}
txTextOutput::~txTextOutput()
{
}
void txTextOutput::attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue)
{
}
void txTextOutput::characters(const String& aData)
{
*mOut << aData;
}
void txTextOutput::charactersNoOutputEscaping(const String& aData)
{
characters(aData);
}
void txTextOutput::comment(const String& aData)
{
}
void txTextOutput::endDocument()
{
}
void txTextOutput::endElement(const String& aName,
const PRInt32 aNsID)
{
}
void txTextOutput::processingInstruction(const String& aTarget,
const String& aData)
{
}
void txTextOutput::startDocument()
{
}
void txTextOutput::startElement(const String& aName,
const PRInt32 aNsID)
{
}
void txTextOutput::getOutputStream(ostream** aOutputStream)
{
if (aOutputStream)
aOutputStream = mOut;
}
void txTextOutput::setOutputStream(ostream* aOutputStream)
{
mOut = aOutputStream;
}
void txTextOutput::setOutputFormat(txOutputFormat* aOutputFormat)
{
mOutputFormat.reset();
mOutputFormat.merge(*aOutputFormat);
mOutputFormat.setFromDefaults();
}

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

@ -0,0 +1,147 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_TEXT_OUTPUT_H
#define TRANSFRMX_TEXT_OUTPUT_H
#include "txXMLEventHandler.h"
#include "txOutputFormat.h"
class txTextOutput : public txStreamXMLEventHandler
{
public:
txTextOutput();
~txTextOutput();
/*
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue);
/*
* Signals to receive characters.
*
* @param aData the characters to receive
*/
void characters(const String& aData);
/*
* Signals to receive characters that don't need output escaping.
*
* @param aData the characters to receive
*/
virtual void charactersNoOutputEscaping(const String& aData);
/*
* Signals to receive data that should be treated as a comment.
*
* @param data the comment data to receive
*/
void comment(const String& aData);
/*
* Signals the end of a document. It is an error to call
* this method more than once.
*/
void endDocument();
/*
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void endElement(const String& aName,
const PRInt32 aNsID);
/*
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
void processingInstruction(const String& aTarget,
const String& aData);
/*
* Signals the start of a document.
*/
void startDocument();
/*
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
void startElement(const String& aName,
const PRInt32 aNsID);
/*
* Sets the output format.
*
* @param aOutputFormat the output format
*/
void setOutputFormat(txOutputFormat* aOutputFormat);
/**
* Get the output stream.
*
* @param aOutputStream the current output stream
*/
void getOutputStream(ostream** aOutputStream);
/**
* Sets the output stream.
*
* @param aDocument the Mozilla output document
*/
void setOutputStream(ostream* aOutputStream);
private:
ostream* mOut;
txOutputFormat mOutputFormat;
};
#endif

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

@ -0,0 +1,180 @@
/* -*- 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 Keith Visco.
* Portions created by Keith Visco
* (C) 1999-2000 Keith Visco. All Rights Reserved.
*
* Contributor(s):
* Keith Visco <kvisco@ziplink.net>
*
*/
#ifndef TRANSFRMX_XML_EVENT_HANDLER_H
#define TRANSFRMX_XML_EVENT_HANDLER_H
#include "baseutils.h"
class String;
class txOutputFormat;
#ifdef TX_EXE
#include <iostream.h>
#else
class nsIContent;
class nsIDOMDocument;
class nsIDOMHTMLScriptElement;
#endif
/*
* An interface for handling XML documents, loosely modeled
* after Dave Megginson's SAX 1.0 API.
*/
class txXMLEventHandler
{
public:
virtual ~txXMLEventHandler() {};
/*
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
virtual void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue) = 0;
/*
* Signals to receive characters.
*
* @param aData the characters to receive
*/
virtual void characters(const String& aData) = 0;
/*
* Signals to receive data that should be treated as a comment.
*
* @param data the comment data to receive
*/
virtual void comment(const String& aData) = 0;
/*
* Signals the end of a document. It is an error to call
* this method more than once.
*/
virtual void endDocument() = 0;
/*
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
virtual void endElement(const String& aName,
const PRInt32 aNsID) = 0;
/*
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
virtual void processingInstruction(const String& aTarget,
const String& aData) = 0;
/*
* Signals the start of a document.
*/
virtual void startDocument() = 0;
/*
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
virtual void startElement(const String& aName,
const PRInt32 aNsID) = 0;
};
class txOutputXMLEventHandler : public txXMLEventHandler
{
public:
/*
* Sets the output format.
*
* @param aOutputFormat the output format
*/
virtual void setOutputFormat(txOutputFormat* aOutputFormat) = 0;
};
#ifdef TX_EXE
class txStreamXMLEventHandler : public txOutputXMLEventHandler
{
public:
/*
* Sets the output stream.
*
* @param aOutputStream the output stream
*/
virtual void setOutputStream(ostream* aOutputStream) = 0;
/*
* Signals to receive characters that don't need output escaping.
*
* @param aData the characters to receive
*/
virtual void charactersNoOutputEscaping(const String& aData) = 0;
};
#else
class txMozillaXMLEventHandler : public txOutputXMLEventHandler
{
public:
/*
* Disables loading of stylesheets.
*/
virtual void disableStylesheetLoad() = 0;
/*
* Returns the root content of the result.
*
* @param aReturn the root content
*/
virtual nsresult getRootContent(nsIContent** aReturn) = 0;
/*
* Returns PR_TRUE if the event handler has finished anything
* extra that had to happen after the transform has finished.
*/
virtual PRBool isDone() = 0;
/*
* Removes a script element from the array of elements that are
* still loading.
*
* @param aReturn the script element to remove
*/
virtual void removeScriptElement(nsIDOMHTMLScriptElement *aElement) = 0;
/*
* Sets the Mozilla output document.
*
* @param aDocument the Mozilla output document
*/
virtual void setOutputDocument(nsIDOMDocument* aDocument) = 0;
};
#endif
#endif

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

@ -0,0 +1,367 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 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 "txXMLOutput.h"
const int txXMLOutput::DEFAULT_INDENT = 2;
txAttribute::txAttribute(PRInt32 aNsID, txAtom* aLocalName, const String& aValue) :
mName(aNsID, aLocalName),
mValue(aValue),
mShorthand(MB_FALSE)
{
}
txXMLOutput::txXMLOutput() : mUseEmptyElementShorthand(MB_TRUE),
mHaveDocumentElement(MB_FALSE),
mStartTagOpen(MB_FALSE),
mAfterEndTag(MB_FALSE),
mInCDATASection(MB_FALSE),
mIndentLevel(0)
{
}
txXMLOutput::~txXMLOutput()
{
}
void txXMLOutput::attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue)
{
if (!mStartTagOpen)
// XXX Signal this? (can't add attributes after element closed)
return;
txListIterator iter(&mAttributes);
String localPart;
XMLUtils::getLocalPart(aName, localPart);
txAtom* localName = TX_GET_ATOM(localPart);
txExpandedName att(aNsID, localName);
txAttribute* setAtt = 0;
while ((setAtt = (txAttribute*)iter.next())) {
if (setAtt->mName == att) {
setAtt->mValue = aValue;
break;
}
}
if (!setAtt) {
setAtt = new txAttribute(aNsID, localName, aValue);
mAttributes.add(setAtt);
}
TX_IF_RELEASE_ATOM(localName);
}
void txXMLOutput::characters(const String& aData)
{
closeStartTag(MB_FALSE);
if (mInCDATASection) {
PRInt32 i = 0;
PRInt32 j = 0;
PRInt32 length = aData.length();
*mOut << CDATA_START;
if (length <= 3) {
printUTF8Chars(aData);
}
else {
mBuffer[j++] = aData.charAt(i++);
mBuffer[j++] = aData.charAt(i++);
mBuffer[j++] = aData.charAt(i++);
while (i < length) {
mBuffer[j++] = aData.charAt(i++);
if (mBuffer[(j - 1) % 4] == ']' &&
mBuffer[j % 4] == ']' &&
mBuffer[(j + 1) % 4] == '>') {
*mOut << CDATA_END;
*mOut << CDATA_START;
}
j = j % 4;
printUTF8Char(mBuffer[j]);
}
j = ++j % 4;
printUTF8Char(mBuffer[j]);
j = ++j % 4;
printUTF8Char(mBuffer[j]);
j = ++j % 4;
printUTF8Char(mBuffer[j]);
}
*mOut << CDATA_END;
}
else {
printWithXMLEntities(aData);
}
}
void txXMLOutput::charactersNoOutputEscaping(const String& aData)
{
closeStartTag(MB_FALSE);
printUTF8Chars(aData);
}
void txXMLOutput::comment(const String& aData)
{
closeStartTag(MB_FALSE);
if (&aData == &NULL_STRING)
return;
if (mOutputFormat.mIndent == eTrue) {
for (PRUint32 i = 0; i < mIndentLevel; i++)
*mOut << ' ';
}
*mOut << COMMENT_START;
printUTF8Chars(aData);
*mOut << COMMENT_END;
if (mOutputFormat.mIndent == eTrue)
*mOut << endl;
}
void txXMLOutput::endDocument()
{
}
void txXMLOutput::endElement(const String& aName,
const PRInt32 aNsID)
{
MBool newLine = (mOutputFormat.mIndent == eTrue) && mAfterEndTag;
MBool writeEndTag = !(mStartTagOpen && mUseEmptyElementShorthand);
closeStartTag(mUseEmptyElementShorthand);
if (newLine)
*mOut << endl;
if (mOutputFormat.mIndent == eTrue)
mIndentLevel -= DEFAULT_INDENT;
if (writeEndTag) {
if (newLine) {
for (PRUint32 i = 0; i < mIndentLevel; i++)
*mOut << ' ';
}
*mOut << L_ANGLE_BRACKET << FORWARD_SLASH;
*mOut << aName;
*mOut << R_ANGLE_BRACKET;
}
if (mOutputFormat.mIndent == eTrue)
*mOut << endl;
mAfterEndTag = MB_TRUE;
mInCDATASection = (MBool)mCDATASections.pop();
}
void txXMLOutput::processingInstruction(const String& aTarget,
const String& aData)
{
closeStartTag(MB_FALSE);
if (mOutputFormat.mIndent == eTrue) {
for (PRUint32 i = 0; i < mIndentLevel; i++)
*mOut << ' ';
}
*mOut << PI_START << aTarget << SPACE << aData << PI_END;
if (mOutputFormat.mIndent == eTrue)
*mOut << endl;
}
void txXMLOutput::startDocument()
{
if (mOutputFormat.mMethod == eMethodNotSet) {
// XXX We should "cache" content until we have a
// document element
}
*mOut << PI_START << XML_DECL << DOUBLE_QUOTE;
*mOut << XML_VERSION;
*mOut << DOUBLE_QUOTE << PI_END << endl;
}
void txXMLOutput::startElement(const String& aName,
const PRInt32 aNsID)
{
if (!mHaveDocumentElement) {
// XXX Output doc type and "cached" content
mHaveDocumentElement = MB_TRUE;
}
MBool newLine = mStartTagOpen || mAfterEndTag;
closeStartTag(MB_FALSE);
if (mOutputFormat.mIndent == eTrue) {
if (newLine) {
*mOut << endl;
for (PRUint32 i = 0; i < mIndentLevel; i++)
*mOut << ' ';
}
}
*mOut << L_ANGLE_BRACKET;
*mOut << aName;
mStartTagOpen = MB_TRUE;
if (mOutputFormat.mIndent == eTrue)
mIndentLevel += DEFAULT_INDENT;
mCDATASections.push((void*)mInCDATASection);
mInCDATASection = MB_FALSE;
txAtom* localName = TX_GET_ATOM(aName);
txExpandedName currentElement(aNsID, localName);
TX_IF_RELEASE_ATOM(localName);
txListIterator iter(&(mOutputFormat.mCDATASectionElements));
while (iter.hasNext()) {
if (currentElement == *(txExpandedName*)iter.next()) {
mInCDATASection = MB_TRUE;
break;
}
}
}
void txXMLOutput::getOutputStream(ostream** aOutputStream)
{
if (aOutputStream)
aOutputStream = mOut;
}
void txXMLOutput::setOutputStream(ostream* aOutputStream)
{
mOut = aOutputStream;
}
void txXMLOutput::setOutputFormat(txOutputFormat* aOutputFormat)
{
mOutputFormat.reset();
mOutputFormat.merge(*aOutputFormat);
mOutputFormat.setFromDefaults();
}
void txXMLOutput::closeStartTag(MBool aUseEmptyElementShorthand)
{
mAfterEndTag = aUseEmptyElementShorthand;
if (mStartTagOpen) {
txListIterator iter(&mAttributes);
txAttribute* att;
while ((att = (txAttribute*)iter.next())) {
*mOut << SPACE;
*mOut << *(att->mName.mLocalName);
if (!att->mShorthand) {
*mOut << EQUALS << DOUBLE_QUOTE;
printWithXMLEntities(att->mValue, MB_TRUE);
*mOut << DOUBLE_QUOTE;
}
delete (txAttribute*)iter.remove();
}
if (aUseEmptyElementShorthand)
*mOut << FORWARD_SLASH;
*mOut << R_ANGLE_BRACKET;
mStartTagOpen = MB_FALSE;
}
}
void txXMLOutput::printUTF8Char(DOM_CHAR& ch)
{
// DOM_CHAR is 16-bits so we only need to cover up to 0xFFFF
// 0x0000-0x007F
if (ch < 128) {
*mOut << (char)ch;
}
// 0x0080-0x07FF
else if (ch < 2048) {
*mOut << (char) (192+(ch/64)); // 0xC0 + x/64
*mOut << (char) (128+(ch%64)); // 0x80 + x%64
}
// 0x800-0xFFFF
else {
*mOut << (char) (224+(ch/4096)); // 0xE0 + x/64^2
*mOut << (char) (128+((ch/64)%64)); // 0x80 + (x/64)%64
*mOut << (char) (128+(ch%64)); // 0x80 + x%64
}
}
void txXMLOutput::printUTF8Chars(const String& aData)
{
DOM_CHAR currChar;
PRInt32 i = 0;
while (i < aData.length()) {
currChar = aData.charAt(i++);
printUTF8Char(currChar);
}
}
void txXMLOutput::printWithXMLEntities(const String& aData,
MBool aAttribute)
{
DOM_CHAR currChar;
PRInt32 i;
if (&aData == &NULL_STRING)
return;
for (i = 0; i < aData.length(); i++) {
currChar = aData.charAt(i);
switch (currChar) {
case AMPERSAND:
*mOut << AMP_ENTITY;
break;
case APOSTROPHE:
if (aAttribute)
*mOut << APOS_ENTITY;
else
printUTF8Char(currChar);
break;
case GT:
*mOut << GT_ENTITY;
break;
case LT:
*mOut << LT_ENTITY;
break;
case QUOTE:
if (aAttribute)
*mOut << QUOT_ENTITY;
else
printUTF8Char(currChar);
break;
default:
printUTF8Char(currChar);
break;
}
}
*mOut << flush;
}

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

@ -0,0 +1,215 @@
/* -*- 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 the TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* 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 MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef TRANSFRMX_XML_OUTPUT_H
#define TRANSFRMX_XML_OUTPUT_H
#include "txXMLEventHandler.h"
#include "dom.h"
#include "List.h"
#include "Stack.h"
#include "txOutputFormat.h"
#include "XMLUtils.h"
#define DASH '-'
#define TX_CR '\r'
#define TX_LF '\n'
#define AMPERSAND '&'
#define APOSTROPHE '\''
#define GT '>'
#define LT '<'
#define QUOTE '"'
#define AMP_ENTITY "&amp"
#define APOS_ENTITY "&apos"
#define GT_ENTITY "&gt;"
#define LT_ENTITY "&lt;"
#define QUOT_ENTITY "&quot"
#define HEX_ENTITY "&#"
#define CDATA_END "]]>"
#define CDATA_START "<![CDATA["
#define COMMENT_START "<!--"
#define COMMENT_END "-->"
#define DOCTYPE_START "<!DOCTYPE "
#define DOCTYPE_END ">"
#define DOUBLE_QUOTE "\""
#define EQUALS "="
#define FORWARD_SLASH "/"
#define L_ANGLE_BRACKET "<"
#define PI_START "<?"
#define PI_END "?>"
#define PUBLIC "PUBLIC"
#define R_ANGLE_BRACKET ">"
#define SEMICOLON ";"
#define SPACE " "
#define SYSTEM "SYSTEM"
#define XML_DECL "xml version="
#define XML_VERSION "1.0"
class txAttribute {
public:
txAttribute(PRInt32 aNsID, txAtom* aLocalName, const String& aValue);
txExpandedName mName;
String mValue;
MBool mShorthand;
};
class txXMLOutput : public txStreamXMLEventHandler
{
public:
txXMLOutput();
virtual ~txXMLOutput();
static const int DEFAULT_INDENT;
/*
* Signals to receive the start of an attribute.
*
* @param aName the name of the attribute
* @param aNsID the namespace ID of the attribute
* @param aValue the value of the attribute
*/
virtual void attribute(const String& aName,
const PRInt32 aNsID,
const String& aValue);
/*
* Signals to receive characters.
*
* @param aData the characters to receive
*/
virtual void characters(const String& aData);
/*
* Signals to receive characters that don't need output escaping.
*
* @param aData the characters to receive
*/
virtual void charactersNoOutputEscaping(const String& aData);
/*
* Signals to receive data that should be treated as a comment.
*
* @param data the comment data to receive
*/
void comment(const String& aData);
/*
* Signals the end of a document. It is an error to call
* this method more than once.
*/
virtual void endDocument();
/*
* Signals to receive the end of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
virtual void endElement(const String& aName,
const PRInt32 aNsID);
/*
* Signals to receive a processing instruction.
*
* @param aTarget the target of the processing instruction
* @param aData the data of the processing instruction
*/
virtual void processingInstruction(const String& aTarget,
const String& aData);
/*
* Signals the start of a document.
*/
virtual void startDocument();
/*
* Signals to receive the start of an element.
*
* @param aName the name of the element
* @param aNsID the namespace ID of the element
*/
virtual void startElement(const String& aName,
const PRInt32 aNsID);
/*
* Sets the output format.
*
* @param aOutputFormat the output format
*/
void setOutputFormat(txOutputFormat* aOutputFormat);
/**
* Get the output stream.
*
* @param aOutputStream the current output stream
*/
void getOutputStream(ostream** aOutputStream);
/**
* Sets the output stream.
*
* @param aOutputStream the new output stream
*/
void setOutputStream(ostream* aOutputStream);
protected:
virtual void closeStartTag(MBool aUseEmptyElementShorthand);
void printUTF8Char(DOM_CHAR& ch);
void printUTF8Chars(const String& aData);
void printWithXMLEntities(const String& aData, MBool aAttribute = MB_FALSE);
void write(const String& aData);
ostream* mOut;
txOutputFormat mOutputFormat;
MBool mUseEmptyElementShorthand;
MBool mHaveDocumentElement;
MBool mStartTagOpen;
MBool mAfterEndTag;
MBool mInCDATASection;
PRUint32 mIndentLevel;
txList mAttributes;
Stack mCDATASections;
private:
DOM_CHAR mBuffer[4];
};
#endif

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

@ -42,6 +42,7 @@ TX_ATOM(applyTemplates, "apply-templates");
TX_ATOM(attribute, "attribute");
TX_ATOM(attributeSet, "attribute-set");
TX_ATOM(callTemplate, "call-template");
TX_ATOM(caseOrder, "case-order");
TX_ATOM(choose, "choose");
TX_ATOM(comment, "comment");
TX_ATOM(copy, "copy");
@ -77,8 +78,8 @@ TX_ATOM(cdataSectionElements, "cdata-section-elements");
TX_ATOM(count, "count");
TX_ATOM(dataType, "data-type");
TX_ATOM(decimalSeparator, "decimal-separator");
TX_ATOM(defaultSpace, "default-space");
TX_ATOM(digit, "digit");
TX_ATOM(disableOutputEscaping, "disable-output-escaping");
TX_ATOM(doctypePublic, "doctype-public");
TX_ATOM(doctypeSystem, "doctype-system");
TX_ATOM(elements, "elements");

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

@ -42,6 +42,7 @@
#include "Names.h"
#include "ProcessorState.h"
#include "txXPathResultComparator.h"
#include "txAtoms.h"
/*
* Sorts Nodes as specified by the W3C XSLT 1.0 Recommendation
@ -98,7 +99,7 @@ MBool txNodeSorter::addSortElement(Element* aSortElement,
// Order
MBool ascending;
MBool hasAttr = getAttrAsAVT(aSortElement, ORDER_ATTR, aContext, attrValue);
MBool hasAttr = getAttrAsAVT(aSortElement, txXSLTAtoms::order, aContext, attrValue);
if (!hasAttr || attrValue.isEqual(ASCENDING_VALUE)) {
ascending = MB_TRUE;
}
@ -114,18 +115,18 @@ MBool txNodeSorter::addSortElement(Element* aSortElement,
// Create comparator depending on datatype
String dataType;
hasAttr = getAttrAsAVT(aSortElement, DATA_TYPE_ATTR, aContext, dataType);
hasAttr = getAttrAsAVT(aSortElement, txXSLTAtoms::dataType, aContext, dataType);
if (!hasAttr || dataType.isEqual(TEXT_VALUE)) {
// Text comparator
// Language
String lang;
if (!getAttrAsAVT(aSortElement, LANG_ATTR, aContext, lang))
if (!getAttrAsAVT(aSortElement, txXSLTAtoms::lang, aContext, lang))
lang = DEFAULT_LANG;
// Case-order
MBool upperFirst;
hasAttr = getAttrAsAVT(aSortElement, CASE_ORDER_ATTR, aContext, attrValue);
hasAttr = getAttrAsAVT(aSortElement, txXSLTAtoms::caseOrder, aContext, attrValue);
if (!hasAttr || attrValue.isEqual(UPPER_FIRST_VALUE)) {
upperFirst = MB_TRUE;
}
@ -263,17 +264,16 @@ int txNodeSorter::compareNodes(SortableNode* aSNode1,
}
MBool txNodeSorter::getAttrAsAVT(Element* aSortElement,
const String& aAttrName,
txAtom* aAttrName,
Node* aContext,
String& aResult)
{
aResult.clear();
Node* tempNode = aSortElement->getAttributeNode(aAttrName);
if (!tempNode)
String attValue;
if (!aSortElement->getAttr(aAttrName, kNameSpaceID_None, attValue))
return MB_FALSE;
const String& attValue = tempNode->getNodeValue();
mPs->processAttrValueTemplate(attValue, aContext, aResult);
return MB_TRUE;
}

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

@ -42,6 +42,7 @@
#include "baseutils.h"
#include "List.h"
#include "txAtom.h"
class Element;
class Expr;
@ -85,7 +86,7 @@ private:
SortableNode* sNode2);
MBool getAttrAsAVT(Element* aSortElement,
const String& aAttrName,
txAtom* aAttrName,
Node* aContext,
String& aResult);