001: package org.enhydra.dm.presentation;
002:
003: import java.text.SimpleDateFormat;
004: import java.util.Date;
005: import java.util.Properties;
006:
007: import org.enhydra.dm.EnhydraDM;
008: import org.enhydra.dm.api.Document;
009: import org.enhydra.dm.util.EnhydraDMConstants;
010:
011: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
012: import com.lutris.logging.LogChannel;
013: import com.lutris.logging.Logger;
014:
015: public class Details extends Base {
016:
017: /**
018: * Corresponding XMLC object
019: */
020: private DetailsHTML page;
021:
022: /*
023: * Function needed in order to be a presentation object.
024: */
025: public void run(HttpPresentationComms comms) throws Exception {
026: page = (DetailsHTML) comms.xmlcFactory
027: .create(DetailsHTML.class);
028:
029: comms.request.getHttpServletRequest().setCharacterEncoding(
030: EnhydraDMConstants.ENCODING);
031:
032: String documentId = comms.request
033: .getParameter(EnhydraDMConstants.DOCUMENT_ID);
034:
035: documentManager = ((EnhydraDM) comms.application)
036: .getDocumentManager();
037:
038: SimpleDateFormat sdf = new SimpleDateFormat(
039: EnhydraDMConstants.DATE_FORMAT);
040:
041: boolean doCommit = true;
042: try {
043: initTransaction();
044: String user = getUser(comms);
045:
046: page.setTextUser(user);
047:
048: page.getElementLogoutLink().setHref(
049: EnhydraDMConstants.NAVIG_MANAGER + "?"
050: + EnhydraDMConstants.ACTION + "="
051: + EnhydraDMConstants.ACTION_LOGOUT);
052:
053: Properties prop = ((EnhydraDM) comms.application)
054: .getProperties("documentdetail", "documentdetail");
055: setI18n(prop, comms.application.getLogChannel());
056:
057: if (documentId != null) {
058: String mode = EnhydraDMConstants.MODE_DOCUMENT;
059: Document document = documentManager
060: .getDocument(documentId);
061:
062: String previewerURL = EnhydraDM.previewerURL;
063: if (previewerURL == null || previewerURL.equals(""))
064: previewerURL = setPreviewerURL(comms);
065:
066: page.getElementDocumentPreviewLink().setHref(
067: previewerURL + "?fullFilePath="
068: + document.getFilepath()
069: + "&parseOnFly=true&xsl="
070: + EnhydraDM.previewerXSL);
071: page.getElementDocumentIdValueLabel().setTextContent(
072: document.getNumber());
073: page.getElementDocumentNameValueLabel().setTextContent(
074: document.getName());
075: page.getElementFilePathValueLabel().setTextContent(
076: document.getFilepath());
077: page.getElementSizeValueLabel().setTextContent(
078: Long.toString(document.getSize()) + " (B)");
079: page.getElementMimeTypeValueLabel().setTextContent(
080: document.getMimeType());
081: if (document.getLockedBy() != null) {
082: page.getElementLockedByValueLabel().setTextContent(
083: document.getLockedBy());
084: } else {
085: page
086: .getElementLockedByLabel()
087: .getParentNode()
088: .removeChild(page.getElementLockedByLabel());
089: }
090: if (document.getCheckedOutBy() != null) {
091: page.getElementCheckedOutByValueLabel()
092: .setTextContent(document.getCheckedOutBy());
093: } else {
094: page.getElementCheckedOutByLabel().getParentNode()
095: .removeChild(
096: page.getElementCheckedOutByLabel());
097: }
098: if (document.isArchived()) {
099: page.getElementArchivrdValue().setAttribute(
100: "checked", "true");
101: }
102: if (document.isAutoversionable()) {
103: page.getElementAutovrsionableValue().setAttribute(
104: "checked", "true");
105: }
106: page.getElementCuttentVersionNumberValueLabel()
107: .setTextContent(
108: document.getCurrentVersionNumber());
109: page.getElementCreatedByValueLabel().setTextContent(
110: document.getCreatedBy());
111: Date createdDate = new Date(document.getCreatedDate());
112: if (createdDate != null) {
113: page.getElementCreatedDateValueLabel()
114: .setTextContent(sdf.format(createdDate));
115: }
116: page.getElementLastModifiedByValueLabel()
117: .setTextContent(document.getLastModifiedBy());
118: Date lastModifiedDate = new Date(document
119: .getLastModifiedDate());
120: if (lastModifiedDate != null) {
121: page.getElementLastModifiedDateValueLabel()
122: .setTextContent(
123: sdf.format(lastModifiedDate));
124: }
125: if (document.getDeletedBy() != null) {
126: page.getElementDeletedByValueLabel()
127: .setTextContent(document.getDeletedBy());
128: Date deletedDate = new Date(document
129: .getDeletedDate());
130: if (lastModifiedDate != null) {
131: page
132: .getElementDeletedDateValueLabel()
133: .setTextContent(sdf.format(deletedDate));
134: }
135: } else {
136: page.getElementDeletedByLabel().getParentNode()
137: .removeChild(
138: page.getElementDeletedByLabel());
139: page.getElementDeletedDateLabel().getParentNode()
140: .removeChild(
141: page.getElementDeletedDateLabel());
142: }
143: if (document.isTemplate()) {
144: page.getElementTemplateValue().setAttribute(
145: "checked", "true");
146: mode = EnhydraDMConstants.MODE_TEMPLATE;
147: }
148: if (document.getTemplateRef() != null) {
149: page
150: .getElementTemplateNameValueLabel()
151: .setTextContent(
152: document.getTemplateRef().getName());
153: } else {
154: page.getElementTemplateNameLabel().getParentNode()
155: .removeChild(
156: page.getElementTemplateNameLabel());
157: }
158: page.getElementBackLink().setHref(
159: EnhydraDMConstants.NAVIG_MANAGER + "?"
160: + EnhydraDMConstants.MODE + "=" + mode);
161: }
162:
163: comms.response.writeDOM(page);
164: } catch (Throwable e) {
165: doCommit = false;
166: comms.application.getLogChannel().write(Logger.ERROR,
167: "just failed", e);
168: throw new Exception(e);
169:
170: } finally {
171: if (doCommit) {
172: commitTransaction();
173: } else {
174: rollbackTransaction();
175: }
176: }
177: }
178:
179: private String setPreviewerURL(HttpPresentationComms comms) {
180: StringBuffer sb = new StringBuffer();
181: sb.append(comms.request.getScheme());
182: sb.append("://");
183: sb.append(comms.request.getServerName());
184: sb.append(":");
185: sb.append(comms.request.getServerPort());
186: sb.append("/");
187: sb.append("tdv/Preview.po");
188: return sb.toString();
189: }
190:
191: private void setI18n(Properties prop, LogChannel logChannel) {
192: try {
193: super .setI18n(prop, page);
194: } catch (Exception e) {
195: if (null != logChannel) {
196: logChannel.write(Logger.WARNING,
197: "documentdetail.properties not found");
198: }
199: }
200: }
201: }
|