1 19 package org.openharmonise.rm.view.servlet; 20 import java.io.*; 21 import java.util.logging.*; 22 23 import javax.servlet.*; 24 import javax.servlet.http.*; 25 import javax.xml.parsers.*; 26 27 import org.openharmonise.rm.config.*; 28 import org.openharmonise.rm.dsi.*; 29 import org.openharmonise.rm.factory.*; 30 import org.openharmonise.rm.publishing.*; 31 import org.openharmonise.rm.resources.*; 32 import org.openharmonise.rm.resources.publishing.*; 33 import org.openharmonise.rm.view.servlet.utils.*; 34 import org.w3c.dom.*; 35 36 37 44 45 public class HarmoniseXMLServlet extends HarmoniseServlet { 46 47 51 static final String MAXFILESIZE_PNAME = "MAX_UPLOADED_FILESIZE_MB"; 52 53 57 static final String TEMPDIR_PNAME = "UPLOADED_TEMPFILE_DIR"; 58 59 62 private static final Logger m_logger = Logger.getLogger(HarmoniseXMLServlet.class.getName()); 63 64 68 public HarmoniseXMLServlet() { 69 } 70 71 74 public void init(ServletConfig config) throws ServletException { 75 super.init(config); 76 77 try { 78 m_dbintrf = DataStoreInterfaceFactory.getDataStoreInterface(); 79 } catch (Exception e) { 80 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 81 } 82 } 83 84 85 88 public void doGet(HttpServletRequest request, HttpServletResponse response) 89 throws ServletException, IOException { 90 doPost(request, response); 91 } 92 93 94 97 public void doPost( 98 HttpServletRequest request, 99 HttpServletResponse response) 100 throws ServletException, IOException { 101 OutputStream out = response.getOutputStream(); 102 103 try { 104 HttpRequestManager req_mgr = null; 105 106 int max_filesize_mb = 107 ConfigSettings.getIntProperty( 108 MAXFILESIZE_PNAME, 109 "1"); 110 int m_MAX_FILESIZE = max_filesize_mb * 1024 * 1024; 111 112 String m_TEMP_FILE_DIR = 113 ConfigSettings.getProperty( 114 TEMPDIR_PNAME, 115 "c:\\Harmonise\\temp"); 116 117 118 req_mgr = new HttpRequestManager(request, m_MAX_FILESIZE, m_TEMP_FILE_DIR); 119 120 String sState = req_mgr.getStringFromReqReader(); 121 122 org.w3c.dom.Document xml_doc = 123 DocumentBuilderFactory 124 .newInstance() 125 .newDocumentBuilder() 126 .parse( 127 new org.xml.sax.InputSource (new StringReader(sState))); 128 129 State state = new State(xml_doc, this.m_dbintrf); 130 131 NodeList nodes = state.getElementsByTagName(WebPage.TAG_PAGE); 132 int nPage = 1; 133 134 if (nodes.getLength() > 0) { 135 nPage = 136 Integer.parseInt( 137 ((Element) nodes.item(0)).getAttribute( 138 AbstractObject.ATTRIB_ID)); 139 } 140 141 org.w3c.dom.Document xml = null; 142 143 WebPageEngine pageEngine = null; 144 WebPage page = null; 145 String sXMLfile = "Filename not known"; 146 String sXSLfile = "Filename not known"; 147 148 if (true) { 149 try { 150 151 152 String sSessionId = state.getSessionId(); 153 154 if ((sSessionId == null) || (sSessionId.length() == 0)) { 155 pageEngine = new WebPageEngine(this.m_dbintrf); 157 158 } else { 159 pageEngine = 161 WebPageEngineCache.getInstance( 162 m_dbintrf).getWebPageEngine( 163 sSessionId); 164 165 } 166 167 page = 168 (WebPage) HarmoniseObjectFactory.instantiateHarmoniseObject( 169 this.m_dbintrf, 170 WebPage.class.getName(), 171 nPage); 172 173 xml = pageEngine.createXML(page, state); 174 175 if (xml == null && m_logger.isLoggable(Level.FINE)) { 176 m_logger.logp(Level.FINE,this.getClass().getName(),"doPost", "Null XML document returned."); 177 } 178 179 pageEngine.render(page, state, out); 180 181 } catch (Exception e) { 182 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 183 throw e; 184 } 185 } 186 187 out.flush(); 188 189 } catch (Exception e) { 190 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 191 } finally { 192 out.flush(); 193 out.close(); 194 } 195 196 } 197 } 198 | Popular Tags |