Fix for bug 71367 (use Node::getBaseURI to resolve relative urls for import and include). Not part of default build. Patch by sicking, r=me, sr=shaver.

This commit is contained in:
peterv%netscape.com 2001-04-12 14:04:52 +00:00
Родитель be33a15835
Коммит 9fa9f6b879
3 изменённых файлов: 10 добавлений и 93 удалений

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

@ -25,13 +25,13 @@
* -- added code in ::resolveFunctionCall to support the * -- added code in ::resolveFunctionCall to support the
* document() function. * document() function.
* *
* $Id: ProcessorState.cpp,v 1.24 2001/04/11 15:01:05 axel%pike.org Exp $ * $Id: ProcessorState.cpp,v 1.25 2001/04/12 14:04:49 peterv%netscape.com Exp $
*/ */
/** /**
* Implementation of ProcessorState * Implementation of ProcessorState
* Much of this code was ported from XSL:P * Much of this code was ported from XSL:P
* @version $Revision: 1.24 $ $Date: 2001/04/11 15:01:05 $ * @version $Revision: 1.25 $ $Date: 2001/04/12 14:04:49 $
**/ **/
#include "ProcessorState.h" #include "ProcessorState.h"
@ -399,40 +399,6 @@ Stack* ProcessorState::getDefaultNSURIStack() {
return &defaultNameSpaceURIStack; return &defaultNameSpaceURIStack;
} //-- getDefaultNSURIStack } //-- getDefaultNSURIStack
/**
* Returns the global document base for resolving relative URIs within
* the XSL stylesheets
**/
const String& ProcessorState::getDocumentBase() {
return documentBase;
} //-- getDocumentBase
/**
* Returns the href for the given XSL document by looking in the
* includes and imports lists
**/
void ProcessorState::getDocumentHref
(Document* xslDocument, String& documentBase)
{
documentBase.clear();
//-- lookup includes
StringList* keys = includes.keys();
StringListIterator* iter = keys->iterator();
while (iter->hasNext()) {
String* key = iter->next();
TxObjectWrapper* objWrapper
= (TxObjectWrapper*)includes.get(*key);
if (xslDocument == objWrapper->object) {
documentBase.append(*key);
break;
}
}
delete iter;
delete keys;
} //-- getDocumentBase
/** /**
* @return the included xsl document that was associated with the * @return the included xsl document that was associated with the
* given href, or null if no document is found * given href, or null if no document is found
@ -674,10 +640,6 @@ void ProcessorState::setDefaultNameSpaceURIForResult(const String& nsURI) {
/** /**
* Sets the document base for use when resolving relative URIs * Sets the document base for use when resolving relative URIs
**/ **/
void ProcessorState::setDocumentBase(const String& documentBase) {
this->documentBase = documentBase;
} //-- setDocumentBase
/** /**
* Sets the output method. Valid output method options are, * Sets the output method. Valid output method options are,
* "xml", "html", or "text". * "xml", "html", or "text".

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

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net * Keith Visco, kvisco@ziplink.net
* -- original author. * -- original author.
* *
* $Id: ProcessorState.h,v 1.12 2001/04/08 14:33:28 peterv%netscape.com Exp $ * $Id: ProcessorState.h,v 1.13 2001/04/12 14:04:52 peterv%netscape.com Exp $
*/ */
@ -43,7 +43,7 @@
/** /**
* Class used for keeping the current state of the XSL Processor * Class used for keeping the current state of the XSL Processor
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a> * @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.12 $ $Date: 2001/04/08 14:33:28 $ * @version $Revision: 1.13 $ $Date: 2001/04/12 14:04:52 $
**/ **/
class ProcessorState : public ContextState { class ProcessorState : public ContextState {
@ -127,17 +127,6 @@ public:
**/ **/
Stack* getDefaultNSURIStack(); Stack* getDefaultNSURIStack();
/**
* Returns the document base for resolving relative URIs
**/
const String& getDocumentBase();
/**
* Returns the href for the given xsl document by returning
* it's reference from the include or import list
**/
void getDocumentHref(Document* xslDocument, String& documentBase);
/** /**
* @return the included xsl document that was associated with the * @return the included xsl document that was associated with the
* given href, or null if no document is found * given href, or null if no document is found
@ -242,11 +231,6 @@ public:
**/ **/
void setDefaultNameSpaceURIForResult(const String& nsURI); void setDefaultNameSpaceURIForResult(const String& nsURI);
/**
* Sets the document base for including and importing stylesheets
**/
void setDocumentBase(const String& documentBase);
/** /**
* Sets the output method. Valid output method options are, * Sets the output method. Valid output method options are,
* "xml", "html", or "text". * "xml", "html", or "text".
@ -435,8 +419,6 @@ private:
Element* dfWildCardTemplate; Element* dfWildCardTemplate;
Element* dfTextTemplate; Element* dfTextTemplate;
String documentBase;
/** /**
* Returns the closest xml:space value for the given node * Returns the closest xml:space value for the given node
**/ **/

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

@ -38,7 +38,7 @@
* Olivier Gerardin * Olivier Gerardin
* -- Changed behavior of passing parameters to templates * -- Changed behavior of passing parameters to templates
* *
* $Id: XSLTProcessor.cpp,v 1.41 2001/04/12 10:13:59 peterv%netscape.com Exp $ * $Id: XSLTProcessor.cpp,v 1.42 2001/04/12 14:04:45 peterv%netscape.com Exp $
*/ */
#include "XSLTProcessor.h" #include "XSLTProcessor.h"
@ -68,7 +68,7 @@
/** /**
* XSLTProcessor is a class for Processing XSL stylesheets * XSLTProcessor is a class for Processing XSL stylesheets
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a> * @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.41 $ $Date: 2001/04/12 10:13:59 $ * @version $Revision: 1.42 $ $Date: 2001/04/12 14:04:45 $
**/ **/
/** /**
@ -428,21 +428,19 @@ void XSLTProcessor::processTopLevel
//-- Read in XSL document //-- Read in XSL document
if (ps->getInclude(href)) { if (ps->getInclude(href)) {
/* XXX this is wrong, it's allowed to include one stylesheet multiple
times but we should build some sort of stack to make sure that we
don't have circular inclusions */
String err("stylesheet already included: "); String err("stylesheet already included: ");
err.append(href); err.append(href);
notifyError(err, ErrorObserver::WARNING); notifyError(err, ErrorObserver::WARNING);
break; break;
} }
//-- get document base
String realHref;
String thisDocBase = ps->getDocumentBase();
String errMsg; String errMsg;
XMLParser xmlParser; XMLParser xmlParser;
URIUtils::resolveHref(href, thisDocBase, realHref); Document* xslDoc = xmlParser.getDocumentFromURI(href, element->getBaseURI(), errMsg);
Document* xslDoc = xmlParser.getDocumentFromURI(realHref, thisDocBase, errMsg);
if (!xslDoc) { if (!xslDoc) {
String err("error including XSL stylesheet: "); String err("error including XSL stylesheet: ");
@ -454,11 +452,7 @@ void XSLTProcessor::processTopLevel
else { else {
//-- add stylesheet to list of includes //-- add stylesheet to list of includes
ps->addInclude(href, xslDoc); ps->addInclude(href, xslDoc);
String newDocBase;
URIUtils::getDocumentBase(realHref, newDocBase);
ps->setDocumentBase(newDocBase);
processTopLevel(xslDoc, ps); processTopLevel(xslDoc, ps);
ps->setDocumentBase(thisDocBase);
} }
break; break;
@ -552,7 +546,6 @@ Document* XSLTProcessor::process
//-- create a new ProcessorState //-- create a new ProcessorState
ProcessorState ps(xslDocument, *result); ProcessorState ps(xslDocument, *result);
ps.setDocumentBase(xslDocument.getBaseURI());
//-- add error observers //-- add error observers
ListIterator* iter = errorObservers.iterator(); ListIterator* iter = errorObservers.iterator();
@ -591,7 +584,6 @@ void XSLTProcessor::process
//-- create a new ProcessorState //-- create a new ProcessorState
ProcessorState ps(xslDocument, *result); ProcessorState ps(xslDocument, *result);
ps.setDocumentBase(xslDocument.getBaseURI());
//-- add error observers //-- add error observers
ListIterator* iter = errorObservers.iterator(); ListIterator* iter = errorObservers.iterator();
@ -1754,25 +1746,6 @@ XSLTProcessor::TransformDocument(nsIDOMNode* aSourceDOM,
//-- create a new ProcessorState //-- create a new ProcessorState
ProcessorState* ps = new ProcessorState(*xslDocument, *resultDocument); ProcessorState* ps = new ProcessorState(*xslDocument, *resultDocument);
// XXX HACK, baseURI is something to be done in the DOM
nsIURI* docURL = nsnull;
nsCOMPtr<nsIDocument> sourceNsDocument = do_QueryInterface(styleDOMDocument);
sourceNsDocument->GetBaseURL(docURL);
if (docURL) {
char* urlString;
docURL->GetSpec(&urlString);
String documentBase(urlString);
// NS_IMPL_LOG(XSLT)
// PRINTF("Transforming with stylesheet %s",documentBase.toCharArray());
// FLUSH();
ps->setDocumentBase(documentBase);
nsCRT::free(urlString);
NS_IF_RELEASE(docURL);
}
else
ps->setDocumentBase("");
//-- add error observers //-- add error observers
//------------------------------------------------------/ //------------------------------------------------------/