зеркало из https://github.com/mozilla/pjs.git
Adding the architecture for an external transformation engine to hook into Raptor's layout process. One way this architecture can be used is for doing XSL transforms using a 3rd party component that implements the XSL processor. More details will be posted in mozilla.layout.
Currently enabled on windows only. Set MOZ_XSL to 1 in your environment and build mozilla/layout.
This commit is contained in:
Родитель
34a671540b
Коммит
863dcf6860
|
@ -25,6 +25,9 @@
|
|||
|
||||
class nsIAtom;
|
||||
class nsICSSLoader;
|
||||
#ifdef XSL
|
||||
class nsITransformMediator;
|
||||
#endif
|
||||
|
||||
#define NS_IXMLDOCUMENT_IID \
|
||||
{ 0xa6cf90ca, 0x15b3, 0x11d2, \
|
||||
|
@ -38,6 +41,9 @@ public:
|
|||
// XXX This (or a variant thereof) should be in a DOM interface.
|
||||
// Since it isn't, we add it here temporarily
|
||||
NS_IMETHOD GetContentById(const nsString& aName, nsIContent** aContent)=0;
|
||||
#ifdef XSL
|
||||
NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator)=0;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // nsIXMLDocument_h___
|
||||
|
|
|
@ -21,7 +21,10 @@ LIBRARY_NAME=raptorxmldoc_s
|
|||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor pref
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN \
|
||||
!if defined(MOZ_XSL)
|
||||
-DXSL
|
||||
!endif
|
||||
|
||||
CPPSRCS= \
|
||||
nsXMLContentSink.cpp \
|
||||
|
@ -33,13 +36,13 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\nsXMLDocument.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
|
||||
-I..\..\..\html\style\src -I..\..\..\html\base\src -I$(PUBLIC)\dom \
|
||||
-I..\..\..\html\content\src -I..\..\..\html\document\src \
|
||||
-I..\..\..\xul\content\src \
|
||||
-I..\..\..\xul\content\src -I..\..\..\xsl\document\src \
|
||||
-I$(PUBLIC)\netlib -I..\..\..\base\src -I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\expat
|
||||
|
||||
|
|
|
@ -91,11 +91,14 @@ nsXMLDocument::nsXMLDocument()
|
|||
// XUL world lives within XML world until it gets a place of its own
|
||||
nsXULAtoms::AddrefAtoms();
|
||||
#endif
|
||||
#ifdef XSL
|
||||
mTransformMediator = nsnull;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsXMLDocument::~nsXMLDocument()
|
||||
{
|
||||
NS_IF_RELEASE(mParser);
|
||||
NS_IF_RELEASE(mParser);
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
mAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
NS_RELEASE(mAttrStyleSheet);
|
||||
|
@ -111,6 +114,9 @@ nsXMLDocument::~nsXMLDocument()
|
|||
#ifdef INCLUDE_XUL
|
||||
nsXULAtoms::ReleaseAtoms();
|
||||
#endif
|
||||
#ifdef XSL
|
||||
NS_IF_RELEASE(mTransformMediator);
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -461,6 +467,17 @@ nsXMLDocument::GetContentById(const nsString& aName, nsIContent** aContent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef XSL
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::SetTransformMediator(nsITransformMediator* aMediator)
|
||||
{
|
||||
NS_ASSERTION(nsnull == mTransformMediator, "nsXMLDocument::SetTransformMediator(): \
|
||||
Cannot set a second transform mediator\n");
|
||||
mTransformMediator = aMediator;
|
||||
NS_IF_ADDREF(mTransformMediator);
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include "nsMarkupDocument.h"
|
||||
#include "nsIXMLDocument.h"
|
||||
#include "nsIHTMLContentContainer.h"
|
||||
#ifdef XSL
|
||||
#include "nsITransformMediator.h"
|
||||
#endif
|
||||
|
||||
class nsIParser;
|
||||
class nsIDOMNode;
|
||||
|
@ -64,6 +67,9 @@ public:
|
|||
|
||||
// nsIXMLDocument interface
|
||||
NS_IMETHOD GetContentById(const nsString& aName, nsIContent** aContent);
|
||||
#ifdef XSL
|
||||
NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator);
|
||||
#endif
|
||||
|
||||
// nsIHTMLContentContainer
|
||||
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);
|
||||
|
@ -81,6 +87,9 @@ protected:
|
|||
|
||||
nsIParser *mParser;
|
||||
nsICSSLoader* mCSSLoader;
|
||||
#ifdef XSL
|
||||
nsITransformMediator* mTransformMediator;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS=src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,59 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
LIBRARY_NAME=raptorxsldoc_s
|
||||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor pref
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= \
|
||||
nsXSLContentSink.cpp \
|
||||
nsTransformMediator.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsXSLContentSink.obj \
|
||||
.\$(OBJDIR)\nsTransformMediator.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsIDocumentTransformer.h \
|
||||
nsITransformMediator.h \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
|
||||
-I..\..\..\html\style\src -I..\..\..\html\base\src -I$(PUBLIC)\dom \
|
||||
-I..\..\..\html\content\src -I..\..\..\html\document\src \
|
||||
-I..\..\..\xul\content\src -I..\..\..\xml\document\src \
|
||||
-I$(PUBLIC)\netlib -I..\..\..\base\src -I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\expat
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,59 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsITransformMediator_h___
|
||||
#define nsITransformMediator_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIDOMElement;
|
||||
class nsIDOMDocument;
|
||||
class nsIObserver;
|
||||
class nsIXMLContentSink;
|
||||
class nsString;
|
||||
|
||||
/* 6f4c2d0e-2cdf-11d3-aef3-00108300ff91 */
|
||||
#define NS_ITRANSFORM_MEDIATOR_IID \
|
||||
{ 0x6f4c2d0e, 0x2cdf, 0x11d3, {0xae, 0xf3, 0x00, 0x10, 0x83, 0x00, 0xff, 0x91} }
|
||||
|
||||
/**
|
||||
* This interface represents a mediator between raptor and an external
|
||||
* transformation engine. The following process of document transformation
|
||||
* is assumed : a source document, a stylesheet specifying the transform,
|
||||
* and an output document are passed to a transformation engine. All three
|
||||
* documents expose nsIDOMDocument interfaces. The transformation engine
|
||||
* uses the nsIDOMDocument interfaces to read the source document and
|
||||
* stylesheet, and write the output document.
|
||||
*/
|
||||
|
||||
class nsITransformMediator : public nsISupports {
|
||||
public:
|
||||
|
||||
NS_IMETHOD SetEnabled(PRBool aValue)=0;
|
||||
NS_IMETHOD SetSourceContentModel(nsIDOMElement* aSource)=0;
|
||||
NS_IMETHOD SetStyleSheetContentModel(nsIDOMElement* aStyle)=0;
|
||||
NS_IMETHOD SetCurrentDocument(nsIDOMDocument* aDoc)=0;
|
||||
NS_IMETHOD SetTransformObserver(nsIObserver* aObserver)=0;
|
||||
|
||||
};
|
||||
|
||||
extern nsresult NS_NewTransformMediator(nsITransformMediator** aInstancePtrResult,
|
||||
const nsString& aMimeType);
|
||||
|
||||
#endif // nsITransformMediator_h___
|
|
@ -0,0 +1,165 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTransformMediator.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kITransformMediatorIID, NS_ITRANSFORM_MEDIATOR_IID);
|
||||
static NS_DEFINE_IID(kIDocumentTransformerIID, NS_IDOCUMENT_TRANSFORMER_IID);
|
||||
|
||||
const char* kTransformerProgIDPrefix = "component://netscape/document-converter?type=";
|
||||
|
||||
nsresult
|
||||
NS_NewTransformMediator(nsITransformMediator** aResult,
|
||||
const nsString& aMimeType)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
||||
if (nsnull == aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsTransformMediator* it;
|
||||
NS_NEWXPCOM(it, nsTransformMediator);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = it->Init(aMimeType);
|
||||
if (NS_OK != rv) {
|
||||
delete it;
|
||||
return rv;
|
||||
}
|
||||
return it->QueryInterface(kITransformMediatorIID, (void **)aResult);
|
||||
}
|
||||
|
||||
nsTransformMediator::nsTransformMediator()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mEnabled = PR_FALSE;
|
||||
mTransformer = nsnull;
|
||||
mSourceDOM = nsnull;
|
||||
mStyleDOM = nsnull;
|
||||
mCurrentDoc = nsnull;
|
||||
mObserver = nsnull;
|
||||
}
|
||||
|
||||
nsTransformMediator::~nsTransformMediator()
|
||||
{
|
||||
NS_IF_RELEASE(mTransformer);
|
||||
NS_IF_RELEASE(mSourceDOM);
|
||||
NS_IF_RELEASE(mStyleDOM);
|
||||
mCurrentDoc = nsnull;
|
||||
NS_IF_RELEASE(mObserver);
|
||||
}
|
||||
|
||||
static
|
||||
nsresult ConstructProgID(nsString& aProgID, const nsString& aMimeType)
|
||||
{
|
||||
aProgID = kTransformerProgIDPrefix;
|
||||
aProgID.Append(aMimeType);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransformMediator::Init(const nsString& aMimeType)
|
||||
{
|
||||
nsString progID;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Construct prog ID for the document tranformer component
|
||||
rv = ConstructProgID(progID, aMimeType);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCID cid;
|
||||
char* progIDStr = (char*)progID.ToNewCString();
|
||||
rv = nsComponentManager::ProgIDToCLSID((const char*)progIDStr, &cid);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Try to find a component that implements the nsIDocumentTransformer interface
|
||||
rv = nsComponentManager::CreateInstance(cid, nsnull,
|
||||
kIDocumentTransformerIID, (void**) &mTransformer);
|
||||
}
|
||||
delete [] progIDStr;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// nsISupports
|
||||
NS_IMPL_ISUPPORTS(nsTransformMediator, kITransformMediatorIID)
|
||||
|
||||
|
||||
void
|
||||
nsTransformMediator::TryToTransform()
|
||||
{
|
||||
if (mEnabled && mSourceDOM &&
|
||||
mStyleDOM && mCurrentDoc &&
|
||||
mObserver && mTransformer)
|
||||
{
|
||||
mTransformer->TransformDocument(mSourceDOM,
|
||||
mStyleDOM,
|
||||
mCurrentDoc,
|
||||
mObserver);
|
||||
}
|
||||
}
|
||||
|
||||
// nsITransformMediator
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetEnabled(PRBool aValue)
|
||||
{
|
||||
mEnabled = aValue;
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetSourceContentModel(nsIDOMElement* aSource)
|
||||
{
|
||||
NS_IF_RELEASE(mSourceDOM);
|
||||
mSourceDOM = aSource;
|
||||
NS_IF_ADDREF(mSourceDOM);
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetStyleSheetContentModel(nsIDOMElement* aStyle)
|
||||
{
|
||||
NS_IF_RELEASE(mStyleDOM);
|
||||
mStyleDOM = aStyle;
|
||||
NS_IF_ADDREF(mStyleDOM);
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetCurrentDocument(nsIDOMDocument* aDoc)
|
||||
{
|
||||
mCurrentDoc = aDoc;
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetTransformObserver(nsIObserver* aObserver)
|
||||
{
|
||||
NS_IF_RELEASE(mObserver);
|
||||
mObserver = aObserver;
|
||||
NS_IF_ADDREF(mObserver);
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsTransformMediator_h__
|
||||
#define nsTransformMediator_h__
|
||||
|
||||
#include "nsITransformMediator.h"
|
||||
#include "nsIDocumentTransformer.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class nsTransformMediator : public nsITransformMediator {
|
||||
public:
|
||||
nsTransformMediator();
|
||||
virtual ~nsTransformMediator();
|
||||
|
||||
nsresult Init(const nsString& aMimeType);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsITransformMediator
|
||||
NS_IMETHOD SetEnabled(PRBool aValue);
|
||||
NS_IMETHOD SetSourceContentModel(nsIDOMElement* aSource);
|
||||
NS_IMETHOD SetStyleSheetContentModel(nsIDOMElement* aStyle);
|
||||
NS_IMETHOD SetCurrentDocument(nsIDOMDocument* aDoc);
|
||||
NS_IMETHOD SetTransformObserver(nsIObserver* aObserver);
|
||||
|
||||
protected:
|
||||
void TryToTransform();
|
||||
|
||||
PRBool mEnabled;
|
||||
nsIDocumentTransformer* mTransformer; // Strong reference
|
||||
nsIDOMElement* mSourceDOM; // Weak reference
|
||||
nsIDOMElement* mStyleDOM; // Weak reference
|
||||
nsIDOMDocument* mCurrentDoc; // Weak reference
|
||||
nsIObserver* mObserver; // Weak reference
|
||||
};
|
||||
|
||||
#endif // nsTransformMediator_h__
|
|
@ -18,12 +18,16 @@
|
|||
*/
|
||||
|
||||
#include "nsXSLContentSink.h"
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsITransformMediator.h"
|
||||
|
||||
static NS_DEFINE_IID(kIXMLContentSinkIID, NS_IXMLCONTENT_SINK_IID);
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
|
||||
nsresult
|
||||
NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
||||
nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURI* aURL,
|
||||
nsIWebShell* aWebShell)
|
||||
|
@ -37,7 +41,7 @@ NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
|||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = it->Init(aDoc, aURL, aWebShell);
|
||||
nsresult rv = it->Init(aTM, aDoc, aURL, aWebShell);
|
||||
if (NS_OK != rv) {
|
||||
delete it;
|
||||
return rv;
|
||||
|
@ -47,24 +51,27 @@ NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
|||
|
||||
nsXSLContentSink::nsXSLContentSink()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Empty
|
||||
}
|
||||
|
||||
nsXSLContentSink::~nsXSLContentSink()
|
||||
{
|
||||
|
||||
// Empty
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
nsresult
|
||||
nsXSLContentSink::Init(nsIDocument* aDoc,
|
||||
nsXSLContentSink::Init(nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURI* aURL,
|
||||
nsIWebShell* aContainer)
|
||||
{
|
||||
// We'll use nsXMLContentSink::Init() for now...
|
||||
}
|
||||
*/
|
||||
nsresult rv;
|
||||
rv = nsXMLContentSink::Init(aDoc, aURL, aContainer);
|
||||
mXSLTransformMediator = aTM;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHODIMP
|
||||
|
@ -76,6 +83,16 @@ nsXSLContentSink::WillBuildModel(void)
|
|||
NS_IMETHODIMP
|
||||
nsXSLContentSink::DidBuildModel(PRInt32 aQualityLevel)
|
||||
{
|
||||
nsIDOMElement* style;
|
||||
nsresult rv;
|
||||
|
||||
rv = mDocElement->QueryInterface(kIDOMElementIID, (void **) &style);
|
||||
if (NS_SUCCEEDED(rv) && mXSLTransformMediator) {
|
||||
// Pass the style content model to the tranform mediator.
|
||||
mXSLTransformMediator->SetStyleSheetContentModel(style);
|
||||
NS_RELEASE(style);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -142,14 +159,18 @@ nsXSLContentSink::AddComment(const nsIParserNode& aNode)
|
|||
NS_IMETHODIMP
|
||||
nsXSLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
||||
{
|
||||
return NS_OK;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
result = nsXMLContentSink::AddProcessingInstruction(aNode);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXSLContentSink::NotifyError(nsresult aErrorResult)
|
||||
nsXSLContentSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
printf("nsXSLContentSink::NotifyError\n");
|
||||
return NS_OK;
|
||||
nsresult result = NS_OK;
|
||||
result = nsXMLContentSink::NotifyError(aError);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,32 +31,44 @@ public:
|
|||
nsXSLContentSink();
|
||||
~nsXSLContentSink();
|
||||
|
||||
nsresult Init(nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aContainer);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
//NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHOD WillBuildModel(void);
|
||||
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
|
||||
NS_IMETHOD WillInterrupt(void);
|
||||
NS_IMETHOD WillResume(void);
|
||||
NS_IMETHOD SetParser(nsIParser* aParser);
|
||||
//NS_IMETHOD WillInterrupt(void);
|
||||
//NS_IMETHOD WillResume(void);
|
||||
//NS_IMETHOD SetParser(nsIParser* aParser);
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(nsresult aErrorResult);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
|
||||
// nsIXMLContentSink
|
||||
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||
|
||||
//NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
||||
nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aWebShell);
|
||||
#endif // nsXSLContentSink_h__
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
DIRS=document
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -581,6 +581,9 @@ public:
|
|||
|
||||
// nsIXMLDocument interface
|
||||
NS_IMETHOD GetContentById(const nsString& aName, nsIContent** aContent);
|
||||
#ifdef XSL
|
||||
NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator);
|
||||
#endif
|
||||
|
||||
// nsIRDFDocument interface
|
||||
NS_IMETHOD SetRootResource(nsIRDFResource* resource);
|
||||
|
@ -2337,6 +2340,14 @@ XULDocumentImpl::GetContentById(const nsString& aName, nsIContent** aContent)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#ifdef XSL
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::SetTransformMediator(nsITransformMediator* aMediator)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFDocument interface
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
DEPTH=..
|
||||
|
||||
DIRS=base html xml xul events build
|
||||
DIRS=base html xml xul events build \
|
||||
!if defined(MOZ_XSL)
|
||||
xsl \
|
||||
!endif
|
||||
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
|
||||
class nsIAtom;
|
||||
class nsICSSLoader;
|
||||
#ifdef XSL
|
||||
class nsITransformMediator;
|
||||
#endif
|
||||
|
||||
#define NS_IXMLDOCUMENT_IID \
|
||||
{ 0xa6cf90ca, 0x15b3, 0x11d2, \
|
||||
|
@ -38,6 +41,9 @@ public:
|
|||
// XXX This (or a variant thereof) should be in a DOM interface.
|
||||
// Since it isn't, we add it here temporarily
|
||||
NS_IMETHOD GetContentById(const nsString& aName, nsIContent** aContent)=0;
|
||||
#ifdef XSL
|
||||
NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator)=0;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // nsIXMLDocument_h___
|
||||
|
|
|
@ -21,7 +21,10 @@ LIBRARY_NAME=raptorxmldoc_s
|
|||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor pref
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN \
|
||||
!if defined(MOZ_XSL)
|
||||
-DXSL
|
||||
!endif
|
||||
|
||||
CPPSRCS= \
|
||||
nsXMLContentSink.cpp \
|
||||
|
@ -33,13 +36,13 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\nsXMLDocument.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
|
||||
-I..\..\..\html\style\src -I..\..\..\html\base\src -I$(PUBLIC)\dom \
|
||||
-I..\..\..\html\content\src -I..\..\..\html\document\src \
|
||||
-I..\..\..\xul\content\src \
|
||||
-I..\..\..\xul\content\src -I..\..\..\xsl\document\src \
|
||||
-I$(PUBLIC)\netlib -I..\..\..\base\src -I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\expat
|
||||
|
||||
|
|
|
@ -91,11 +91,14 @@ nsXMLDocument::nsXMLDocument()
|
|||
// XUL world lives within XML world until it gets a place of its own
|
||||
nsXULAtoms::AddrefAtoms();
|
||||
#endif
|
||||
#ifdef XSL
|
||||
mTransformMediator = nsnull;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsXMLDocument::~nsXMLDocument()
|
||||
{
|
||||
NS_IF_RELEASE(mParser);
|
||||
NS_IF_RELEASE(mParser);
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
mAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
NS_RELEASE(mAttrStyleSheet);
|
||||
|
@ -111,6 +114,9 @@ nsXMLDocument::~nsXMLDocument()
|
|||
#ifdef INCLUDE_XUL
|
||||
nsXULAtoms::ReleaseAtoms();
|
||||
#endif
|
||||
#ifdef XSL
|
||||
NS_IF_RELEASE(mTransformMediator);
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -461,6 +467,17 @@ nsXMLDocument::GetContentById(const nsString& aName, nsIContent** aContent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef XSL
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::SetTransformMediator(nsITransformMediator* aMediator)
|
||||
{
|
||||
NS_ASSERTION(nsnull == mTransformMediator, "nsXMLDocument::SetTransformMediator(): \
|
||||
Cannot set a second transform mediator\n");
|
||||
mTransformMediator = aMediator;
|
||||
NS_IF_ADDREF(mTransformMediator);
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#include "nsMarkupDocument.h"
|
||||
#include "nsIXMLDocument.h"
|
||||
#include "nsIHTMLContentContainer.h"
|
||||
#ifdef XSL
|
||||
#include "nsITransformMediator.h"
|
||||
#endif
|
||||
|
||||
class nsIParser;
|
||||
class nsIDOMNode;
|
||||
|
@ -64,6 +67,9 @@ public:
|
|||
|
||||
// nsIXMLDocument interface
|
||||
NS_IMETHOD GetContentById(const nsString& aName, nsIContent** aContent);
|
||||
#ifdef XSL
|
||||
NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator);
|
||||
#endif
|
||||
|
||||
// nsIHTMLContentContainer
|
||||
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);
|
||||
|
@ -81,6 +87,9 @@ protected:
|
|||
|
||||
nsIParser *mParser;
|
||||
nsICSSLoader* mCSSLoader;
|
||||
#ifdef XSL
|
||||
nsITransformMediator* mTransformMediator;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS=src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,59 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
LIBRARY_NAME=raptorxsldoc_s
|
||||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor pref
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= \
|
||||
nsXSLContentSink.cpp \
|
||||
nsTransformMediator.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsXSLContentSink.obj \
|
||||
.\$(OBJDIR)\nsTransformMediator.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsIDocumentTransformer.h \
|
||||
nsITransformMediator.h \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
|
||||
-I..\..\..\html\style\src -I..\..\..\html\base\src -I$(PUBLIC)\dom \
|
||||
-I..\..\..\html\content\src -I..\..\..\html\document\src \
|
||||
-I..\..\..\xul\content\src -I..\..\..\xml\document\src \
|
||||
-I$(PUBLIC)\netlib -I..\..\..\base\src -I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\expat
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,47 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIDocumentTransformer_h___
|
||||
#define nsIDocumentTransformer_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIDOMElement;
|
||||
class nsIDOMDocument;
|
||||
class nsIObserver;
|
||||
|
||||
/* 3fbff728-2d20-11d3-aef3-00108300ff91 */
|
||||
#define NS_IDOCUMENT_TRANSFORMER_IID \
|
||||
{ 0x3fbff728, 0x2d20, 0x11d3, {0xae, 0xf3, 0x00, 0x10, 0x83, 0x00, 0xff, 0x91} }
|
||||
|
||||
/**
|
||||
* This interface should be implemented by any object that wants to
|
||||
* transform the content model of the current document before the
|
||||
* document is displayed. One possible implementor of this interface
|
||||
* is an XSL processor.
|
||||
*/
|
||||
class nsIDocumentTransformer : public nsISupports {
|
||||
public:
|
||||
NS_IMETHOD TransformDocument(nsIDOMElement* aSourceDOM,
|
||||
nsIDOMElement* aStyleDOM,
|
||||
nsIDOMDocument* aOutputDoc,
|
||||
nsIObserver* aObserver)=0;
|
||||
};
|
||||
|
||||
#endif // nsIDocumentTransformer_h___
|
|
@ -0,0 +1,59 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsITransformMediator_h___
|
||||
#define nsITransformMediator_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIDOMElement;
|
||||
class nsIDOMDocument;
|
||||
class nsIObserver;
|
||||
class nsIXMLContentSink;
|
||||
class nsString;
|
||||
|
||||
/* 6f4c2d0e-2cdf-11d3-aef3-00108300ff91 */
|
||||
#define NS_ITRANSFORM_MEDIATOR_IID \
|
||||
{ 0x6f4c2d0e, 0x2cdf, 0x11d3, {0xae, 0xf3, 0x00, 0x10, 0x83, 0x00, 0xff, 0x91} }
|
||||
|
||||
/**
|
||||
* This interface represents a mediator between raptor and an external
|
||||
* transformation engine. The following process of document transformation
|
||||
* is assumed : a source document, a stylesheet specifying the transform,
|
||||
* and an output document are passed to a transformation engine. All three
|
||||
* documents expose nsIDOMDocument interfaces. The transformation engine
|
||||
* uses the nsIDOMDocument interfaces to read the source document and
|
||||
* stylesheet, and write the output document.
|
||||
*/
|
||||
|
||||
class nsITransformMediator : public nsISupports {
|
||||
public:
|
||||
|
||||
NS_IMETHOD SetEnabled(PRBool aValue)=0;
|
||||
NS_IMETHOD SetSourceContentModel(nsIDOMElement* aSource)=0;
|
||||
NS_IMETHOD SetStyleSheetContentModel(nsIDOMElement* aStyle)=0;
|
||||
NS_IMETHOD SetCurrentDocument(nsIDOMDocument* aDoc)=0;
|
||||
NS_IMETHOD SetTransformObserver(nsIObserver* aObserver)=0;
|
||||
|
||||
};
|
||||
|
||||
extern nsresult NS_NewTransformMediator(nsITransformMediator** aInstancePtrResult,
|
||||
const nsString& aMimeType);
|
||||
|
||||
#endif // nsITransformMediator_h___
|
|
@ -0,0 +1,165 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTransformMediator.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kITransformMediatorIID, NS_ITRANSFORM_MEDIATOR_IID);
|
||||
static NS_DEFINE_IID(kIDocumentTransformerIID, NS_IDOCUMENT_TRANSFORMER_IID);
|
||||
|
||||
const char* kTransformerProgIDPrefix = "component://netscape/document-converter?type=";
|
||||
|
||||
nsresult
|
||||
NS_NewTransformMediator(nsITransformMediator** aResult,
|
||||
const nsString& aMimeType)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
||||
if (nsnull == aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsTransformMediator* it;
|
||||
NS_NEWXPCOM(it, nsTransformMediator);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = it->Init(aMimeType);
|
||||
if (NS_OK != rv) {
|
||||
delete it;
|
||||
return rv;
|
||||
}
|
||||
return it->QueryInterface(kITransformMediatorIID, (void **)aResult);
|
||||
}
|
||||
|
||||
nsTransformMediator::nsTransformMediator()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mEnabled = PR_FALSE;
|
||||
mTransformer = nsnull;
|
||||
mSourceDOM = nsnull;
|
||||
mStyleDOM = nsnull;
|
||||
mCurrentDoc = nsnull;
|
||||
mObserver = nsnull;
|
||||
}
|
||||
|
||||
nsTransformMediator::~nsTransformMediator()
|
||||
{
|
||||
NS_IF_RELEASE(mTransformer);
|
||||
NS_IF_RELEASE(mSourceDOM);
|
||||
NS_IF_RELEASE(mStyleDOM);
|
||||
mCurrentDoc = nsnull;
|
||||
NS_IF_RELEASE(mObserver);
|
||||
}
|
||||
|
||||
static
|
||||
nsresult ConstructProgID(nsString& aProgID, const nsString& aMimeType)
|
||||
{
|
||||
aProgID = kTransformerProgIDPrefix;
|
||||
aProgID.Append(aMimeType);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransformMediator::Init(const nsString& aMimeType)
|
||||
{
|
||||
nsString progID;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Construct prog ID for the document tranformer component
|
||||
rv = ConstructProgID(progID, aMimeType);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCID cid;
|
||||
char* progIDStr = (char*)progID.ToNewCString();
|
||||
rv = nsComponentManager::ProgIDToCLSID((const char*)progIDStr, &cid);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Try to find a component that implements the nsIDocumentTransformer interface
|
||||
rv = nsComponentManager::CreateInstance(cid, nsnull,
|
||||
kIDocumentTransformerIID, (void**) &mTransformer);
|
||||
}
|
||||
delete [] progIDStr;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// nsISupports
|
||||
NS_IMPL_ISUPPORTS(nsTransformMediator, kITransformMediatorIID)
|
||||
|
||||
|
||||
void
|
||||
nsTransformMediator::TryToTransform()
|
||||
{
|
||||
if (mEnabled && mSourceDOM &&
|
||||
mStyleDOM && mCurrentDoc &&
|
||||
mObserver && mTransformer)
|
||||
{
|
||||
mTransformer->TransformDocument(mSourceDOM,
|
||||
mStyleDOM,
|
||||
mCurrentDoc,
|
||||
mObserver);
|
||||
}
|
||||
}
|
||||
|
||||
// nsITransformMediator
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetEnabled(PRBool aValue)
|
||||
{
|
||||
mEnabled = aValue;
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetSourceContentModel(nsIDOMElement* aSource)
|
||||
{
|
||||
NS_IF_RELEASE(mSourceDOM);
|
||||
mSourceDOM = aSource;
|
||||
NS_IF_ADDREF(mSourceDOM);
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetStyleSheetContentModel(nsIDOMElement* aStyle)
|
||||
{
|
||||
NS_IF_RELEASE(mStyleDOM);
|
||||
mStyleDOM = aStyle;
|
||||
NS_IF_ADDREF(mStyleDOM);
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetCurrentDocument(nsIDOMDocument* aDoc)
|
||||
{
|
||||
mCurrentDoc = aDoc;
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransformMediator::SetTransformObserver(nsIObserver* aObserver)
|
||||
{
|
||||
NS_IF_RELEASE(mObserver);
|
||||
mObserver = aObserver;
|
||||
NS_IF_ADDREF(mObserver);
|
||||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsTransformMediator_h__
|
||||
#define nsTransformMediator_h__
|
||||
|
||||
#include "nsITransformMediator.h"
|
||||
#include "nsIDocumentTransformer.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class nsTransformMediator : public nsITransformMediator {
|
||||
public:
|
||||
nsTransformMediator();
|
||||
virtual ~nsTransformMediator();
|
||||
|
||||
nsresult Init(const nsString& aMimeType);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsITransformMediator
|
||||
NS_IMETHOD SetEnabled(PRBool aValue);
|
||||
NS_IMETHOD SetSourceContentModel(nsIDOMElement* aSource);
|
||||
NS_IMETHOD SetStyleSheetContentModel(nsIDOMElement* aStyle);
|
||||
NS_IMETHOD SetCurrentDocument(nsIDOMDocument* aDoc);
|
||||
NS_IMETHOD SetTransformObserver(nsIObserver* aObserver);
|
||||
|
||||
protected:
|
||||
void TryToTransform();
|
||||
|
||||
PRBool mEnabled;
|
||||
nsIDocumentTransformer* mTransformer; // Strong reference
|
||||
nsIDOMElement* mSourceDOM; // Weak reference
|
||||
nsIDOMElement* mStyleDOM; // Weak reference
|
||||
nsIDOMDocument* mCurrentDoc; // Weak reference
|
||||
nsIObserver* mObserver; // Weak reference
|
||||
};
|
||||
|
||||
#endif // nsTransformMediator_h__
|
|
@ -18,12 +18,16 @@
|
|||
*/
|
||||
|
||||
#include "nsXSLContentSink.h"
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsITransformMediator.h"
|
||||
|
||||
static NS_DEFINE_IID(kIXMLContentSinkIID, NS_IXMLCONTENT_SINK_IID);
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
|
||||
nsresult
|
||||
NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
||||
nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURI* aURL,
|
||||
nsIWebShell* aWebShell)
|
||||
|
@ -37,7 +41,7 @@ NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
|||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = it->Init(aDoc, aURL, aWebShell);
|
||||
nsresult rv = it->Init(aTM, aDoc, aURL, aWebShell);
|
||||
if (NS_OK != rv) {
|
||||
delete it;
|
||||
return rv;
|
||||
|
@ -47,24 +51,27 @@ NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
|||
|
||||
nsXSLContentSink::nsXSLContentSink()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Empty
|
||||
}
|
||||
|
||||
nsXSLContentSink::~nsXSLContentSink()
|
||||
{
|
||||
|
||||
// Empty
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
nsresult
|
||||
nsXSLContentSink::Init(nsIDocument* aDoc,
|
||||
nsXSLContentSink::Init(nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURI* aURL,
|
||||
nsIWebShell* aContainer)
|
||||
{
|
||||
// We'll use nsXMLContentSink::Init() for now...
|
||||
}
|
||||
*/
|
||||
nsresult rv;
|
||||
rv = nsXMLContentSink::Init(aDoc, aURL, aContainer);
|
||||
mXSLTransformMediator = aTM;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHODIMP
|
||||
|
@ -76,6 +83,16 @@ nsXSLContentSink::WillBuildModel(void)
|
|||
NS_IMETHODIMP
|
||||
nsXSLContentSink::DidBuildModel(PRInt32 aQualityLevel)
|
||||
{
|
||||
nsIDOMElement* style;
|
||||
nsresult rv;
|
||||
|
||||
rv = mDocElement->QueryInterface(kIDOMElementIID, (void **) &style);
|
||||
if (NS_SUCCEEDED(rv) && mXSLTransformMediator) {
|
||||
// Pass the style content model to the tranform mediator.
|
||||
mXSLTransformMediator->SetStyleSheetContentModel(style);
|
||||
NS_RELEASE(style);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -142,14 +159,18 @@ nsXSLContentSink::AddComment(const nsIParserNode& aNode)
|
|||
NS_IMETHODIMP
|
||||
nsXSLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
||||
{
|
||||
return NS_OK;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
result = nsXMLContentSink::AddProcessingInstruction(aNode);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXSLContentSink::NotifyError(nsresult aErrorResult)
|
||||
nsXSLContentSink::NotifyError(const nsParserError* aError)
|
||||
{
|
||||
printf("nsXSLContentSink::NotifyError\n");
|
||||
return NS_OK;
|
||||
nsresult result = NS_OK;
|
||||
result = nsXMLContentSink::NotifyError(aError);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,32 +31,44 @@ public:
|
|||
nsXSLContentSink();
|
||||
~nsXSLContentSink();
|
||||
|
||||
nsresult Init(nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aContainer);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
//NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHOD WillBuildModel(void);
|
||||
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
|
||||
NS_IMETHOD WillInterrupt(void);
|
||||
NS_IMETHOD WillResume(void);
|
||||
NS_IMETHOD SetParser(nsIParser* aParser);
|
||||
//NS_IMETHOD WillInterrupt(void);
|
||||
//NS_IMETHOD WillResume(void);
|
||||
//NS_IMETHOD SetParser(nsIParser* aParser);
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(nsresult aErrorResult);
|
||||
NS_IMETHOD NotifyError(const nsParserError* aError);
|
||||
|
||||
// nsIXMLContentSink
|
||||
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||
|
||||
//NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||
//NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewXSLContentSink(nsIXMLContentSink** aResult,
|
||||
nsITransformMediator* aTM,
|
||||
nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aWebShell);
|
||||
#endif // nsXSLContentSink_h__
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
DIRS=document
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -581,6 +581,9 @@ public:
|
|||
|
||||
// nsIXMLDocument interface
|
||||
NS_IMETHOD GetContentById(const nsString& aName, nsIContent** aContent);
|
||||
#ifdef XSL
|
||||
NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator);
|
||||
#endif
|
||||
|
||||
// nsIRDFDocument interface
|
||||
NS_IMETHOD SetRootResource(nsIRDFResource* resource);
|
||||
|
@ -2337,6 +2340,14 @@ XULDocumentImpl::GetContentById(const nsString& aName, nsIContent** aContent)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#ifdef XSL
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::SetTransformMediator(nsITransformMediator* aMediator)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFDocument interface
|
||||
|
|
Загрузка…
Ссылка в новой задаче