2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2005-11-02 07:42:04 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2005-11-02 07:33:49 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* 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/
|
2005-11-02 07:33:49 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* 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.
|
2005-11-02 07:33:49 +00:00
|
|
|
*
|
2005-11-02 07:42:05 +00:00
|
|
|
* The Original Code is TransforMiiX XSLT processor code.
|
2005-11-02 07:33:49 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The MITRE Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2005-11-02 07:33:49 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2005-11-02 07:42:05 +00:00
|
|
|
* Keith Visco <kvisco@ziplink.net> (Original Author)
|
|
|
|
* Larry Fitzpatrick, OpenText <lef@opentext.com>
|
2005-11-02 07:33:49 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* 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.
|
2005-11-02 07:33:49 +00:00
|
|
|
*
|
2005-11-02 07:42:04 +00:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2005-11-02 07:33:49 +00:00
|
|
|
|
|
|
|
#include "txURIUtils.h"
|
|
|
|
#include "nsNetUtil.h"
|
2005-11-02 07:39:26 +00:00
|
|
|
#include "nsIAttribute.h"
|
2005-11-02 07:38:05 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIContent.h"
|
2005-11-02 07:38:08 +00:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsINodeInfo.h"
|
2005-11-02 07:33:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* URIUtils
|
|
|
|
* A set of utilities for handling URIs
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves the given href argument, using the given documentBase
|
|
|
|
* if necessary.
|
|
|
|
* The new resolved href will be appended to the given dest String
|
|
|
|
**/
|
2005-11-02 07:39:22 +00:00
|
|
|
void URIUtils::resolveHref(const nsAString& href, const nsAString& base,
|
|
|
|
nsAString& dest) {
|
2005-11-02 07:38:52 +00:00
|
|
|
if (base.IsEmpty()) {
|
|
|
|
dest.Append(href);
|
2005-11-02 07:33:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-11-02 07:38:52 +00:00
|
|
|
if (href.IsEmpty()) {
|
|
|
|
dest.Append(base);
|
2005-11-02 07:33:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> pURL;
|
2005-11-02 07:39:22 +00:00
|
|
|
nsAutoString resultHref;
|
Landing TX_BRIDGE_1_1_BRANCH.
Rewrite pretty much all variable and parameter handling. Makes global and local variables be handled differently. Global variables are no longer part of the variables stack, and are lazily evaluated. Fixes bugs 117658, 92929 and some unfiled bugs and fixes remaining parts of bugs 83651 and 96802. Patch by sicking, r=Pike sr=bz.
Fix for bug 156464: fix rounding problems in module, allow patterns without any '0's in the integer part and fix problems with grouping for standalone. Patch by sicking, r=Pike sr=bz.
Fix for bug 157340 (Probable bugs in extensions/transformiix/source/base/txMozillaString.h). Patch by peterv, r=Pike, sr=bz.
Fix for bug 146967 (Clean up Transformiix strings). Patch by peterv, r=sicking, sr=jst.
Fix for bug 156464 (Remove static strings from Transformiix). Patch by peterv, r=Pike, sr=jst.
2005-11-02 07:38:17 +00:00
|
|
|
nsresult result = NS_NewURI(getter_AddRefs(pURL), base);
|
2005-11-02 07:33:49 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
Landing TX_BRIDGE_1_1_BRANCH.
Rewrite pretty much all variable and parameter handling. Makes global and local variables be handled differently. Global variables are no longer part of the variables stack, and are lazily evaluated. Fixes bugs 117658, 92929 and some unfiled bugs and fixes remaining parts of bugs 83651 and 96802. Patch by sicking, r=Pike sr=bz.
Fix for bug 156464: fix rounding problems in module, allow patterns without any '0's in the integer part and fix problems with grouping for standalone. Patch by sicking, r=Pike sr=bz.
Fix for bug 157340 (Probable bugs in extensions/transformiix/source/base/txMozillaString.h). Patch by peterv, r=Pike, sr=bz.
Fix for bug 146967 (Clean up Transformiix strings). Patch by peterv, r=sicking, sr=jst.
Fix for bug 156464 (Remove static strings from Transformiix). Patch by peterv, r=Pike, sr=jst.
2005-11-02 07:38:17 +00:00
|
|
|
NS_MakeAbsoluteURI(resultHref, href, pURL);
|
2005-11-02 07:38:52 +00:00
|
|
|
dest.Append(resultHref);
|
2005-11-02 07:33:49 +00:00
|
|
|
}
|
|
|
|
} //-- resolveHref
|
|
|
|
|
2005-11-02 07:40:49 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode)
|
|
|
|
{
|
2006-02-02 20:02:34 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aSourceNode);
|
|
|
|
if (!node) {
|
2006-01-10 21:58:25 +00:00
|
|
|
// XXXbz passing nsnull as the first arg to Reset is illegal
|
2005-11-02 07:40:49 +00:00
|
|
|
aNewDoc->Reset(nsnull, nsnull);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-02 20:02:34 +00:00
|
|
|
nsCOMPtr<nsIDocument> sourceDoc = node->GetOwnerDoc();
|
2005-11-02 07:40:49 +00:00
|
|
|
if (!sourceDoc) {
|
2006-02-02 20:02:34 +00:00
|
|
|
NS_ERROR("no source document found");
|
2006-01-10 21:58:25 +00:00
|
|
|
// XXXbz passing nsnull as the first arg to Reset is illegal
|
2005-11-02 07:40:49 +00:00
|
|
|
aNewDoc->Reset(nsnull, nsnull);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-04-27 18:21:11 +00:00
|
|
|
nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal();
|
2006-01-10 21:58:25 +00:00
|
|
|
|
2006-01-04 06:38:46 +00:00
|
|
|
// Copy the channel and loadgroup from the source document.
|
2005-11-02 07:41:29 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup();
|
2006-01-10 21:58:25 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel = sourceDoc->GetChannel();
|
|
|
|
if (!channel) {
|
|
|
|
// Need to synthesize one
|
|
|
|
if (NS_FAILED(NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
sourceDoc->GetDocumentURI(),
|
|
|
|
nsnull,
|
|
|
|
loadGroup))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
channel->SetOwner(sourcePrincipal);
|
|
|
|
}
|
|
|
|
aNewDoc->Reset(channel, loadGroup);
|
|
|
|
aNewDoc->SetPrincipal(sourcePrincipal);
|
2010-04-19 15:40:15 +00:00
|
|
|
aNewDoc->SetBaseURI(sourceDoc->GetDocBaseURI());
|
2005-11-02 07:40:49 +00:00
|
|
|
|
2005-11-02 07:41:33 +00:00
|
|
|
// Copy charset
|
|
|
|
aNewDoc->SetDocumentCharacterSetSource(
|
|
|
|
sourceDoc->GetDocumentCharacterSetSource());
|
2007-05-09 02:47:58 +00:00
|
|
|
aNewDoc->SetDocumentCharacterSet(sourceDoc->GetDocumentCharacterSet());
|
2005-11-02 07:40:49 +00:00
|
|
|
}
|