public void init(FilterConfig config) throws ServletException {

    Log log = LogFactory.getLog(this.getClass());
    log.info("PsqStoreConfigFilter: init(config) called");

    String path = "";

    try {
      URL pathUrl = config.getServletContext().getResource("/");

      path = new File(config.getServletContext().getRealPath("/")).getAbsolutePath();

      log.info(" protocol=" + pathUrl.getProtocol());
      log.info(" path=" + path);

    } catch (Exception ex) {
      ex.printStackTrace();
    }

    if (config.getInitParameter("derby-home") != null) {

      String myHome = config.getInitParameter("derby-home");
      if (!myHome.startsWith("/")) {
        myHome = path + File.separator + myHome;
      }

      log.info("derby-home(final)=" + myHome);
      System.setProperty("xpsq.derby.home", myHome);

      if (PsqContext.getStore("derby") != null) {
        PsqContext.getStore("derby").initialize();
      }
    }

    if (config.getInitParameter("bdb-home") != null) {

      String myHome = config.getInitParameter("bdb-home");
      if (!myHome.startsWith("/")) {
        myHome = path + File.separator + myHome;
      }

      log.info("bdb-home(final)=" + myHome);
      System.setProperty("xpsq.bdb.home", myHome);

      if (PsqContext.getStore("bdb") != null) {
        PsqContext.getStore("bdb").initialize();
      }
    }
  }
  /**
   * Initializes the servlet context, based on the servlet context. Parses all context parameters
   * and passes them on to the database context.
   *
   * @param sc servlet context
   * @throws IOException I/O exception
   */
  static synchronized void init(final ServletContext sc) throws IOException {
    // skip process if context has already been initialized
    if (context != null) return;

    // set servlet path as home directory
    final String path = sc.getRealPath("/");
    System.setProperty(Prop.PATH, path);

    // parse all context parameters
    final HashMap<String, String> map = new HashMap<String, String>();
    // store default web root
    map.put(MainProp.HTTPPATH[0].toString(), path);

    final Enumeration<?> en = sc.getInitParameterNames();
    while (en.hasMoreElements()) {
      final String key = en.nextElement().toString();
      if (!key.startsWith(Prop.DBPREFIX)) continue;

      // only consider parameters that start with "org.basex."
      String val = sc.getInitParameter(key);
      if (eq(key, DBUSER, DBPASS, DBMODE, DBVERBOSE)) {
        // store servlet-specific parameters as system properties
        System.setProperty(key, val);
      } else {
        // prefix relative paths with absolute servlet path
        if (key.endsWith("path") && !new File(val).isAbsolute()) {
          val = path + File.separator + val;
        }
        // store remaining parameters (without project prefix) in map
        map.put(key.substring(Prop.DBPREFIX.length()).toUpperCase(Locale.ENGLISH), val);
      }
    }
    context = new Context(map);

    if (SERVER.equals(System.getProperty(DBMODE))) {
      new BaseXServer(context);
    } else {
      context.log = new Log(context);
    }
  }
Example #3
0
  public void doGet(
      javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
      throws ServletException, IOException {
    try {
      PrintWriter out = res.getWriter();

      System.setProperty(
          "com.cisco.appsui.rootPath",
          this.getServletContext().getRealPath("/") + "/WEB-INF/templates/");

      String appTemplatesDir = "FooTemplates1.0";

      // creates an instance of PageComposer
      PageComposer myPage =
          new PageComposer(
              this.getServletContext().getRealPath("/") + "/WEB-INF/data/PageComposer.properties",
              true);

      // Determine the Image Path and SpacerImage Name
      String lImagePath = myPage.getProperty("appImagePath");
      String lSpacerImage = myPage.getProperty("appSpacerImg");

      // setting the body string
      StringBuffer bodySb;
      bodySb = new StringBuffer();

      // Add the Content Header to the body
      bodySb.append("<!-- This piece if for the header tab in the contents -->");
      bodySb.append("<!-- Please change the text to what it should say for your Content -->");
      bodySb.append("<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">");
      bodySb.append("	<tr bgcolor=\"#FFCC66\">");
      bodySb.append(
          "		<td bgcolor=\"#ffffff\"><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"7\" height=\"1\" alt=\"\"></td>");
      bodySb.append(
          "		<td><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"6\" height=\"22\" alt=\"\"></td>");
      bodySb.append("		<!--This should be changed to your App Name -->");
      bodySb.append(
          "		<td nowrap=\"\" width=\"100%\"><span class=\"contenttitle\">your appname here:</span>");
      bodySb.append("			<!--This should be changed to your app title-->");
      bodySb.append("			<span class=\"contenttitlesub\">your page title here</span></td>");
      bodySb.append(
          "		<td valign=\"top\" align=\"right\"><img src=\""
              + lImagePath
              + "/corner_ur_13.gif\" width=\"13\" height=\"13\" alt=\"\"></td> ");
      bodySb.append(
          "		<td bgcolor=\"#ffffff\"><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"7\" height=\"1\" alt=\"\"></td>");
      bodySb.append("	</tr>");
      bodySb.append("	<tr>");
      bodySb.append(
          "		<td colspan=\"5\"><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"1\" height=\"1\" alt=\"\"></td>");
      bodySb.append("	</tr>");
      bodySb.append("	<tr>");
      bodySb.append(
          "		<td><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"7\" height=\"1\" alt=\"\"></td>");
      bodySb.append(
          "		<td colspan=\"3\" bgcolor=\"#FFCC66\"><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"1\" height=\"1\" alt=\"\"></td>");
      bodySb.append(
          "		<td><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"7\" height=\"1\" alt=\"\"></td>");
      bodySb.append("	</tr>");
      bodySb.append("	<tr>");
      bodySb.append(
          "		<td colspan=\"5\"><img src=\""
              + lImagePath
              + "/"
              + lSpacerImage
              + "\" width=\"1\" height=\"10\" alt=\"\"></td>");
      bodySb.append("	</tr>");
      bodySb.append("</table>");

      // Add the actual body
      bodySb.append("<br><P align=center> CONTENT BODY <br>");

      bodySb.append("<BR><BR>");
      bodySb.append("<span class=\"contentbold\"> Hello Cisco Systems </span>");
      bodySb.append("<BR><BR>");
      bodySb.append(
          "<span class=\"content\"> This example shows how to generate a content window </span>");
      bodySb.append("<BR><BR>");

      // setting the window type to help
      myPage.setWindowType("content");

      // setting swt
      myPage.setSWT(
          "CampPrintSample", "CampEmailSample", null, null, "CampFeedbackSample", "CampHelpSample");
      myPage.activateApplMargin(true);

      out.print(myPage.renderPage(bodySb.toString()));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }