| | |
| | | * |
| | | * @version 1, September 16, 2012 |
| | | */ |
| | | public class TransitServletRS extends HttpServlet { |
| | | public class TransitServletRS extends AbstractServlet { |
| | | |
| | | /** Proforma Konstante fuer Schnittstelle Serializable */ |
| | | public static final long serialVersionUID = 42L; |
| | | |
| | | private static final Logger logger = Logger.getLogger(TransitServletRS.class.getName()); |
| | | |
| | | public static final String MIME_JSON = "application/json"; |
| | | public static final String MIME_XML = "text/xml"; |
| | | |
| | | private static final String[] specialChars = {new String("\u00c4"), new String("\u00d6"), |
| | | new String("\u00dc"), new String("\u00e4"), new String("\u00f6"), new String("\u00fc"), new String("\u00df")}; |
| | | |
| | | private String klassen; |
| | | |
| | | public void init(ServletConfig servletConfig) throws ServletException{ |
| | | this.klassen = servletConfig.getInitParameter("klassen"); |
| | | super.init(servletConfig); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Eine Anfrage via HTTP GET verarbeiten |
| | | * |
| | |
| | | JavaServer server = null; |
| | | try { |
| | | /* |
| | | String klassenName = null; |
| | | String methodenName = null; |
| | | List parameterListe = new ArrayList(); |
| | | String formatName = null; |
| | | Enumeration en = req.getParameterNames(); |
| | | while(en.hasMoreElements()) { |
| | | String pName = en.nextElement().toString(); |
| | | String[] pWerte = req.getParameterValues(pName); |
| | | if(pName.equals(CLASS_NAME)) { |
| | | klassenName = pWerte[0]; |
| | | } else if(pName.equals(METHOD_NAME)) { |
| | | methodenName = pWerte[0]; |
| | | } else if(pName.equals(FORMAT_NAME)) { |
| | | formatName = pWerte[0]; |
| | | } else { |
| | | for(int i = 0; i < pWerte.length; i++) { |
| | | parameterListe.add(pWerte[i]); |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | |
| | | /* |
| | | http://server:port/contextpfad/servletpfad/de.irgend.eine.Klasse/methode/format/param1/param2/../paramN |
| | | wird zu |
| | | elemente[0] = / |
| | | elemente[1] = de.irgend.eine.Klasse |
| | | elemente[2] = methode |
| | | elemente[3] = format |
| | | elemente[4]-[n] = param1 |
| | | elemente[4]-[n] = param1 - paramn |
| | | */ |
| | | |
| | | String pathInfo = req.getPathInfo(); |
| | | logger.info("pathInfo: " + pathInfo); |
| | | logger.log(Level.INFO, "pathInfo: {0}", pathInfo); |
| | | String[] elemente = pathInfo.split("/"); |
| | | String klassenName = elemente[1]; |
| | | StringBuffer buf = new StringBuffer(); |
| | | if(this.klassen.contains(klassenName)) { |
| | | StringBuilder buf = new StringBuilder(); |
| | | if(istErlaubt(klassenName)) { |
| | | String methodenName = elemente[2]; |
| | | String formatName = elemente[3]; |
| | | List parameterListe = new ArrayList(); |
| | |
| | | Object o = cls.newInstance(); |
| | | if(o != null) { |
| | | if(o instanceof NutzerKontext) { |
| | | ((NutzerKontext) o).setNutzerId(Waechter.getUserName(req)); |
| | | ((NutzerKontext) o).setNutzerId(getUserName(req)); |
| | | } |
| | | if(o instanceof WebKontext) { |
| | | ((WebKontext) o).setServletContext(getServletContext()); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public String escapeHtml(String text) { |
| | | text = text.replace(specialChars[0], "Ä"); |
| | | text = text.replace(specialChars[1], "Ö"); |
| | | text = text.replace(specialChars[2], "Ü"); |
| | | text = text.replace(specialChars[3], "ä"); |
| | | text = text.replace(specialChars[4], "ö"); |
| | | text = text.replace(specialChars[5], "ü"); |
| | | text = text.replace(specialChars[6], "ß"); |
| | | return text; |
| | | } |
| | | |
| | | } |