예제 #1
0
  public static String getDbConfig(String field) {
    String value = "";
    try {
      File directory = new File(".");
      String path = directory.getCanonicalPath();
      String s = File.separator;
      FileInputStream fstream =
          new FileInputStream(path + s + "src" + s + "config" + s + "dbconfig.cfg");

      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;

      while ((strLine = br.readLine()) != null) {
        if (strLine.indexOf("password") >= 0 && field.equals("password") == true) {
          value = strLine.substring(strLine.indexOf('\t') + 1);
          break;
        }

        if (strLine.indexOf("username") >= 0 && field.equals("username") == true) {
          value = strLine.substring(strLine.indexOf('\t') + 1);
        }
      }

    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, e);
    }

    return value;
  }
예제 #2
0
 public static void setIconImage(JFrame jf) {
   File directory = new File(".");
   try {
     String path = directory.getCanonicalPath();
     String s = File.separator;
     jf.setIconImage(
         Toolkit.getDefaultToolkit().getImage(path + s + "src" + s + "images" + s + "logo.gif"));
   } catch (Exception e) {
     JOptionPane.showMessageDialog(null, "Unexpected Error. Exiting application");
   }
 }
예제 #3
0
  // Logs a new entry in the library RSS file
  public static synchronized void addRSSEntry(
      String title, String link, String description, File rssFile) {
    // File rssFile=new File("nofile.xml");

    try {
      System.out.println("Looking for RSS file: " + rssFile.getCanonicalPath());
      if (rssFile.exists()) {

        SAXReader reader = new SAXReader();
        Document document = reader.read(rssFile);
        Element root = document.getRootElement();
        Element channel = root.element("channel");
        List items = channel.elements("item");
        int numItems = items.size();
        items = null;
        if (numItems > 9) {
          Element removeThisItem = channel.element("item");
          channel.remove(removeThisItem);
        }

        Element newItem = channel.addElement("item");
        Element newTitle = newItem.addElement("title");
        Element newLink = newItem.addElement("link");
        Element newDescription = newItem.addElement("description");
        newTitle.setText(title);
        newDescription.setText(description);
        newLink.setText(link);

        Element pubDate = channel.element("pubDate");
        pubDate.setText((new java.util.Date()).toString());

        // now save changes
        FileWriter mywriter = new FileWriter(rssFile);
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setLineSeparator(System.getProperty("line.separator"));
        XMLWriter writer = new XMLWriter(mywriter, format);
        writer.write(document);
        writer.close();
      }
    } catch (IOException ioe) {
      System.out.println("ERROR: Could not find the RSS file.");
      ioe.printStackTrace();
    } catch (DocumentException de) {
      System.out.println("ERROR: Could not read the RSS file.");
      de.printStackTrace();
    } catch (Exception e) {
      System.out.println("Unknown exception trying to add an entry to the RSS file.");
      e.printStackTrace();
    }
  }