0001: /*
0002: * <copyright>
0003: *
0004: * Copyright 1997-2004 BBNT Solutions, LLC
0005: * under sponsorship of the Defense Advanced Research Projects
0006: * Agency (DARPA).
0007: *
0008: * You can redistribute this software and/or modify it under the
0009: * terms of the Cougaar Open Source License as published on the
0010: * Cougaar Open Source Website (www.cougaar.org).
0011: *
0012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0023: *
0024: * </copyright>
0025: */
0026:
0027: package org.cougaar.planning.servlet;
0028:
0029: import java.io.FilterWriter;
0030: import java.io.IOException;
0031: import java.io.InputStream;
0032: import java.io.PrintWriter;
0033: import java.io.Writer;
0034: import java.lang.reflect.Method;
0035: import java.net.URLDecoder;
0036: import java.net.URLEncoder;
0037: import java.text.SimpleDateFormat;
0038: import java.util.ArrayList;
0039: import java.util.Arrays;
0040: import java.util.Calendar;
0041: import java.util.Collection;
0042: import java.util.Collections;
0043: import java.util.Comparator;
0044: import java.util.Date;
0045: import java.util.Enumeration;
0046: import java.util.HashMap;
0047: import java.util.Iterator;
0048: import java.util.List;
0049: import java.util.Set;
0050:
0051: import javax.servlet.ServletException;
0052: import javax.servlet.http.HttpServlet;
0053: import javax.servlet.http.HttpServletRequest;
0054: import javax.servlet.http.HttpServletResponse;
0055:
0056: import org.apache.xerces.dom.DocumentImpl;
0057: import org.apache.xml.serialize.OutputFormat;
0058: import org.apache.xml.serialize.XMLSerializer;
0059: import org.cougaar.core.blackboard.PublisherInfo;
0060: import org.cougaar.core.blackboard.PublisherSubscription;
0061: import org.cougaar.core.mts.MessageAddress;
0062: import org.cougaar.core.plugin.ComponentPlugin;
0063: import org.cougaar.core.servlet.ServletUtil;
0064: import org.cougaar.core.service.BlackboardQueryService;
0065: import org.cougaar.core.service.ServletService;
0066: import org.cougaar.core.util.UID;
0067: import org.cougaar.core.util.UniqueObject;
0068: import org.cougaar.planning.ldm.asset.AggregateAsset;
0069: import org.cougaar.planning.ldm.asset.Asset;
0070: import org.cougaar.planning.ldm.asset.AssetGroup;
0071: import org.cougaar.planning.ldm.asset.ClusterPG;
0072: import org.cougaar.planning.ldm.asset.ItemIdentificationPG;
0073: import org.cougaar.planning.ldm.asset.LocationSchedulePG;
0074: import org.cougaar.planning.ldm.asset.TypeIdentificationPG;
0075: import org.cougaar.planning.ldm.measure.AbstractMeasure;
0076: import org.cougaar.planning.ldm.plan.Aggregation;
0077: import org.cougaar.planning.ldm.plan.Allocation;
0078: import org.cougaar.planning.ldm.plan.AllocationResult;
0079: import org.cougaar.planning.ldm.plan.AllocationforCollections;
0080: import org.cougaar.planning.ldm.plan.AspectScorePoint;
0081: import org.cougaar.planning.ldm.plan.AspectScoreRange;
0082: import org.cougaar.planning.ldm.plan.AspectType;
0083: import org.cougaar.planning.ldm.plan.AspectValue;
0084: import org.cougaar.planning.ldm.plan.AssetAssignment;
0085: import org.cougaar.planning.ldm.plan.AssetTransfer;
0086: import org.cougaar.planning.ldm.plan.Composition;
0087: import org.cougaar.planning.ldm.plan.Disposition;
0088: import org.cougaar.planning.ldm.plan.Expansion;
0089: import org.cougaar.planning.ldm.plan.ItineraryElement;
0090: import org.cougaar.planning.ldm.plan.Location;
0091: import org.cougaar.planning.ldm.plan.LocationRangeScheduleElement;
0092: import org.cougaar.planning.ldm.plan.LocationScheduleElement;
0093: import org.cougaar.planning.ldm.plan.MPTask;
0094: import org.cougaar.planning.ldm.plan.Plan;
0095: import org.cougaar.planning.ldm.plan.PlanElement;
0096: import org.cougaar.planning.ldm.plan.Preference;
0097: import org.cougaar.planning.ldm.plan.PrepositionalPhrase;
0098: import org.cougaar.planning.ldm.plan.Role;
0099: import org.cougaar.planning.ldm.plan.RoleSchedule;
0100: import org.cougaar.planning.ldm.plan.Schedule;
0101: import org.cougaar.planning.ldm.plan.ScheduleElement;
0102: import org.cougaar.planning.ldm.plan.ScoringFunction;
0103: import org.cougaar.planning.ldm.plan.Task;
0104: import org.cougaar.planning.ldm.plan.TimeAspectValue;
0105: import org.cougaar.planning.ldm.plan.Verb;
0106: import org.cougaar.planning.ldm.plan.Workflow;
0107: import org.cougaar.planning.plugin.util.PluginHelper;
0108: import org.cougaar.util.ConfigFinder;
0109: import org.cougaar.util.PropertyTree;
0110: import org.cougaar.util.Sortings;
0111: import org.cougaar.util.StackElements;
0112: import org.cougaar.util.TimeSpan;
0113: import org.cougaar.util.UnaryPredicate;
0114: import org.w3c.dom.Document;
0115: import org.w3c.dom.Element;
0116:
0117: /**
0118: * A <code>Servlet</code> that generates HTML views of an Agent's Blackboard.
0119: * <p>
0120: * This Servlet allows the user to: <ol>
0121: * <li> List Tasks, PlanElements, Assets, UniqueObjects</li>
0122: * <li> View detailed information for Tasks, PlanElements,
0123: * etc.</li>
0124: * <li> Search for an item by UID</li>
0125: * <li> Illustrates the use of URLs to allow the user to
0126: * seamlessly jump between views of separate blackboards</li>
0127: * <li> Provide XML views of data (using XMLize)</li>
0128: * </ol>.
0129: * <p>
0130: * This is a very large Servlet and is overly-complex to be
0131: * a good example for future Servlet developers. Consider
0132: * using this simple example:
0133: * <pre>
0134: * public class HelloServlet extends HttpServlet {
0135: * private SimpleServletSupport support;
0136: * public void setSimpleServletSupport(SimpleServletSupport support) {
0137: * this.support = support;
0138: * }
0139: * public void doGet(
0140: * HttpServletRequest req,
0141: * HttpServletResponse res) throws IOException {
0142: * PrintWriter out = req.getWriter();
0143: * out.print("Hello from agent "+support.getEncodedAgentName());
0144: * }
0145: * }
0146: * </pre>
0147: * <p>
0148: * <pre>
0149: * @property org.cougaar.planning.servlet.planview.preds
0150: * Name of the example predicate file that is loading into
0151: * the "Advanced Search" page, which defaults to
0152: * "default.preds.dat"
0153: * </pre>
0154: */
0155: public class PlanViewServlet extends ComponentPlugin {
0156:
0157: // this matches the Subscriber system property that's required to capture
0158: // the additional blackboard detail.
0159: private static final boolean ENABLE_STACKS = Boolean
0160: .getBoolean("org.cougaar.core.blackboard.trackPublishers");
0161:
0162: private BlackboardQueryService blackboardQueryService;
0163: private ServletService servletService;
0164: private String myPath;
0165: private PublisherSubscription sub;
0166:
0167: // *not* the one in core -- see below for our private adapter class.
0168: private SimpleServletSupport support;
0169:
0170: // set out path
0171: public void setParameter(Object o) {
0172: if (o instanceof String) {
0173: myPath = (String) o;
0174: } else if (o instanceof List) {
0175: List l = (List) o;
0176: if (l.size() > 0) {
0177: Object o1 = l.get(0);
0178: if (o1 instanceof String) {
0179: myPath = (String) o1;
0180: }
0181: }
0182: }
0183: }
0184:
0185: public void setBlackboardQueryService(
0186: BlackboardQueryService blackboardQueryService) {
0187: this .blackboardQueryService = blackboardQueryService;
0188: }
0189:
0190: public void setServletService(ServletService servletService) {
0191: this .servletService = servletService;
0192: }
0193:
0194: public void load() {
0195: super .load();
0196:
0197: this .support = new SimpleServletSupport();
0198:
0199: HttpServlet servlet = new HttpServlet() {
0200: public void doGet(HttpServletRequest request,
0201: HttpServletResponse response) throws IOException,
0202: ServletException {
0203: PlanViewServlet.this .doGet(request, response);
0204: }
0205: };
0206: try {
0207: servletService.register(myPath, servlet);
0208: } catch (Exception e) {
0209: throw new RuntimeException("Unable register " + myPath, e);
0210: }
0211: }
0212:
0213: protected void setupSubscriptions() {
0214: if (ENABLE_STACKS) {
0215: UnaryPredicate pred = new UniqueObjectPredicate();
0216: sub = (PublisherSubscription) getBlackboardService()
0217: .subscribe(new PublisherSubscription(pred));
0218: }
0219: }
0220:
0221: protected void execute() {
0222: // ignore changes
0223: }
0224:
0225: private static final class UniqueObjectPredicate implements
0226: UnaryPredicate {
0227: public boolean execute(Object o) {
0228: return (o instanceof UniqueObject);
0229: }
0230: }
0231:
0232: // adapted from old "SimpleServletSupport":
0233: private class SimpleServletSupport {
0234: private final String encAgentName;
0235:
0236: public SimpleServletSupport() {
0237: this .encAgentName = encodeAgentName(getAgentIdentifier()
0238: .getAddress());
0239: }
0240:
0241: public String getPath() {
0242: return myPath;
0243: }
0244:
0245: public String getEncodedAgentName() {
0246: return encAgentName;
0247: }
0248:
0249: public String encodeAgentName(String name) {
0250: try {
0251: return URLEncoder.encode(name, "UTF-8");
0252: } catch (java.io.UnsupportedEncodingException e) {
0253: // should never happen
0254: throw new RuntimeException("Unable to encode to UTF-8?");
0255: }
0256: }
0257:
0258: public Collection queryBlackboard(UnaryPredicate pred) {
0259: return blackboardQueryService.query(pred);
0260: }
0261:
0262: // note that our sub is thread-safe and can be used outside of a
0263: // blackboard transaction
0264: public PublisherInfo getInfo(UID uid) {
0265: return (sub == null ? null : sub.getInfo(uid));
0266: }
0267: }
0268:
0269: public void doGet(HttpServletRequest request,
0270: HttpServletResponse response) throws IOException,
0271: ServletException {
0272: // create a new "PlanViewer" context per request
0273: PlanViewer pv = new PlanViewer(support);
0274: pv.execute(request, response);
0275: }
0276:
0277: /**
0278: * This inner class does all the work.
0279: * <p>
0280: * A new class is created per request, to keep all the
0281: * instance fields separate. If there was only one
0282: * instance then multiple simultaneous requests would
0283: * corrupt the instance fields (e.g. the "out" stream).
0284: * <p>
0285: * This acts as a <b>context</b> per request.
0286: */
0287: private static class PlanViewer {
0288:
0289: // some constants:
0290: private static final String PREDS_FILENAME_PROPERTY = "org.cougaar.planning.servlet.planview.preds";
0291: private static final String DEFAULT_PREDS_FILENAME = "default.preds.dat";
0292: private static final boolean DEBUG = false;
0293: private static final int DEFAULT_LIMIT = 100;
0294:
0295: //
0296: // parameters from the URL:
0297: //
0298:
0299: /**
0300: * "mode" constants, which control which page to generate.
0301: */
0302: public static final String MODE = "mode";
0303: public static final int MODE_FRAME = 0;
0304: public static final int MODE_ALL_TASKS = 1;
0305: public static final int MODE_AGENTS = 2;
0306: public static final int MODE_TASK_DETAILS = 3;
0307: public static final int MODE_TASKS_SUMMARY = 4;
0308: public static final int MODE_PLAN_ELEMENT_DETAILS = 5;
0309: public static final int MODE_ALL_PLAN_ELEMENTS = 6;
0310: public static final int MODE_ASSET_DETAILS = 7;
0311: public static final int MODE_ALL_ASSETS = 8;
0312: public static final int MODE_SEARCH = 9;
0313: public static final int MODE_XML_HTML_DETAILS = 10;
0314: public static final int MODE_XML_RAW_DETAILS = 11;
0315: public static final int MODE_ALL_UNIQUE_OBJECTS = 12;
0316: public static final int MODE_WELCOME = 13;
0317: public static final int MODE_WELCOME_DETAILS = 14;
0318: public static final int MODE_TASK_DIRECT_OBJECT_DETAILS = 15;
0319: public static final int MODE_ASSET_TRANSFER_ASSET_DETAILS = 16;
0320: public static final int MODE_XML_HTML_ATTACHED_DETAILS = 17;
0321: public static final int MODE_XML_RAW_ATTACHED_DETAILS = 18;
0322: public static final int MODE_ADVANCED_SEARCH_FORM = 19;
0323: public static final int MODE_ADVANCED_SEARCH_RESULTS = 20;
0324: public static final int MODE_STACK_DETAILS = 21;
0325: private int mode = -1;
0326:
0327: // filter by uid
0328: public static final String ITEM_UID = "uid";
0329: private String itemUID;
0330:
0331: // filter by task verb
0332: public static final String VERB = "verb";
0333: private String verbFilter;
0334:
0335: // limit quantity of data
0336: public static final String LIMIT = "limit";
0337: private boolean limit;
0338:
0339: // predicate
0340: public static final String PREDICATE = "pred";
0341: private String pred;
0342:
0343: // view parsed predicate for debugging
0344: public static final String PREDICATE_DEBUG = "predDebug";
0345: private boolean predDebug;
0346:
0347: // sort results by UID
0348: public static final String SORT_BY_UID = "sortByUID";
0349: private boolean sortByUID;
0350:
0351: // sort results by END_TIME preference
0352: public static final String SORT_BY_END_TIME = "sortByEndTime";
0353: private boolean sortByEndTime;
0354:
0355: // writer from the request
0356: private PrintWriter out;
0357:
0358: // since "PlanViewer" is a static inner class, here
0359: // we hold onto the support API.
0360: //
0361: // this makes it clear that PlanViewer only uses
0362: // the "support" from the outer class.
0363: private SimpleServletSupport support;
0364:
0365: public PlanViewer(SimpleServletSupport support) {
0366: this .support = support;
0367: }
0368:
0369: /**
0370: * Main method.
0371: */
0372: public void execute(HttpServletRequest request,
0373: HttpServletResponse response) throws IOException,
0374: ServletException {
0375: this .out = response.getWriter();
0376:
0377: // create a URL parameter visitor
0378: ServletUtil.ParamVisitor vis = new ServletUtil.ParamVisitor() {
0379: public void setParam(String name, String value) {
0380: if (name.equalsIgnoreCase(MODE)) {
0381: try {
0382: mode = Integer.parseInt(value);
0383: } catch (Exception eBadNumber) {
0384: System.err
0385: .println("INVALID MODE: " + value);
0386: mode = MODE_FRAME;
0387: }
0388: } else if (name.equalsIgnoreCase(ITEM_UID)) {
0389: if (value != null) {
0390: try {
0391: itemUID = URLDecoder.decode(value,
0392: "UTF-8");
0393: } catch (Exception eBadEnc) {
0394: System.err.println("INVALID UID: "
0395: + value);
0396: }
0397: }
0398: } else if (name.equalsIgnoreCase(VERB)) {
0399: verbFilter = value;
0400: } else if (name.equalsIgnoreCase(LIMIT)) {
0401: limit = "true".equalsIgnoreCase(value);
0402: } else if (name.equalsIgnoreCase(PREDICATE)) {
0403: pred = value;
0404: } else if (name.equalsIgnoreCase(PREDICATE_DEBUG)) {
0405: predDebug = ((value != null) ? value
0406: .equalsIgnoreCase("true") : true);
0407: } else if (name.equalsIgnoreCase(SORT_BY_UID)) {
0408: sortByUID = ((value != null) ? value
0409: .equalsIgnoreCase("true") : true);
0410: } else if (name.equalsIgnoreCase(SORT_BY_END_TIME)) {
0411: sortByEndTime = ((value != null) ? value
0412: .equalsIgnoreCase("true") : true);
0413: }
0414: }
0415: };
0416:
0417: // visit the URL parameters
0418: ServletUtil.parseParams(vis, request);
0419:
0420: try {
0421: // decide which page to generate
0422: switch (mode) {
0423: default:
0424: if (DEBUG) {
0425: System.err.println("DEFAULT MODE");
0426: }
0427: case MODE_FRAME:
0428: displayFrame();
0429: break;
0430: case MODE_WELCOME:
0431: displayWelcome();
0432: break;
0433: case MODE_WELCOME_DETAILS:
0434: displayWelcomeDetails();
0435: break;
0436: case MODE_ALL_TASKS:
0437: displayAllTasks();
0438: break;
0439: case MODE_TASK_DETAILS:
0440: displayTaskDetails();
0441: break;
0442: case MODE_TASKS_SUMMARY:
0443: displayTasksSummary();
0444: break;
0445: case MODE_PLAN_ELEMENT_DETAILS:
0446: displayPlanElementDetails();
0447: break;
0448: case MODE_ALL_PLAN_ELEMENTS:
0449: displayAllPlanElements();
0450: break;
0451: case MODE_ASSET_DETAILS:
0452: case MODE_TASK_DIRECT_OBJECT_DETAILS:
0453: case MODE_ASSET_TRANSFER_ASSET_DETAILS:
0454: displayAssetDetails();
0455: break;
0456: case MODE_ALL_ASSETS:
0457: displayAllAssets();
0458: break;
0459: case MODE_AGENTS:
0460: case MODE_SEARCH:
0461: displaySearch();
0462: break;
0463: case MODE_XML_HTML_DETAILS:
0464: case MODE_XML_HTML_ATTACHED_DETAILS:
0465: case MODE_XML_RAW_DETAILS:
0466: case MODE_XML_RAW_ATTACHED_DETAILS:
0467: displayUniqueObjectDetails();
0468: break;
0469: case MODE_ALL_UNIQUE_OBJECTS:
0470: displayAllUniqueObjects();
0471: break;
0472: case MODE_ADVANCED_SEARCH_FORM:
0473: displayAdvancedSearchForm();
0474: break;
0475: case MODE_ADVANCED_SEARCH_RESULTS:
0476: displayAdvancedSearchResults();
0477: break;
0478: case MODE_STACK_DETAILS:
0479: displayStackDetails();
0480: break;
0481: }
0482: } catch (Exception e) {
0483: System.err.println("/$" + support.getEncodedAgentName()
0484: + support.getPath() + " Exception: ");
0485: e.printStackTrace();
0486: out
0487: .print("<html><body><h1>"
0488: + "<font color=red>Unexpected Exception!</font>"
0489: + "</h1><p><pre>");
0490: e.printStackTrace(out);
0491: out.print("</pre></body></html>");
0492: out.flush();
0493: }
0494: }
0495:
0496: /** BEGIN DISPLAY ROUTINES **/
0497:
0498: /**
0499: * displayFrame.
0500: */
0501: private void displayFrame() {
0502: if (DEBUG) {
0503: System.out.println("\nDisplay Frame");
0504: }
0505: out.print("<html>\n" + "<head>\n" + "<title>"
0506: + "Cougaar PlanViewer" + "</title>\n" + "</head>\n"
0507: + "<frameset cols=\"25%,75%\">\n"
0508: + "<frameset rows=\"40%,60%\">\n"
0509: + "<frameset rows=\"25%,75%\">\n" + "<frame"
0510: + " src=\"" + "/agents?format=select&suffix="
0511: + support.getEncodedAgentName()
0512: + "\" name=\"agentFrame\">\n" + "<frame src=\"/$"
0513: + support.getEncodedAgentName() + support.getPath()
0514: + "?" + MODE + "=" + MODE_SEARCH
0515: + "\" name=\"searchFrame\">\n" + "</frameset>\n");
0516: //
0517: // Show blank WelcomeDetails page in itemFrame, since user
0518: // probably didn't specify $encodedAgentName in URL.
0519: //
0520: out.print("<frame src=\"/$");
0521: out.print(support.getEncodedAgentName());
0522: out.print(support.getPath());
0523: out.print("?" + MODE + "=" + MODE_WELCOME_DETAILS
0524: + "\" name=\"itemFrame\">\n" + "</frameset>\n"
0525: + "<frame src=\"/$");
0526: out.print(support.getEncodedAgentName());
0527: out.print(support.getPath());
0528: //
0529: // Show blank Welcome page in tablesFrame, since user
0530: // probably didn't specify $encodedAgentName in URL.
0531: //
0532: out
0533: .print("?"
0534: + MODE
0535: + "="
0536: + MODE_WELCOME
0537: + "\" name=\"tablesFrame\">\n"
0538: + "</frameset>\n"
0539: + "<noframes>\n"
0540: + "<h2>Frame Task</h2>\n"
0541: + "<p>"
0542: + "This document is designed to be viewed using the frames feature. "
0543: + "If you see this message, you are using a non-frame-capable web "
0544: + "client.\n" + "</html>\n");
0545: out.flush();
0546: }
0547:
0548: /**
0549: * displayWelcome.
0550: */
0551: private void displayWelcome() {
0552: if (DEBUG) {
0553: System.out.println("Display Welcome");
0554: }
0555: out.print("<html>\n" + "<head>\n" + "<title>"
0556: + "COUGAAR PlanView" + "</title>\n" + "</head>\n"
0557: + "<body ");
0558: out
0559: .print("bgcolor=\"#F0F0F0\">\n"
0560: + "<p>"
0561: + "<font size=small color=mediumblue>No Agent selected.</font>\n"
0562: + "</body>\n" + "</html>\n");
0563: out.flush();
0564: }
0565:
0566: /**
0567: * displayWelcomeDetails.
0568: */
0569: private void displayWelcomeDetails() {
0570: if (DEBUG) {
0571: System.out.println("Display Welcome Details");
0572: }
0573: out
0574: .print("<html>\n"
0575: + "<head>\n"
0576: + "<title>"
0577: + "Item Details View"
0578: + "</title>\n"
0579: + "</head>\n"
0580: + "<body bgcolor=\"#F0F0F0\">\n"
0581: + "<p>"
0582: + "<font size=small color=mediumblue>No Item selected.</font>\n"
0583: + "</body>\n" + "</html>\n");
0584: out.flush();
0585: }
0586:
0587: /**
0588: * displayTaskDetails.
0589: */
0590: private void displayTaskDetails() {
0591: if (DEBUG) {
0592: System.out.println("\nDisplay Task Details");
0593: }
0594: out.print("<html>\n" + "<head>\n" + "<title>"
0595: + "Children Task View" + "</title>" + "</head>\n"
0596: + "<body bgcolor=\"#F0F0F0\">\n" + "<b>");
0597: // link to agent
0598: printLinkToTasksSummary();
0599: out.print("</b><br>\n" + "Task<br>");
0600: // find task
0601: UniqueObject baseObj = findUniqueObjectWithUID(itemUID);
0602: if (baseObj instanceof Task) {
0603: printTaskDetails((Task) baseObj);
0604: } else {
0605: out.print("<p>" + "<font size=small color=mediumblue>");
0606: if (itemUID == null) {
0607: out.print("No Task selected.");
0608: } else if (baseObj == null) {
0609: out.print("No Task matching \"");
0610: out.print(itemUID);
0611: out.print("\" found.");
0612: } else {
0613: out.print("UniqueObject with UID \"");
0614: out.print(itemUID);
0615: out.print("\" is not a Task: ");
0616: out.print(baseObj.getClass().getName());
0617: }
0618: out.print("</font>" + "<p>\n");
0619: }
0620: out.print("</body>\n" + "</html>\n");
0621: out.flush();
0622: }
0623:
0624: /**
0625: * displayAllTasks.
0626: */
0627: private void displayAllTasks() {
0628: if (DEBUG) {
0629: System.out.println("\nDisplay All Tasks");
0630: }
0631: // find tasks
0632: Collection col;
0633: if (verbFilter != null) {
0634: col = findTasksWithVerb(verbFilter);
0635: } else {
0636: col = findAllTasks();
0637: }
0638: int numTasks = col.size();
0639: Iterator tasksIter = col.iterator();
0640: if (DEBUG) {
0641: System.out.println("Fetched Tasks");
0642: }
0643: // begin page
0644: out.print("<html>\n" + "<head>\n" + "<title>");
0645: out.print(support.getEncodedAgentName());
0646: out.print(" Tasks" + "</title>\n" + "</head>\n"
0647: + "<body bgcolor=\"#F0F0F0\">\n" + "<p>"
0648: + "<center>");
0649: if (limit && (numTasks > DEFAULT_LIMIT)) {
0650: out.print("Showing first <b>");
0651: out.print(DEFAULT_LIMIT);
0652: out.print("</b> of ");
0653: }
0654: out.print("<b>");
0655: out.print(numTasks);
0656: out.print("</b> Task");
0657: if (numTasks != 1) {
0658: out.print("s");
0659: }
0660: if (verbFilter != null) {
0661: out.print(" with verb ");
0662: out.print(verbFilter);
0663: }
0664: out.print(" at ");
0665: out.print(support.getEncodedAgentName());
0666: out.print("</center>\n");
0667: if (limit && (numTasks > DEFAULT_LIMIT)) {
0668: out.print("<center>");
0669: // link to all tasks.
0670: printLinkToAllTasks(verbFilter, 0, numTasks, true);
0671: out.print("</center>\n");
0672: }
0673: // print table headers
0674: out
0675: .print("\n<table align=center border=1 cellpadding=1\n"
0676: + " cellspacing=1 width=75%\n"
0677: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n"
0678: + "<tr>\n"
0679: + "<td colspan=8>"
0680: + "<font size=+1 color=mediumblue><b>Tasks</b></font>"
0681: + "</td>\n"
0682: + "</tr>\n"
0683: + "<tr>\n"
0684: + "<td rowspan=2><font color=mediumblue><b>UID</b></font></td>\n"
0685: + "<td rowspan=2><font color=mediumblue><b>Verb</b></font></td>\n"
0686: + "<td colspan=4>"
0687: + "<font color=mediumblue><b>Direct Object</b></font>"
0688: + "</td>\n"
0689: + "<td rowspan=2>"
0690: + "<font color=mediumblue><b>Prepositional Phrases</b></font>"
0691: + "</td>\n"
0692: + "<td rowspan=2>"
0693: + "<font color=mediumblue><b>Preference Best Values</b></font>"
0694: + "</td>\n"
0695: + "</tr>\n"
0696: + "<tr>\n"
0697: + "<td><font color=mediumblue><b>UID</b></font></td>\n"
0698: + "<td><font color=mediumblue><b>TypeID</b></font></td>\n"
0699: + "<td><font color=mediumblue><b>ItemID</b></font></td>\n"
0700: + "<td><font color=mediumblue><b>Quantity</b></font></td>\n"
0701: + "</tr>\n");
0702: if (numTasks > 0) {
0703: // print table rows
0704: int rows = 0;
0705: while (tasksIter.hasNext()) {
0706: Task task = (Task) tasksIter.next();
0707: out.print("<tr>\n" + "<td>\n");
0708: printLinkToLocalTask(task);
0709: out.print("</td>\n" + "<td>\n");
0710: // show verb
0711: Verb v = task.getVerb();
0712: if (v != null) {
0713: out.print(v.toString());
0714: } else {
0715: out
0716: .print("<font color=red>missing verb</font>");
0717: }
0718: out.print("</td>\n");
0719: // show direct object
0720: printTaskDirectObjectTableRow(task);
0721: // show prepositional phrases
0722: out.print("<td>" + "<font size=-1>");
0723: Enumeration enprep = task.getPrepositionalPhrases();
0724: while (enprep.hasMoreElements()) {
0725: PrepositionalPhrase pp = (PrepositionalPhrase) enprep
0726: .nextElement();
0727: String prep = pp.getPreposition();
0728: out.print("<font color=mediumblue>");
0729: out.print(prep);
0730: out.print("</font> ");
0731: printObject(pp.getIndirectObject());
0732: out.print("<br>");
0733: }
0734: out.print("</font></td><td><font size=-1>");
0735: Enumeration enpref = task.getPreferences();
0736: while (enpref.hasMoreElements()) {
0737: Preference pref = (Preference) enpref
0738: .nextElement();
0739: AspectValue av = pref.getScoringFunction()
0740: .getBest().getAspectValue();
0741: String type = AspectValue.aspectTypeToString(av
0742: .getAspectType());
0743: out.print(encodeHTML(type + ": "
0744: + av.toString(), true));
0745: out.print("<br>");
0746: }
0747: out.print("</font>" + "</td>\n" + "</tr>\n");
0748: if ((++rows % DEFAULT_LIMIT) == 0) {
0749: if (limit) {
0750: // limit to DEFAULT_LIMIT
0751: break;
0752: }
0753: // restart table
0754: out.print("</table>\n");
0755: out.flush();
0756: out
0757: .print("<table align=center border=1 cellpadding=1\n"
0758: + " cellspacing=1 width=75%\n"
0759: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n");
0760: }
0761: }
0762: // end table
0763: out.print("</table>\n");
0764: if (limit && (rows == DEFAULT_LIMIT)) {
0765: // link to unlimited view
0766: out.print("<p>" + "<center>");
0767: printLinkToAllTasks(verbFilter, 0, numTasks, true);
0768: out.print("<br>" + "</center>\n");
0769: }
0770: } else {
0771: // end table
0772: out.print("</table>\n" + "<center>"
0773: + "<font color=mediumblue>\n" + "No Tasks");
0774: if (verbFilter != null) {
0775: out.print(" with verb ");
0776: out.print(verbFilter);
0777: }
0778: out.print(" found in ");
0779: out.print(support.getEncodedAgentName());
0780: out.print("\n...try again" + "</font>" + "</center>\n");
0781: }
0782: // end page
0783: out.print("</body>" + "</html>\n");
0784: out.flush();
0785: }
0786:
0787: /**
0788: * displayTaskSummary.
0789: */
0790: private void displayTasksSummary() {
0791: if (DEBUG) {
0792: System.out.println("\nDisplay Tasks Summary");
0793: }
0794: // find tasks
0795: boolean oldSortByUID = sortByUID;
0796: sortByUID = false;
0797: boolean oldSortByEndTime = sortByEndTime;
0798: sortByEndTime = false;
0799: Collection col = findAllTasks();
0800: sortByUID = oldSortByUID;
0801: sortByEndTime = oldSortByEndTime;
0802: int numTasks = col.size();
0803: Iterator tasksIter = col.iterator();
0804: if (DEBUG) {
0805: System.out.println("Fetched Tasks");
0806: }
0807: // begin page
0808: out.print("<html>\n" + "<head>\n" + "<title>");
0809: out.print(support.getEncodedAgentName());
0810: out.print(" Tasks Summary" + "</title>\n" + "</head>\n"
0811: + "<body bgcolor=\"#F0F0F0\">\n" + "<center>");
0812: printLinkToAllTasks(null, 0, numTasks, false);
0813: out.print("</center>\n");
0814: if (numTasks > DEFAULT_LIMIT) {
0815: // give limit option
0816: out.print("<center>");
0817: printLinkToAllTasks(null, DEFAULT_LIMIT, numTasks,
0818: false);
0819: out.print("</center>\n");
0820: }
0821: // begin table
0822: out
0823: .print("<p>\n"
0824: + "<table align=center border=1 cellpadding=1 cellspacing=1\n"
0825: + " width=75% bordercolordark=#660000 bordercolorlight=#cc9966>\n"
0826: + "<tr>\n"
0827: + "<td colspan=2>"
0828: + "<font size=+1 color=mediumblue><b>Tasks Summary</b></font>"
0829: + "</td>\n"
0830: + "</tr>\n"
0831: + "<tr>\n"
0832: + "<td><font color=mediumblue><b>Verb</font></b></td>\n"
0833: + "<td><font color=mediumblue><b>Count</font></b></td>\n"
0834: + "</tr>\n");
0835: // table rows
0836: if (numTasks != 0) {
0837: // count by verb
0838: HashMap tasksInfoMap = new HashMap();
0839: while (tasksIter.hasNext()) {
0840: Task task = (Task) tasksIter.next();
0841: Verb verb = task.getVerb();
0842: VerbSummaryInfo info = (VerbSummaryInfo) tasksInfoMap
0843: .get(verb);
0844: if (info == null) {
0845: info = new VerbSummaryInfo(verb);
0846: tasksInfoMap.put(verb, info);
0847: }
0848: ++info.counter;
0849: }
0850: // sort by verb
0851: Collection sortedInfosCol = Sortings.sort(tasksInfoMap
0852: .values(),
0853: SummaryInfo.LARGEST_COUNTER_FIRST_ORDER);
0854: Iterator sortedInfosIter = sortedInfosCol.iterator();
0855: // print rows
0856: while (sortedInfosIter.hasNext()) {
0857: VerbSummaryInfo info = (VerbSummaryInfo) sortedInfosIter
0858: .next();
0859: out.print("<tr>\n" + "<td>\n");
0860: // link to all tasks with verb
0861: printLinkToAllTasks(info.verb.toString(), 0,
0862: info.counter, false);
0863: if (info.counter > DEFAULT_LIMIT) {
0864: // link to limited number of tasks with verb
0865: out.print(" (");
0866: printLinkToAllTasks(info.verb.toString(),
0867: DEFAULT_LIMIT, info.counter, false);
0868: out.print(")");
0869: }
0870: out.print("</td>\n" + "<td align=right>");
0871: out.print(info.counter);
0872: out.print("</td>\n" + "</tr>\n");
0873: }
0874: }
0875: // end table
0876: out.print("</table>\n");
0877: if (numTasks == 0) {
0878: out.print("<center>" + "<font color=mediumblue >\n"
0879: + "No Tasks found in ");
0880: out.print(support.getEncodedAgentName());
0881: out.print("\n...try again" + "</font>" + "</center>\n");
0882: }
0883: // end page
0884: out.print("</body>" + "</html>\n");
0885: out.flush();
0886: }
0887:
0888: /**
0889: /**
0890: * displayPlanElementDetails.
0891: */
0892: private void displayPlanElementDetails() {
0893: if (DEBUG) {
0894: System.out.println("\nDisplay PlanElement Details");
0895: }
0896: out.print("<html>\n" + "<head>\n" + "<title>"
0897: + "PlanElement View" + "</title>" + "</head>\n"
0898: + "<body bgcolor=\"#F0F0F0\">\n" + "<b>");
0899: // link to agent
0900: printLinkToTasksSummary();
0901: out.print("</b><br>\n");
0902: // find plan element
0903: UniqueObject baseObj = findUniqueObjectWithUID(itemUID);
0904: if (baseObj instanceof PlanElement) {
0905: printPlanElementDetails((PlanElement) baseObj);
0906: } else {
0907: out.print("<p>" + "<font size=small color=mediumblue>");
0908: if (itemUID == null) {
0909: out.print("No PlanElement selected.");
0910: } else if (baseObj == null) {
0911: out.print("No PlanElement matching \"");
0912: out.print(itemUID);
0913: out.print("\" found.");
0914: } else {
0915: out.print("UniqueObject with UID \"");
0916: out.print(itemUID);
0917: out.print("\" is not a PlanElement: ");
0918: out.print(baseObj.getClass().getName());
0919: }
0920: out.print("</font>" + "<p>\n");
0921: }
0922: out.print("</body>" + "</html>\n");
0923: out.flush();
0924: }
0925:
0926: /**
0927: * displayAllPlanElements.
0928: */
0929: private void displayAllPlanElements() {
0930: if (DEBUG) {
0931: System.out.println("\nDisplay All PlanElements");
0932: }
0933: Collection col = findAllPlanElements();
0934: int numPlanElements = col.size();
0935: Iterator peIter = col.iterator();
0936: if (DEBUG) {
0937: System.out.println("Fetched PlanElements");
0938: }
0939: // begin page
0940: out.print("<html>\n" + "<head>\n" + "<title>");
0941: out.print(support.getEncodedAgentName());
0942: out.print(" PlanElements" + "</title>\n" + "</head>\n"
0943: + "<body bgcolor=\"#F0F0F0\">\n" + "<center>");
0944: if (limit && (numPlanElements > DEFAULT_LIMIT)) {
0945: out.print("Showing first <b>");
0946: out.print(DEFAULT_LIMIT);
0947: out.print("</b> of ");
0948: }
0949: out.print("<b>");
0950: out.print(numPlanElements);
0951: out.print("</b> PlanElement");
0952: if (numPlanElements != 1) {
0953: out.print("s");
0954: }
0955: out.print(" at ");
0956: out.print(support.getEncodedAgentName());
0957: out.print("</center>");
0958: if (limit && (numPlanElements > DEFAULT_LIMIT)) {
0959: out.print("<center>");
0960: // link to all pes
0961: printLinkToAllPlanElements(0, numPlanElements, false);
0962: out.print("</center>");
0963: }
0964: out
0965: .print("\n<table align=center border=1 cellpadding=1\n"
0966: + " cellspacing=1 width=75%\n"
0967: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n"
0968: + "<tr>\n"
0969: + "<td colspan=2>"
0970: + "<font size=+1 color=mediumblue><b>PlanElements</b></font>"
0971: + "</td>\n"
0972: + "</tr>\n"
0973: + "<tr>\n"
0974: + "<td><font color=mediumblue><b>UID</b></font></td>\n"
0975: + "<td><font color=mediumblue><b>Type</b></font></td>\n"
0976: + "</tr>\n");
0977: if (numPlanElements > 0) {
0978: // print table rows
0979: int rows = 0;
0980: while (peIter.hasNext()) {
0981: PlanElement pe = (PlanElement) peIter.next();
0982: out.print("<tr>\n" + "<td>\n");
0983: printLinkToPlanElement(pe);
0984: out.print("</td>\n" + "<td>\n");
0985: int peType = getItemType(pe);
0986: if (peType != ITEM_TYPE_OTHER) {
0987: out.print(ITEM_TYPE_NAMES[peType]);
0988: } else {
0989: out.print("<font color=red>");
0990: if (pe != null) {
0991: out.print(pe.getClass().getName());
0992: } else {
0993: out.print("null");
0994: }
0995: out.print("</font>");
0996: }
0997: out.print("</td>" + "</tr>\n");
0998: if ((++rows % DEFAULT_LIMIT) == 0) {
0999: if (limit) {
1000: // limit to DEFAULT_LIMIT
1001: break;
1002: }
1003: // restart table
1004: out.print("</table>\n");
1005: out.flush();
1006: out
1007: .print("<table align=center border=1 cellpadding=1\n"
1008: + " cellspacing=1 width=75%\n"
1009: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n");
1010: }
1011: }
1012: // end table
1013: out.print("</table>\n");
1014: if (limit && (rows == DEFAULT_LIMIT)) {
1015: // link to unlimited view
1016: out.print("<p>" + "<center>");
1017: printLinkToAllPlanElements(0, numPlanElements,
1018: false);
1019: out.print("<br>" + "</center>\n");
1020: }
1021: } else {
1022: out.print("</table>" + "<center>"
1023: + "<font color=mediumblue>\n"
1024: + "No PlanElements found in ");
1025: out.print(support.getEncodedAgentName());
1026: out.print("\n...try again" + "</font>" + "</center>\n");
1027: }
1028: // end page
1029: out.print("</body>" + "</html>\n");
1030: out.flush();
1031: }
1032:
1033: /**
1034: * displayAssetDetails.
1035: */
1036: private void displayAssetDetails() {
1037: if (DEBUG) {
1038: System.out.println("\nDisplay Asset Details");
1039: }
1040: out.print("<html>\n" + "<head>\n" + "<title>"
1041: + "Asset View" + "</title>" + "</head>\n"
1042: + "<body bgcolor=\"#F0F0F0\">\n" + "<b>");
1043: // link to agent
1044: printLinkToTasksSummary();
1045: out.print("</b><br>\n" + "Asset<br>");
1046: // find "base" UniqueObject with the specifed UID
1047: UniqueObject baseObj = findUniqueObjectWithUID(itemUID);
1048: Asset asset = null;
1049: // get asset
1050: switch (mode) {
1051: case MODE_ASSET_DETAILS:
1052: // asset itself
1053: if (baseObj instanceof Asset) {
1054: asset = (Asset) baseObj;
1055: }
1056: break;
1057: case MODE_TASK_DIRECT_OBJECT_DETAILS:
1058: // asset attached to Task
1059: if (baseObj instanceof Task) {
1060: asset = ((Task) baseObj).getDirectObject();
1061: }
1062: break;
1063: case MODE_ASSET_TRANSFER_ASSET_DETAILS:
1064: // asset attached to AssetTransfer
1065: if (baseObj instanceof AssetTransfer) {
1066: asset = ((AssetTransfer) baseObj).getAsset();
1067: }
1068: break;
1069: default:
1070: break;
1071: }
1072: if (asset != null) {
1073: printAssetDetails(baseObj, asset);
1074: } else {
1075: String baseType;
1076: switch (mode) {
1077: case MODE_ASSET_DETAILS:
1078: baseType = "Asset";
1079: break;
1080: case MODE_TASK_DIRECT_OBJECT_DETAILS:
1081: baseType = "Task";
1082: break;
1083: case MODE_ASSET_TRANSFER_ASSET_DETAILS:
1084: baseType = "AssetTransfer";
1085: break;
1086: default:
1087: baseType = "<font color=red>Error</font>";
1088: break;
1089: }
1090: out.print("<p>" + "<font size=small color=mediumblue>");
1091: if (itemUID == null) {
1092: out.print("No ");
1093: out.print(baseType);
1094: out.print(" selected.");
1095: } else if (baseObj == null) {
1096: out.print("No ");
1097: out.print(baseType);
1098: out.print(" matching \"");
1099: out.print(itemUID);
1100: out.print("\" found in ");
1101: out.print(support.getEncodedAgentName());
1102: out.print(".");
1103: } else {
1104: out.print("UniqueObject with UID \"");
1105: out.print(itemUID);
1106: out.print("\" is not of type ");
1107: out.print(baseType);
1108: out.print(": ");
1109: out.print(baseObj.getClass().getName());
1110: }
1111: out.print("</font>" + "<p>\n");
1112: }
1113: out.print("</body>" + "</html>\n");
1114: out.flush();
1115: }
1116:
1117: /**
1118: * displayAllAssets.
1119: */
1120: private void displayAllAssets() {
1121: if (DEBUG) {
1122: System.out.println("\nDisplay All Assets");
1123: }
1124: Collection col = findAllAssets();
1125: int numAssets = col.size();
1126: Iterator assetIter = col.iterator();
1127: if (DEBUG) {
1128: System.out.println("Fetched Assets");
1129: }
1130: // begin page
1131: out.print("<html>\n" + "<head>\n" + "<title>");
1132: out.print(support.getEncodedAgentName());
1133: out.print(" Assets" + "</title>\n" + "</head>\n"
1134: + "<body bgcolor=\"#F0F0F0\">\n" + "<center>");
1135: if (limit && (numAssets > DEFAULT_LIMIT)) {
1136: out.print("Showing first <b>");
1137: out.print(DEFAULT_LIMIT);
1138: out.print("</b> of ");
1139: }
1140: out.print("<b>");
1141: out.print(numAssets);
1142: out.print("</b> Asset");
1143: if (numAssets != 1) {
1144: out.print("s");
1145: }
1146: out.print(" at ");
1147: out.print(support.getEncodedAgentName());
1148: out.print("</center>");
1149: if (limit && (numAssets > DEFAULT_LIMIT)) {
1150: out.print("<center>");
1151: // link to all assets
1152: printLinkToAllAssets(0, numAssets, false);
1153: out.print("</center>");
1154: }
1155: out
1156: .print("\n<table align=center border=1 cellpadding=1\n"
1157: + " cellspacing=1 width=75%\n"
1158: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n"
1159: + "<tr>\n"
1160: + "<td colspan=4>"
1161: + "<font size=+1 color=mediumblue><b>Assets</b></font>"
1162: + "</td>\n"
1163: + "</tr>\n"
1164: + "<tr>\n"
1165: + "<td><font color=mediumblue><b>UID</font></b></td>\n"
1166: + "<td><font color=mediumblue><b>TypeID</font></b></td>\n"
1167: + "<td><font color=mediumblue><b>ItemID</font></b></td>\n"
1168: + "<td><font color=mediumblue><b>Quantity</font></b></td>\n"
1169: + "</tr>\n");
1170: if (numAssets > 0) {
1171: // print table rows
1172: int rows = 0;
1173: while (assetIter.hasNext()) {
1174: Asset asset = (Asset) assetIter.next();
1175: out.print("<tr>\n");
1176: printAssetTableRow(asset);
1177: out.print("</tr>\n");
1178: if ((++rows % DEFAULT_LIMIT) == 0) {
1179: // restart table
1180: if (limit) {
1181: // limit to DEFAULT_LIMIT
1182: break;
1183: }
1184: out.print("</table>\n");
1185: out.flush();
1186: out
1187: .print("<table align=center border=1 cellpadding=1\n"
1188: + " cellspacing=1 width=75%\n"
1189: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n");
1190: }
1191: }
1192: // end table
1193: out.print("</table>\n");
1194: if (limit && (rows == DEFAULT_LIMIT)) {
1195: // link to unlimited view
1196: out.print("<p>" + "<center>");
1197: printLinkToAllAssets(0, numAssets, false);
1198: out.print("<br>" + "</center>\n");
1199: }
1200: } else {
1201: out.print("</table>" + "<center>"
1202: + "<font color=mediumblue>\n"
1203: + "No Assets found in ");
1204: out.print(support.getEncodedAgentName());
1205: out.print("\n...try again" + "</font>" + "</center>\n");
1206: }
1207: // end page
1208: out.print("</body>" + "</html>\n");
1209: out.flush();
1210: }
1211:
1212: /**
1213: * displaySearch.
1214: * <p>
1215: * Uses JavaScript to set the FORM action, since the user selects
1216: * the agent _after_ page load and the action must point to the
1217: * correct Agent's URL.
1218: */
1219: private void displaySearch() {
1220: if (DEBUG) {
1221: System.out.println("\nDisplay Form");
1222: }
1223: out
1224: .print("<html>\n"
1225: + "<head>"
1226: + "<title>Logplan Search</title>\n"
1227: + "<script language=\"JavaScript\">\n"
1228: + "<!--\n"
1229: + "function mySubmit() {\n"
1230: + " var obj = top.agentFrame.document.agent.name;\n"
1231: + " var encAgent = obj.value;\n"
1232: + " if (encAgent.charAt(0) == '.') {\n"
1233: + " alert(\"Please select an agent name\")\n"
1234: + " return false;\n"
1235: + " }\n"
1236: + " document.myForm.name.value = encAgent;\n"
1237: + " var type = document.myForm.formType.selectedIndex\n"
1238: + " var uid = trim(document.myForm."
1239: + ITEM_UID
1240: + ".value)\n"
1241: + " if (uid.length > 0) {\n"
1242: + " document.myForm.target=\"itemFrame\"\n"
1243: + " if (type == 0) {\n"
1244: + " document.myForm."
1245: + MODE
1246: + ".value= \""
1247: + MODE_TASK_DETAILS
1248: + "\"\n"
1249: + " } else if (type == 1) {\n"
1250: + " document.myForm."
1251: + MODE
1252: + ".value= \""
1253: + MODE_PLAN_ELEMENT_DETAILS
1254: + "\"\n"
1255: + " } else if (type == 2) {\n"
1256: + " document.myForm."
1257: + MODE
1258: + ".value= \""
1259: + MODE_ASSET_DETAILS
1260: + "\"\n"
1261: + " } else {\n"
1262: + " document.myForm."
1263: + MODE
1264: + ".value= \""
1265: + MODE_XML_HTML_DETAILS
1266: + "\"\n"
1267: + " }\n"
1268: + " if (uid.charAt(0) == '/') {\n"
1269: + " document.myForm."
1270: + ITEM_UID
1271: + ".value = encAgent + uid\n"
1272: + " } else if (uid != document.myForm."
1273: + ITEM_UID
1274: + ".value) {\n"
1275: + " document.myForm."
1276: + ITEM_UID
1277: + ".value = uid\n"
1278: + " }\n"
1279: + " } else {\n"
1280: + " document.myForm.target=\"tablesFrame\"\n"
1281: + " if (type == 0) {\n"
1282: + " document.myForm."
1283: + MODE
1284: + ".value= \""
1285: + MODE_TASKS_SUMMARY
1286: + "\"\n"
1287: + " } else if (type == 1) {\n"
1288: + " document.myForm."
1289: + MODE
1290: + ".value= \""
1291: + MODE_ALL_PLAN_ELEMENTS
1292: + "\"\n"
1293: + " } else if (type == 2) {\n"
1294: + " document.myForm."
1295: + MODE
1296: + ".value= \""
1297: + MODE_ALL_ASSETS
1298: + "\"\n"
1299: + " } else {\n"
1300: + " document.myForm."
1301: + MODE
1302: + ".value= \""
1303: + MODE_ALL_UNIQUE_OBJECTS
1304: + "\"\n"
1305: + " }\n"
1306: + " }\n"
1307: + " document.myForm.action=\"/$\"+encAgent+\"");
1308: out.print(support.getPath());
1309: out
1310: .print("\"\n"
1311: + " return true\n"
1312: + "}\n"
1313: + "\n"
1314: + "// javascript lacks String.trim()?\n"
1315: + "function trim(val) {\n"
1316: + " var len = val.length\n"
1317: + " if (len == 0) {\n"
1318: + " return \"\"\n"
1319: + " }\n"
1320: + " var i\n"
1321: + " for (i = 0; ((i < len) && (val.charAt(i) == ' ')); i++) {}\n"
1322: + " if (i == len) {\n"
1323: + " return \"\";\n"
1324: + " }\n"
1325: + " var j \n"
1326: + " for (j = len-1; ((j > i) && (val.charAt(j) == ' ')); j--) {}\n"
1327: + " j++\n"
1328: + " if ((i == 0) && (j == len)) {\n"
1329: + " return val\n"
1330: + " }\n"
1331: + " var ret = val.substring(i, j)\n"
1332: + " return ret\n"
1333: + "}\n"
1334: + "// -->\n"
1335: + "</script>\n"
1336: + "</head>\n"
1337: + "<body bgcolor=\"#F0F0F0\">\n"
1338: + "<noscript>\n"
1339: + "<b>This page needs Javascript!</b><br>\n"
1340: + "Consult your browser's help pages..\n"
1341: + "</noscript>\n"
1342: + "<form name=\"myForm\" method=\"get\" onSubmit=\"return mySubmit()\">\n"
1343: + "<input type=\"hidden\" name=\""
1344: + MODE
1345: + "\" value=\"fromJavaScript\">\n"
1346: + "<input type=\"hidden\" name=\""
1347: + LIMIT
1348: + "\" value=\"true\">\n"
1349: + "<select name=\"formType\">\n"
1350: + " <option selected value=\"0\">Tasks</option>\n"
1351: + " <option value=\"1\">PlanElements</option>\n"
1352: + " <option value=\"2\">Assets</option>\n"
1353: + " <option value=\"3\">UniqueObjects</option>\n"
1354: + "</select><br>\n"
1355: + "UID:<input type=\"text\" name=\""
1356: +
1357: // user should enter an encoded UID
1358: ITEM_UID
1359: + "\" size=12><br>\n"
1360: + "Sort results by UID<input type=\"checkbox\" name=\"sortByUID\" value=\"true\"><br>\n"
1361: + "Sort tasks by End Time<input type=\"checkbox\" name=\"sortByEndTime\" value=\"true\"><br>\n"
1362: + "<input type=\"submit\" name=\"formSubmit\" value=\"Search\"><br>\n"
1363: + "<p>\n" +
1364: // link to advanced search
1365: "<a href=\"/$");
1366: out.print(support.getEncodedAgentName());
1367: out.print(support.getPath());
1368: out.print("?" + MODE + "=" + MODE_ADVANCED_SEARCH_FORM
1369: + "\" target=\"advSearch\">Advanced search</a>"
1370: + "</form>\n" + "</body>\n" + "</html>\n");
1371: }
1372:
1373: /**
1374: * displayUniqueObjectDetails.
1375: */
1376: private void displayUniqueObjectDetails() {
1377: boolean asHTML;
1378: boolean isAttached;
1379: switch (mode) {
1380: default:
1381: // error, but treat as "MODE_XML_HTML_DETAILS"
1382: case MODE_XML_HTML_DETAILS:
1383: asHTML = true;
1384: isAttached = false;
1385: break;
1386: case MODE_XML_HTML_ATTACHED_DETAILS:
1387: asHTML = true;
1388: isAttached = true;
1389: break;
1390: case MODE_XML_RAW_DETAILS:
1391: asHTML = false;
1392: isAttached = false;
1393: break;
1394: case MODE_XML_RAW_ATTACHED_DETAILS:
1395: asHTML = false;
1396: isAttached = true;
1397: break;
1398: }
1399: if (DEBUG) {
1400: System.out.println("\nDisplay UniqueObject "
1401: + (asHTML ? "HTML" : "Raw")
1402: + (isAttached ? " Attached" : "") + " Details");
1403: }
1404: // find base object using the specified UID
1405: UniqueObject baseObj = findUniqueObjectWithUID(itemUID);
1406: // get the attached object
1407: Object attachedObj;
1408: if (isAttached) {
1409: // examine baseObj to find attached xml
1410: //
1411: // currently only a few cases are supported:
1412: // Asset itself
1413: // Task's "getDirectObject()"
1414: // AssetTransfer's "getAsset()"
1415: if (baseObj instanceof Asset) {
1416: // same as above "MODE_XML_[HTML|RAW]_DETAILS"
1417: attachedObj = baseObj;
1418: } else if (baseObj instanceof Task) {
1419: attachedObj = ((Task) baseObj).getDirectObject();
1420: } else if (baseObj instanceof AssetTransfer) {
1421: attachedObj = ((AssetTransfer) baseObj).getAsset();
1422: } else {
1423: // error
1424: attachedObj = null;
1425: }
1426: } else {
1427: // the base itself
1428: attachedObj = baseObj;
1429: }
1430: Object xo = attachedObj;
1431: if (asHTML) {
1432: // print as HTML
1433: out.print("<html>\n<head>\n<title>");
1434: out.print(itemUID);
1435: out.print(" View</title>"
1436: + "</head>\n<body bgcolor=\"#F0F0F0\">\n<b>");
1437: // link to agent
1438: printLinkToTasksSummary();
1439: out.print("</b><br>\n" + "UniqueObject<br>");
1440: if (xo != null) {
1441: // link to non-html view of object
1442: out.print("<p>");
1443: printLinkToXML(xo, false);
1444: if (ENABLE_STACKS) {
1445: out.print("<br><p>"
1446: + "<nowrap>Publisher: ");
1447: UID uid = UID.toUID(itemUID);
1448: printLinkToStack(uid, support.getInfo(uid));
1449: out.print("</nowrap>");
1450: }
1451: out.print("<br><hr><br><pre>\n");
1452: // print HTML-wrapped XML
1453: printXMLDetails(xo, true);
1454: out.print("\n</pre><br><hr><br>\n");
1455: } else {
1456: out.print("<p><font size=small color=mediumblue>");
1457: if (itemUID == null) {
1458: out.print("No UniqueObject selected.");
1459: } else if (baseObj == null) {
1460: out.print("No UniqueObject matching \"");
1461: out.print(itemUID);
1462: out.print("\" found.");
1463: } else if (attachedObj == null) {
1464: out.print("UniqueObject with UID \"");
1465: out.print(itemUID);
1466: out.print("\" of type ");
1467: out.print(baseObj.getClass().getName());
1468: out.print(" has null attached Object.");
1469: } else {
1470: out.print("UniqueObject with UID \"");
1471: out.print(itemUID);
1472: out.print("\" of type ");
1473: out.print(baseObj.getClass().getName());
1474: out.print(" has no XML attached Object: ");
1475: out.print(attachedObj.getClass().getName());
1476: out.print(" (internal error?)");
1477: }
1478: out.print("</font><p>\n");
1479: }
1480: out.print("</body></html>\n");
1481: } else {
1482: // print raw XML
1483: printXMLDetails(xo, false);
1484: }
1485: out.flush();
1486: }
1487:
1488: private static Comparator typeUniqueObjectComparator = new Comparator() {
1489: public int compare(Object o1, Object o2) {
1490: String s1 = getItemTypeString(o1);
1491: String s2 = getItemTypeString(o2);
1492: int diff = s1.compareTo(s2);
1493: if (diff == 0) {
1494: Comparable c1 = ((UniqueObject) o1).getUID();
1495: Comparable c2 = ((UniqueObject) o2).getUID();
1496: diff = c1.compareTo(c2);
1497: }
1498: return diff;
1499: }
1500: };
1501:
1502: /**
1503: * displayAllUniqueObjects.
1504: */
1505: private void displayAllUniqueObjects() {
1506: if (DEBUG) {
1507: System.out.println("\nDisplay All UniqueObjects");
1508: }
1509: List col = new ArrayList(findAllUniqueObjects());
1510: Collections.sort(col, typeUniqueObjectComparator);
1511: int numUniqueObjects = col.size();
1512: Iterator uoIter = col.iterator();
1513: if (DEBUG) {
1514: System.out.println("Fetched UniqueObjects");
1515: }
1516: // begin page
1517: out.print("<html>\n" + "<head>\n" + "<title>");
1518: out.print(support.getEncodedAgentName());
1519: out.print(" UniqueObjects" + "</title>\n" + "</head>\n"
1520: + "<body bgcolor=\"#F0F0F0\">\n" + "<center>");
1521: if (limit && (numUniqueObjects > DEFAULT_LIMIT)) {
1522: out.print("Showing first <b>");
1523: out.print(DEFAULT_LIMIT);
1524: out.print("</b> of ");
1525: }
1526: out.print("<b>");
1527: out.print(numUniqueObjects);
1528: out.print("</b> UniqueObject");
1529: if (numUniqueObjects != 1) {
1530: out.print("s");
1531: }
1532: out.print(" at ");
1533: out.print(support.getEncodedAgentName());
1534: out.print("</center>\n");
1535: if (limit && (numUniqueObjects > DEFAULT_LIMIT)) {
1536: out.print("<center>");
1537: // link to all uniqueObjects.
1538: printLinkToAllUniqueObjects(0, numUniqueObjects, false);
1539: out.print("</center>\n");
1540: }
1541: out
1542: .print("\n<table align=center border=1 cellpadding=1\n"
1543: + " cellspacing=1 width=75%\n"
1544: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n"
1545: + "<tr>\n"
1546: + "<td colspan=2>"
1547: + "<font size=+1 color=mediumblue><b>UniqueObjects</b></font>"
1548: + "</td>\n"
1549: + "</tr>\n"
1550: + "<tr>\n"
1551: + "<td><font color=mediumblue><b>UID</b></font></td>\n"
1552: + "<td><font color=mediumblue><b>Type</b></font></td>\n"
1553: + "</tr>\n");
1554: if (numUniqueObjects > 0) {
1555: // print table rows
1556: int rows = 0;
1557: while (uoIter.hasNext()) {
1558: UniqueObject uo = (UniqueObject) uoIter.next();
1559: int itemType = getItemType(uo);
1560: out.print("<tr>\n" + "<td>");
1561: switch (itemType) {
1562: case ITEM_TYPE_ALLOCATION:
1563: case ITEM_TYPE_EXPANSION:
1564: case ITEM_TYPE_AGGREGATION:
1565: case ITEM_TYPE_DISPOSITION:
1566: case ITEM_TYPE_ASSET_TRANSFER:
1567: printLinkToPlanElement((PlanElement) uo);
1568: break;
1569: case ITEM_TYPE_TASK:
1570: printLinkToLocalTask((Task) uo);
1571: break;
1572: case ITEM_TYPE_ASSET:
1573: // found this asset in local blackboard
1574: printLinkToLocalAsset((Asset) uo);
1575: break;
1576: case ITEM_TYPE_WORKFLOW:
1577: default:
1578: // xml for a local UniqueObject
1579: printLinkToXML(uo, true);
1580: break;
1581: }
1582: out.print("</td>\n" + "<td>");
1583: if (itemType != ITEM_TYPE_OTHER) {
1584: out.print(ITEM_TYPE_NAMES[itemType]);
1585: } else {
1586: out.print("<font color=red>");
1587: out.print(uo.getClass().getName());
1588: out.print("</font>");
1589: }
1590: out.print("</td>\n" + "</tr>\n");
1591: if ((++rows % DEFAULT_LIMIT) == 0) {
1592: if (limit) {
1593: // limit to DEFAULT_LIMIT
1594: break;
1595: }
1596: // restart table
1597: out.print("</table>\n");
1598: out.flush();
1599: out
1600: .print("<table align=center border=1 cellpadding=1\n"
1601: + " cellspacing=1 width=75%\n"
1602: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n");
1603: }
1604: }
1605: // end table
1606: out.print("</table>\n");
1607: if (limit && (rows == DEFAULT_LIMIT)) {
1608: // link to unlimited view
1609: out.print("<p>" + "<center>");
1610: printLinkToAllUniqueObjects(0, numUniqueObjects,
1611: false);
1612: out.print("<br>" + "</center>\n");
1613: }
1614: } else {
1615: out.print("</table>" + "<center>"
1616: + "<font color=mediumblue>\n"
1617: + "No UniqueObjects found in ");
1618: out.print(support.getEncodedAgentName());
1619: out.print("\n...try again" + "</font>" + "</center>\n");
1620: }
1621: // end page
1622: out.print("</body>" + "</html>\n");
1623: out.flush();
1624: }
1625:
1626: // keep a Map of ordered (name, value) pairs
1627: private static PropertyTree TEMPLATE_PREDS = null;
1628:
1629: private static synchronized final PropertyTree getTemplatePreds() {
1630: if (TEMPLATE_PREDS == null) {
1631: String fname = System
1632: .getProperty(PREDS_FILENAME_PROPERTY);
1633: if (fname == null) {
1634: fname = DEFAULT_PREDS_FILENAME;
1635: }
1636: try {
1637: InputStream in = ConfigFinder.getInstance().open(
1638: fname);
1639: TEMPLATE_PREDS = PredTableParser.parse(in);
1640: } catch (IOException ioe) {
1641: System.err
1642: .println("Unable to open predicate file \""
1643: + fname + "\":");
1644: TEMPLATE_PREDS = new PropertyTree(1);
1645: TEMPLATE_PREDS.put("Unable to load \\\\" + fname
1646: + "\\\"", "");
1647: }
1648: }
1649: return TEMPLATE_PREDS;
1650: }
1651:
1652: private void displayAdvancedSearchForm() {
1653: if (DEBUG) {
1654: System.out.println("\nDisplay Advanced Search Form");
1655: }
1656: out
1657: .print("<html>\n"
1658: + "<script language=\"JavaScript\">\n"
1659: + "<!--\n"
1660: + "function mySubmit() {\n"
1661: + " var encAgent = document.myForm.formAgent.value\n"
1662: + " document.myForm.action=\"/$\"+encAgent+\"");
1663: out.print(support.getPath());
1664: out
1665: .print("\"\n"
1666: + " return true\n"
1667: + "}\n"
1668: + "\n"
1669: + "function setPred() {\n"
1670: + " var i = document.myForm.formPred.selectedIndex\n"
1671: + " var s\n"
1672: + " switch(i) {\n"
1673: + " default: alert(\"unknown (\"+i+\")\"); break\n");
1674: PropertyTree templatePreds = getTemplatePreds();
1675: int nTemplatePreds = templatePreds.size();
1676: for (int i = 0; i < nTemplatePreds; i++) {
1677: out.print("case ");
1678: out.print(i);
1679: out.print(": s=\"");
1680: out.print(templatePreds.getValue(i));
1681: out.print("\"; break\n");
1682: }
1683: out.print(" }\n" + " document.myForm.pred.value=s\n"
1684: + "}\n" + "// -->\n" + "</script>\n" + "<head>\n"
1685: + "<title>");
1686: out.print(support.getEncodedAgentName());
1687: out
1688: .print(" Advanced Search Form"
1689: + "</title>\n"
1690: + "</head>\n"
1691: + "<body bgcolor=\"#F0F0F0\" "
1692: + " onload=\"setPred()\">\n"
1693: + "<font size=+1><b>Advanced Search</b></font><p>"
1694: +
1695: // should add link here for usage!!!
1696: "<noscript>\n"
1697: + "<b>This page needs Javascript!</b><br>\n"
1698: + "Consult your browser's help pages..\n"
1699: + "<p><p><p>\n"
1700: + "</noscript>\n"
1701: + "<form name=\"myForm\" method=\"get\" "
1702: + "target=\"predResults\" onSubmit=\"return mySubmit()\">\n"
1703: + "Search agent <input type=\"text\" name=\"formAgent\" value=\"");
1704: out.print(support.getEncodedAgentName());
1705: out.print("\"><br>\n");
1706: if (nTemplatePreds > 0) {
1707: out.print("<b>Find all </b>"
1708: + "<select name=\"formPred\" "
1709: + "onchange=\"setPred()\">\n");
1710: for (int i = 0; i < nTemplatePreds; i++) {
1711: out.print("<option>");
1712: out.print(templatePreds.getKey(i));
1713: out.print("</option>\n");
1714: }
1715: out.print("</select><br>\n");
1716: }
1717: out
1718: .print("<input type=\"checkbox\" name=\""
1719: + LIMIT
1720: + "\" value=\"true\" checked>"
1721: + "limit to "
1722: + DEFAULT_LIMIT
1723: + " matches<br>\n"
1724: + "<input type=\"submit\" name=\"formSubmit\" value=\"Search\"><br>\n"
1725: + "<p><hr>\n"
1726: + "<input type=\"checkbox\" name=\""
1727: + PREDICATE_DEBUG
1728: + "\" value=\"true\">View parsed predicate<br>\n"
1729: + "<textarea name=\""
1730: + PREDICATE
1731: + "\" rows=15 cols=70>\n"
1732: + "</textarea><br>\n"
1733: + "<input type=\"hidden\" name=\""
1734: + MODE
1735: + "\" value=\""
1736: + MODE_ADVANCED_SEARCH_RESULTS
1737: + "\">\n"
1738: + "<br><hr>\n"
1739: + "</form>\n"
1740: + "<i><b>Documentation</b> is available in the \"contract\" "
1741: + "guide and javadocs, as "
1742: + "/src/org/cougaar/lib/contract/lang/index.html"
1743: + "</i>" + "</body>" + "</html>\n");
1744: out.flush();
1745: }
1746:
1747: private void displayAdvancedSearchResults() {
1748: if (DEBUG) {
1749: System.out.println("\nDisplay Advanced Search Results");
1750: }
1751:
1752: String inputPred = pred;
1753:
1754: out.print("<html><head><title>");
1755: out.print(support.getEncodedAgentName());
1756: out.print(" Advanced Search Results</title><head>\n"
1757: + "<body bgcolor=\"#F0F0F0\"><p>\n" + "Search <b>");
1758: out.print(support.getEncodedAgentName());
1759: out.print("</b> using Lisp-style predicate: <br><pre>\n");
1760: out.print(inputPred);
1761: out.print("</pre><p>\n<hr><br>\n");
1762:
1763: // parse the input to create a unary predicate
1764: UnaryPredicate parsedPred;
1765: try {
1766: parsedPred = UnaryPredicateParser.parse(inputPred);
1767: } catch (Exception parseE) {
1768: // display compile error
1769: out
1770: .print("<font color=red size=+1>Parsing failure:</font>"
1771: + "<p><pre>");
1772: out.print(parseE.getMessage());
1773: out.print("</pre></body></html>");
1774: out.flush();
1775: return;
1776: }
1777:
1778: if (parsedPred == null) {
1779: // empty string?
1780: out
1781: .print("<font color=red size=+1>Given empty string?</font>"
1782: + "</body></html>");
1783: out.flush();
1784: return;
1785: }
1786:
1787: if (predDebug) {
1788: // this is useful in general, but clutters the screen...
1789: out.print("Parsed as:<pre>\n");
1790: out.print(parsedPred);
1791: out.print("</pre><br><hr><br>\n");
1792: }
1793:
1794: Collection col = searchUsingPredicate(parsedPred);
1795: int numObjects = col.size();
1796: Iterator oIter = col.iterator();
1797: if (DEBUG) {
1798: System.out.println("Fetched Matching Objects["
1799: + numObjects + "]");
1800: }
1801: out.print("<b>Note:</b> "
1802: + "links below will appear in the \"");
1803: out.print(support.getPath());
1804: out.print("\" lower-left \"details\" " + "frame<p>"
1805: + "<center>");
1806: if (limit && (numObjects > DEFAULT_LIMIT)) {
1807: out.print("Showing first <b>");
1808: out.print(DEFAULT_LIMIT);
1809: out.print("</b> of ");
1810: }
1811: out.print("<b>");
1812: out.print(numObjects);
1813: out.print("</b> Object");
1814: if (numObjects != 1) {
1815: out.print("s");
1816: }
1817: out.print(" at ");
1818: out.print(support.getEncodedAgentName());
1819: out.print("</center>\n");
1820: out
1821: .print("\n<table align=center border=1 cellpadding=1\n"
1822: + " cellspacing=1 width=75%\n"
1823: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n"
1824: + "<tr>\n"
1825: + "<td colspan=2>"
1826: + "<font size=+1 color=mediumblue><b>Matching Objects</b></font>"
1827: + "</td>\n"
1828: + "</tr>\n"
1829: + "<tr>\n"
1830: + "<td><font color=mediumblue><b>UID</font></b></td>\n"
1831: + "<td><font color=mediumblue><b>Type</font></b></td>\n"
1832: + "</tr>\n");
1833: if (numObjects > 0) {
1834: // print table rows
1835: int rows = 0;
1836: while (oIter.hasNext()) {
1837: Object o = oIter.next();
1838: int itemType = getItemType(o);
1839: out.print("<tr>\n" + "<td>");
1840: switch (itemType) {
1841: case ITEM_TYPE_ALLOCATION:
1842: case ITEM_TYPE_EXPANSION:
1843: case ITEM_TYPE_AGGREGATION:
1844: case ITEM_TYPE_DISPOSITION:
1845: case ITEM_TYPE_ASSET_TRANSFER:
1846: printLinkToPlanElement((PlanElement) o);
1847: break;
1848: case ITEM_TYPE_TASK:
1849: printLinkToLocalTask((Task) o);
1850: break;
1851: case ITEM_TYPE_ASSET:
1852: // found this asset in local blackboard
1853: printLinkToLocalAsset((Asset) o);
1854: break;
1855: case ITEM_TYPE_WORKFLOW:
1856: default:
1857: // xml for a local UniqueObject
1858: printLinkToXML(o, true);
1859: break;
1860: }
1861: out.print("</td>\n" + "<td>");
1862: if (itemType != ITEM_TYPE_OTHER) {
1863: out.print(ITEM_TYPE_NAMES[itemType]);
1864: } else {
1865: out.print("<font color=red>");
1866: out.print(o.getClass().getName());
1867: out.print("</font>");
1868: }
1869: out.print("</td>\n" + "</tr>\n");
1870: if ((++rows % DEFAULT_LIMIT) == 0) {
1871: if (limit) {
1872: // limit to DEFAULT_LIMIT
1873: break;
1874: }
1875: // restart table
1876: out.print("</table>\n");
1877: out.flush();
1878: out
1879: .print("<table align=center border=1 cellpadding=1\n"
1880: + " cellspacing=1 width=75%\n"
1881: + " bordercolordark=#660000 bordercolorlight=#cc9966>\n");
1882: }
1883: }
1884: // end table
1885: out.print("</table>\n");
1886: } else {
1887: out.print("</table>" + "<center>"
1888: + "<font color=mediumblue>\n"
1889: + "No matching Objects found in ");
1890: out.print(support.getEncodedAgentName());
1891: out.print("\n...try again" + "</font>" + "</center>\n");
1892: }
1893: // end page
1894: out.print("</body>" + "</html>\n");
1895: out.flush();
1896: }
1897:
1898: private void displayStackDetails() {
1899: out.print("<html><head><title>");
1900: out.print(support.getEncodedAgentName());
1901: out.print(" Stack Details</title></head>\n"
1902: + "<body bgcolor=\"#F0F0F0\"><p>\n" + "<b>");
1903: // link to agent
1904: printLinkToTasksSummary();
1905: out.print("</b><br>\n");
1906: if (itemUID == null) {
1907: out.print("<font color=red>Missing UID</font>");
1908: } else {
1909: UniqueObject uo = findUniqueObjectWithUID(itemUID);
1910: out.print("Publisher info for " + getItemTypeString(uo)
1911: + " " + itemUID + "<p>");
1912: UID uid = UID.toUID(itemUID);
1913: PublisherInfo info = support.getInfo(uid);
1914: if (info == null) {
1915: out
1916: .print("<font color=red>Unable to find info for "
1917: + uid.toString() + "</font>");
1918: } else {
1919: // print publisher
1920: String publisher = info.getPublisher();
1921: out
1922: .print("<font color=mediumblue><nowrap>Publisher: ");
1923: if (publisher == null) {
1924: out.print("<font color=red>Unknown</font>");
1925: } else {
1926: out.print(encodeHTML(publisher, true));
1927: }
1928: out.print("</nowrap></font>" + "<p>\n");
1929: // print add
1930: printStack(info.getAddStack(), uid, "publishAdd");
1931: // print changes
1932: Set change_stacks = info.getChangeStacks();
1933: int n = (change_stacks == null ? 0 : change_stacks
1934: .size());
1935: if (n > 0) {
1936: Iterator iter = change_stacks.iterator();
1937: for (int i = 0; i < n; i++) {
1938: StackElements se = (StackElements) iter
1939: .next();
1940: String id = "publishChange[" + i + " / "
1941: + n + "]";
1942: printStack(se, uid, id);
1943: }
1944: if (n > 1) {
1945: out
1946: .print("<p>"
1947: + "<b>Note</b>:"
1948: + " Only unique publishChange stacks are shown, and they"
1949: + " are listed in the order that they were <i>first</i>"
1950: + " observed.");
1951: }
1952: }
1953: }
1954: }
1955: out.print("</body>\n" + "</html>\n");
1956: out.flush();
1957: }
1958:
1959: /** END DISPLAY ROUTINES **/
1960:
1961: /** BEGIN PRINT ROUTINES **/
1962:
1963: /**
1964: * printTaskDetails.
1965: *
1966: * Includes support for printing early-best-latest dates
1967: * for END_TIMEs with VScoringFunctions.
1968: *
1969: */
1970: private void printTaskDetails(Task task) {
1971: out.print("<ul>\n" + "<li>"
1972: + "<font size=small color=mediumblue>UID= ");
1973: // show uid
1974: UID tu;
1975: String tuid;
1976: if (((tu = task.getUID()) != null)
1977: && ((tuid = tu.toString()) != null)) {
1978: out.print(tuid);
1979: } else {
1980: out.print("</font><font color=red>missing</font>");
1981: }
1982: out.print("</font>" + "</li>\n");
1983: printListItemForStack(tu);
1984: out.print("<li>"
1985: + "<font size=small color=mediumblue>Verb= ");
1986: // show verb
1987: Verb verb = task.getVerb();
1988: if (verb != null) {
1989: out.print(verb.toString());
1990: } else {
1991: out.print("</font><font color=red>missing");
1992: }
1993: out.print("</font>" + "</li>\n" + "<li>"
1994: + "<font size=small color=mediumblue>"
1995: + "DirectObject= ");
1996: // link to Task's direct object
1997: printLinkToTaskDirectObject(task);
1998: out.print("</font>" + "</li>\n" + "<li>"
1999: + "<font size=small color=mediumblue>"
2000: + "PlanElement= ");
2001: // link to plan element
2002: PlanElement pe = task.getPlanElement();
2003: printLinkToPlanElement(pe);
2004: out.print(" (");
2005: int peType = getItemType(pe);
2006: if (peType != ITEM_TYPE_OTHER) {
2007: out.print(ITEM_TYPE_NAMES[peType]);
2008: } else {
2009: out.print("<font color=red>");
2010: if (pe != null) {
2011: out.print(pe.getClass().getName());
2012: } else {
2013: out.print("null");
2014: }
2015: out.print("</font>");
2016: }
2017: out.print(")" + "</font>" + "</li>");
2018: // show parent task(s) by UID
2019: if (task instanceof MPTask) {
2020: out.print("<li>\n"
2021: + "<font size=small color=mediumblue>"
2022: + "ParentTasks<br>\n" + "<ol>\n");
2023: /********************************************************
2024: * Only want UIDs, so easy fix when getParentTasks is *
2025: * replaced with getParentTaskUIDs. *
2026: ********************************************************/
2027: Enumeration parentsEn = ((MPTask) task)
2028: .getParentTasks();
2029: while (parentsEn.hasMoreElements()) {
2030: Task pt = (Task) parentsEn.nextElement();
2031: out.print("<li>");
2032: // parents of an MPTask are always local
2033: printLinkToLocalTask(pt);
2034: out.print("</li>\n");
2035: }
2036: out.print("</ol>\n" + "</font>\n" + "</li>\n");
2037: } else {
2038: out.print("<li>\n"
2039: + "<font size=small color=mediumblue>"
2040: + "ParentTask= \n");
2041: printLinkToParentTask(task);
2042: out.print("</font>" + "</li>\n");
2043: }
2044: // show preferences
2045: out.print("<li>" + "<font size=small color=mediumblue>"
2046: + "Preferences" + "</font>" + "<ol>\n");
2047: Enumeration enpref = task.getPreferences();
2048: while (enpref.hasMoreElements()) {
2049: Preference pref = (Preference) enpref.nextElement();
2050: int type = pref.getAspectType();
2051: out
2052: .print("<font size=small color=mediumblue>"
2053: + "<li>");
2054: out.print(AspectValue.aspectTypeToString(type));
2055: out.print("= ");
2056: ScoringFunction sf = pref.getScoringFunction();
2057: AspectScorePoint best = sf.getBest();
2058: double bestVal = best.getValue();
2059: String bestString;
2060: if ((type == AspectType.START_TIME)
2061: || (type == AspectType.END_TIME)) {
2062: if ((type == AspectType.END_TIME)
2063: && (sf instanceof ScoringFunction.VScoringFunction)) {
2064: bestString = "<br>" + "Earliest "
2065: + getTimeString(getEarlyDate(sf))
2066: + "<br>" + "Best "
2067: + getTimeString((long) bestVal)
2068: + "<br>" + "Latest "
2069: + getTimeString(getLateDate(sf));
2070: } else {
2071: bestString = getTimeString((long) bestVal);
2072: }
2073: } else {
2074: bestString = Double.toString(bestVal);
2075: }
2076: out.print(bestString);
2077: out.print("</li>" + "</font>\n");
2078: }
2079: out.print("</ol>" + "</li>\n" + "<li>\n"
2080: + "<font size=small color=mediumblue>"
2081: + "PrepositionalPhrases<br>\n" + "<ol>\n");
2082: // show prepositional phrases
2083: Enumeration enprep = task.getPrepositionalPhrases();
2084: while (enprep.hasMoreElements()) {
2085: PrepositionalPhrase pp = (PrepositionalPhrase) enprep
2086: .nextElement();
2087: out.print("<li>");
2088: if (pp != null) {
2089: String prep = pp.getPreposition();
2090: out.print("<i>");
2091: out.print(prep);
2092: out.print(" </i>");
2093: Object indObj = pp.getIndirectObject();
2094: if (!(indObj instanceof Schedule)) {
2095: // typical case
2096: printObject(indObj);
2097: } else {
2098: // display full schedule information
2099: Schedule sc = (Schedule) indObj;
2100: out.print("Schedule:<ul>\n" + "<li>Type: ");
2101: out.print(sc.getScheduleType());
2102: if (sc.isEmpty()) {
2103: out
2104: .print("</li>\n<li><font color=red>empty</font>");
2105: } else {
2106: out.print("</li>\n<li>StartTime= ");
2107: out.print(getTimeString(sc.getStartTime()));
2108: out.print("</li>\n<li>EndTime= ");
2109: out.print(getTimeString(sc.getEndTime()));
2110: out.print("</li>\n");
2111: out.print("<li>Elements:");
2112: out.print("\n<ol>\n");
2113: Iterator iterator = new ArrayList(sc)
2114: .iterator();
2115: while (iterator.hasNext()) {
2116: ScheduleElement se = (ScheduleElement) iterator
2117: .next();
2118: out.print("<li>StartTime= ");
2119: out.print(getTimeString(se
2120: .getStartTime()));
2121: out.print("<br>EndTime= ");
2122: out
2123: .print(getTimeString(se
2124: .getEndTime()));
2125: if (se instanceof LocationRangeScheduleElement) {
2126: LocationRangeScheduleElement locSE = (LocationRangeScheduleElement) se;
2127: out.print("<br>StartLocation= ");
2128: out.print(locSE.getStartLocation());
2129: out.print("<br>EndLocation= ");
2130: out.print(locSE.getEndLocation());
2131: if (locSE instanceof ItineraryElement) {
2132: out.print("<br>Verb= ");
2133: out
2134: .print(((ItineraryElement) locSE)
2135: .getRole());
2136: }
2137: } else if (se instanceof LocationScheduleElement) {
2138: out.print("<br>Location= ");
2139: out
2140: .print(((LocationScheduleElement) se)
2141: .getLocation());
2142: }
2143: out.print("</li>\n");
2144: }
2145: out.print("</ol>\n");
2146: }
2147: out.print("</li>\n</ul>\n");
2148: }
2149: } else {
2150: out.print("<font color=red>null</font>");
2151: }
2152: out.print("</li>");
2153: }
2154: out.print("</font>" + "</ol>\n" + "</li>\n" + "</ul>\n");
2155: // link to XML view
2156: out.print("<font size=small color=mediumblue>");
2157: // this task is local
2158: printLinkToXML(task, true);
2159: out.print("</font>");
2160: }
2161:
2162: /**
2163: * Part of support for printing early-best-latest dates
2164: * for END_TIMEs with VScoringFunctions.
2165: */
2166: private static long getEarlyDate(ScoringFunction vsf) {
2167: Enumeration validRanges = getValidEndDateRanges(vsf);
2168: while (validRanges.hasMoreElements()) {
2169: AspectScoreRange range = (AspectScoreRange) validRanges
2170: .nextElement();
2171: return ((AspectScorePoint) range.getRangeStartPoint())
2172: .getAspectValue().longValue();
2173: }
2174: // should be TimeSpan.MIN_VALUE!
2175: return 0;
2176: }
2177:
2178: /**
2179: * Part of support for printing early-best-latest dates
2180: * for END_TIMEs with VScoringFunctions.
2181: */
2182: private static long getLateDate(ScoringFunction vsf) {
2183: Enumeration validRanges = getValidEndDateRanges(vsf);
2184: while (validRanges.hasMoreElements()) {
2185: AspectScoreRange range = (AspectScoreRange) validRanges
2186: .nextElement();
2187: if (!validRanges.hasMoreElements())
2188: return ((AspectScorePoint) range.getRangeEndPoint())
2189: .getAspectValue().longValue();
2190: }
2191: return TimeSpan.MAX_VALUE;
2192: }
2193:
2194: /* Needed for support of printing early-best-latest END_TIMEs */
2195: private static Calendar cal = java.util.Calendar.getInstance();
2196:
2197: /* Needed for support of printing early-best-latest END_TIMEs */
2198: private static Date endOfRange;
2199: static {
2200: cal.set(2200, 0, 0, 0, 0, 0);
2201: cal.set(Calendar.MILLISECOND, 0);
2202: endOfRange = (Date) cal.getTime();
2203: }
2204:
2205: /**
2206: * Part of support for printing early-best-latest dates
2207: * for END_TIMEs with VScoringFunctions.
2208: */
2209: private static Enumeration getValidEndDateRanges(
2210: ScoringFunction sf) {
2211: Enumeration validRanges = sf.getValidRanges(TimeAspectValue
2212: .create(AspectType.END_TIME, 0l), TimeAspectValue
2213: .create(AspectType.END_TIME, endOfRange));
2214: return validRanges;
2215: }
2216:
2217: /**
2218: * printPlanElementDetails.
2219: *
2220: * PlanElements are always in the blackboard and have UIDs, so we
2221: * don't need a "baseObj" (e.g. the Task that this PlanElement
2222: * is attached to).
2223: */
2224: private void printPlanElementDetails(PlanElement pe) {
2225: int peType = getItemType(pe);
2226: // show type
2227: if (peType != ITEM_TYPE_OTHER) {
2228: out.print(ITEM_TYPE_NAMES[peType]);
2229: } else {
2230: out.print("<font color=red>");
2231: out.print(pe.getClass().getName());
2232: out.print("</font>\n");
2233: }
2234: out.print("<ul>\n");
2235: // show UID
2236: out.print("<li>" + "<font size=small color=mediumblue>"
2237: + "UID= ");
2238: UID peu = pe.getUID();
2239: out.print((peu != null) ? peu.toString() : "null");
2240: out.print("</font>" + "</li>\n");
2241: printListItemForStack(peu);
2242: // show task
2243: out.print("<li>" + "<font size=small color=mediumblue>"
2244: + "Task= ");
2245: printLinkToLocalTask(pe.getTask());
2246: out.print("</font>" + "</li>\n");
2247: // show plan
2248: Plan plan = pe.getPlan();
2249: if (plan != null) {
2250: out.print("<li>" + "<font size=small color=mediumblue>"
2251: + "Plan= ");
2252: out.print(plan.getPlanName());
2253: out.print("</font>" + "</li>\n");
2254: }
2255: // show allocation results
2256: out.print("<li>" + "<font size=small color=mediumblue>"
2257: + "Allocation Results</font>\n" + "<ul>\n");
2258: AllocationResult ar;
2259: if ((ar = pe.getEstimatedResult()) != null) {
2260: out.print("<li>" + "<font size=small color=mediumblue>"
2261: + "Estimated</font>");
2262: printAllocationResultDetails(ar);
2263: out.print("</li>\n");
2264: }
2265: if ((ar = pe.getReportedResult()) != null) {
2266: out.print("<li>" + "<font size=small color=mediumblue>"
2267: + "Reported</font>");
2268: printAllocationResultDetails(ar);
2269: out.print("</li>\n");
2270: }
2271: if ((ar = pe.getReceivedResult()) != null) {
2272: out.print("<li>" + "<font size=small color=mediumblue>"
2273: + "Received</font>");
2274: printAllocationResultDetails(ar);
2275: out.print("</li>\n");
2276: }
2277: if ((ar = pe.getObservedResult()) != null) {
2278: out.print("<li>" + "<font size=small color=mediumblue>"
2279: + "Observed</font>");
2280: printAllocationResultDetails(ar);
2281: out.print("</li>\n");
2282: }
2283: out.print("</ul>" + "</li>\n");
2284: // show PE subclass information
2285: switch (peType) {
2286: case ITEM_TYPE_ALLOCATION:
2287: printAllocationDetails((Allocation) pe);
2288: break;
2289: case ITEM_TYPE_EXPANSION:
2290: printExpansionDetails((Expansion) pe);
2291: break;
2292: case ITEM_TYPE_AGGREGATION:
2293: printAggregationDetails((Aggregation) pe);
2294: break;
2295: case ITEM_TYPE_DISPOSITION:
2296: printDispositionDetails((Disposition) pe);
2297: break;
2298: case ITEM_TYPE_ASSET_TRANSFER:
2299: printAssetTransferDetails((AssetTransfer) pe);
2300: break;
2301: default: // other
2302: out.print("<li>" + "<font color=red>"
2303: + "No details for class ");
2304: out.print(pe.getClass().getName());
2305: out.print("</font></li>");
2306: break;
2307: }
2308: out.print("</ul>\n");
2309: // link to XML view
2310: out.print("<font size=small color=mediumblue>");
2311: // planElements are always local
2312: printLinkToXML(pe, true);
2313: out.print("</font>");
2314: }
2315:
2316: /**
2317: * printAllocationResultDetails.
2318: */
2319: private void printAllocationResultDetails(AllocationResult ar) {
2320: out.print("<ul>\n" + "<font size=small color=mediumblue>"
2321: + "<li>" + "isSuccess= ");
2322: // show isSuccess
2323: out.print(ar.isSuccess());
2324: out.print("</li>" + "</font>\n"
2325: + "<font size=small color=mediumblue>" + "<li>"
2326: + "Confidence= ");
2327: // show confidence rating
2328: out.print(ar.getConfidenceRating());
2329: out.print("</li>" + "</font>\n");
2330: // for all (type, result) pairs
2331: AspectValue[] ava = ar.getAspectValueResults();
2332: for (int i = 0; i < ava.length; i++) {
2333: AspectValue avi = ava[i];
2334: out
2335: .print("<font size=small color=mediumblue>"
2336: + "<li>");
2337: // show type
2338: out
2339: .print(AspectValue.aspectTypeToString(avi
2340: .getType()));
2341: out.print("= ");
2342: // show value
2343: if (avi instanceof TimeAspectValue) {
2344: // print the date in our format
2345: long time = ((TimeAspectValue) avi).timeValue();
2346: out.print(getTimeString(time));
2347: } else {
2348: out.print(avi);
2349: }
2350: out.print("</li>" + "</font>\n");
2351: }
2352: // show phased details
2353: if (ar.isPhased()) {
2354: out.print("<font size=small color=mediumblue>" + "<li>"
2355: + "isPhased= true" + "</li>" + "</font>\n");
2356: // user likely not interested in phased results
2357: }
2358: out.print("</ul>\n");
2359: }
2360:
2361: /**
2362: * printAllocationDetails.
2363: */
2364: private void printAllocationDetails(Allocation ac) {
2365: // show asset
2366: Asset asset = ac.getAsset();
2367: if (asset != null) {
2368: // link to allocated asset
2369: ClusterPG clusterPG = asset.getClusterPG();
2370: MessageAddress agentID;
2371: String remoteAgentID = ((((clusterPG = asset
2372: .getClusterPG()) != null) && ((agentID = clusterPG
2373: .getMessageAddress()) != null)) ? agentID
2374: .toString() : null);
2375: boolean isRemoteAgent = (remoteAgentID != null);
2376: out
2377: .print("<li>"
2378: + "<font size=small color=mediumblue>");
2379: out.print(isRemoteAgent ? "Agent" : "Asset");
2380: out.print("= ");
2381: // allocations are always to an asset in the local blackboard
2382: printLinkToLocalAsset(asset);
2383: out.print("</font>" + "</li>\n");
2384: if (isRemoteAgent) {
2385: // link to task in other agent
2386: String encRemoteAgentID = support
2387: .encodeAgentName(remoteAgentID);
2388: UID allocTaskUID = ((AllocationforCollections) ac)
2389: .getAllocationTaskUID();
2390: out.print("<li>"
2391: + "<font size=small color=mediumblue>"
2392: + "AllocTask= ");
2393: printLinkToTask(allocTaskUID, encRemoteAgentID);
2394: out.print("</font>" + "</li>\n");
2395: }
2396: } else {
2397: out.print("<li>" + "<font size=small color=mediumblue>"
2398: + "Asset= </font>"
2399: + "<font color=red>null</font>" + "</li>\n");
2400: }
2401: }
2402:
2403: /**
2404: * printExpansionDetails.
2405: */
2406: private void printExpansionDetails(Expansion ex) {
2407: // link to child tasks
2408: out.print("<li>" + "<font size=small color=black>"
2409: + "<i>Child Tasks</i>" + "</font>" + "<ol>\n");
2410: Enumeration en = ex.getWorkflow().getTasks();
2411: while (en.hasMoreElements()) {
2412: Task tsk = (Task) en.nextElement();
2413: out
2414: .print("<font size=small color=mediumblue>"
2415: + "<li>");
2416: // expanded task is always local
2417: printLinkToLocalTask(tsk);
2418: out.print("</li>" + "</font>");
2419: }
2420: out.print("</ol>" + "</li>\n");
2421: }
2422:
2423: /**
2424: * printAggregationDetails.
2425: */
2426: private void printAggregationDetails(Aggregation agg) {
2427: out.print("<li>" + "<font size=small color=mediumblue>"
2428: + "MPTask= ");
2429: Composition comp = agg.getComposition();
2430: if (comp != null) {
2431: // link to composed mp task
2432: Task compTask = comp.getCombinedTask();
2433: // composed task is always local
2434: printLinkToLocalTask(compTask);
2435: } else {
2436: out.print("<font color=red>null Composition</font>");
2437: }
2438: out.print("</font>\n" + "</li>\n");
2439: }
2440:
2441: /**
2442: * printDispositionDetails.
2443: */
2444: private void printDispositionDetails(Disposition d) {
2445: // nothing to say?
2446: out.print("<font size=small color=mediumblue>"
2447: + "Success= ");
2448: out.print(d.isSuccess());
2449: out.print("</font>\n");
2450: }
2451:
2452: /**
2453: * printAssetTransferDetails.
2454: */
2455: private void printAssetTransferDetails(AssetTransfer atrans) {
2456: // show attached asset
2457: out.print("<li>" + "<font size=small color=mediumblue>"
2458: + "Asset= ");
2459: printLinkToAssetTransferAsset(atrans);
2460: out.print("</font>" + "</li>\n");
2461: // show role
2462: Role role = atrans.getRole();
2463: if (role != null) {
2464: out.print("<li>" + "<font size=small color=mediumblue>"
2465: + "Role= ");
2466: out.print(role.getName());
2467: out.print("</font>" + "</li>\n");
2468: }
2469: // show assignor
2470: MessageAddress assignor = atrans.getAssignor();
2471: if (assignor != null) {
2472: String name = assignor.toString();
2473: String encName = ((name != null) ? (support
2474: .encodeAgentName(name)) : (null));
2475: out.print("<li>" + "<font size=small color=mediumblue>"
2476: + "Assignor= ");
2477: printLinkToTasksSummary(encName);
2478: out.print("</font>" + "</li>\n");
2479: }
2480: // show assignee
2481: Asset assignee = atrans.getAssignee();
2482: if (assignee != null) {
2483: out.print("<li>" + "<font size=small color=mediumblue>"
2484: + "Assignee= ");
2485: // assignee asset is always in the local blackboard
2486: printLinkToLocalAsset(assignee);
2487: out.print("</font>" + "</li>\n");
2488: }
2489: }
2490:
2491: /**
2492: * printAssetDetails.
2493: */
2494: private void printAssetDetails(UniqueObject baseObj, Asset asset) {
2495: if (asset instanceof AssetGroup) {
2496: // recursive for AssetGroups!
2497: List assets = ((AssetGroup) asset).getAssets();
2498: int nAssets = ((assets != null) ? assets.size() : 0);
2499: out.print("AssetGroup[");
2500: out.print(nAssets);
2501: out.print("]:\n<ol>\n");
2502: for (int i = 0; i < nAssets; i++) {
2503: Asset as = (Asset) assets.get(i);
2504: out.print("<li>\n");
2505: if (as != null) {
2506: // recurse!
2507: //
2508: // unable to show XML for elements, so pass null baseObj
2509: printAssetDetails(null, as);
2510: } else {
2511: out.print("<font color=red>null</font>");
2512: }
2513: out.print("\n</li>\n");
2514: }
2515: out.print("</ol>\n");
2516: if (baseObj != null) {
2517: // link to HTML-encoded XML view
2518: out.print("<font size=small color=mediumblue>");
2519: printLinkToAttachedXML(baseObj, asset, true);
2520: }
2521: return;
2522: }
2523: // if asset is an aggregate, info_asset is the
2524: // aggregate's asset which contains Type and Item info.
2525: Asset info_asset = asset;
2526: int quantity = 1;
2527: boolean isAggregateAsset = (asset instanceof AggregateAsset);
2528: if (isAggregateAsset) {
2529: do {
2530: AggregateAsset agg = (AggregateAsset) info_asset;
2531: quantity *= (int) agg.getQuantity();
2532: info_asset = agg.getAsset();
2533: } while (info_asset instanceof AggregateAsset);
2534: if (info_asset == null) {
2535: // bad! should throw exception, but I doubt this will
2536: // ever happen...
2537: info_asset = asset;
2538: }
2539: }
2540: out.print("<ul>\n");
2541: if (isAggregateAsset) {
2542: out.print("<li>" + "<font size=small color=mediumblue>"
2543: + "Quantity= ");
2544: // show quantity
2545: out.print(quantity);
2546: out.print("</font>" + "</li>\n");
2547: } else {
2548: out.print("<li>" + "<font size=small color=mediumblue>"
2549: + "UID= ");
2550: // show UID
2551: UID u = asset.getUID();
2552: String foundUID = ((u != null) ? u.toString() : "null");
2553: out.print(foundUID);
2554: out.print("</font>" + "</li>\n");
2555: printListItemForStack(asset.getUID());
2556: }
2557: // show class
2558: out.print("<li>" + "<font size=small color=mediumblue>"
2559: + "Class= ");
2560: out.print(info_asset.getClass().getName());
2561: out.print("</font>" + "</li>\n");
2562: // show type id info
2563: TypeIdentificationPG tipg = info_asset
2564: .getTypeIdentificationPG();
2565: if (tipg != null) {
2566: String tiid = tipg.getTypeIdentification();
2567: if (tiid != null) {
2568: out.print("<li>"
2569: + "<font size=small color=mediumblue>"
2570: + "TypeID= ");
2571: out.print(tiid);
2572: out.print("</font>" + "</li>");
2573: }
2574: String tin = tipg.getNomenclature();
2575: if (tin != null) {
2576: out.print("<li>"
2577: + "<font size=small color=mediumblue>"
2578: + "TypeNomenclature= ");
2579: out.print(tin);
2580: out.print("</font>" + "</li>");
2581: }
2582: String tiati = tipg.getAlternateTypeIdentification();
2583: if (tiati != null) {
2584: out.print("<li>"
2585: + "<font size=small color=mediumblue>"
2586: + "AlternateTypeID= ");
2587: out.print(tiati);
2588: out.print("</font>" + "</li>");
2589: }
2590: } else {
2591: out.print("<li>" + "<font color=red>"
2592: + "TypeID missing" + "</font>" + "</li>\n");
2593: }
2594: // show item id
2595: ItemIdentificationPG iipg = info_asset
2596: .getItemIdentificationPG();
2597: if (iipg != null) {
2598: String iiid = iipg.getItemIdentification();
2599: if (iiid != null) {
2600: out.print("<li>"
2601: + "<font size=small color=mediumblue>"
2602: + "ItemID= ");
2603: out.print(iiid);
2604: out.print("</font>" + "</li>");
2605: }
2606: String iin = iipg.getNomenclature();
2607: if (iin != null) {
2608: out.print("<li>"
2609: + "<font size=small color=mediumblue>"
2610: + "ItemNomenclature= ");
2611: out.print(iin);
2612: out.print("</font>" + "</li>");
2613: }
2614: String iiati = iipg.getAlternateItemIdentification();
2615: if (iiati != null) {
2616: out.print("<li>"
2617: + "<font size=small color=mediumblue>"
2618: + "AlternateItemID= ");
2619: out.print(iiati);
2620: out.print("</font>" + "</li>");
2621: }
2622: } else {
2623: out.print("<li>" + "<font color=red>"
2624: + "ItemID missing" + "</font>" + "</li>\n");
2625: }
2626: // show role schedule
2627: RoleSchedule rs;
2628: Schedule sc;
2629: if (((rs = asset.getRoleSchedule()) != null)
2630: && ((sc = rs.getAvailableSchedule()) != null)
2631: && !sc.isEmpty()) {
2632: out.print("<li>" + "<font size=small color=mediumblue>"
2633: + "RoleSchedule<br>\n" + "Start= ");
2634: out.print(getTimeString(sc.getStartTime()));
2635: out.print("<br>End= ");
2636: out.print(getTimeString(sc.getEndTime()));
2637: out.print("<br>\n");
2638: Enumeration rsEn = rs.getRoleScheduleElements();
2639: if (rsEn.hasMoreElements()) {
2640: out.print("RoleScheduleElements<br>\n" + "<ol>\n");
2641: do {
2642: PlanElement pe = (PlanElement) rsEn
2643: .nextElement();
2644: out.print("<li>");
2645: // planElements are always local
2646: printLinkToPlanElement(pe);
2647: out.print("</li>\n");
2648: } while (rsEn.hasMoreElements());
2649: out.print("</ol>\n");
2650: } else {
2651: out.print("RoleScheduleElements: none<br>\n");
2652: }
2653: Iterator iterator = new ArrayList(sc).iterator();
2654: if (iterator.hasNext()) {
2655: out.print("AvailableScheduleElements<br>\n"
2656: + "<ol>\n");
2657: while (iterator.hasNext()) {
2658: ScheduleElement se = (ScheduleElement) iterator
2659: .next();
2660: out.print("<li>Start= ");
2661: out.print(getTimeString(se.getStartTime()));
2662: out.print("<br>End= ");
2663: out.print(getTimeString(se.getEndTime()));
2664: out.print("</li>\n");
2665: }
2666: out.print("</ol>\n");
2667: } else {
2668: out.print("AvailableScheduleElements: none<br>\n");
2669: }
2670: out.print("</font>" + "</li>\n");
2671: }
2672: // show location schedule
2673: LocationSchedulePG locSchedPG;
2674: Schedule locSched;
2675: if (((locSchedPG = asset.getLocationSchedulePG()) != null)
2676: && ((locSched = locSchedPG.getSchedule()) != null)
2677: && (!(locSched.isEmpty()))) {
2678: out.print("<li>" + "<font size=small color=mediumblue>"
2679: + "LocationSchedule<br>\n" + "Start= ");
2680: out.print(getTimeString(locSched.getStartTime()));
2681: out.print("<br>End= ");
2682: out.print(getTimeString(locSched.getEndTime()));
2683: out.print("<br>\n");
2684: Enumeration locSchedEn = locSched
2685: .getAllScheduleElements();
2686: if (locSchedEn.hasMoreElements()) {
2687: out.print("LocationScheduleElements<br>\n"
2688: + "<ol>\n");
2689: do {
2690: ScheduleElement se = (ScheduleElement) locSchedEn
2691: .nextElement();
2692: out.print("<li>Start= ");
2693: out.print(getTimeString(se.getStartTime()));
2694: out.print("<br>End= ");
2695: out.print(getTimeString(se.getEndTime()));
2696: if (se instanceof LocationScheduleElement) {
2697: LocationScheduleElement lse = (LocationScheduleElement) se;
2698: Location loc = lse.getLocation();
2699: if (loc != null) {
2700: out.print("<br>Location= \"");
2701: out.print(loc);
2702: out.print("\"");
2703: }
2704: }
2705: out.print("</li>\n");
2706: } while (locSchedEn.hasMoreElements());
2707: out.print("</ol>\n");
2708: } else {
2709: out.print("LocationScheduleElements: none<br>\n");
2710: }
2711: out.print("</font>" + "</li>\n");
2712: }
2713: // PGs?
2714: out.print("</ul>");
2715: if (baseObj != null) {
2716: // link to HTML-encoded XML view
2717: out.print("<font size=small color=mediumblue>");
2718: printLinkToAttachedXML(baseObj, asset, true);
2719: out.print("</font>");
2720: } else {
2721: // likely recursed on an AssetGroup, and the top-level group
2722: // had a "View XML" link.
2723: }
2724: }
2725:
2726: /**
2727: * printAssetTableRow.
2728: *
2729: * Asset that is in the local blackboard and has a UID. Treat this
2730: * as an Asset attached to itself.
2731: */
2732: private void printAssetTableRow(Asset asset) {
2733: printAttachedAssetTableRow(asset, asset, MODE_ASSET_DETAILS);
2734: }
2735:
2736: /**
2737: * printTaskDirectObjectTableRow.
2738: */
2739: private void printTaskDirectObjectTableRow(Task task) {
2740: printAttachedAssetTableRow(task, ((task != null) ? task
2741: .getDirectObject() : null),
2742: MODE_TASK_DIRECT_OBJECT_DETAILS);
2743: }
2744:
2745: /**
2746: * printAttachedAssetTableRow.
2747: * <p>
2748: * Print asset information in three table columns:<br>
2749: * <ol>
2750: * <li>UID</li>
2751: * <li>TypeID</li>
2752: * <li>ItemID</li>
2753: * <li>Quantity</li>
2754: * </ol>
2755: * Be sure to have a corresponding table!
2756: *
2757: * @see #printTaskDirectObjectTableRow
2758: */
2759: private void printAttachedAssetTableRow(UniqueObject baseObj,
2760: Asset asset, int baseMode) {
2761: if ((baseObj == null) || (asset == null)) {
2762: out.print("<td colspan=4>"
2763: + "<font color=red>null</font>" + "</td>\n");
2764: } else if (asset instanceof AssetGroup) {
2765: // link to asset group
2766: // "UID" of the baseObj, and a link using that UID
2767: // "TypeID" is a bold "AssetGroup"
2768: // "ItemID" is "N/A"
2769: // "Quantity" is the number of items in the group
2770: out.print("<td>");
2771: printLinkToAttachedAsset(baseObj, asset, baseMode);
2772: out.print("</td>\n" + "<td>" + "<b>AssetGroup</b>"
2773: + "</td>\n" + "<td>" + "N/A" + "</td>\n"
2774: + "<td align=right>");
2775: List assets = ((AssetGroup) asset).getAssets();
2776: int nAssets = ((assets != null) ? assets.size() : 0);
2777: out.print(nAssets);
2778: out.print("</td>\n");
2779: } else {
2780: // if asset is an aggregate, info_asset is the
2781: // aggregate's asset which contains Type and Item info.
2782: Asset info_asset;
2783: int quantity;
2784: if (asset instanceof AggregateAsset) {
2785: info_asset = asset;
2786: quantity = 1;
2787: do {
2788: AggregateAsset agg = (AggregateAsset) info_asset;
2789: quantity *= (int) agg.getQuantity();
2790: info_asset = agg.getAsset();
2791: } while (info_asset instanceof AggregateAsset);
2792: if (info_asset == null) {
2793: out.print("<td colspan=4>"
2794: + "<font color=red>null</font>"
2795: + "</td>\n");
2796: return;
2797: }
2798: } else {
2799: info_asset = asset;
2800: if (asset instanceof AssetGroup) {
2801: List assets = ((AssetGroup) asset).getAssets();
2802: quantity = ((assets != null) ? assets.size()
2803: : 0);
2804: } else {
2805: quantity = 1;
2806: }
2807: }
2808: // link to asset
2809: out.print("<td>");
2810: printLinkToAttachedAsset(baseObj, asset, baseMode);
2811: out.print("</td>\n" + "<td>");
2812: // show type id
2813: TypeIdentificationPG tipg = info_asset
2814: .getTypeIdentificationPG();
2815: if (tipg != null) {
2816: out.print(tipg.getTypeIdentification());
2817: } else {
2818: out.print("<font color=red>missing typeID</font>");
2819: }
2820: out.print("</td>\n" + "<td>");
2821: // show item id
2822: ItemIdentificationPG iipg = info_asset
2823: .getItemIdentificationPG();
2824: if (iipg != null) {
2825: out.print(iipg.getItemIdentification());
2826: } else {
2827: out.print("<font color=red>missing itemID</font>");
2828: }
2829: out.print("</td>\n" + "<td align=right>");
2830: // show quantity
2831: out.print(quantity);
2832: out.print("</td>\n");
2833: }
2834: }
2835:
2836: /**
2837: * printXMLDetails.
2838: * <p>
2839: * Prints XML for given Object.
2840: * <p>
2841: * Considered embedding some Applet JTree viewer, e.g.<br>
2842: * <code>ui.planviewer.XMLViewer</code>
2843: * but would need separate Applet code.
2844: * <p>
2845: * Also considered using some nifty javascript XML tree viewer, e.g.<br>
2846: * <code>http://developer.iplanet.com/viewsource/smith_jstree/smith_jstree.html</code><br>
2847: * but would take some work...
2848: * <p>
2849: * @param printAsHTML uses XMLtoHTMLOutputStream to pretty-print the XML
2850: */
2851: private void printXMLDetails(Object xo, boolean printAsHTML) {
2852: try {
2853: // convert to XML
2854: Document doc = new DocumentImpl();
2855: Element element = XMLize.getPlanObjectXML(xo, doc);
2856: doc.appendChild(element);
2857:
2858: // print to output
2859: if (printAsHTML) {
2860: OutputFormat format = new OutputFormat();
2861: format.setPreserveSpace(false);
2862: format.setIndent(2);
2863:
2864: PrintWriter pout = new PrintWriter(
2865: new XMLtoHTMLOutputStream(out));
2866: XMLSerializer serializer = new XMLSerializer(pout,
2867: format);
2868: out.print("<pre>\n");
2869: serializer.serialize(doc);
2870: out.print("\n</pre>\n");
2871: pout.flush();
2872: } else {
2873: OutputFormat format = new OutputFormat();
2874: format.setPreserveSpace(true);
2875:
2876: PrintWriter pout = new PrintWriter(out);
2877: XMLSerializer serializer = new XMLSerializer(pout,
2878: format);
2879: serializer.serialize(doc);
2880: pout.flush();
2881: }
2882: } catch (Exception e) {
2883: if (printAsHTML) {
2884: out.print("\nException!\n\n");
2885: e.printStackTrace(out);
2886: }
2887: }
2888: }
2889:
2890: private void printListItemForStack(UID uid) {
2891: if (ENABLE_STACKS) {
2892: out.print("<li>" + "<font size=small color=mediumblue>"
2893: + "<nowrap>Publisher: ");
2894: printLinkToStack(uid, support.getInfo(uid));
2895: out.print("</nowrap></font>" + "</li>\n");
2896: }
2897: }
2898:
2899: private void printStack(StackElements stack, UID uid,
2900: String type) {
2901: if (stack == null) {
2902: out.print("<font color=red>Unable to find " + type
2903: + " stack for " + uid.toString() + "</font>");
2904: } else {
2905: out.print("<font color=mediumblue>" + type
2906: + ":</font>\n" + "<font color=green><pre>");
2907: Throwable t = stack.getThrowable();
2908: if (t == null) {
2909: out.print("null");
2910: } else {
2911: StackTraceElement[] trace = t.getStackTrace();
2912: boolean show = false;
2913: for (int i = 0; i < trace.length; i++) {
2914: StackTraceElement ste = trace[i];
2915: if (!show) {
2916: String cl = ste.getClassName();
2917: if (cl != null
2918: && cl
2919: .startsWith("org.cougaar.core.blackboard.")) {
2920: // hide blackboard internals
2921: continue;
2922: }
2923: show = true;
2924: }
2925: out.print("\tat " + ste + "\n");
2926: }
2927: }
2928: out.print("</pre></font>\n");
2929: }
2930: }
2931:
2932: /** END PRINT ROUTINES **/
2933:
2934: /** BEGIN PRINTLINK ROUTINES **/
2935:
2936: /**
2937: * print link to task summary at this agent.
2938: */
2939:
2940: private void printLinkToTasksSummary() {
2941: printLinkToTasksSummary(support.getEncodedAgentName());
2942: }
2943:
2944: /**
2945: * print link to task summary for given agent
2946: */
2947: private void printLinkToTasksSummary(String encodedAgentName) {
2948: if (encodedAgentName != null) {
2949: out.print("<a href=\"/$");
2950: // link to agent
2951: out.print(encodedAgentName);
2952: out.print(support.getPath());
2953: out.print("?" + MODE + "=" + MODE_TASKS_SUMMARY);
2954: out.print("\" target=\"tablesFrame\">");
2955: out.print(support.getEncodedAgentName());
2956: out.print("</a>");
2957: } else {
2958: out.print("<font color=red>Unknown agent</font>");
2959: }
2960: }
2961:
2962: /** simple flags for parameter checking **/
2963: private static final byte _FLAG_LIMIT = (1 << 0);
2964: private static final byte _FLAG_VERB = (1 << 1);
2965: private static final byte _FLAG_VERBOSE = (1 << 2);
2966: private static final byte _FLAG_SORT = (1 << 3);
2967:
2968: /**
2969: * printLinkToAllTasks for the local agent.
2970: */
2971: private void printLinkToAllTasks(String verb, int limit,
2972: int numTasks, boolean verbose) {
2973: printLinkToAllTasks(support.getEncodedAgentName(), verb,
2974: limit, numTasks, verbose);
2975: }
2976:
2977: /**
2978: * printLinkToAllTasks.
2979: */
2980: private void printLinkToAllTasks(String encodedAgentName,
2981: String verb, int limit, int numTasks, boolean verbose) {
2982: if (encodedAgentName != null) {
2983: out.print("<a href=\"/$");
2984: out.print(encodedAgentName);
2985: out.print(support.getPath());
2986: out.print("?" + MODE + "=" + MODE_ALL_TASKS);
2987: // set flags
2988: byte flags = 0;
2989: if (limit > 0) {
2990: out.print("&" + LIMIT + "=true");
2991: flags |= _FLAG_LIMIT;
2992: }
2993: if (verb != null) {
2994: out.print("&" + VERB + "=");
2995: out.print(verb);
2996: flags |= _FLAG_VERB;
2997: }
2998: if (verbose) {
2999: flags |= _FLAG_VERBOSE;
3000: }
3001: if (sortByUID)
3002: out.print("&" + SORT_BY_UID + "=true");
3003: if (sortByEndTime)
3004: out.print("&" + SORT_BY_END_TIME + "=true");
3005:
3006: out.print("\" target=\"tablesFrame\">");
3007: // print over-customized output .. make parameter?
3008: switch (flags) {
3009: case (_FLAG_LIMIT):
3010: out.print("View first <b>");
3011: out.print(limit);
3012: out.print("</b>");
3013: break;
3014: case (_FLAG_LIMIT | _FLAG_VERBOSE):
3015: out.print("View first <b>");
3016: out.print(limit);
3017: out.print("</b> of <b>");
3018: out.print(numTasks);
3019: out.print("</b> Tasks at ");
3020: out.print(encodedAgentName);
3021: break;
3022: case (_FLAG_LIMIT | _FLAG_VERB):
3023: out.print("View first <b>");
3024: out.print(limit);
3025: out.print("</b>");
3026: break;
3027: case (_FLAG_LIMIT | _FLAG_VERB | _FLAG_VERBOSE):
3028: out.print("View first <b>");
3029: out.print(limit);
3030: out.print("</b> of <b>");
3031: out.print(numTasks);
3032: out.print("</b> Tasks with verb ");
3033: out.print(verb);
3034: out.print("at ");
3035: out.print(encodedAgentName);
3036: break;
3037: case (_FLAG_VERB):
3038: out.print(verb);
3039: break;
3040: case (_FLAG_VERB | _FLAG_VERBOSE):
3041: out.print("View all <b>");
3042: out.print(numTasks);
3043: out.print("</b> Tasks with verb ");
3044: out.print(verb);
3045: out.print(" at ");
3046: out.print(encodedAgentName);
3047: break;
3048: default:
3049: case (0):
3050: case (_FLAG_VERBOSE):
3051: out.print("View all <b>");
3052: out.print(numTasks);
3053: out.print("</b> Tasks at ");
3054: out.print(support.getEncodedAgentName());
3055: break;
3056: }
3057: out.print("</a>");
3058: } else {
3059: out.print("<font color=red>Unknown agent</font>");
3060: }
3061: }
3062:
3063: /**
3064: * printLinkToAllPlanElements for the local agent.
3065: */
3066: private void printLinkToAllPlanElements(int limit,
3067: int numPlanElements, boolean verbose) {
3068: printLinkToAllPlanElements(support.getEncodedAgentName(),
3069: limit, numPlanElements, verbose);
3070: }
3071:
3072: /**
3073: * printLinkToAllPlanElements.
3074: */
3075: private void printLinkToAllPlanElements(
3076: String encodedAgentName, int limit,
3077: int numPlanElements, boolean verbose) {
3078: if (encodedAgentName != null) {
3079: out.print("<a href=\"/$");
3080: out.print(encodedAgentName);
3081: out.print(support.getPath());
3082: out.print("?" + MODE + "=" + MODE_ALL_PLAN_ELEMENTS);
3083: // set flags
3084: byte flags = 0;
3085: if (limit > 0) {
3086: out.print("&" + LIMIT + "=true");
3087: flags |= _FLAG_LIMIT;
3088: }
3089: if (verbose) {
3090: flags |= _FLAG_VERBOSE;
3091: }
3092: out.print("\" target=\"tablesFrame\">");
3093: // print over-customized output .. make parameter?
3094: switch (flags) {
3095: case (_FLAG_LIMIT):
3096: out.print("View first <b>");
3097: out.print(limit);
3098: out.print("</b>");
3099: break;
3100: case (_FLAG_LIMIT | _FLAG_VERBOSE):
3101: out.print("View first <b>");
3102: out.print(limit);
3103: out.print("</b> of <b>");
3104: out.print(numPlanElements);
3105: out.print("</b> PlanElements at ");
3106: out.print(encodedAgentName);
3107: break;
3108: default:
3109: case (0):
3110: case (_FLAG_VERBOSE):
3111: out.print("View all <b>");
3112: out.print(numPlanElements);
3113: out.print("</b> PlanElements at ");
3114: out.print(encodedAgentName);
3115: break;
3116: }
3117: out.print("</a>");
3118: } else {
3119: out.print("<font color=red>Unknown agent</font>");
3120: }
3121: }
3122:
3123: /**
3124: * printLinkToAllAssets for the local agent.
3125: */
3126: private void printLinkToAllAssets(int limit, int numAssets,
3127: boolean verbose) {
3128: printLinkToAllAssets(support.getEncodedAgentName(), limit,
3129: numAssets, verbose);
3130: }
3131:
3132: /**
3133: * printLinkToAllAssets.
3134: */
3135: private void printLinkToAllAssets(String encodedAgentName,
3136: int limit, int numAssets, boolean verbose) {
3137: if (encodedAgentName != null) {
3138: out.print("<a href=\"/$");
3139: out.print(encodedAgentName);
3140: out.print(support.getPath());
3141: out.print("?" + MODE + "=" + MODE_ALL_ASSETS);
3142: // set flags
3143: byte flags = 0;
3144: if (limit > 0) {
3145: out.print("&" + LIMIT + "=true");
3146: flags |= _FLAG_LIMIT;
3147: }
3148: if (verbose) {
3149: flags |= _FLAG_VERBOSE;
3150: }
3151: out.print("\" target=\"tablesFrame\">");
3152: // print over-customized output .. make parameter?
3153: switch (flags) {
3154: case (_FLAG_LIMIT):
3155: out.print("View first <b>");
3156: out.print(limit);
3157: out.print("</b>");
3158: break;
3159: case (_FLAG_LIMIT | _FLAG_VERBOSE):
3160: out.print("View first <b>");
3161: out.print(limit);
3162: out.print("</b> of <b>");
3163: out.print(numAssets);
3164: out.print("</b> Assets at ");
3165: out.print(encodedAgentName);
3166: break;
3167: default:
3168: case (0):
3169: case (_FLAG_VERBOSE):
3170: out.print("View all <b>");
3171: out.print(numAssets);
3172: out.print("</b> Assets at ");
3173: out.print(encodedAgentName);
3174: break;
3175: }
3176: out.print("</a>");
3177: } else {
3178: out.print("<font color=red>Unknown agent</font>");
3179: }
3180: }
3181:
3182: /**
3183: * printLinkToAllUniqueObjects for the local agent.
3184: */
3185: private void printLinkToAllUniqueObjects(int limit,
3186: int numUniqueObjects, boolean verbose) {
3187: printLinkToAllUniqueObjects(support.getEncodedAgentName(),
3188: limit, numUniqueObjects, verbose);
3189: }
3190:
3191: /**
3192: * printLinkToAllUniqueObjects.
3193: */
3194: private void printLinkToAllUniqueObjects(
3195: String encodedAgentName, int limit,
3196: int numUniqueObjects, boolean verbose) {
3197: if (encodedAgentName != null) {
3198: out.print("<a href=\"/$");
3199: out.print(encodedAgentName);
3200: out.print(support.getPath());
3201: out.print("?" + MODE + "=" + MODE_ALL_UNIQUE_OBJECTS);
3202: // set flags
3203: byte flags = 0;
3204: if (limit > 0) {
3205: out.print("&" + LIMIT + "=true");
3206: flags |= _FLAG_LIMIT;
3207: }
3208: if (verbose) {
3209: flags |= _FLAG_VERBOSE;
3210: }
3211: out.print("\" target=\"tablesFrame\">");
3212: // print over-customized output .. make parameter?
3213: switch (flags) {
3214: case (_FLAG_LIMIT):
3215: out.print("View first <b>");
3216: out.print(limit);
3217: out.print("</b>");
3218: break;
3219: case (_FLAG_LIMIT | _FLAG_VERBOSE):
3220: out.print("View first <b>");
3221: out.print(limit);
3222: out.print("</b> of <b>");
3223: out.print(numUniqueObjects);
3224: out.print("</b> UniqueObjects at ");
3225: out.print(encodedAgentName);
3226: break;
3227: default:
3228: case (0):
3229: case (_FLAG_VERBOSE):
3230: out.print("View all <b>");
3231: out.print(numUniqueObjects);
3232: out.print("</b> UniqueObjects at ");
3233: out.print(encodedAgentName);
3234: break;
3235: }
3236: out.print("</a>");
3237: } else {
3238: out.print("<font color=red>Unknown agent</font>");
3239: }
3240: }
3241:
3242: /**
3243: * printLinkToParentTask.
3244: * <p>
3245: * Get task's parent before linking.
3246: */
3247: private void printLinkToParentTask(Task task) {
3248: UID ptU;
3249: String ptUID;
3250: if (task == null) {
3251: out.print("<font color=red>null</font>");
3252: } else if (((ptU = task.getParentTaskUID()) == null)
3253: || ((ptUID = ptU.toString()) == null)) {
3254: out.print("<font color=red>parent not unique</font>");
3255: } else {
3256: MessageAddress tAgentID = task.getSource();
3257: String ptEncodedAgentName;
3258: if ((tAgentID == null)
3259: || ((ptEncodedAgentName = tAgentID.toString()) == null)) {
3260: ptEncodedAgentName = support.getEncodedAgentName();
3261: } else {
3262: ptEncodedAgentName = support
3263: .encodeAgentName(ptEncodedAgentName);
3264: }
3265: out.print("<a href=\"/$");
3266: out.print(ptEncodedAgentName);
3267: out.print(support.getPath());
3268: out.print("?" + MODE + "=" + MODE_TASK_DETAILS + "&"
3269: + ITEM_UID + "=");
3270: out.print(encodeUID(ptUID));
3271: out.print("\" target=\"itemFrame\">");
3272: out.print(ptUID);
3273: out.print("</a>");
3274: }
3275: }
3276:
3277: /**
3278: * printLinkToLocalTask.
3279: * <p>
3280: * Tasks that stay in the current agent.
3281: */
3282: private void printLinkToLocalTask(Task task) {
3283: printLinkToTask(task == null ? null : task.getUID(),
3284: support.getEncodedAgentName());
3285: }
3286:
3287: /**
3288: * printLinkToTask.
3289: * <p>
3290: * This method attempts to works around task forwarding across
3291: * agents in the "Down" sense, i.e. allocations.
3292: */
3293: private void printLinkToTask(UID taskU,
3294: String atEncodedAgentName) {
3295: String taskUID;
3296: if (taskU == null) {
3297: out.print("<font color=red>null</font>");
3298: } else {
3299: taskUID = taskU.toString();
3300: if (taskUID == null) {
3301: out.print("<font color=red>not unique</font>");
3302: } else {
3303: out.print("<a href=\"/$");
3304: out.print(atEncodedAgentName);
3305: out.print(support.getPath());
3306: out.print("?" + MODE + "=" + MODE_TASK_DETAILS
3307: + "&" + ITEM_UID + "=");
3308: out.print(encodeUID(taskUID));
3309: out.print("\" target=\"itemFrame\">");
3310: out.print(taskUID);
3311: out.print("</a>");
3312: }
3313: }
3314: }
3315:
3316: /**
3317: * printLinkToPlanElement.
3318: * <p>
3319: * PlanElements stay in their agent
3320: */
3321: private void printLinkToPlanElement(PlanElement pe) {
3322: UID peU;
3323: String peUID;
3324: if (pe == null) {
3325: out.print("<font color=red>null</font>\n");
3326: } else if (((peU = pe.getUID()) == null)
3327: || ((peUID = peU.toString()) == null)) {
3328: out.print("<font color=red>not unique</font>\n");
3329: } else {
3330: out.print("<a href=\"/$");
3331: out.print(support.getEncodedAgentName());
3332: out.print(support.getPath());
3333: out.print("?" + MODE + "=" + MODE_PLAN_ELEMENT_DETAILS
3334: + "&" + ITEM_UID + "=");
3335: out.print(encodeUID(peUID));
3336: out.print("\" target=\"itemFrame\">");
3337: out.print(peUID);
3338: out.print("</a>");
3339: }
3340: }
3341:
3342: /**
3343: * printLinkToLocalAsset.
3344: * <p>
3345: * Asset that is in the local blackboard and has a UID. Treat this
3346: * as an Asset attached to itself.
3347: **/
3348: private void printLinkToLocalAsset(Asset asset) {
3349: printLinkToAttachedAsset(asset, asset, MODE_ASSET_DETAILS);
3350: }
3351:
3352: /**
3353: * printLinkToTaskDirectObject.
3354: **/
3355: private void printLinkToTaskDirectObject(Task task) {
3356: printLinkToAttachedAsset(task, ((task != null) ? task
3357: .getDirectObject() : null),
3358: MODE_TASK_DIRECT_OBJECT_DETAILS);
3359: }
3360:
3361: /**
3362: * printLinkToAssetTransferAsset.
3363: **/
3364: private void printLinkToAssetTransferAsset(AssetTransfer atrans) {
3365: printLinkToAttachedAsset(atrans, ((atrans != null) ? atrans
3366: .getAsset() : null),
3367: MODE_ASSET_TRANSFER_ASSET_DETAILS);
3368: }
3369:
3370: /**
3371: * printLinkToAttachedAsset.
3372: *
3373: * @see #printLinkToTaskDirectObject
3374: * @see #printLinkToAssetTransferAsset
3375: **/
3376: private void printLinkToAttachedAsset(UniqueObject baseObj,
3377: Asset asset, int baseMode) {
3378: UID baseObjU;
3379: String baseObjUID;
3380: if ((baseObj == null) || (asset == null)) {
3381: out.print("<font color=red>null</font>");
3382: } else if (((baseObjU = baseObj.getUID()) == null)
3383: || ((baseObjUID = baseObjU.toString()) == null)) {
3384: out.print("<font color=red>not unique</font>");
3385: } else {
3386: out.print("<a href=\"/$");
3387: out.print(support.getEncodedAgentName());
3388: out.print(support.getPath());
3389: out.print("?" + MODE + "=" + baseMode + "&" + ITEM_UID
3390: + "=");
3391: out.print(encodeUID(baseObjUID));
3392: out.print("\" target=\"itemFrame\">");
3393: String assetName;
3394: if (asset == baseObj) {
3395: // asset it it's own base
3396: assetName = baseObjUID;
3397: } else {
3398: UID assetU;
3399: // asset attached to the base UniqueObject
3400: if (((assetU = asset.getUID()) == null)
3401: || ((assetName = assetU.toString()) == null)) {
3402: if (asset instanceof AggregateAsset) {
3403: assetName = "Non-UID Aggregate";
3404: } else if (asset instanceof AssetGroup) {
3405: assetName = "Non-UID Group";
3406: } else {
3407: assetName = "Non-UID "
3408: + asset.getClass().getName();
3409: }
3410: }
3411: }
3412: out.print(assetName);
3413: out.print("</a>");
3414: }
3415: }
3416:
3417: /**
3418: * printLinkToXML.
3419: * <p>
3420: * XML objects stay in agent.
3421: **/
3422: private void printLinkToXML(UniqueObject uo, boolean asHTML) {
3423: if (uo != null) {
3424: // link to HTML-encoded XML view
3425: printLinkToAttachedXML(uo, uo, asHTML);
3426: } else {
3427: out.print("<font color=red>null</font>");
3428: }
3429: }
3430:
3431: /**
3432: * printLinkToXML.
3433: * <p>
3434: * XML objects stay in agent.
3435: **/
3436: private void printLinkToXML(Object xo, boolean asHTML) {
3437: if (xo instanceof UniqueObject) {
3438: // link to HTML-encoded XML view
3439: printLinkToAttachedXML((UniqueObject) xo, xo, asHTML);
3440: } else if (xo == null) {
3441: out.print("<font color=red>null</font>");
3442: } else {
3443: // asset not unique
3444: out.print("<font color=red>");
3445: out.print(xo.getClass().getName());
3446: out.print(" not a UniqueObject</font>");
3447: }
3448: }
3449:
3450: /**
3451: * printLinkToAttachedXML.
3452: **/
3453: private void printLinkToAttachedXML(UniqueObject baseObj,
3454: Object xo, boolean asHTML) {
3455: UID baseObjU;
3456: String baseObjUID;
3457: if ((xo == null) || (baseObj == null)
3458: || ((baseObjU = baseObj.getUID()) == null)
3459: || ((baseObjUID = baseObjU.toString()) == null)) {
3460: if (asHTML) {
3461: out
3462: .print("<font color=red>Unable to view XML</font>\n");
3463: } else {
3464: out
3465: .print("<font color=red>Raw XML unavailable</font>\n");
3466: }
3467: } else {
3468: out.print("<a href=\"/$");
3469: out.print(support.getEncodedAgentName());
3470: out.print(support.getPath());
3471: out.print("?" + MODE + "=");
3472: int mode = ((xo == baseObj) ? (asHTML ? MODE_XML_HTML_DETAILS
3473: : MODE_XML_RAW_DETAILS)
3474: : (asHTML ? MODE_XML_HTML_ATTACHED_DETAILS
3475: : MODE_XML_RAW_ATTACHED_DETAILS));
3476: out.print(mode);
3477: out.print("&" + ITEM_UID + "=");
3478: String encBaseObjUID = encodeUID(baseObjUID);
3479: out.print(encBaseObjUID);
3480: out.print("\" target=\"xml_");
3481: out.print(encBaseObjUID);
3482: out.print("_page\">");
3483: String xoName;
3484: if (xo == baseObj) {
3485: xoName = baseObjUID;
3486: } else {
3487: if (xo instanceof UniqueObject) {
3488: UID xoU;
3489: if (((xoU = ((UniqueObject) xo).getUID()) == null)
3490: || ((xoName = xoU.toString()) == null)) {
3491: if (xo instanceof AggregateAsset) {
3492: xoName = "Non-UID Aggregate";
3493: } else if (xo instanceof AssetGroup) {
3494: xoName = "Non-UID Group";
3495: } else {
3496: xoName = "Non-UID "
3497: + xo.getClass().getName();
3498: }
3499: }
3500: } else {
3501: xoName = "Non-UniqueObject "
3502: + xo.getClass().getName();
3503: }
3504: }
3505: if (asHTML) {
3506: out.print("View XML for ");
3507: out.print(xoName);
3508: } else {
3509: out.print("Raw XML for ");
3510: out.print(xoName);
3511: }
3512: out.print("</a>\n");
3513: }
3514: }
3515:
3516: /**
3517: * printLinkToStack
3518: */
3519: private void printLinkToStack(UID uid, PublisherInfo info) {
3520: String publisher = (info == null ? null : info
3521: .getPublisher());
3522: String suid;
3523: if (publisher == null) {
3524: out.print("<font color=red>Unknown</font>\n");
3525: } else if ((info.getAddStack() == null) || (uid == null)
3526: || ((suid = uid.toString()) == null)) {
3527: out.print(encodeHTML(publisher, true));
3528: } else {
3529: String encUID = encodeUID(suid);
3530: out.print("<a href=\"/$");
3531: out.print(support.getEncodedAgentName());
3532: out.print(support.getPath());
3533: out.print("?" + MODE + "=" + MODE_STACK_DETAILS + "&"
3534: + ITEM_UID + "=" + encodeUID(suid)
3535: + "\" target=\"itemFrame\">");
3536: out.print(encodeHTML(publisher, true));
3537: out.print("</a>\n");
3538: }
3539: }
3540:
3541: /** END PRINTLINK ROUTINES **/
3542:
3543: /** BEGIN UTILITY PARSERS **/
3544:
3545: /**
3546: * printObject.
3547: * <p>
3548: * Currently used to print Preposition.getIndirectObject()
3549: * <p>
3550: * recursive for AssetGroups!
3551: */
3552: private void printObject(Object io) {
3553: try {
3554: if (io == null) {
3555: out.print("<font color=red>null</font>");
3556: } else if (io instanceof String) {
3557: out.print((String) io);
3558: } else if (io instanceof Location) {
3559: out.print("Location: \"");
3560: out.print(io.toString());
3561: out.print("\"");
3562: } else if (io instanceof Asset) {
3563: Asset as = (Asset) io;
3564: out.print("Asset: \"");
3565: TypeIdentificationPG tipg;
3566: String tiNomen;
3567: if (((tipg = as.getTypeIdentificationPG()) != null)
3568: && ((tiNomen = tipg.getNomenclature()) != null)) {
3569: out.print(tiNomen);
3570: }
3571: out.print("(asset type=");
3572: out.print(as.getClass().getName());
3573: out.print(", asset uid=");
3574: UID asu;
3575: String uid;
3576: if (((asu = as.getUID()) != null)
3577: && ((uid = asu.toString()) != null)) {
3578: out.print(uid);
3579: } else {
3580: out.print("None");
3581: }
3582: out.print(")\"");
3583: } else if (io instanceof Schedule) {
3584: out.print(io.getClass().getName());
3585: } else if (io instanceof MessageAddress) {
3586: out.print("AID: \"");
3587: out.print(((MessageAddress) io).toString());
3588: out.print("\"");
3589: } else if (io instanceof AssetTransfer) {
3590: out.print("AssetTransfer: \"");
3591: out
3592: .print(((AssetTransfer) io).getAsset()
3593: .getName());
3594: out.print("\"");
3595: } else if (io instanceof AssetAssignment) {
3596: out.print("AssetAssignment: \"");
3597: out.print(((AssetAssignment) io).getAsset()
3598: .getName());
3599: out.print("\"");
3600: } else if (io instanceof AssetGroup) {
3601: out.print("AssetGroup: \"[");
3602: List assets = ((AssetGroup) io).getAssets();
3603: for (int i = 0; i < assets.size(); i++) {
3604: Asset as = (Asset) assets.get(i);
3605: // recursive!
3606: printObject(as);
3607: }
3608: out.print("]\"");
3609: } else if (io instanceof AbstractMeasure) {
3610: String clName = ((AbstractMeasure) io).getClass()
3611: .getName();
3612: int i = clName.lastIndexOf('.');
3613: if (i > 0) {
3614: clName = clName.substring(i + i);
3615: }
3616: out.print(clName);
3617: out.print(": ");
3618: out.print(io.toString());
3619: } else {
3620: out.print(io.getClass().getName());
3621: out.print(": ");
3622: out.print(io.toString());
3623: }
3624: } catch (Exception e) {
3625: out.print("<font color=red>invalid</font>");
3626: }
3627: }
3628:
3629: /** END UTILITY PARSERS **/
3630:
3631: /** BEGIN BLACKBOARD SEARCHERS **/
3632:
3633: private UnaryPredicate getUniqueObjectWithUIDPred(
3634: final String uidFilter) {
3635: UID findUID = UID.toUID(uidFilter);
3636: return new UniqueObjectWithUIDPredicate(findUID);
3637: }
3638:
3639: private static final class UniqueObjectWithUIDPredicate
3640: implements UnaryPredicate {
3641: private final UID findUID;
3642:
3643: public UniqueObjectWithUIDPredicate(UID findUID) {
3644: this .findUID = findUID;
3645: }
3646:
3647: public boolean execute(Object o) {
3648: if (o instanceof UniqueObject) {
3649: UID u = ((UniqueObject) o).getUID();
3650: return findUID.equals(u);
3651: }
3652: return false;
3653: }
3654: }
3655:
3656: private UnaryPredicate getTaskPred() {
3657: return new TaskPredicate();
3658: }
3659:
3660: private static final class TaskPredicate implements
3661: UnaryPredicate {
3662: public boolean execute(Object o) {
3663: return (o instanceof Task);
3664: }
3665: }
3666:
3667: private UnaryPredicate getTaskWithVerbPred(Verb v) {
3668: return new TaskWithVerbPredicate(v);
3669: }
3670:
3671: private static final class TaskWithVerbPredicate implements
3672: UnaryPredicate {
3673: private final Verb v;
3674:
3675: public TaskWithVerbPredicate(Verb v) {
3676: this .v = v;
3677: }
3678:
3679: public boolean execute(Object o) {
3680: return ((o instanceof Task) && v.equals(((Task) o)
3681: .getVerb()));
3682: }
3683:
3684: public String toString() {
3685: return getClass().getName() + "[verb=" + v + "]";
3686: }
3687: }
3688:
3689: private UnaryPredicate getPlanElementPred() {
3690: return new PlanElementPredicate();
3691: }
3692:
3693: private static final class PlanElementPredicate implements
3694: UnaryPredicate {
3695: public boolean execute(Object o) {
3696: return (o instanceof PlanElement);
3697: }
3698: }
3699:
3700: private UnaryPredicate getAssetPred() {
3701: return new AssetPredicate();
3702: }
3703:
3704: public static final class AssetPredicate implements
3705: UnaryPredicate {
3706: public boolean execute(Object o) {
3707: return (o instanceof Asset);
3708: }
3709: }
3710:
3711: private UnaryPredicate getUniqueObjectPred() {
3712: return new UniqueObjectPredicate();
3713: }
3714:
3715: private Collection searchUsingPredicate(UnaryPredicate pred) {
3716: Collection col = support.queryBlackboard(pred);
3717: if (col.size() > 1) {
3718: Comparator comparator = null;
3719: if (sortByEndTime) {
3720: comparator = THE_ONLY_END_TIME_COMPARATOR;
3721: } else if (sortByUID) {
3722: comparator = THE_ONLY_UID_COMPARATOR;
3723: }
3724: if (comparator != null) {
3725: Object[] a = col.toArray();
3726: Arrays.sort(a, comparator);
3727: return Arrays.asList(a);
3728: }
3729: }
3730: return col;
3731: }
3732:
3733: private static final Comparator THE_ONLY_UID_COMPARATOR = new UIDComparator();
3734:
3735: private static class UIDComparator implements Comparator {
3736: public int compare(Object first, Object second) {
3737: if (first instanceof UniqueObject) {
3738: if (second instanceof UniqueObject) {
3739: // return the usual UID compare
3740: UID u1 = ((UniqueObject) first).getUID();
3741: UID u2 = ((UniqueObject) second).getUID();
3742: return u1.compareTo(u2);
3743: } else {
3744: return -1;
3745: }
3746: } else if (second instanceof UniqueObject) {
3747: return 1;
3748: } else {
3749: return 0;
3750: }
3751: }
3752: }
3753:
3754: private static final Comparator THE_ONLY_END_TIME_COMPARATOR = new EndTimeComparator();
3755:
3756: private static class EndTimeComparator implements Comparator {
3757: public int compare(Object first, Object second) {
3758: if (first instanceof Task) {
3759: if (second instanceof Task) {
3760: // return the usual UID compare
3761: try {
3762: long t1 = PluginHelper
3763: .getEndTime((Task) first);
3764: long t2 = PluginHelper
3765: .getEndTime((Task) second);
3766: if (t1 < t2)
3767: return -1;
3768: if (t1 > t2)
3769: return 1;
3770: } catch (Exception e) {
3771: // Probably no end time preference
3772: }
3773: return THE_ONLY_UID_COMPARATOR.compare(first,
3774: second);
3775: } else {
3776: return -1;
3777: }
3778: } else if (second instanceof Task) {
3779: return 1;
3780: } else {
3781: return 0;
3782: }
3783: }
3784: }
3785:
3786: private UniqueObject findUniqueObjectWithUID(
3787: final String itemUID) {
3788: if (itemUID == null) {
3789: // missing UID
3790: return null;
3791: }
3792: Collection col = searchUsingPredicate(getUniqueObjectWithUIDPred(itemUID));
3793: if (col.size() < 1) {
3794: // item not found
3795: return null;
3796: }
3797: // take first match
3798: Iterator iter = col.iterator();
3799: UniqueObject uo = (UniqueObject) iter.next();
3800: if (DEBUG) {
3801: if (iter.hasNext()) {
3802: System.err.println("Multiple matches for "
3803: + itemUID + "?");
3804: }
3805: }
3806: return uo;
3807: }
3808:
3809: private Collection findAllTasks() {
3810: return searchUsingPredicate(getTaskPred());
3811: }
3812:
3813: private Collection findTasksWithVerb(final String verbFilter) {
3814: if (verbFilter == null) {
3815: // missing verb
3816: return null;
3817: }
3818: Verb v = Verb.get(verbFilter);
3819: return searchUsingPredicate(getTaskWithVerbPred(v));
3820: }
3821:
3822: private Collection findAllPlanElements() {
3823: return searchUsingPredicate(getPlanElementPred());
3824: }
3825:
3826: private Collection findAllAssets() {
3827: return searchUsingPredicate(getAssetPred());
3828: }
3829:
3830: private Collection findAllUniqueObjects() {
3831: return searchUsingPredicate(getUniqueObjectPred());
3832: }
3833:
3834: /** END BLACKBOARD SEARCHERS **/
3835:
3836: /** BEGIN MISC UTILITIES **/
3837:
3838: /**
3839: * Item type codes to show interface name instead of "*Impl".
3840: **/
3841: private static final int ITEM_TYPE_ALLOCATION = 0;
3842: private static final int ITEM_TYPE_EXPANSION = 1;
3843: private static final int ITEM_TYPE_AGGREGATION = 2;
3844: private static final int ITEM_TYPE_DISPOSITION = 3;
3845: private static final int ITEM_TYPE_ASSET_TRANSFER = 4;
3846: private static final int ITEM_TYPE_TASK = 5;
3847: private static final int ITEM_TYPE_ASSET = 6;
3848: private static final int ITEM_TYPE_WORKFLOW = 7;
3849: private static final int ITEM_TYPE_OTHER = 8;
3850: private static String[] ITEM_TYPE_NAMES;
3851: static {
3852: ITEM_TYPE_NAMES = new String[(ITEM_TYPE_OTHER + 1)];
3853: ITEM_TYPE_NAMES[ITEM_TYPE_ALLOCATION] = "Allocation";
3854: ITEM_TYPE_NAMES[ITEM_TYPE_EXPANSION] = "Expansion";
3855: ITEM_TYPE_NAMES[ITEM_TYPE_AGGREGATION] = "Aggregation";
3856: ITEM_TYPE_NAMES[ITEM_TYPE_DISPOSITION] = "Disposition";
3857: ITEM_TYPE_NAMES[ITEM_TYPE_ASSET_TRANSFER] = "AssetTransfer";
3858: ITEM_TYPE_NAMES[ITEM_TYPE_TASK] = "Task";
3859: ITEM_TYPE_NAMES[ITEM_TYPE_ASSET] = "Asset";
3860: ITEM_TYPE_NAMES[ITEM_TYPE_WORKFLOW] = "Workflow";
3861: ITEM_TYPE_NAMES[ITEM_TYPE_OTHER] = null;
3862: }
3863:
3864: private static String getItemTypeString(Object item) {
3865: int itemType = getItemType(item);
3866: if (itemType == ITEM_TYPE_OTHER)
3867: return item.getClass().getName();
3868: return ITEM_TYPE_NAMES[itemType];
3869: }
3870:
3871: /**
3872: * getItemType.
3873: * <p>
3874: * Replace with synchronized hashmap lookup on obj.getClass()?
3875: **/
3876: private static int getItemType(Object obj) {
3877: if (obj instanceof PlanElement) {
3878: if (obj instanceof Allocation) {
3879: return ITEM_TYPE_ALLOCATION;
3880: } else if (obj instanceof Expansion) {
3881: return ITEM_TYPE_EXPANSION;
3882: } else if (obj instanceof Aggregation) {
3883: return ITEM_TYPE_AGGREGATION;
3884: } else if (obj instanceof Disposition) {
3885: return ITEM_TYPE_DISPOSITION;
3886: } else if (obj instanceof AssetTransfer) {
3887: return ITEM_TYPE_ASSET_TRANSFER;
3888: } else {
3889: return ITEM_TYPE_OTHER;
3890: }
3891: } else if (obj instanceof Task) {
3892: return ITEM_TYPE_TASK;
3893: } else if (obj instanceof Asset) {
3894: return ITEM_TYPE_ASSET;
3895: } else if (obj instanceof Workflow) {
3896: return ITEM_TYPE_WORKFLOW;
3897: } else {
3898: return ITEM_TYPE_OTHER;
3899: }
3900: }
3901:
3902: /**
3903: * SummaryInfo.
3904: * <p>
3905: * Counter holder
3906: **/
3907: private static class SummaryInfo {
3908: public int counter;
3909:
3910: public SummaryInfo() {
3911: counter = 0;
3912: }
3913:
3914: public static final Comparator LARGEST_COUNTER_FIRST_ORDER = new Comparator() {
3915: public final int compare(Object o1, Object o2) {
3916: int c1 = ((SummaryInfo) o1).counter;
3917: int c2 = ((SummaryInfo) o2).counter;
3918: return ((c1 > c2) ? -1 : ((c1 == c2) ? 0 : 1));
3919: }
3920: };
3921: }
3922:
3923: /**
3924: * SummaryInfo.
3925: */
3926: private static class VerbSummaryInfo extends SummaryInfo {
3927: public Verb verb;
3928:
3929: public VerbSummaryInfo(Verb vb) {
3930: super ();
3931: verb = vb;
3932: }
3933: }
3934:
3935: /**
3936: * Dates are formatted to "month_day_year_hour:minute[AM|PM]"
3937: */
3938: private static SimpleDateFormat myDateFormat;
3939: private static Date myDateInstance;
3940: private static java.text.FieldPosition myFieldPos;
3941: static {
3942: myDateFormat = new SimpleDateFormat("MM_dd_yyyy_h:mma");
3943: myDateInstance = new Date();
3944: myFieldPos = new java.text.FieldPosition(
3945: SimpleDateFormat.YEAR_FIELD);
3946: }
3947:
3948: /**
3949: * getTimeString.
3950: * <p>
3951: * Formats time to String.
3952: */
3953: private static String getTimeString(long time) {
3954: synchronized (myDateFormat) {
3955: myDateInstance.setTime(time);
3956: return myDateFormat.format(myDateInstance,
3957: new StringBuffer(20), myFieldPos).toString();
3958: }
3959: }
3960:
3961: /**
3962: * bit[] based upon URLEncoder.
3963: */
3964: static boolean[] DONT_NEED_ENCODING;
3965: static {
3966: DONT_NEED_ENCODING = new boolean[256];
3967: for (int i = 'a'; i <= 'z'; i++) {
3968: DONT_NEED_ENCODING[i] = true;
3969: }
3970: for (int i = 'A'; i <= 'Z'; i++) {
3971: DONT_NEED_ENCODING[i] = true;
3972: }
3973: for (int i = '0'; i <= '9'; i++) {
3974: DONT_NEED_ENCODING[i] = true;
3975: }
3976: DONT_NEED_ENCODING['-'] = true;
3977: DONT_NEED_ENCODING['_'] = true;
3978: DONT_NEED_ENCODING['.'] = true;
3979: DONT_NEED_ENCODING['*'] = true;
3980:
3981: // special-case to not encode "/"
3982: DONT_NEED_ENCODING['/'] = true;
3983: }
3984:
3985: /**
3986: * Saves some String allocations.
3987: */
3988: private static String encodeUID(String s) {
3989: int n = s.length();
3990: for (int i = 0; i < n; i++) {
3991: // int c = (int)s.charAt(i);
3992: if (!(DONT_NEED_ENCODING[i])) {
3993: try {
3994: return URLEncoder.encode(s, "UTF-8");
3995: } catch (Exception e) {
3996: throw new IllegalArgumentException(
3997: "Unable to encode URL (" + s + ")");
3998: }
3999: }
4000: }
4001: return s;
4002: }
4003:
4004: /**
4005: * Encodes a string that may contain HTML syntax-significant
4006: * characters by replacing with a character entity.
4007: **/
4008: private static String encodeHTML(String s, boolean noBreakSpaces) {
4009: StringBuffer buf = null; // In case we need to edit the string
4010: int ix = 0; // Beginning of uncopied part of s
4011: for (int i = 0, n = s.length(); i < n; i++) {
4012: String replacement = null;
4013: switch (s.charAt(i)) {
4014: case '"':
4015: replacement = """;
4016: break;
4017: case '<':
4018: replacement = "<";
4019: break;
4020: case '>':
4021: replacement = ">";
4022: break;
4023: case '&':
4024: replacement = "&";
4025: break;
4026: case ' ':
4027: if (noBreakSpaces)
4028: replacement = " ";
4029: break;
4030: }
4031: if (replacement != null) {
4032: if (buf == null)
4033: buf = new StringBuffer();
4034: buf.append(s.substring(ix, i));
4035: buf.append(replacement);
4036: ix = i + 1;
4037: }
4038: }
4039: if (buf != null) {
4040: buf.append(s.substring(ix));
4041: return buf.toString();
4042: } else {
4043: return s;
4044: }
4045: }
4046:
4047: /**
4048: * XMLtoHTMLOutputStream.
4049: * <p>
4050: * Filter which converts XML to simple HTML.
4051: * Assumes <pre> tag surrounds this call, e.g.
4052: * <pre><code>
4053: * String xml = ">tag<value>/tag<";
4054: * PrintStream out = System.out;
4055: * XMLtoHTMLOutputStream xout = new XMLtoHTMLOutputStream(out);
4056: * out.print("<pre>\n");
4057: * xout.print(xml);
4058: * xout.flush();
4059: * out.print("\n</pre>");
4060: * </code></pre>
4061: * This keeps the spacing uniform and saves some writing.
4062: */
4063: public static class XMLtoHTMLOutputStream extends FilterWriter {
4064: private static final char[] LESS_THAN;
4065: private static final char[] GREATER_THAN;
4066: static {
4067: LESS_THAN = "<font color=green><".toCharArray();
4068: GREATER_THAN = "></font>".toCharArray();
4069: }
4070:
4071: public XMLtoHTMLOutputStream(Writer w) {
4072: super (w);
4073: }
4074:
4075: public void write(String str, int off, int len)
4076: throws IOException {
4077: int n = off + len;
4078: for (int i = off; i < n; i++) {
4079: write(str.charAt(i));
4080: }
4081: }
4082:
4083: public void write(char cbuf[], int off, int len)
4084: throws IOException {
4085: int n = off + len;
4086: for (int i = off; i < n; i++) {
4087: write(cbuf[i]);
4088: }
4089: }
4090:
4091: public void write(int c) throws IOException {
4092: //
4093: // NOTE: "this.out" is *not* the PlanViewer's "out"!
4094: //
4095: if (c == '<') {
4096: this .out.write(LESS_THAN);
4097: } else if (c == '>') {
4098: this .out.write(GREATER_THAN);
4099: } else {
4100: this .out.write(c);
4101: }
4102: }
4103: }
4104:
4105: private static class UnaryPredicateParser {
4106: private static String CLNAME = "org.cougaar.lib.contract.lang.OperatorFactoryImpl";
4107: private static Integer STYLE = new Integer(13); //paren-pretty-verbose
4108:
4109: private static Exception loadE;
4110: private static Object inst;
4111: private static Method meth;
4112:
4113: public static UnaryPredicate parse(String s)
4114: throws Exception {
4115: ensureIsLoaded();
4116: return (UnaryPredicate) meth.invoke(inst, new Object[] {
4117: STYLE, s });
4118: }
4119:
4120: private static synchronized void ensureIsLoaded()
4121: throws Exception {
4122: if (inst == null) {
4123: if (loadE == null) {
4124: try {
4125: Class cl = Class.forName(CLNAME);
4126: meth = cl.getMethod("create", new Class[] {
4127: Integer.TYPE, Object.class });
4128: inst = cl.newInstance();
4129: return;
4130: } catch (Exception e) {
4131: loadE = new RuntimeException(
4132: "Unable to load " + CLNAME, e);
4133: }
4134: }
4135: throw loadE;
4136: }
4137: }
4138: }
4139:
4140: /** END MISC UTILITIES **/
4141: }
4142: }
|