Exemplo n.º 1
0
  public static void main(String[] args) {
    BD bd = new BD();
    String lsTable = "pays";
    String lsContenu = "";
    lsContenu += "<?xml version='1.0' encoding='utf-8'?>\n";
    lsContenu += "<!-- " + lsTable + "Document.xml -->\n";
    lsContenu += "<" + lsTable + ">\n";

    String lsEnfant = lsTable.substring(0, lsTable.length() - 1);

    try {
      bd.seConnecter("cours", "root", "alonso");
      Connection lcn = bd.getConnexion();
      PreparedStatement lpst =
          lcn.prepareStatement("SELECT * FROM pays"); // paysSelect() ou villesSelect()
      ResultSet lrs = lpst.executeQuery();

      ResultSetMetaData lrsmd = lrs.getMetaData();

      int liCols = lrsmd.getColumnCount();

      while (lrs.next()) {
        lsContenu += "\t<" + lsEnfant + " ";

        for (int i = 1; i <= liCols; i++) {
          lsContenu += lrsmd.getColumnName(i) + "='" + lrs.getString(i) + "' ";
        }

        lsContenu += "/>\n";
      }

      lsContenu += "</" + lsTable + ">";

      System.out.println(lsContenu);

      FileWriter lfwFichier = new FileWriter(lsTable + ".xml"); // pays.csv ou villes.csv
      BufferedWriter lbwBuffer = new BufferedWriter(lfwFichier);
      lbwBuffer.write(lsContenu);
      lbwBuffer.close();
      lfwFichier.close();

      bd.seDeconnecter();

    } catch (Exception e) {
      System.out.println("Erreor : ");
    }
  }
Exemplo n.º 2
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();
    }
  }