| 1 | package tmcsim.cadmodels; |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | import java.io.Serializable; |
|---|
| 5 | import java.util.Vector; |
|---|
| 6 | |
|---|
| 7 | import org.w3c.dom.Document; |
|---|
| 8 | import org.w3c.dom.Element; |
|---|
| 9 | import org.w3c.dom.Node; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * IncidentInquiryDetails extends from IncidentInquiryLogEntry to provide a |
|---|
| 13 | * model object containing information used to display a detail log entry. |
|---|
| 14 | * Data for a detail includes a String of text.<br/> |
|---|
| 15 | * <br/> |
|---|
| 16 | * This element parses and creates the following XML schema in its toXML() and |
|---|
| 17 | * fromXML() methods. The ROOT element is the parameter for those methods.<br/> |
|---|
| 18 | * <ROOT><br/> |
|---|
| 19 | * <TEXT/><br/> |
|---|
| 20 | * <POSITION_INFO/><br/> |
|---|
| 21 | * <TIMESTAMP/><br/> |
|---|
| 22 | * </ROOT><br/> |
|---|
| 23 | * |
|---|
| 24 | * @author Matthew Cechini |
|---|
| 25 | * @version |
|---|
| 26 | */ |
|---|
| 27 | @SuppressWarnings("serial") |
|---|
| 28 | public class IncidentInquiryDetails extends IncidentInquiryLogEntry |
|---|
| 29 | implements Serializable { |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * Enumeration with XML tag names. |
|---|
| 33 | * @author Matthew Cechini |
|---|
| 34 | */ |
|---|
| 35 | private static enum XML_TAGS { |
|---|
| 36 | /** Detail Text. */ |
|---|
| 37 | TEXT ("TEXT"); |
|---|
| 38 | |
|---|
| 39 | public String tag; |
|---|
| 40 | |
|---|
| 41 | private XML_TAGS(String t) { |
|---|
| 42 | tag = t; |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /** Detail text. */ |
|---|
| 48 | public String details; |
|---|
| 49 | |
|---|
| 50 | /** */ |
|---|
| 51 | public Boolean sensitive; |
|---|
| 52 | |
|---|
| 53 | //public boolean highlighted; |
|---|
| 54 | |
|---|
| 55 | /** |
|---|
| 56 | * Constructor. Initialize all detail data to empty strings or false. |
|---|
| 57 | * |
|---|
| 58 | * @param newPosInfo String containing position info for this log entry |
|---|
| 59 | */ |
|---|
| 60 | public IncidentInquiryDetails(String newPosInfo, Boolean sens) { |
|---|
| 61 | super(newPosInfo, "0000"); |
|---|
| 62 | |
|---|
| 63 | details = ""; |
|---|
| 64 | sensitive = sens; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * Constructor. Initialize all detail data to the parameter. |
|---|
| 69 | * |
|---|
| 70 | * @param newPosInfo String containing position info for this log entry. |
|---|
| 71 | * @param newDetails String containing detail text for this log entry. |
|---|
| 72 | */ |
|---|
| 73 | public IncidentInquiryDetails(String newPosInfo, String newDetails, Boolean sens) { |
|---|
| 74 | super(newPosInfo, "0000"); |
|---|
| 75 | |
|---|
| 76 | details = newDetails; |
|---|
| 77 | sensitive = sens; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * Constructor. Parse parameter node for Detail log entry data. |
|---|
| 82 | * |
|---|
| 83 | * @param theNode Node containing data for this Detail log entry |
|---|
| 84 | */ |
|---|
| 85 | public IncidentInquiryDetails(Node theNode) { |
|---|
| 86 | fromXML(theNode); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | public void toXML(Element currElem) { |
|---|
| 90 | Document theDoc = currElem.getOwnerDocument(); |
|---|
| 91 | Element tempElem = null; |
|---|
| 92 | |
|---|
| 93 | tempElem = theDoc.createElement(XML_TAGS.TEXT.tag); |
|---|
| 94 | tempElem.appendChild(theDoc.createTextNode(details)); |
|---|
| 95 | currElem.appendChild(tempElem); |
|---|
| 96 | |
|---|
| 97 | super.toXML(currElem); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | public void fromXML(Node modelNode) { |
|---|
| 101 | |
|---|
| 102 | Node childNode = null; |
|---|
| 103 | |
|---|
| 104 | childNode = modelNode.getFirstChild(); |
|---|
| 105 | details = childNode.getTextContent(); |
|---|
| 106 | |
|---|
| 107 | childNode = childNode.getNextSibling(); |
|---|
| 108 | super.fromXML(childNode); |
|---|
| 109 | |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /** |
|---|
| 113 | * Parse the details text into a list of endline terminated strings which are |
|---|
| 114 | * no longer than the parameter width. Words which would be split by an endline |
|---|
| 115 | * are moved in whole to the next line. Words longer than a line width are split |
|---|
| 116 | * accordingly. |
|---|
| 117 | * |
|---|
| 118 | * @param width Line width used for parsing details |
|---|
| 119 | * @return A vector of endline terminated detail strings. |
|---|
| 120 | */ |
|---|
| 121 | public Vector<String> parseDetails(int width) { |
|---|
| 122 | Vector<String> parsedDetails = new Vector<String>(); |
|---|
| 123 | |
|---|
| 124 | int currPos = 0; |
|---|
| 125 | int spaceIdx = 0; |
|---|
| 126 | |
|---|
| 127 | while((details.length() - currPos) > width) { |
|---|
| 128 | |
|---|
| 129 | spaceIdx = details.substring(currPos, currPos + width).lastIndexOf(" "); |
|---|
| 130 | |
|---|
| 131 | if(spaceIdx > 0) { |
|---|
| 132 | parsedDetails.add(details.substring(currPos, currPos + spaceIdx).trim() + "\n"); |
|---|
| 133 | currPos += spaceIdx; |
|---|
| 134 | } |
|---|
| 135 | else { |
|---|
| 136 | parsedDetails.add(details.substring(currPos, currPos + width).trim() + "\n"); |
|---|
| 137 | currPos += width; |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | //remainder |
|---|
| 142 | parsedDetails.add(details.substring(currPos).trim() + "\n"); |
|---|
| 143 | |
|---|
| 144 | return parsedDetails; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | } |
|---|