Back to index

lightning-sunbird  0.9+nobinonly
nsAddbookUrl.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsIURI.h"
00039 #include "nsNetCID.h"
00040 #include "nsAddbookUrl.h"
00041 #include "nsString.h"
00042 #include "nsXPIDLString.h"
00043 #include "nsAbBaseCID.h"
00044 #include "nsEscape.h"
00045 
00047 // addbook url definition
00049 nsAddbookUrl::nsAddbookUrl()
00050 {
00051   m_baseURL = do_CreateInstance(NS_SIMPLEURI_CONTRACTID);
00052 
00053   mOperationType = nsIAddbookUrlOperation::InvalidUrl; 
00054 }
00055 
00056 nsAddbookUrl::~nsAddbookUrl()
00057 {
00058 }
00059 
00060 NS_IMPL_ISUPPORTS2(nsAddbookUrl, nsIAddbookUrl, nsIURI)
00061 
00062 NS_IMETHODIMP 
00063 nsAddbookUrl::SetSpec(const nsACString &aSpec)
00064 {
00065   m_baseURL->SetSpec(aSpec);
00066        return ParseUrl();
00067 }
00068 
00069 nsresult nsAddbookUrl::ParseUrl()
00070 {
00071   nsCAutoString pathStr;
00072 
00073   nsresult rv = m_baseURL->GetPath(pathStr);
00074   NS_ENSURE_SUCCESS(rv,rv);
00075 
00076   if (strstr(pathStr.get(), "?action=print"))
00077     mOperationType = nsIAddbookUrlOperation::PrintAddressBook;
00078   else if (strstr(pathStr.get(), "?action=add"))
00079     mOperationType = nsIAddbookUrlOperation::AddVCard;
00080   else
00081     mOperationType = nsIAddbookUrlOperation::InvalidUrl;
00082   return NS_OK;
00083 }
00084 
00086 // Begin nsIURI support
00088 
00089 
00090 NS_IMETHODIMP nsAddbookUrl::GetSpec(nsACString &aSpec)
00091 {
00092        return m_baseURL->GetSpec(aSpec);
00093 }
00094 
00095 NS_IMETHODIMP nsAddbookUrl::GetPrePath(nsACString &aPrePath)
00096 {
00097        return m_baseURL->GetPrePath(aPrePath);
00098 }
00099 
00100 NS_IMETHODIMP nsAddbookUrl::GetScheme(nsACString &aScheme)
00101 {
00102        return m_baseURL->GetScheme(aScheme);
00103 }
00104 
00105 NS_IMETHODIMP nsAddbookUrl::SetScheme(const nsACString &aScheme)
00106 {
00107        return m_baseURL->SetScheme(aScheme);
00108 }
00109 
00110 NS_IMETHODIMP nsAddbookUrl::GetUserPass(nsACString &aUserPass)
00111 {
00112        return m_baseURL->GetUserPass(aUserPass);
00113 }
00114 
00115 NS_IMETHODIMP nsAddbookUrl::SetUserPass(const nsACString &aUserPass)
00116 {
00117        return m_baseURL->SetUserPass(aUserPass);
00118 }
00119 
00120 NS_IMETHODIMP nsAddbookUrl::GetUsername(nsACString &aUsername)
00121 {
00122        return m_baseURL->GetUsername(aUsername);
00123 }
00124 
00125 NS_IMETHODIMP nsAddbookUrl::SetUsername(const nsACString &aUsername)
00126 {
00127        return m_baseURL->SetUsername(aUsername);
00128 }
00129 
00130 NS_IMETHODIMP nsAddbookUrl::GetPassword(nsACString &aPassword)
00131 {
00132        return m_baseURL->GetPassword(aPassword);
00133 }
00134 
00135 NS_IMETHODIMP nsAddbookUrl::SetPassword(const nsACString &aPassword)
00136 {
00137        return m_baseURL->SetPassword(aPassword);
00138 }
00139 
00140 NS_IMETHODIMP nsAddbookUrl::GetHostPort(nsACString &aHostPort)
00141 {
00142        return m_baseURL->GetHostPort(aHostPort);
00143 }
00144 
00145 NS_IMETHODIMP nsAddbookUrl::SetHostPort(const nsACString &aHostPort)
00146 {
00147        return m_baseURL->SetHostPort(aHostPort);
00148 }
00149 
00150 NS_IMETHODIMP nsAddbookUrl::GetHost(nsACString &aHost)
00151 {
00152        return m_baseURL->GetHost(aHost);
00153 }
00154 
00155 NS_IMETHODIMP nsAddbookUrl::SetHost(const nsACString &aHost)
00156 {
00157        return m_baseURL->SetHost(aHost);
00158 }
00159 
00160 NS_IMETHODIMP nsAddbookUrl::GetPort(PRInt32 *aPort)
00161 {
00162        return m_baseURL->GetPort(aPort);
00163 }
00164 
00165 NS_IMETHODIMP nsAddbookUrl::SetPort(PRInt32 aPort)
00166 {
00167        return m_baseURL->SetPort(aPort);
00168 }
00169 
00170 NS_IMETHODIMP nsAddbookUrl::GetPath(nsACString &aPath)
00171 {
00172        return m_baseURL->GetPath(aPath);
00173 }
00174 
00175 NS_IMETHODIMP nsAddbookUrl::SetPath(const nsACString &aPath)
00176 {
00177        return m_baseURL->SetPath(aPath);
00178 }
00179 
00180 NS_IMETHODIMP nsAddbookUrl::GetAsciiHost(nsACString &aHostA)
00181 {
00182        return m_baseURL->GetAsciiHost(aHostA);
00183 }
00184 
00185 NS_IMETHODIMP nsAddbookUrl::GetAsciiSpec(nsACString &aSpecA)
00186 {
00187        return m_baseURL->GetAsciiSpec(aSpecA);
00188 }
00189 
00190 NS_IMETHODIMP nsAddbookUrl::GetOriginCharset(nsACString &aOriginCharset)
00191 {
00192     return m_baseURL->GetOriginCharset(aOriginCharset);
00193 }
00194 
00195 NS_IMETHODIMP nsAddbookUrl::SchemeIs(const char *aScheme, PRBool *_retval)
00196 {
00197        return m_baseURL->SchemeIs(aScheme, _retval);
00198 }
00199 
00200 NS_IMETHODIMP nsAddbookUrl::Equals(nsIURI *other, PRBool *_retval)
00201 {
00202        return m_baseURL->Equals(other, _retval);
00203 }
00204 
00205 NS_IMETHODIMP nsAddbookUrl::Clone(nsIURI **_retval)
00206 {
00207        return m_baseURL->Clone(_retval);
00208 }      
00209 
00210 NS_IMETHODIMP nsAddbookUrl::Resolve(const nsACString &relativePath, nsACString &result) 
00211 {
00212        return m_baseURL->Resolve(relativePath, result);
00213 }
00214 
00215 //
00216 // Specific nsAddbookUrl operations
00217 //
00218 NS_IMETHODIMP 
00219 nsAddbookUrl::GetAddbookOperation(PRInt32 *_retval)
00220 {
00221   *_retval = mOperationType;
00222   return NS_OK;
00223 }