Source code: org/mitre/cvw/CVWDocument.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw;
8
9 import java.util.*;
10
11 import org.mitre.cvw.docserv.DocServException;
12
13 /**
14 * This class represents the Document object of the CVW server.
15 * @version 1.0
16 * @author Marc Cannava
17 * @autho Deb Ercolini
18 */
19 class CVWDocument extends CVWObject {
20 String docID;
21 String docType;
22 String docServer; // document server that this document resides on
23 boolean checked_out = false;
24
25 private CVWDocument changedDoc;
26
27 /********** static/class methods *********/
28
29 /* 4/10/98 dage - use DSIController class to get the
30 * current instance of DSIController not CVWCoordinator
31 */
32 /**
33 * Returns the instance of the DSIController
34 * Don't want this no more. Should ask DocumentServerList for a particular dsic
35 * @return the instance of the DSIController
36 *
37 public static DSIController getDocServer() {
38 return DSIController.();
39 }
40 */
41 /** Get user specified Doc Types
42 * 12/23/98 dage - Changed Op parameter to type boolean
43 * 8/27/98 srj - Added Op parameter
44 * 3/24/98 dage - moved from CVWCoordinator '
45 * @param docidVec Vector of document id's to retrieve
46 * @param Op Operation to perform. Should be:
47 * false use <code>DSIController.GETDOCTEXTS</code> or
48 * true use <code>DSIController.GETDOCTEXTSCO</code>
49 * @return vector of document types
50 */
51 public static Vector getDocTypes(Vector docidVec, boolean checkOutCheck) {
52 // use this for a local retrieval
53
54 DSIController dsi;
55 try {
56 dsi = DocumentServerList.getDocumentServerList().getLocalDocServer();
57 } catch (NoSuchElementException nsee) {
58 System.err.println("Couldn't contact document server for this document");
59 return null;
60 }
61
62 Vector docTypes = null;
63 DSIParms indsip= new DSIParms();
64 DSIParms outdsip;
65
66 if (CVWCoordinator.DEBUG) System.err.println("in getDocTypes " + docidVec);
67
68 int Op = ObjectValues.GETDOCTEXTS;
69 if (checkOutCheck)
70 Op = ObjectValues.GETDOCTEXTSCO;
71
72 try {
73 indsip.docIDs = docidVec;
74 outdsip = dsi.startDSSyncOp(Op, indsip);
75 if (outdsip.exc != null) throw outdsip.exc;
76 docTypes = outdsip.vectorResult;
77 } catch (DocInUseException e) {
78 System.err.println("get doc types = Docserver in use.");
79 } catch (DocServException d) {
80 //System.err.println(d.toString());
81 System.err.println(d.toString());
82 }
83 return docTypes;
84 }
85
86 /** Get the Doc Types information vector
87 * This uses the default operation (DSIController.GETDOCTEXTS)
88 * 8/28/98 srj - changed this method to call the other getDocTypes
89 * 3/24/98 dage - moved from CVWCoordinator
90 * @param docidVec A Vector consisting of the document id's to fetch
91 * @return A Vector with the requested document information
92 */
93 public static Vector getDocTypes(Vector docidVec) {
94 return (getDocTypes(docidVec, false));
95 }
96
97
98 public static void getDocTypes(Vector docs, Vector docids, boolean checkOutCheck) {
99 // request the doctypes from the docserver
100 if (docs.isEmpty())
101 return;
102 int howMany = docs.size();
103 CheckVector docTypes;
104 Vector docReturn = null;
105 Enumeration docTypesEnum, docCOTypesEnum = null;
106
107 if (CVWCoordinator.DEBUG) System.err.println("getDocTypes w/choutch = " + checkOutCheck);
108 docReturn = getDocTypes(docids, checkOutCheck);
109 if (docReturn == null) return;
110 docTypes = new CheckVector(docReturn);
111 if (checkOutCheck) {
112 docTypes.createCOVector();
113 if (docTypes.sizeOf() != howMany) { // probably a bad command. run the old one. remove later...
114 docTypes = new CheckVector(docReturn);
115 }
116 }
117
118 if (docTypes == null)
119 return;
120
121 if (docTypes.sizeOf() != howMany) {
122 System.err.println("ERROR # of docids sent != # of string types received - CVWDocument");
123 return;
124 }
125
126 docTypesEnum = docTypes.elementsOf();
127 if (docTypes.isCOVector())
128 docCOTypesEnum = docTypes.coElementsOf();
129
130 for (int i = 0; i < howMany; i++) {
131 CVWDocument theDoc = (CVWDocument)docs.elementAt(i);
132 try {
133 theDoc.docType = CVWDocument.parseDocType((String)(docTypesEnum.nextElement()));
134
135 if (docTypes.isCOVector()) {
136 String co_value;
137 co_value = (String)docCOTypesEnum.nextElement();
138 if (co_value.equals("1"))
139 theDoc.setCheckOut(true);
140 }
141 } catch (Exception e) { // sort of bogus. catching just in case it's null
142 System.err.println("exception while processing the doc types" + e);
143 }
144
145 }
146 //System.err.println("done doc batch");
147 }
148
149 // this just does a little cleanup on the docType results from the docserver
150 // wanted to centralize so we don't duplicate this code everywhere
151 /**
152 * Returns the document type of the passed in parameter with out the
153 * trailing "document"
154 * @param dType the document type to be parsed
155 * @return the document type with out the trailing "document"
156 */
157 public static String parseDocType(String dType) {
158 if (!dType.equals("Unknown")) { // The docid is prolly not set
159 if (dType.endsWith(" document"))
160 return dType.substring(0,dType.lastIndexOf(" "));
161 else
162 return dType;
163 }
164 return null;
165 }
166
167 /**
168 * Returns the document type as stored on the Document server given a full filename.
169 * This is store in the trans table on the Document server
170 * @param path the filename
171 * @return the document type
172 */
173 public static String getDocTypeFromFile(String path) {
174
175 CVWCoordinator jcvw = CVWCoordinator.getInstance();
176 DSIController dsi = DocumentServerList.getDocumentServerList().getLocalDocServer(); // since we only want a doc type, just go local
177 if(dsi == null) {
178 return null;
179 }
180
181 // given a file. Find the extension.
182 String extension;
183 int index;
184 DSIParms indsip = new DSIParms();
185 DSIParms outdsip = null;
186
187 index=path.lastIndexOf('.');
188 if(index != -1 && index != path.length()) {
189 // extension=path.substring(index+1,path.length());
190 extension = path.substring(index+1);
191 } else extension="unknown";
192
193 indsip.extension = extension;
194 try {
195 outdsip=dsi.startDSSyncOp(DSIController.GETEXTDESC, indsip);
196 } catch (DocInUseException e) {
197 // This is not possible. There's no docid associated with
198 // this operation.
199 jcvw.displayError("Could not import file because an exception occurred.");
200 return null;
201 }
202 String docType=outdsip.stringResult;
203 return docType;
204 }
205
206 /* 9/13/98 dage - had to put it here because the DocServerInterface
207 * knows if Checkin/Revert was cancelled but doesnt know the actual cvw
208 * object represented .. just the objNum
209 * 9/15/98 dage - moved from CVWCoordinator.
210 */
211 /**
212 * Sets the checked out state of a document given the object number.
213 * @param state current state
214 * @param oNum object number of the document
215 */
216 public static void setDocCheckOut(boolean state, String oNum) {
217 CVWObject obj = CVWCache.getInstance().get(oNum);
218 if (oNum == null || !(obj instanceof CVWDocument)) return; //should never happen
219 ((CVWDocument)obj).setCheckOut(state);
220 }
221
222 //11/4/99 dage - updated to cvw-document 1.4 to have object number be sent
223 //11/4/99 dage - converted from a static method
224 /**
225 * When the user requests a document to be copied, the CVWServer sends an
226 * object number of a new CVW document object with the doc id to be copied.
227 * The doc id of the document is sent to the document server.
228 * If the copy was successful, the document server returns a new doc id of
229 * the copy of the original document. Either the new doc id is sent to the
230 * CVW server or a message noting that there was an error on the document server.
231 * <br> MCP receive cvw-document-copy
232 * <br> MCP send cvw-document-copy-result
233 *
234 * @param docid the document id of the document to be copied
235 * @param newObjNum the object number of the new document to be created
236 *
237 * @see DSIController#getNewDocID
238 */
239 public void doDocCopy(String newObjNum) {
240 if(CVWCoordinator.DEBUG) System.err.println("Copy DOCID: " + docID);
241
242 int newID = 0;
243 DSIController dsic;
244 try {
245 dsic = DocumentServerList.getDocumentServerList().getLocalDocServer();
246 } catch (NoSuchElementException nsee) {
247 System.err.println("Couldn't contact local document server");
248 return;
249 }
250
251 if (!dsic.documentIsBusy(docID))
252 newID = dsic.getNewDocID(docID);
253
254 if(CVWCoordinator.DEBUG) System.err.println("THE NEW DOCID IS: " + newID);
255
256 if (newID == 0) //error
257 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-copy-result ",
258 " new_object: " + newObjNum +
259 " error_msg: DocServer error occurred.");
260 else
261 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-copy-result ",
262 " new_object: " + newObjNum +
263 " new_docid: " + newID);
264 }
265
266
267 /********** end of static/class methods *********/
268
269 /**
270 * Constructor
271 *
272 * @param type the type of this object as defined by the ObjectValues
273 * @param the document id
274 */
275 public CVWDocument(int type, String id) {
276 this(DocumentServerList.getLocalDocServerName(), type, id);
277 }
278
279 public CVWDocument(String docServer, int type, String id) {
280 super(type);
281 this.docServer = docServer;
282 docID = id;
283 }
284
285 /**
286 * Constructor
287 *
288 * @param docServer The server this document resides on
289 */
290 public CVWDocument(String docServer) {
291 super(CVWObject.DOCUMENT);
292 this.docServer = docServer;
293 }
294 /**
295 * Constructor
296 */
297 public CVWDocument() {
298 this(DocumentServerList.getLocalDocServerName());
299 }
300
301 /**
302 * Returns whether this document is a shortcut.
303 * @return <code>true</true> if this document is a shortcut
304 */
305 public boolean isShortcut() {
306 return (typeValue == DOC_SC);
307 }
308
309 /**
310 * Opens the Get Info window for this object.
311 * <br> MCP receive cvw-object-detail
312 *
313 * @param desc the description of this object
314 * @param perms whether the user has permissions to edit this object
315 * @param owners space delimited string of object numbers of the owners
316 *
317 * @see FolderDialog
318 * @see ObjectPanel
319 * @see ObjectOwnerPanel
320 * @see DSIController
321 *
322 */
323 public void getInfo(String desc, String perms, String owners) {
324 this.desc = desc;
325 if (isShortcut()) {
326 perms = "shortcut"; // not editable regardless of ownership
327 }
328
329 CVWCoordinator jcvw = CVWCoordinator.getInstance();
330
331 Integer id = new Integer(docID);
332 DSIParms indsip = new DSIParms();
333 DSIParms outdsip = null;
334 String creator;
335 String docDesc;
336 String createDate;
337 String type;
338 String status;
339 Vector editor;
340 Dictionary info;
341
342 DSIController dsi;
343 try {
344 dsi = DocumentServerList.getDocumentServerList().getDocServer(docServer);
345 } catch (NoSuchElementException nsee) {
346 jcvw.displayDocServNotInstalled();
347 return;
348 }
349
350 indsip.docID = id;
351
352 try {
353 if(jcvw.DEBUG) System.err.println("DSI/GDI: Here1");
354 outdsip = dsi.startDSSyncOp(DSIController.DOCINFO,indsip);
355 info = outdsip.dictionaryResult;
356 docDesc = (String)info.get("Document-Description");
357 creator = (String)info.get("Document-Owner");
358 createDate = (String)info.get("Document-Created-On");
359 type = (String)info.get("Document-Type");
360 // outdsip = dsi.startDSSyncOp(DSIController.DOCDESC,indsip);
361 // if(outdsip.exc != null) throw outdsip.exc;
362 // docDesc = outdsip.stringResult;
363
364 // if(jcvw.DEBUG) System.err.println("DSI/GDI: Here2");
365 // outdsip = dsi.startDSSyncOp(DSIController.DOCCREATORONLY,indsip);
366 // if(outdsip.exc != null) throw outdsip.exc;
367 // creator = outdsip.stringResult;
368
369 // if(jcvw.DEBUG) System.err.println("DSI/GDI: Here3");
370 // outdsip = dsi.startDSSyncOp(DSIController.DOCCREATEDATE,indsip);
371 // if(outdsip.exc != null) throw outdsip.exc;
372 // createDate = outdsip.stringResult;
373
374 // if(jcvw.DEBUG) System.err.println("DSI/GDI: Here4");
375 // outdsip = dsi.startDSSyncOp(DSIController.DOCTYPE,indsip);
376 // if(outdsip.exc != null) throw outdsip.exc;
377 // type = outdsip.stringResult;
378
379 if(jcvw.DEBUG) System.err.println("DSI/GDI: Here5");
380 outdsip = dsi.startDSSyncOp(DSIController.DOCEDITORS,indsip);
381 if(outdsip.exc != null) throw outdsip.exc;
382 editor = outdsip.vectorResult;
383
384 if(jcvw.DEBUG) System.err.println("DSI/GDI: Here6");
385 outdsip = dsi.startDSSyncOp(DSIController.DOCSTATUS,indsip);
386 if(outdsip.exc != null) throw outdsip.exc;
387 status = outdsip.stringResult;
388
389 } catch (DocServException d) {
390 //jcvw.displayError(d.message, false);
391 jcvw.displayError("Sorry, system could not retrieve info on document \"" + name + "\" (" + d.toString() + ")", false);
392 return;
393 } catch (DocInUseException e) {
394 jcvw.displayDocServInUseError("Sorry, system could not retrieve info on document \"" + name + "\".");
395 //jcvw.displayError("Sorry, system could not retrieve info on document \"" + name + "\" (" + d.message + ")", false);
396 return;
397 } catch (Exception e) {
398 jcvw.displayError("Error retrieving document: " + e.toString());
399 return;
400 }
401
402 String editors = new String("");
403 StringBuffer edits;
404 for (Enumeration e = editor.elements(); e.hasMoreElements();) {
405 edits = new StringBuffer(" "); //55 spaces
406 Vector v = (Vector)e.nextElement();
407 String name = (String)v.elementAt(0);
408 String date = (String)v.elementAt(1);
409 String comm = (String)v.elementAt(2);
410 try {
411 if (name.length() > 10)
412 name = name.substring(0, 10);
413 edits.insert(0, name);
414 edits.insert(10," "+date);
415 edits.insert(35," "+comm);
416 } catch (StringIndexOutOfBoundsException sie) {
417 System.err.println(sie.toString());
418 for (int i = 0; i<3;i++)
419 edits = new StringBuffer(name + "\t" + date + "\t" + comm);
420 }
421 editors += edits.toString().trim() + "\n";
422 }
423
424 FolderDialog dialog = new FolderDialog("Information About " + name);
425 DocumentObjectPanel doc = new DocumentObjectPanel(this, dialog, perms,
426 creator, createDate, type,
427 editors, status);
428 dialog.addTab("Description", doc);
429 ObjectOwnerPanel acl = new ObjectOwnerPanel(this, dialog, perms);
430 dialog.addTab("Permissions", acl);
431
432 // 9/10/99 - update for system users permission list
433 dialog.folder.addChangeListener(acl);
434
435 WindowMgr.getWindowMgr().addObjectWindow(WindowMgr.OBJECT, dialog, objNum);
436 dialog.pack();
437 dialog.setVisible(true);
438 dialog.toFront(getMetaDataType());
439
440 this.setOwners(owners);
441
442 }
443
444 // RJT 7/30/98
445 /**
446 * Returns the document id for this document
447 * @return the document id for this document
448 */
449 public String getDocID() {
450 return docID;
451 }
452
453 /**
454 * Starts building the MCP for notifying the server of any change to the information
455 * of this object, also notifies the document server of any change to the name or
456 * description of this document.
457 *
458 * @param newName name from the get info dialog box
459 * @param newMove sessile value from the get info dialog box
460 * @param newDesc description from the get info dialog box
461 */
462 public void objectModify(String newName, boolean newMove, String newDesc) {
463
464 DSIController dsi;
465 try {
466 dsi = DocumentServerList.getDocumentServerList().getDocServer(docServer);
467 } catch (NoSuchElementException nsee) {
468 System.err.println("Document server " + docServer + " not found");
469 return;
470 }
471
472 String param = getObjectModifyMCP(newName, newMove, newDesc);
473 if (param.length() == 0)
474 return;
475
476 changedDoc = new CVWDocument(docServer, CVWObject.DOCUMENT, docID);
477 changedDoc.objNum = this.objNum;
478 changedDoc.name = newName;
479 changedDoc.sessile = newMove;
480 changedDoc.desc = newDesc;
481
482 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-modify-request",
483 "object: " + objNum.strValue() +
484 " docid: " + docID);
485 }
486
487 /**
488 * Starts building the MCP for notifying the server of any change to the information
489 * of this object, also notifies the document server of any change to the name or
490 * description of this document.
491 */
492 public void objectModifyResult() {
493 if (changedDoc == null) return;
494
495 DSIController dsi;
496 try {
497 dsi = DocumentServerList.getDocumentServerList().getDocServer(docServer);
498 } catch (NoSuchElementException nsee) {
499 System.err.println("Document Server " + docServer + " not found");
500 return;
501 }
502
503 CVWCoordinator jcvw = CVWCoordinator.getInstance();
504 DSIParms indsip = new DSIParms();
505 DSIParms outdsip;
506 indsip.docID = new Integer(docID);
507 indsip.checkedOut = checked_out;
508
509 String newName = changedDoc.name;
510 boolean newMove = changedDoc.sessile;
511 String newDesc = changedDoc.desc;
512
513 String param = getObjectModifyMCP(newName, newMove, newDesc);
514 if (param.length() == 0)
515 return;
516
517 boolean error = false;
518 try {
519 // set the name and description
520 indsip.desc = null;
521 indsip.name = null;
522 if (param.indexOf("description:") != -1) indsip.desc = newDesc;
523 if (param.indexOf("name:") != -1) indsip.name = newName;
524 outdsip = dsi.startDSSyncOp(DSIController.SETDOCATTRS, indsip);
525 if (outdsip.exc != null) throw outdsip.exc;
526 // Set the description
527 // if(DEBUG) System.err.println("GAB - Trying to set desc on doc" + docID);
528 // if (param.indexOf("description:") != -1) {
529 // indsip.desc = newDesc;
530 // outdsip = dsi.startDSSyncOp(DSIController.DOCSETDESC,indsip);
531 // if(outdsip.exc != null) throw outdsip.exc;
532 // }
533
534 // Set the name
535 // if(DEBUG) System.err.println("GAB - Trying to set name on doc" + docID);
536 // if (param.indexOf("name:") != -1) {
537 // indsip.name = newName;
538 // outdsip = dsi.startDSSyncOp(DSIController.SETDOCNAME,indsip);
539 // if(outdsip.exc != null) throw outdsip.exc;
540 // }
541 } catch (DocServException e) {
542 jcvw.displayError(e.toString());
543 error= true;
544 } catch (DocInUseException e) {
545 jcvw.displayDocServInUseError();
546 error= true;
547 }
548
549 if (!error) {
550 objectModify(param);
551 changedDoc = null;
552 }
553 }
554
555 /**
556 * Processes a modify object error for this document from the CVW server.
557 * <br> MCP receive cvw-document-modify
558 * @param errMsg the error message from the CVW server
559 */
560 public void objectModifyResultError(String errMsg) {
561 jcvw.displayError(errMsg, "Document Error");
562 }
563
564 /**
565 * Starts the process of creating the MCP to be sent to the CVW server when
566 * the user creates a new document, tries to create it on the document server
567 * first and if that is successfull, then creates it on the CVW server.
568 *
569 * @param name name from the get info dialog box
570 * @param mimeType the document type
571 * @param sessile sessile value from the get info dialog box
572 * @param desc description from the get info dialog box
573 * @param path full filename to used to create this document
574 *
575 * @see getDocTypeFromFile
576 * @see objectCreate(String name, String mimeType, boolean sessile, String desc, Str
577 ing path, Integer docID)
578 * @see DSIController.startDSOp
579 */
580 public void objectCreate(String name, String mimeType, boolean sessile, String desc, String path) {
581
582 DSIController dsi;
583 try {
584 dsi = DocumentServerList.getDocumentServerList().getDocServer(docServer);
585 } catch (NoSuchElementException nsee) {
586 System.err.println("Document Server " + docServer + " not found");
587 return;
588 }
589
590 DSIParms outdsip;
591 DSIParms indsip = new DSIParms();
592
593 indsip.name = name;
594 indsip.mimeType = mimeType;
595 indsip.desc = desc;
596 indsip.path = path;
597 indsip.sessile = sessile;
598
599 System.err.println("starting create ds op");
600 try {
601 dsi.startDSOp(DSIController.DOCCREATE,indsip);
602 } catch (DocInUseException e) {
603 CVWCoordinator.getInstance().displayDocServInUseError();
604 return;
605 }
606 System.err.println("done create ds op");
607 }
608
609 /**
610 * Starts the process of building the MCP to be sent to the CVW server to create a
611 * new document when it has been created succesfully on the document server
612 * 3/25/98
613 *
614 * @param name name from the get info dialog box
615 * @param mimeType the document type
616 * @param sessile sessile value from the get info dialog box
617 * @param desc description from the get info dialog box
618 * @param path full filename to used to create this document
619 * @param docID the document id of this new document
620 *
621 * @see getObjectCreateMCP
622 * @see objectCreate(String name, String mimeType, boolean sessile, String desc, Str
623 ing path)
624 * @see DSIController
625 */
626 public void objectCreate(String name, String mimeType, boolean sessile, String desc, String path, Integer docID) {
627
628 String cmd = getObjectCreateMCP(name, sessile, desc);
629 cmd = cmd + " path: " + prepTextForServer(path) +
630 " docid: " + docID +
631 " mimetype: " + prepTextForServer(mimeType);
632 objectCreate(cmd);
633 }
634
635 /**
636 * Imports a document by showing the standard system file open dialog
637 * and then a standard CVW document get information dialog.
638 *
639 * @see NPDocServer#fileBrowse
640 * @see FolderDialog
641 * @see DocumentObjectPanel
642 */
643 public void create() {
644
645 String path = NPDocServer.getInstance().fileBrowse("Import File");
646
647 if(path == null)
648 return;
649
650 String docType = CVWDocument.getDocTypeFromFile(path);
651 if(docType == null) docType = "deb"; //shouldnt happen
652
653 if(CVWCoordinator.DEBUG) System.err.println("File " + path + " is of type: "+docType);
654
655 //CVWDocument cvwDoc = new CVWDocument();
656
657 FolderDialog dialog = new FolderDialog("CVW - Import File");
658 DocumentObjectPanel doc = new DocumentObjectPanel(this, dialog,
659 path, docType);
660
661 dialog.addTab("Description", doc);
662 dialog.pack();
663 dialog.setVisible(true);
664 doc.nameField.requestFocus();
665 doc.nameField.selectAll();
666 }
667
668
669 /**
670 * Creates a whiteboard from this document by opening a
671 * a standard CVW whiteboard get information dialog.
672 */
673 public void createWhiteboardInit() {
674 if (CVWObject.checkQuota())
675 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-whiteboard-request",
676 "object: " + objNum.strValue());
677 }
678
679 public void createWhiteboard() {
680
681 CVWCoordinator jcvw = CVWCoordinator.getInstance();
682 // Duplicate doc obtaining a new docID
683 System.err.println("copy doc id for wb" + docID);
684 int newDocID = DocumentServerList.getDocumentServerList().getDocServer(docServer).getNewDocID(docID);
685 System.err.println("got new doc id for wb" + newDocID);
686 if (newDocID == 0) {
687 jcvw.displayPrvSysMsg("Error copying document \"" + name + "\" for whiteboard background.");
688 return;
689 }
690
691 String dsurl = jcvw.getParameter("dsurl");
692 if (dsurl.charAt(0) != '/')
693 dsurl = "/"+dsurl;
694 if (dsurl.charAt(dsurl.length()-1) != '/')
695 dsurl += "/";
696 String newDocIDStr = new Integer(newDocID).toString();
697 String path = new String("http://" + jcvw.getParameter("dshost") + ":" +
698 jcvw.getParameter("dsport") + dsurl + newDocID);
699 CVWObject cvwObj = new CVWWhiteboard(newDocIDStr, path);
700
701 cvwObj.create();
702
703 }
704
705 public void createWhiteboardError(String err) {
706 String msg = "Server could not sucessfully create a whiteboard from \"" +
707 name + "\"" ;
708 if (err.equals("quota"))
709 msg += "because you have reached your quota and cannot create any more objects on the CVW server. Please contact your administrator for help.";
710 else if (err.equals("invalid"))
711 msg += "because it is not a valid document to create a whiteboard from.";
712 else if (err.equals("permission"))
713 msg += "because you do not have permission to create a whiteboard from it.";
714 else
715 msg += ".";
716 CVWCoordinator.getInstance().displayPrvSysMsg(msg);
717 }
718
719 public void startOpen() {
720 doDocFunction("Open for View");
721 }
722
723 //9/9/98 dage/dee
724 //11/5/99 dage - if invalid docid, then maybe ask user if still want to delete.
725 // doc doesnt exist on server, so delete cvw object ... only drawback is
726 // if cvw doc server parameters are wrong in .cvw file, then user could be
727 // deleting cvw objects and not deleting doc objects on the correct
728 // corresponding doc server.
729
730 /**
731 * Tries to delete the document on the Doc server, sends whether the
732 * the deletion was successful to the CVW server.
733 * <br> MCP receive cvw-document-delete
734 * <br> MCP send cvw-document-delete
735 *
736 * @param finalTime this is the final time the doc server is contacted
737 * @return wheter the document was deleted
738 * @see CVWObject#confirmDelete
739 */
740 public boolean doDocDelete(boolean finalTime) {
741 boolean res = DocumentServerList.getDocumentServerList().getDocServer(docServer).doDocDelete(objNum.strValue(), new Integer(docID), finalTime);
742 //send res to cvw server
743 if (finalTime)
744 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-delete",
745 "object: " + objNum.strValue() +
746 " error: " + (res ? "0" : "1"));
747 return res;
748 }
749
750 /** 3/5/97 dage - dont do doDocFunction for deletion of SC to Document
751 */
752 /**
753 * Either notifies the user that the object has been deleted or confirms the
754 * delete of the object with the user because the CVW server has okayed
755 * the user to delete the object (i.e. the suer has permissions)
756 * <br> MCP receive cvw-object-delete-result
757 * @param objNum the object number of the object to be deleted
758 * @param name the name of the object to be deleted
759 * @param finalTime if "1" then the object has been deleted, notify the user
760 * if not, then ask the user if they really want to delete the object
761 * @see CVWDocument#doDocFunction
762 * @see CVWDocument#doDocDelete
763 */
764 public void confirmDelete(String name, int finalTime) {
765 if (finalTime == 1) {
766 jcvw.displayPrvSysMsg("\""+name+"\" has been deleted.");
767 return;
768 }
769
770 boolean succeed = true;
771 if (this.typeValue != DOC_SC) { // have to check with Doc Server
772 succeed = DocumentServerList.getDocumentServerList().getDocServer(docServer).doDocMenu(this, "Delete");
773 }
774 if (succeed)
775 showDeleteDialog();
776 }
777
778 /**
779 * Copy or create Shortcut of this document.
780 * User selected Copy or Shortcut from the object menu.
781 *
782 * @param type the type of copy either <code>Copy</code> or <code>Shortcut</code>
783 * @see #doDocCopy
784 * @see DSIController#documentIsBusy
785 */
786 public void objectCopy(String copyType) {
787 //System.err.println("in CVWDocument::copy");
788 // First, see if this document is busy in another operation
789 //System.err.println("in doc copy " + copyType);
790 if(copyType.equals("duplicate")) {
791 if (!DocumentServerList.getDocumentServerList().getDocServer(docServer).isAvailable())
792 return;
793 //if (DSIController.documentIsBusy(docID))
794 // return;
795 }
796 super.objectCopy(copyType);
797 }
798
799 /* 2/16/98 dage - also called by CVWServerComm upon catch of cvw-document-checkout
800 * 4/10/98 dage - replaced initDocServerCheck with docServerAvailable
801 * 2/3/99 dage - renamed from doDocMenu and moved from CVWCoordinator
802 */
803 /**
804 * Processes a function performed on this CVWDocument
805 * @param function the to be performed
806 * @return for 'delete' operation; must see if that succeeds first.
807 */
808 public boolean doDocFunction(String funct) {
809
810 if (!DocumentServerList.getDocumentServerList().getDocServer(docServer).isAvailable())
811 return false;
812
813 if ((funct.startsWith("Check Out")) ||
814 (funct.startsWith("Open for Edit")))
815 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-checkout-request",
816 "object: " + objNum.strValue());
817 else if (funct.startsWith("Open for View"))
818 CVWServerComm.sendMCPCmdToServer("#$#cvw-object-open",
819 "object: " + objNum.strValue());
820 else if(funct.startsWith("Export"))
821 CVWServerComm.sendMCPCmdToServer("#$#cvw-object-export",
822 "object: " + objNum.strValue());
823 else if(funct.startsWith("Save") || //save or discard changes
824 funct.startsWith("Discard")) {
825 int save = (funct.startsWith("Save")) ? 1 : 0;
826 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-checkin-request",
827 "object: " + objNum.strValue() +
828 " save_changes: " + save);
829 } else // now that we go to the cvw server first, there are no functions to fall thru
830 return false; //DSIController.doDocMenu(this, funct);
831 return true;
832 }
833
834 /**
835 * Processes a open for view for this document from the CVW server.
836 * <br> MCP receive cvw-object-window
837 */
838 public void open() {
839 DocumentServerList.getDocumentServerList().getDocServer(docServer).doDocMenu(this, "Open for View");
840 }
841
842 /**
843 * Processes an export for this document from the CVW server.
844 * <br> MCP receive cvw-object-export
845 */
846 public void export() {
847 DocumentServerList.getDocumentServerList().getDocServer(docServer).doDocMenu(this, "Export");
848 }
849
850 /**
851 * Processes a checkin for this document from the CVW server.
852 * <br> MCP receive cvw-document-checkin
853 */
854 public void checkIn(String save) {
855 String s = "Save Changes";
856 if (save.equals("0"))
857 s = "Discard Changes";
858 DocumentServerList.getDocumentServerList().getDocServer(docServer).doDocMenu(this, s);
859 }
860
861 /**
862 * Processes a checkin error for this document from the CVW server.
863 * <br> MCP receive cvw-document-checkin
864 * @param errMsg the error message from the CVW server
865 */
866 public void checkInError(String errMsg) {
867 jcvw.displayError(errMsg, "Document Error");
868 }
869
870 public void checkOut() {
871 DSIController dsi;
872
873 try {
874 dsi = DocumentServerList.getDocumentServerList().getDocServer(docServer);
875 } catch (NoSuchElementException nsee) {
876 System.err.println("Document Server " + docServer + " not found");
877 return;
878 }
879
880 if (!checked_out) {
881 boolean success = dsi.doDocMenu(this, "Check Out");
882 if (!success)
883 return;
884
885 CVWServerComm.sendMCPCmdToServer("#$#cvw-document-checkout-result",
886 "object: " + objNum.strValue());
887
888 }
889
890 jcvw.displayPrvSysMsg("You edit \"" + name + "\"");
891 dsi.doDocMenu(this, "Open for Edit");
892 }
893
894
895 /**
896 * Processes a checkout error for this document from the CVW server.
897 * <br> MCP receive cvw-document-checkout
898 * @param errMsg the error message from the CVW server
899 */
900 public void checkOutError(String errMsg) {
901 jcvw.displayError(errMsg, "Document Error");
902 }
903
904 /**
905 * Returns if this document is currently checked out/has been opened for editing
906 * @return if this document is currently checked out
907 */
908 public boolean isCheckedOut() {
909 return (checked_out);
910 }
911
912 /**
913 * Sets the checked out state of this document
914 * @param checkout_value the checked out state of this document
915 */
916 public void setCheckOut(boolean checkout_value) {
917 checked_out = checkout_value;
918 }
919
920 /**
921 * Returns a string representing the state of this component.
922 * @return a string representation of this component's state.
923 */
924 public String paramString() {
925 return ("docid=" + docID + "," + super.paramString());
926 }
927
928 }
929