Source code: org/mitre/cvw/AuditObject.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.awt.*;
10 import java.util.*;
11 //import tea.set.MultiList;
12
13
14 /* 8/27/97 dage - rather than extending CVWObject ... this should just be an object
15 * which has a pointer to the CVWObject. For that matter it could also have
16 * a pointer to the location CVWObject.
17 * If there is time ... rework this!!!
18 * 1/19/98 dage - if document, then show doc type so needed orig CVWObject still in
19 * tack as to get doc id.
20 */
21 /**
22 * This is the display object for all objects owned by a user, specifically for the
23 * AuditListFrame.
24 * @version 1.0 12/98
25 * @author Deb Ercolini
26 */
27 public class AuditObject extends DisplayObject {
28 String location;
29 int locType;
30 String fullPath;
31
32 /**
33 * Constructor
34 * @param obj the CVWObject this object refers to
35 * @param loc the object number of the location
36 * @param type the type of location
37 * @param fPath the full path of the CVWObject
38 */
39 AuditObject(CVWObject obj, String loc, int type, String fPath) {
40 super(obj);
41 location = loc;
42 locType = type;
43 fullPath = fPath;
44 }
45
46 /**
47 * Returns the location character
48 * @return the location character
49 */
50 public String getLocType() {
51 if (locType == CVWObject.ROOM) return "r";
52 if (fullPath.equals("Nowhere")) return " ";
53 if (locType == CVWObject.USER) {
54 //if (fullPath.startsWith("Carrying Folder"))
55 CVWObject currUser = CVWCoordinator.getInstance().getCurrentUser();
56 if (currUser.objNum.equals(cvwObj.getTopLocation()))
57 return "c";
58 else
59 return "u";
60 }
61 return "-";
62 }
63
64 /**
65 * Compares this auditObject to another.
66 * @param aObj the audit object being compared
67 * @param field the field being compared
68 * @return <code>1</code> if this object is less than the passed in object
69 * otherwise <code>-1</code>
70 */
71 public int compareTo(AuditObject aObj, int field) {
72 return compareTo((DisplayObject)aObj, field);
73 }
74
75 /* 8/27/97 dage - these field integers must map to the order of the fields in the
76 * multi-list ... somewhat hardcoded for this
77 */
78 /**
79 * Compares this displayObject to another.
80 * @param dObj the display object being compared
81 * @param field the field being compared
82 * @return <code>1</code> if this object is less than the passed in object
83 * otherwise <code>-1</code>
84 */
85 public int compareTo(DisplayObject dObj, int field) {
86 AuditObject aObj = (AuditObject)dObj;
87 switch (field) {
88 case 0: //Name
89 return (this.getName().toLowerCase().compareTo(aObj.getName().toLowerCase()));
90 case 1: //Type
91 return (this.getType().toLowerCase().compareTo(aObj.getType().toLowerCase()));
92 case 2: //Location Type
93 return (this.getLocType().toLowerCase().compareTo(aObj.getLocType().toLowerCase()));
94 case 3: //Current Location
95 return (this.getCurrentLocation().toLowerCase().compareTo(aObj.getCurrentLocation().toLowerCase()));
96 case 5: //Created By
97 return (this.getOwnerName().toLowerCase().compareTo(aObj.getOwnerName().toLowerCase()));
98 case 4: //<Created> On
99 if (this.getCreatedOn().before(aObj.getCreatedOn()))
100 return 1;
101 else
102 return -1;
103 case 7: //Modified By
104 return (this.getModifiedByName().toLowerCase().compareTo(aObj.getModifiedByName().toLowerCase()));
105 case 6: //<Modified> On
106 if (this.getModOn().before(aObj.getModOn()))
107 return 1;
108 else
109 return -1;
110 default:
111 return -1;
112 }
113 }
114
115 /* 12/29/97 dage - created
116 */
117 /**
118 * Calls getCurrentLocation with <code>true</code> as parameter
119 * @return the abbreviated location
120 */
121 public String getCurrentLocation() {
122 return getCurrentLocation(true);
123 }
124
125 /* 12/29/97 dage - created
126 */
127 /**
128 * Returns either the full or abbreviated location depending on the boolean sent in
129 * current bug ... if group is in group manager, cvw server is sending #-1 for object number and this code displays "Unknown"
130 * @param limitSize if true the full location will be returned so that it can be displayed at the bottom of the window
131 * @return current location of the object
132 */
133 public String getCurrentLocation(boolean limitSize) {
134 String loc, currentLoc, secondLoc;
135 currentLoc = location;
136 secondLoc = fullPath;
137
138 if (cvwObj.typeValue == CVWObject.GROUP &&
139 currentLoc.indexOf("Group Manager") > -1)
140 secondLoc = "";
141
142 //strip "Carrying Folder" off of the second location
143 int ind;
144 if (locType == CVWObject.USER &&
145 (ind=secondLoc.indexOf("Carrying Folder")) != -1) {
146 secondLoc = secondLoc.substring(ind + "Carrying Folder".length());
147 }
148
149 //for locs which are rooms, the first part of fullpath is the room name, strip it
150 //for objs which are rooms, the secondLoc is Nowhere
151 if (locType == CVWObject.ROOM) {
152 if (cvwObj.typeValue != CVWObject.ROOM)
153 secondLoc = secondLoc.substring(currentLoc.length());
154 }
155
156 //if there is a folder, strip of beginning slash
157 if (secondLoc.indexOf("\\") == 0)
158 secondLoc = secondLoc.substring(1);
159
160 //if there is a full path, limit the number of chars in the location
161 //if the full path = Nowhere then location is blank
162 if (secondLoc.trim().length() != 0) {
163 if (secondLoc.equals("Nowhere")) {
164 currentLoc = "Unknown";
165 } else {
166 if (limitSize)
167 loc = currentLoc.substring(0,Math.min(10,currentLoc.length()));
168 else
169 loc = currentLoc;
170 //currentLoc = loc + " - " + contents[a].fullPath;
171 currentLoc = loc + " - " + secondLoc;
172 }
173 }
174
175 return currentLoc;
176 }
177
178 /**
179 * Returns the full location not abbreviated
180 * 12/29/97 dage
181 * @return the full location
182 */
183 public String getFullLocation() {
184 return getCurrentLocation(false);
185 }
186 }
187