⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mvchelper.java

📁 此程序都是企业级 的数据库开发程序 全面揭示了JAVA对数据库的操作
💻 JAVA
字号:
package mvc;/* Standard Java Packages */import java.util.Properties;import java.io.File;import java.io.FileWriter;import java.io.FileInputStream;/* Imported from the J2EE or JBoss servlet.jar */import javax.servlet.jsp.JspWriter;/* Imported from xerces.jar */import org.w3c.dom.Document;import org.w3c.dom.Element;import org.apache.xml.serialize.OutputFormat;import org.apache.xml.serialize.XMLSerializer;public class MVCHelper {  /* Properties object containing all of the XSL File Names and the Request.Action key */  private static Properties xslFileNames = new Properties();  /* Location of the XSL Configuration Information File */  private static String XSLCONFIGPROPERTIES =     new String("c:\\jakarta-tomcat-3.2.2\\webapps\\begjdb\\etc\\xslConfig.properties");  /*   * This method will retrieve the name of an XSL file from the xslFileNames object.  It   * does this by appending the _request and _action parameters into a string that looks   * like this:   * Request.Action   * This string created from the two method parameters is used as a key   * to search xslFileNames for the appropriate file names.   */  public static String getXSLFileName(String _request,                                       String _action) throws Exception {    /* If the xslFileNames object is empty, load the data from the configuration fiel */    if (xslFileNames.isEmpty()) {      xslFileNames.load(new FileInputStream(XSLCONFIGPROPERTIES));    }     /* Building the lookup key */    StringBuffer key = new StringBuffer(_request);    key.append(".");    key.append(_action);    /* Retrieving the string */    String xslFileName = xslFileNames.getProperty(key.toString());    /* If no file name was retrieved throw an exception */    if (xslFileName == null) {      throw new Exception("MVCHelper.getXSLFileName:  Unable to locate XSL file based on the request"                           + " and action passed.  Key=" + key.toString());    }     return xslFileName;  }   /*   * The printDOM method will take the XML document and the File object   * passed into the method and dump its contents out to a file.  This is   * only here for debugging purposes and should not be used in production code.   */  public static void printDOM(Document _xmlDoc,                               File _outputFile) throws Exception {    OutputFormat outputFormat = new OutputFormat(_xmlDoc);    FileWriter fileWriter = new FileWriter(_outputFile);    XMLSerializer xmlSerializer = new XMLSerializer(fileWriter,             outputFormat);    xmlSerializer.asDOMSerializer();    xmlSerializer.serialize(_xmlDoc.getDocumentElement());  }   /*   * The buildDBElement will add a text node onto an element and return it back to the   * method that calls it.  This is simply a helper method that makes it easier to add   * elements to another element.   */  public static Element buildDBElement(Document _xmlDoc,                                        String _elementName,                                        String _elementValue) throws Exception {    Element item = _xmlDoc.createElement(_elementName);    if (_elementValue == null) {      item.appendChild(_xmlDoc.createTextNode(""));    } else {      item.appendChild(_xmlDoc.createTextNode(_elementValue));    }     return item;  }   /*   * Builds a generic help screen.   */  public static void buildErrorPage(Exception _e, JspWriter _out) {    try {      _out.write("<H1>We are currently unable to process your request. : "                  + _e.toString() + "</H1>");      System.out.println(_e.toString());    } catch (Exception e) {      System.out.println(_e.toString());    }   } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -