1 /*
2 ** @(#) $Id$
3 **
4 ** W3C Web Commander can be found at "http://www.w3.org/WinCom/"
5 **
6 ** Copyright � 1995-1998 World Wide Web Consortium, (Massachusetts
7 ** Institute of Technology, Institut National de Recherche en
8 ** Informatique et en Automatique, Keio University). All Rights
9 ** Reserved. This program is distributed under the W3C's Software
10 ** Intellectual Property License. This program is distributed in the hope
11 ** that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 ** implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 ** PURPOSE. See W3C License http://www.w3.org/Consortium/Legal/ for more
14 ** details.
15 **
16 ** WinComDoc.cpp : implementation of the CWinComDoc class
17 */
18
19 #include "stdafx.h"
20 #include "WinCom.h"
21
22 #include "WinComDoc.h"
23 #include "Load.h"
24 #include "Delete.h"
25
26 // From libwww
27 #include "WWWLib.h"
28 #include "WWWApp.h"
29
30
31 #ifdef _DEBUG
32 #define new DEBUG_NEW
33 #undef THIS_FILE
34 static char THIS_FILE[] = __FILE__;
35 #endif
36
37 #define WEBCOMMANDER_LATEST "http://www.w3.org/WinCom/WinCom.zip"
38 #define WEBCOMMANDER_THIS "http://www.w3.org/WinCom/WinCom-0.984.zip"
39
40 /////////////////////////////////////////////////////////////////////////////
41 // CWinComDoc
42
IMPLEMENT_DYNCREATE(CWinComDoc,CDocument)43 IMPLEMENT_DYNCREATE(CWinComDoc, CDocument)
44
45 BEGIN_MESSAGE_MAP(CWinComDoc, CDocument)
46 //{{AFX_MSG_MAP(CWinComDoc)
47 ON_COMMAND(ID_VERSION_CONFLICT, OnVersionConflict)
48 ON_UPDATE_COMMAND_UI(ID_VERSION_CONFLICT, OnUpdateVersionConflict)
49 ON_COMMAND(ID_SHOW_SERVER_STATUS, OnShowServerStatus)
50 ON_UPDATE_COMMAND_UI(ID_SHOW_SERVER_STATUS, OnUpdateShowServerStatus)
51 ON_COMMAND(ID_APP_UPGRADE, OnAppUpgrade)
52 ON_COMMAND(ID_LOAD_ADDRESS, OnLoadAddress)
53 ON_COMMAND(ID_DELETE_ADDRESS, OnDeleteAddress)
54 //}}AFX_MSG_MAP
55 END_MESSAGE_MAP()
56
57 /////////////////////////////////////////////////////////////////////////////
58 // CWinComDoc construction/destruction
59
60 CWinComDoc::CWinComDoc()
61 {
62 CWinComApp * pApp = (CWinComApp *) AfxGetApp();
63 ASSERT(pApp != NULL);
64
65 m_cwd = HTGetCurrentDirectoryURL();
66 m_detectVersionConflict = pApp->GetIniDetectVersionConflict();
67 m_showServerStatus = pApp->GetIniShowServerStatus();
68 }
69
~CWinComDoc()70 CWinComDoc::~CWinComDoc()
71 {
72 CWinComApp * pApp = (CWinComApp *) AfxGetApp();
73 ASSERT(pApp != NULL);
74
75 HT_FREE(m_cwd);
76 pApp->SetIniDetectVersionConflict(m_detectVersionConflict);
77 pApp->SetIniShowServerStatus(m_showServerStatus);
78 }
79
OnNewDocument()80 BOOL CWinComDoc::OnNewDocument()
81 {
82 if (!CDocument::OnNewDocument())
83 return FALSE;
84
85 // TODO: add reinitialization code here
86 // (SDI documents will reuse this document)
87
88 return TRUE;
89 }
90
91 /////////////////////////////////////////////////////////////////////////////
92 // CWinComDoc serialization
93
Serialize(CArchive & ar)94 void CWinComDoc::Serialize(CArchive& ar)
95 {
96 if (ar.IsStoring())
97 {
98 // TODO: add storing code here
99 }
100 else
101 {
102 // TODO: add loading code here
103 }
104 }
105
106 /////////////////////////////////////////////////////////////////////////////
107 // CWinComDoc diagnostics
108
109 #ifdef _DEBUG
AssertValid() const110 void CWinComDoc::AssertValid() const
111 {
112 CDocument::AssertValid();
113 }
114
Dump(CDumpContext & dc) const115 void CWinComDoc::Dump(CDumpContext& dc) const
116 {
117 CDocument::Dump(dc);
118 }
119 #endif //_DEBUG
120
121 /////////////////////////////////////////////////////////////////////////////
122 // CWinComDoc handling of created request objects
123
AddRequest(CRequest * pRequest)124 BOOL CWinComDoc::AddRequest (CRequest * pRequest)
125 {
126 return TRUE;
127 }
128
DeleteRequest(CRequest * pRequest)129 BOOL CWinComDoc::DeleteRequest (CRequest * pRequest)
130 {
131 return TRUE;
132 }
133
134 /////////////////////////////////////////////////////////////////////////////
135 // CWinComDoc commands
136
SaveDocument()137 BOOL CWinComDoc::SaveDocument()
138 {
139 CRequest * request = new CRequest(this);
140 HTAnchor * source = NULL;
141 HTAnchor * destination = NULL;
142
143 // Create the source anchor
144 char * src = HTParse(m_Location.m_source, m_cwd, PARSE_ALL);
145 source = HTAnchor_findAddress(src);
146 HT_FREE(src);
147
148 /* If destination is not http://... then error */
149 if (!m_Location.m_destination.IsEmpty()) {
150 char * access = HTParse(m_Location.m_destination, "", PARSE_ACCESS);
151 if (strcasecomp(access, "http")) {
152 CString strMessage;
153 AfxFormatString1(strMessage, IDS_CANNOT_WRITE_TO_DESTINATION, m_Location.m_destination);
154 AfxMessageBox(strMessage);
155 HT_FREE(access);
156 return FALSE;
157 } else {
158 char * dest = HTParse(m_Location.m_destination, m_cwd, PARSE_ALL);
159 destination = HTAnchor_findAddress(dest);
160 HT_FREE(dest);
161 HT_FREE(access);
162 }
163 }
164
165 // Do we have any metadata to set up?
166 {
167 HTParentAnchor * source_parent = HTAnchor_parent(source);
168
169 if (!m_EntityInfo.m_mediaType.IsEmpty()) {
170 HTAnchor_setFormat(source_parent, HTAtom_for(m_EntityInfo.m_mediaType));
171 }
172 if (!m_EntityInfo.m_contentEncoding.IsEmpty()) {
173 HTAnchor_deleteEncodingAll(source_parent);
174 HTAnchor_addEncoding(source_parent, HTAtom_for(m_EntityInfo.m_contentEncoding));
175 }
176 if (!m_EntityInfo.m_charset.IsEmpty()) {
177 HTAnchor_setCharset(source_parent, HTAtom_for(m_EntityInfo.m_charset));
178 }
179 if (!m_EntityInfo.m_language.IsEmpty()) {
180 HTAnchor_deleteLanguageAll(source_parent);
181 HTAnchor_addLanguage(source_parent, HTAtom_for(m_EntityInfo.m_language));
182 }
183 }
184
185 // Do we have any link relationships to set up?
186 m_Links.AddLinkRelationships(source);
187
188 /* Start the request */
189 if (m_detectVersionConflict) {
190 char * etag = HTAnchor_etag(HTAnchor_parent(destination));
191 if (etag) {
192 request->PutDocument(source, destination, HT_MATCH_THIS);
193 } else {
194 request->PutDocumentWithPrecheck(source, destination);
195 }
196 } else {
197 request->PutDocument(source, destination, HT_NO_MATCH);
198 }
199
200 return TRUE;
201 }
202
OnVersionConflict()203 void CWinComDoc::OnVersionConflict()
204 {
205 m_detectVersionConflict = !m_detectVersionConflict;
206 }
207
OnUpdateVersionConflict(CCmdUI * pCmdUI)208 void CWinComDoc::OnUpdateVersionConflict(CCmdUI* pCmdUI)
209 {
210 pCmdUI->SetCheck(m_detectVersionConflict);
211 }
212
OnShowServerStatus()213 void CWinComDoc::OnShowServerStatus()
214 {
215 m_showServerStatus = !m_showServerStatus;
216 int show_flag = m_showServerStatus ? HT_ERR_SHOW_PARS : 0;
217 HTError_setShow((HTErrorShow) (HT_ERR_SHOW_INFO | show_flag));
218 }
219
OnUpdateShowServerStatus(CCmdUI * pCmdUI)220 void CWinComDoc::OnUpdateShowServerStatus(CCmdUI* pCmdUI)
221 {
222 pCmdUI->SetCheck(m_showServerStatus);
223 }
224
OnAppUpgrade()225 void CWinComDoc::OnAppUpgrade()
226 {
227 if (AfxMessageBox(IDS_APP_UPGRADE, MB_YESNO | MB_ICONEXCLAMATION )) {
228
229 #if 0
230 CRequest * request = new CRequest(this);
231
232 request->m_pHTAnchor = HTAnchor_findAddress(WEBCOMMANDER_THIS);
233
234 request->CheckDocument(FALSE);
235 #endif
236 }
237 }
238
OnLoadAddress()239 void CWinComDoc::OnLoadAddress()
240 {
241 CLoad * load = new CLoad(this);
242 load->DoModal();
243 }
244
OnDeleteAddress()245 void CWinComDoc::OnDeleteAddress()
246 {
247 CDelete * del = new CDelete(this);
248 del->DoModal();
249 }
250