1 32 33 package com.knowgate.http.portlets; 34 35 import java.io.File ; 36 import java.io.IOException ; 37 import java.io.ByteArrayOutputStream ; 38 import java.io.ByteArrayInputStream ; 39 import java.io.OutputStreamWriter ; 40 import java.io.PrintWriter ; 41 42 import java.util.Date ; 43 import java.util.Properties ; 44 import java.util.Enumeration ; 45 46 import java.sql.SQLException ; 47 import java.sql.PreparedStatement ; 48 import java.sql.ResultSet ; 49 import java.sql.Timestamp ; 50 51 import javax.xml.transform.TransformerException ; 52 import javax.xml.transform.TransformerConfigurationException ; 53 54 import javax.portlet.*; 55 56 import com.knowgate.debug.DebugFile; 57 import com.knowgate.jdc.JDCConnection; 58 import com.knowgate.dataobjs.*; 59 import com.knowgate.dataxslt.StylesheetCache; 60 import com.knowgate.misc.Gadgets; 61 import com.knowgate.dfs.FileSystem; 62 63 68 69 public class MyIncidencesTab extends GenericPortlet { 70 public MyIncidencesTab() { } 71 72 public MyIncidencesTab(HipergatePortletConfig oConfig) 73 throws javax.portlet.PortletException { 74 75 init(oConfig); 76 } 77 78 80 public String render(RenderRequest req, String sEncoding) 81 throws PortletException, IOException , IllegalStateException { 82 83 ByteArrayInputStream oInStream; 84 ByteArrayOutputStream oOutStream; 85 86 if (DebugFile.trace) { 87 DebugFile.writeln("Begin MyIncidencesTab.render()"); 88 DebugFile.incIdent(); 89 } 90 91 FileSystem oFS = new FileSystem(FileSystem.OS_PUREJAVA); 92 93 String sOutput; 94 String sDomainId = req.getProperty("domain"); 95 String sWorkAreaId = req.getProperty("workarea"); 96 String sUserId = req.getProperty("user"); 97 String sZone = req.getProperty("zone"); 98 String sLang = req.getProperty("language"); 99 String sTemplatePath = req.getProperty("template"); 100 String sStorage = req.getProperty("storage"); 101 String sFileDir = "file://" + sStorage + "domains" + File.separator + sDomainId + File.separator + "workareas" + File.separator + sWorkAreaId + File.separator + "cache" + File.separator + sUserId; 102 String sCachedFile = "myincidencestab_" + req.getWindowState().toString() + ".xhtm"; 103 104 if (DebugFile.trace) { 105 DebugFile.writeln ("user=" + sUserId); 106 DebugFile.writeln ("template=" + sTemplatePath); 107 DebugFile.writeln ("cache dir=" + sFileDir); 108 DebugFile.writeln ("modified=" + req.getAttribute("modified")); 109 DebugFile.writeln ("encoding=" + sEncoding); 110 } 111 112 Date oDtModified = (Date ) req.getAttribute("modified"); 113 114 if (null!=oDtModified) { 115 try { 116 117 File oCached = new File (sFileDir.substring(7)+File.separator+sCachedFile); 118 119 if (!oCached.exists()) { 120 oFS.mkdirs(sFileDir); 121 } 122 else if (oCached.lastModified()>oDtModified.getTime()) { 123 sOutput = new String (oFS.readfile(sFileDir+File.separator+sCachedFile, sEncoding==null ? "ISO8859_1" : sEncoding)); 124 125 if (DebugFile.trace) { 126 DebugFile.writeln("cache hit " + sFileDir+File.separator+sCachedFile); 127 DebugFile.decIdent(); 128 DebugFile.writeln("End MyIncidencesTab.render()"); 129 } 130 131 return sOutput; 132 } 133 } 134 catch (Exception xcpt) { 135 DebugFile.writeln(xcpt.getClass().getName() + " " + xcpt.getMessage()); 136 } 137 } 138 139 String sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type=\"text/xsl\"?>"; 140 141 int iBugs = 0; 142 143 if (req.getWindowState().equals(WindowState.MINIMIZED)) { 144 sXML += "<bugs/>"; 145 } 146 else { 147 148 DBBind oDBB = (DBBind) getPortletContext().getAttribute("GlobalDBBind"); 149 150 DBSubset oBugs = new DBSubset (DB.k_bugs, DB.gu_bug + "," + DB.tl_bug, 151 "(" + DB.tx_status + " IS NULL OR " + DB.tx_status + " IN ('EN ESPERA', 'ASIGNADO', 'VERIFICADO')) AND (" + DB.nm_assigned + "=? OR " + DB.tx_rep_mail + " IN (SELECT " + DB.tx_main_email + " FROM " + DB.k_users + " WHERE " + DB.gu_user + "=?)) ORDER BY " + DB.od_priority + " DESC", 10); 152 153 JDCConnection oCon = null; 154 155 try { 156 oCon = oDBB.getConnection("MyIncidencesTab"); 157 158 iBugs = oBugs.load (oCon, new Object []{sUserId,sUserId}); 159 160 oCon.close("MyIncidencesTab"); 161 oCon = null; 162 163 sXML += "<bugs>\n"+oBugs.toXML("","bug")+"</bugs>"; 164 } 165 catch (SQLException e) { 166 sXML += "<bugs/>"; 167 168 try { 169 if (null != oCon) 170 if (!oCon.isClosed()) 171 oCon.close("MyIncidencesTab"); 172 } catch (SQLException ignore) { } 173 } 174 } 175 176 try { 177 if (DebugFile.trace) DebugFile.writeln("new ByteArrayInputStream(" + String.valueOf(sXML.length()) + ")"); 178 179 if (sEncoding==null) 180 oInStream = new ByteArrayInputStream (sXML.getBytes()); 181 else 182 oInStream = new ByteArrayInputStream (sXML.getBytes(sEncoding)); 183 184 oOutStream = new ByteArrayOutputStream (4000); 185 186 Properties oProps = new Properties (); 187 188 Enumeration oKeys = req.getPropertyNames(); 189 while (oKeys.hasMoreElements()) { 190 String sKey = (String ) oKeys.nextElement(); 191 oProps.setProperty(sKey, req.getProperty(sKey)); 192 } 194 if (req.getWindowState().equals(WindowState.MINIMIZED)) 195 oProps.setProperty("windowstate", "MINIMIZED"); 196 else 197 oProps.setProperty("windowstate", "NORMAL"); 198 199 StylesheetCache.transform (sTemplatePath, oInStream, oOutStream, oProps); 200 201 if (sEncoding==null) 202 sOutput = oOutStream.toString(); 203 else 204 sOutput = oOutStream.toString("UTF-8"); 205 206 oOutStream.close(); 207 208 oInStream.close(); 209 oInStream = null; 210 211 oFS.writefilestr (sFileDir+File.separator+sCachedFile, sOutput, sEncoding==null ? "ISO8859_1" : sEncoding); 212 } 213 catch (TransformerConfigurationException tce) { 214 if (DebugFile.trace) { 215 DebugFile.writeln("TransformerConfigurationException " + tce.getMessageAndLocation()); 216 try { 217 DebugFile.write("--------------------------------------------------------------------------------\n"); 218 DebugFile.write(FileSystem.readfile(sTemplatePath)); 219 DebugFile.write("\n--------------------------------------------------------------------------------\n"); 220 DebugFile.write(sXML); 221 DebugFile.write("\n--------------------------------------------------------------------------------\n"); 222 } 223 catch (java.io.IOException ignore) { } 224 catch (com.enterprisedt.net.ftp.FTPException ignore) { } 225 226 DebugFile.decIdent(); 227 } 228 throw new PortletException("TransformerConfigurationException " + tce.getMessage(), tce); 229 } 230 catch (TransformerException tex) { 231 if (DebugFile.trace) { 232 DebugFile.writeln("TransformerException " + tex.getMessageAndLocation()); 233 234 try { 235 DebugFile.write("--------------------------------------------------------------------------------\n"); 236 DebugFile.write(FileSystem.readfile(sTemplatePath)); 237 DebugFile.write("\n--------------------------------------------------------------------------------\n"); 238 DebugFile.write(sXML); 239 DebugFile.write("\n--------------------------------------------------------------------------------\n"); 240 } 241 catch (java.io.IOException ignore) { } 242 catch (com.enterprisedt.net.ftp.FTPException ignore) { } 243 244 DebugFile.decIdent(); 245 } 246 throw new PortletException("TransformerException " + tex.getMessage(), tex); 247 } 248 249 if (DebugFile.trace) { 250 DebugFile.decIdent(); 251 DebugFile.writeln("End MyIncidencesTab.render()"); 252 } 253 return sOutput; 254 } 255 256 258 public void render(RenderRequest req, RenderResponse res) 259 throws PortletException, IOException , IllegalStateException { 260 res.getWriter().write(render(req,res.getCharacterEncoding())); 261 } 262 263 } 264 | Popular Tags |