1 //
2 // C++ Implementation: UrlName
3 //
4 // Description: Implements a class with handle url's and permits to return
5 //              filenames, paths, host and verify if this is complete or not.
6 //
7 //
8 // Author: Max Magalhães Velasques <maxvelasques@gmail.com>, (C) 2006
9 //
10 // Copyright: See COPYING file that comes with this distribution
11 //
12 //
13 
14 #include "wxDFast.h"
15 
mUrlName()16 mUrlName::mUrlName() : wxURI()
17 {
18 }
19 
mUrlName(wxString uri)20 mUrlName::mUrlName(wxString uri)
21 {
22     wxString m_uri = uri;
23     //COMPLETE THE ADDRESS
24     if ((m_uri.Mid(0,4).Lower()) == wxT("www."))
25         m_uri = wxT("http://") + m_uri;
26     else if ((m_uri.Mid(0,4).Lower()) == wxT("ftp."))
27         m_uri = wxT("ftp://") + m_uri;
28     else if ((m_uri.Mid(0,1).Lower()) == wxT("/"))
29         m_uri = wxT("file://") + m_uri;
30     else if ((m_uri.Mid(1,1).Lower()) == wxT(":"))
31         m_uri = wxT("file://") + m_uri;
32 
33     wxURI::Create(m_uri);
34     if (wxURI::HasScheme())
35     {
36         wxString scheme = wxURI::GetScheme().Lower();
37         if ((scheme != wxT("http")) && (scheme != wxT("ftp")) && (scheme != wxT("file")))
38             wxURI::Create(wxT("http://") + m_uri);
39     }
40 
41     if (wxURI::HasFragment())
42     {
43         if (wxURI::GetFragment().Mid(0,11).Lower() == wxT("!metalink3!"))
44             wxURI::Create(wxURI::GetFragment().Mid(11));
45         else
46             wxURI::Create(GetFullPath().BeforeLast('#'));
47     }
48 }
49 
IsComplete()50 bool mUrlName::IsComplete()
51 {
52     if (Type() == LOCAL_FILE)
53         return (HasScheme() && HasPath());
54     else
55         return (HasServer() && HasScheme() && HasPath());
56 }
57 
GetHost()58 wxString mUrlName::GetHost()
59 {
60     return wxURI::GetServer();
61 }
62 
GetPort()63 wxString mUrlName::GetPort()
64 {
65     wxString port = wxURI::GetPort();
66     int type = Type();
67     if (!HasPort())
68     {
69         if (type == HTTP)
70             port = wxT("80");
71         else if (type == FTP)
72             port = wxT("21");
73         else
74             port = wxT("0");
75     }
76     return port;
77 }
78 
Type()79 int mUrlName::Type()
80 {
81     wxString scheme = GetScheme();
82     if (scheme == wxT("http"))
83         return HTTP;
84     else if (scheme == wxT("ftp"))
85         return FTP;
86     else if (scheme == wxT("file"))
87         return LOCAL_FILE;
88     else
89         return -1;
90 }
91 
GetDir()92 wxString mUrlName::GetDir()
93 {
94     return wxURI::GetPath().BeforeLast('/') + wxT("/");
95 }
96 
GetFullName()97 wxString mUrlName::GetFullName()
98 {
99     wxString fullrealname = wxURI::GetPath().AfterLast('/');
100     return fullrealname;
101 }
102 
GetFullRealName()103 wxString mUrlName::GetFullRealName()
104 {
105     wxString fullrealname = wxURI::GetPath().AfterLast('/');
106     if (wxURI::HasQuery())
107         return fullrealname + wxT("?") + wxURI::GetQuery();
108     else
109         return fullrealname;
110 }
111 
GetFullPath()112 wxString mUrlName::GetFullPath()
113 {
114     return wxURI::BuildURI();
115 }
116 
117 
118