示例#1
0
  public static String getFooter(String context) {
    try {
      FileReader fileReader =
          new FileReader(findResourceOnFileSystem("servletResponseTemplate.htm"));
      BufferedReader buffread = new BufferedReader(fileReader);
      String templateFile = "", line;
      StringBuffer SBreader = new StringBuffer();
      while ((line = buffread.readLine()) != null) {
        SBreader.append(line).append("\n");
      }
      fileReader.close();
      buffread.close();
      templateFile = SBreader.toString();
      templateFile =
          templateFile.replaceAll(
              "BOTTOMGRAPHIC", CommonConfiguration.getURLToFooterGraphic(context));

      int end_header = templateFile.indexOf("INSERT_HERE");
      return (templateFile.substring(end_header + 11));
    } catch (Exception e) {
      // out.println("I couldn't find the template file to read from.");
      e.printStackTrace();
      String error =
          "An error occurred while attempting to read from an HTML template file. This probably will not affect the success of the operation you were trying to perform.</p></body></html>";
      return error;
    }
  }
示例#2
0
  public static Connection getConnection() throws SQLException {

    Connection conn = null;
    Properties connectionProps = new Properties();
    connectionProps.put(
        "user", CommonConfiguration.getProperty("datanucleus.ConnectionUserName", "context0"));
    connectionProps.put(
        "password", CommonConfiguration.getProperty("datanucleus.ConnectionPassword", "context0"));

    conn =
        DriverManager.getConnection(
            CommonConfiguration.getProperty("datanucleus.ConnectionURL", "context0"),
            connectionProps);

    System.out.println("Connected to database for authentication.");
    return conn;
  }
示例#3
0
  public static String getLanguageCode(HttpServletRequest request) {
    String context = ServletUtilities.getContext(request);

    // worst case scenario default to English
    String langCode = "en";

    // try to detect a default if defined
    if (CommonConfiguration.getProperty("defaultLanguage", context) != null) {
      langCode = CommonConfiguration.getProperty("defaultLanguage", context);
    }

    ArrayList<String> supportedLanguages = new ArrayList<String>();
    if (CommonConfiguration.getSequentialPropertyValues("language", context) != null) {
      supportedLanguages = CommonConfiguration.getSequentialPropertyValues("language", context);
    }

    // if specified directly, always accept the override
    if (request.getParameter("langCode") != null) {
      if (supportedLanguages.contains(request.getParameter("langCode"))) {
        return request.getParameter("langCode");
      }
    }

    // the request cookie is the next thing we check. this should be the primary means of figuring
    // langCode out
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
      for (Cookie cookie : cookies) {
        if ("wildbookLangCode".equals(cookie.getName())) {
          if (supportedLanguages.contains(cookie.getValue())) {
            return cookie.getValue();
          }
        }
      }
    }

    // finally, we will check the URL vs values defined in context.properties to see if we can set
    // the right context
    // TBD - future - detect browser supported language codes and locale from the HTTPServletRequest
    // object

    return langCode;
  }
示例#4
0
  public static String getHeader(HttpServletRequest request) {
    try {
      FileReader fileReader =
          new FileReader(findResourceOnFileSystem("servletResponseTemplate.htm"));
      BufferedReader buffread = new BufferedReader(fileReader);
      String templateFile = "", line;
      StringBuffer SBreader = new StringBuffer();
      while ((line = buffread.readLine()) != null) {
        SBreader.append(line).append("\n");
      }
      fileReader.close();
      buffread.close();
      templateFile = SBreader.toString();

      String context = getContext(request);

      // process the CSS string
      templateFile =
          templateFile.replaceAll(
              "CSSURL", CommonConfiguration.getCSSURLLocation(request, context));

      // set the top header graphic
      templateFile =
          templateFile.replaceAll(
              "TOPGRAPHIC", CommonConfiguration.getURLToMastheadGraphic(context));

      int end_header = templateFile.indexOf("INSERT_HERE");
      return (templateFile.substring(0, end_header));
    } catch (Exception e) {
      // out.println("I couldn't find the template file to read from.");
      e.printStackTrace();
      String error =
          "<html><body><p>An error occurred while attempting to read from the template file servletResponseTemplate.htm. This probably will not affect the success of the operation you were trying to perform.";
      return error;
    }
  }
示例#5
0
  // Logs a new ATOM entry
  public static synchronized void addATOMEntry(
      String title, String link, String description, File atomFile, String context) {
    try {

      if (atomFile.exists()) {

        // System.out.println("ATOM file found!");
        /** Namespace URI for content:encoded elements */
        String CONTENT_NS = "http://www.w3.org/2005/Atom";

        /** Parses RSS or Atom to instantiate a SyndFeed. */
        SyndFeedInput input = new SyndFeedInput();

        /** Transforms SyndFeed to RSS or Atom XML. */
        SyndFeedOutput output = new SyndFeedOutput();

        // Load the feed, regardless of RSS or Atom type
        SyndFeed feed = input.build(new XmlReader(atomFile));

        // Set the output format of the feed
        feed.setFeedType("atom_1.0");

        List<SyndEntry> items = feed.getEntries();
        int numItems = items.size();
        if (numItems > 9) {
          items.remove(0);
          feed.setEntries(items);
        }

        SyndEntry newItem = new SyndEntryImpl();
        newItem.setTitle(title);
        newItem.setLink(link);
        newItem.setUri(link);
        SyndContent desc = new SyndContentImpl();
        desc.setType("text/html");
        desc.setValue(description);
        newItem.setDescription(desc);
        desc.setType("text/html");
        newItem.setPublishedDate(new java.util.Date());

        List<SyndCategory> categories = new ArrayList<SyndCategory>();
        if (CommonConfiguration.getProperty("htmlTitle", context) != null) {
          SyndCategory category2 = new SyndCategoryImpl();
          category2.setName(CommonConfiguration.getProperty("htmlTitle", context));
          categories.add(category2);
        }
        newItem.setCategories(categories);
        if (CommonConfiguration.getProperty("htmlAuthor", context) != null) {
          newItem.setAuthor(CommonConfiguration.getProperty("htmlAuthor", context));
        }
        items.add(newItem);
        feed.setEntries(items);

        feed.setPublishedDate(new java.util.Date());

        FileWriter writer = new FileWriter(atomFile);
        output.output(feed, writer);
        writer.toString();
      }
    } catch (IOException ioe) {
      System.out.println("ERROR: Could not find the ATOM file.");
      ioe.printStackTrace();
    } catch (Exception e) {
      System.out.println("Unknown exception trying to add an entry to the ATOM file.");
      e.printStackTrace();
    }
  }
示例#6
0
  // inform researchers that have logged an interest with the encounter or marked individual
  public static void informInterestedIndividualParties(
      HttpServletRequest request, String shark, String message, String context) {
    Shepherd myShepherd = new Shepherd(context);
    myShepherd.beginDBTransaction();

    if (myShepherd.isMarkedIndividual(shark)) {
      MarkedIndividual sharkie = myShepherd.getMarkedIndividual(shark);
      if (sharkie.getInterestedResearchers() != null) {
        Vector notifyMe = sharkie.getInterestedResearchers();
        int size = notifyMe.size();
        String[] interested = new String[size];
        for (int i = 0; i < size; i++) {
          interested[i] = (String) notifyMe.get(i);
        }
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
        if (size > 0) {

          ThreadPoolExecutor es = MailThreadExecutorService.getExecutorService();

          Vector e_images = new Vector();
          String mailMe = interested[0];
          String email =
              getText("dataUpdate.txt")
                  .replaceAll(
                      "INSERTTEXT",
                      ("Tag "
                          + shark
                          + ": "
                          + message
                          + "\n\nLink to individual: http://"
                          + CommonConfiguration.getURLLocation(request)
                          + "/individuals.jsp?number="
                          + shark));
          email +=
              ("\n\nWant to stop tracking this set of this individual's data? Use this link.\n\nhttp://"
                  + CommonConfiguration.getURLLocation(request)
                  + "/dontTrack?shark="
                  + shark
                  + "&email=");

          es.execute(
              new NotificationMailer(
                  CommonConfiguration.getMailHost(context),
                  CommonConfiguration.getAutoEmailAddress(context),
                  mailMe,
                  ("Marked individual data update: " + shark),
                  (email + mailMe),
                  e_images,
                  context));
          for (int j = 1; j < size; j++) {
            mailMe = interested[j];
            es.execute(
                new NotificationMailer(
                    CommonConfiguration.getMailHost(context),
                    CommonConfiguration.getAutoEmailAddress(context),
                    mailMe,
                    ("Individual data update: " + shark),
                    (email + mailMe),
                    e_images,
                    context));
          }
        }
      } else {
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
      }
    } else {
      myShepherd.rollbackDBTransaction();
      myShepherd.closeDBTransaction();
    }
  }
示例#7
0
  public static void informInterestedParties(
      HttpServletRequest request, String number, String message, String context) {
    // String context="context0";
    // context=ServletUtilities.getContext(request);
    Shepherd myShepherd = new Shepherd(context);
    myShepherd.beginDBTransaction();

    if (myShepherd.isEncounter(number)) {

      Encounter enc = myShepherd.getEncounter(number);
      if (enc.getInterestedResearchers() != null) {
        Vector notifyMe = enc.getInterestedResearchers();
        int size = notifyMe.size();
        String[] interested = new String[size];
        for (int i = 0; i < size; i++) {
          interested[i] = (String) notifyMe.get(i);
        }
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
        if (size > 0) {
          Vector e_images = new Vector();
          String mailMe = interested[0];
          String email =
              getText("dataUpdate.txt")
                  .replaceAll(
                      "INSERTTEXT",
                      ("Encounter "
                          + number
                          + ": "
                          + message
                          + "\n\nLink to encounter: http://"
                          + CommonConfiguration.getURLLocation(request)
                          + "/encounters/encounter.jsp?number="
                          + number));
          email +=
              ("\n\nWant to stop tracking this set of encounter data? Use this link.\nhttp://"
                  + CommonConfiguration.getURLLocation(request)
                  + "/dontTrack?number="
                  + number
                  + "&email=");
          ThreadPoolExecutor es = MailThreadExecutorService.getExecutorService();
          es.execute(
              new NotificationMailer(
                  CommonConfiguration.getMailHost(context),
                  CommonConfiguration.getAutoEmailAddress(context),
                  mailMe,
                  ("Encounter data update: " + number),
                  (email + mailMe),
                  e_images,
                  context));

          // NotificationMailer mailer=new NotificationMailer(CommonConfiguration.getMailHost(),
          // CommonConfiguration.getAutoEmailAddress(), mailMe, ("Encounter data update: "+number),
          // (email+mailMe), e_images);
          for (int j = 1; j < size; j++) {
            mailMe = interested[j];
            es.execute(
                new NotificationMailer(
                    CommonConfiguration.getMailHost(context),
                    CommonConfiguration.getAutoEmailAddress(context),
                    mailMe,
                    ("Encounter data update: " + number),
                    (email + mailMe),
                    e_images,
                    context));
          }
        }
      } else {
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
      }

    } else {
      myShepherd.rollbackDBTransaction();
      myShepherd.closeDBTransaction();
    }
  }