Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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();
    }
  }