зеркало из https://github.com/mozilla/pjs.git
Fix for bug 106844 (XSLT stylesheet of type text/xml not recognized; type text/xsl is recognized). r=heikki, sr=jst.
This commit is contained in:
Родитель
0699f99205
Коммит
b10fc55a1e
|
@ -104,7 +104,7 @@
|
|||
|
||||
static char kNameSpaceSeparator = ':';
|
||||
static char kStyleSheetPI[] = "xml-stylesheet";
|
||||
static char kXSLType[] = "text/xsl";
|
||||
#define kXSLType "text/xsl"
|
||||
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
@ -1052,25 +1052,16 @@ ParseProcessingInstruction(const nsString& aText,
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLContentSink::CreateStyleSheetURL(nsIURI** aUrl,
|
||||
const nsAReadableString& aHref)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
result = NS_NewURI(aUrl, aHref, mDocumentBaseURL);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
// Create an XML parser and an XSL content sink and start parsing
|
||||
// the XSL stylesheet located at the given URL.
|
||||
nsresult
|
||||
nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl, const nsString& aType)
|
||||
nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Create a transform mediator
|
||||
rv = NS_NewTransformMediator(getter_AddRefs(mXSLTransformMediator), aType);
|
||||
rv = NS_NewTransformMediator(getter_AddRefs(mXSLTransformMediator),
|
||||
NS_LITERAL_CSTRING(kXSLType));
|
||||
if (NS_FAILED(rv)) {
|
||||
// No XSLT processor available, continue normal document loading
|
||||
return NS_OK;
|
||||
|
@ -1131,38 +1122,26 @@ nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl, const nsString& aType)
|
|||
|
||||
nsresult
|
||||
nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
|
||||
const nsString& aHref, PRBool aAlternate,
|
||||
const nsString& aTitle, const nsString& aType,
|
||||
const nsString& aHref,
|
||||
PRBool aAlternate,
|
||||
const nsString& aTitle,
|
||||
const nsString& aType,
|
||||
const nsString& aMedia)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (aType.EqualsIgnoreCase(kXSLType) ||
|
||||
aType.EqualsIgnoreCase(kXMLTextContentType) ||
|
||||
aType.EqualsIgnoreCase(kXMLApplicationContentType))
|
||||
rv = ProcessXSLStyleLink(aElement, aHref, aAlternate, aTitle, aType, aMedia);
|
||||
aType.EqualsIgnoreCase(kXMLApplicationContentType)) {
|
||||
// LoadXSLStyleSheet needs a mWebShell.
|
||||
if (!mWebShell)
|
||||
return NS_OK;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLContentSink::ProcessXSLStyleLink(nsIContent* aElement,
|
||||
const nsString& aHref, PRBool aAlternate,
|
||||
const nsString& aTitle, const nsString& aType,
|
||||
const nsString& aMedia)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIURI* url;
|
||||
|
||||
// LoadXSLStyleSheet needs a mWebShell.
|
||||
if (!mWebShell) return rv;
|
||||
|
||||
rv = CreateStyleSheetURL(&url, aHref);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = LoadXSLStyleSheet(url, aType);
|
||||
NS_RELEASE(url);
|
||||
nsCOMPtr<nsIURI> url;
|
||||
rv = NS_NewURI(getter_AddRefs(url), aHref, mDocumentBaseURL);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = LoadXSLStyleSheet(url);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,22 +161,16 @@ protected:
|
|||
|
||||
nsresult RefreshIfEnabled(nsIViewManager* vm);
|
||||
|
||||
nsresult ProcessCSSStyleLink(nsIContent* aElement,
|
||||
const nsString& aHref, PRBool aAlternate,
|
||||
const nsString& aTitle, const nsString& aType,
|
||||
const nsString& aMedia);
|
||||
nsresult ProcessStyleLink(nsIContent* aElement,
|
||||
const nsString& aHref, PRBool aAlternate,
|
||||
const nsString& aTitle, const nsString& aType,
|
||||
const nsString& aHref,
|
||||
PRBool aAlternate,
|
||||
const nsString& aTitle,
|
||||
const nsString& aType,
|
||||
const nsString& aMedia);
|
||||
|
||||
nsresult ProcessXSLStyleLink(nsIContent* aElement,
|
||||
const nsString& aHref, PRBool aAlternate,
|
||||
const nsString& aTitle, const nsString& aType,
|
||||
const nsString& aMedia);
|
||||
nsresult CreateStyleSheetURL(nsIURI** aUrl, const nsAReadableString& aHref);
|
||||
nsresult LoadXSLStyleSheet(nsIURI* aUrl, const nsString& aType);
|
||||
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
||||
nsresult SetupTransformMediator();
|
||||
|
||||
nsresult AddText(const nsAReadableString& aString);
|
||||
|
||||
static void
|
||||
|
|
|
@ -40,12 +40,12 @@
|
|||
#define nsITransformMediator_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsAString.h"
|
||||
|
||||
class nsIDOMNode;
|
||||
class nsIDOMDocument;
|
||||
class nsIObserver;
|
||||
class nsIXMLContentSink;
|
||||
class nsString;
|
||||
|
||||
/* 6f4c2d0e-2cdf-11d3-aef3-00108300ff91 */
|
||||
#define NS_ITRANSFORM_MEDIATOR_IID \
|
||||
|
@ -63,7 +63,7 @@ class nsString;
|
|||
|
||||
class nsITransformMediator : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ITRANSFORM_MEDIATOR_IID; return iid; }
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITRANSFORM_MEDIATOR_IID);
|
||||
|
||||
NS_IMETHOD SetEnabled(PRBool aValue)=0;
|
||||
NS_IMETHOD SetSourceContentModel(nsIDOMNode* aSource)=0;
|
||||
|
@ -75,6 +75,6 @@ public:
|
|||
};
|
||||
|
||||
extern nsresult NS_NewTransformMediator(nsITransformMediator** aInstancePtrResult,
|
||||
const nsString& aMimeType);
|
||||
const nsACString& aMimeType);
|
||||
|
||||
#endif // nsITransformMediator_h___
|
||||
|
|
|
@ -35,31 +35,29 @@
|
|||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTransformMediator.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
nsresult
|
||||
NS_NewTransformMediator(nsITransformMediator** aResult,
|
||||
const nsString& aMimeType)
|
||||
NS_NewTransformMediator(nsITransformMediator** aInstancePtrResult,
|
||||
const nsACString& aMimeType)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
||||
if (nsnull == aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsTransformMediator* it;
|
||||
NS_NEWXPCOM(it, nsTransformMediator);
|
||||
if (nsnull == it) {
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = it->Init(aMimeType);
|
||||
if (NS_OK != rv) {
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
return rv;
|
||||
}
|
||||
return it->QueryInterface(NS_GET_IID(nsITransformMediator), (void **)aResult);
|
||||
return CallQueryInterface(it, aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsTransformMediator::nsTransformMediator()
|
||||
|
@ -73,45 +71,40 @@ nsTransformMediator::~nsTransformMediator()
|
|||
}
|
||||
|
||||
static
|
||||
nsresult ConstructContractID(nsCString& aContractID, const nsString& aMimeType)
|
||||
nsresult ConstructContractID(nsACString& aContractID,
|
||||
const nsACString& aMimeType)
|
||||
{
|
||||
aContractID.Assign(NS_LITERAL_CSTRING("@mozilla.org/document-transformer;1?type="));
|
||||
aContractID.AppendWithConversion(aMimeType);
|
||||
|
||||
aContractID.Append(aMimeType);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransformMediator::Init(const nsString& aMimeType)
|
||||
nsTransformMediator::Init(const nsACString& aMimeType)
|
||||
{
|
||||
nsCString contractID;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Construct prog ID for the document tranformer component
|
||||
rv = ConstructContractID(contractID, aMimeType);
|
||||
nsCAutoString contractID;
|
||||
nsresult rv = ConstructContractID(contractID, aMimeType);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Try to find a component that implements the nsIDocumentTransformer interface
|
||||
mTransformer = do_CreateInstance(contractID.get(), &rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// nsISupports
|
||||
NS_IMPL_ISUPPORTS1(nsTransformMediator, nsITransformMediator)
|
||||
|
||||
|
||||
void
|
||||
nsTransformMediator::TryToTransform()
|
||||
{
|
||||
if (mEnabled && mSourceDOM &&
|
||||
mStyleDOM && mResultDoc &&
|
||||
mObserver && mTransformer)
|
||||
if (mEnabled && mSourceDOM && mStyleDOM &&
|
||||
mResultDoc && mObserver && mTransformer)
|
||||
{
|
||||
mTransformer->TransformDocument(mSourceDOM,
|
||||
mStyleDOM,
|
||||
mResultDoc,
|
||||
mObserver);
|
||||
mStyleDOM,
|
||||
mResultDoc,
|
||||
mObserver);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,4 +156,3 @@ nsTransformMediator::SetTransformObserver(nsIObserver* aObserver)
|
|||
TryToTransform();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
nsTransformMediator();
|
||||
virtual ~nsTransformMediator();
|
||||
|
||||
nsresult Init(const nsString& aMimeType);
|
||||
nsresult Init(const nsACString& aMimeType);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
|
Загрузка…
Ссылка в новой задаче