📄 quoteviewerapp.java
字号:
package components.quoteviewer;import java.io.*; // IOExceptionimport java.util.*; // Hashtableimport javax.servlet.*; // ServletConfigimport javax.servlet.http.*; // HttpServletRequest, HttpServletResponseimport org.jahia.params.*; // ParamBeanimport org.jahia.utils.*; // FileUtilsimport org.jahia.services.applications.*; // JahiaApplicationimport org.jahia.exceptions.*; // JahiaExceptionpublic class QuoteViewerApp extends HttpServlet { private String version = "1.2"; private static final String TEMPLATE_PATH = "\\quoteviewer" + File.separator + "templates" + File.separator; private static final String TEMPLATE_FILE = "std.html"; /*** * doGet * EV 10.12.2000 * */ public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException { PrintWriter out = response.getWriter(); //System.out.println( "Quote View App ver" + version + " responding to " + request.getRemoteAddr() + " GET METHOD " ); //System.out.println( "Current application user : " + request.getRemoteUser()); out.println( drawForm( request, response, "" ) ); } // end doGet /*** * doPost * EV 10.12.2000 * */ public void doPost( HttpServletRequest request, HttpServletResponse response ) throws IOException { //System.out.println( "Quote View App ver" + version + " responding to " + request.getRemoteAddr() + " POST METHOD " ); PrintWriter out = response.getWriter(); String theQuote = request.getParameter( "quote" ); String windowParams = "width=800,height=600,scrollbars=1,status=1,resizable=1"; String html = "<script language=\"javascript\">\n"; html += "window.open( 'http://finance.yahoo.com/q?s=" + theQuote + "&d=v1', 'quote', '" + windowParams + "' );"; html += "</script>"; html += drawForm( request, response, theQuote ); out.println(html); } // end doPost /*** * drawForm * EV 10.12.2000 * */ public String drawForm( HttpServletRequest request, HttpServletResponse response, String defaultQuote ) { String html = ""; ParamBean jParams = (ParamBean) request.getAttribute( "org.jahia.params" ); if (jParams == null) return "This application is designed to be run with Jahia"; String quoteField = "<input type=\"text\" name=\"quote\" maxlength=\"5\" size=\"5\" value=\"" + defaultQuote + "\"><br>\n"; String submitField = "<input type=\"submit\" value=\"View Quote\"><br>\n"; String filePath = jParams.settings().getComponentsDiskPath() + TEMPLATE_PATH + TEMPLATE_FILE; Hashtable tokens = new Hashtable(); tokens.put( "quoteField", quoteField ); tokens.put( "submitField", submitField ); String actionURL; if (request.getContextPath().equals("/")) { actionURL = request.getServletPath(); } else { actionURL = request.getContextPath() + request.getServletPath(); } html = "<form method=\"POST\" action=\"" + response.encodeURL(actionURL) + "\">\n"; html += composeSource( filePath, tokens ); html += "</form>\n"; return html; } // end drawForm /*** * composeSource * EV 10.12.2000 * */ public String composeSource( String filePath, Hashtable tokens ) { String contents = ""; try { contents = FileUtils.getInstance().readFile( filePath ); } catch (Exception e) { //System.out.println( "QuoteViewerApp > Error occured : " + e ); contents = "- Error in reading file - "; return contents; } int pos = 0; String theKey = ""; Enumeration keys = tokens.keys(); while (keys.hasMoreElements()) { theKey = (String) keys.nextElement(); pos = contents.indexOf( "<!--" + theKey + "-->" ); if (pos > -1) { contents = contents.substring( 0, pos ) + tokens.get(theKey) + contents.substring( pos, contents.length() ); } } return contents; } // end composeSource} // end QuoteViewerApp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -