Examples of Factbook


Examples of factbookxml.converter.pda.schema.Factbook

  }

  public static void parseBack(File dir) throws Exception {
    ParsedIndex idx = parse(dir, "index.html", "index", "", ParsedIndex.class);
    String lastupdate = idx.getUpdate();
    Factbook factbook = obf.createFactbook();
    factbook.setLastupdate(toXMLDate(lastupdate));
    ParsedNews news = parse(dir, "news.html", "news", "", ParsedNews.class);
    for (ParsedNews.News n : news.getNews()) {
      Factbook.News nn = new Factbook.News();
      nn.setDate(parseDate(n.getDate()));
      nn.setValue(n.getValue());
      factbook.getNews().add(nn);
    }
    Map<String, String> countryids = new HashMap<String, String>();
    Map<String, String> countrynames = new HashMap<String, String>();
    Map<String, List<String>> countryAliases = new HashMap<String, List<String>>();
    ParsedCountries ctries = parse(dir, "countries.html", "countries", lastupdate, ParsedCountries.class);
    for (ParsedCountries.Country country : ctries.getCountry()) {
      countryids.put(country.getName(), country.getId());
      countrynames.put(country.getId(), country.getName());
      List<String> aliases = countryAliases.get(country.getId());
      if (aliases == null) {
        aliases = new ArrayList<String>();
        countryAliases.put(country.getId(), aliases);
      }
      aliases.add(country.getAlias() == null ? country.getName() : country.getAlias());
    }
    ParsedFields flds = parse(dir, "fields.html", "fields", lastupdate, ParsedFields.class);
    for (ParsedFields.Category cat : flds.getCategory()) {
      Factbook.Category category = obf.createFactbookCategory();
      category.setName(cat.getName());
      factbook.getCategory().add(category);
      category.setDescription(cat.getDescription());
      for (ParsedFields.Category.Field fld : cat.getField()) {
        Factbook.Category.Field field = obf.createFactbookCategoryField();
        String fldname = fld.getName();
        String fldid = fld.getId();
        field.setId(fldid);
        field.setName(fldname);
        ParsedFieldDescription flddesc = parse(dir, "fd-" + fldid + ".html", "fielddesc", lastupdate, ParsedFieldDescription.class);
        if (!flddesc.getName().equals(fldname) ||
            !flddesc.getId().equals(fldid))
          throw new RuntimeException(flddesc.getName() + "/" + flddesc.getId());
        field.setDescription(flddesc.getDescription());
        String unit = flddesc.getUnit();
        if (unit != null) {
          field.setUnit(unit);
        }
        if (flddesc.getRank() != null) {
          ParsedRankOrder ro = parse(dir, "ro-" + fldid + ".html", "rankorder", lastupdate, ParsedRankOrder.class);
          if (!ro.getName().equals(fldname) ||
              !ro.getId().equals(fld.getId()))
            throw new RuntimeException(ro.getId() + "//" + ro.getName());
          for (ParsedRankOrder.Rank r : ro.getRank()) {
            Factbook.Category.Field.Rank rank = obf.createFactbookCategoryFieldRank();
            rank.setCountry(countryids.get(r.getCountry()));
            if (r.getDateEarliest() != null)
              rank.setDateEarliest(XMLGregorianCalendarImpl.parse(r.getDateEarliest()));
            if (r.getDateLatest() != null)
              rank.setDateLatest(XMLGregorianCalendarImpl.parse(r.getDateLatest()));
            rank.setDateText(r.getDate());
            rank.setDateEstimated(r.isDateEstimated());
            String vl = r.getValue();
            if (vl.startsWith("$ ")) {
              vl = vl.substring(2);
              field.setDollars(true);
            }
            rank.setNumber(new BigDecimal(vl));
            field.getRank().add(rank);
          }
          field.setRankorder(ro.getReversed() != null ? -1 : 1);
        }
        category.getField().add(field);
      }
    }
    ParsedRegions regions = parse(dir, "regions.html", "regions", lastupdate, ParsedRegions.class);
    for (ParsedRegions.Region rgn : regions.getRegion())
    {
      Factbook.Region region = obf.createFactbookRegion();
      region.setId(rgn.getId());
      region.setShortId(rgn.getShortId());
      region.setName(rgn.getName());

      factbook.getRegion().add(region);

      for (String id : rgn.getCountry()) {
        String name = countrynames.get(id);

        Factbook.Region.Country country = obf.createFactbookRegionCountry();
        country.setId(id);
        country.setName(name);
        country.getAlias().addAll(countryAliases.get(id));
        ParsedCountry ctry = parse(dir, id + ".html", "country", lastupdate, ParsedCountry.class, "countryid", id, "country", name);
        if (ctry.getFlag() != null)
          country.setFlag(1);
        if (ctry.getAffiliation() != null)
          country.setAffiliation(ctry.getAffiliation());
        country.setLocator(ctry.getLocator());
        country.setAnthem(ctry.getAnthem());
        region.getCountry().add(country);
        country.setLastupdate(toXMLDate(ctry.getLastupdate()));
        country.setPhotocount(ctry.getPhotocount());
        List<FieldContentType> fields = new ArrayList<FieldContentType>();
        for (FieldContentType fld : ctry.getField()) {
          fields.add(fld);
        }
        Collections.sort(fields, new Comparator<FieldContentType>() {
          public int compare(FieldContentType o1, FieldContentType o2) {
            return o1.getRef().compareTo(o2.getRef());
          }
        });
        country.getField().addAll(fields);
      }
    }
    ParsedFaq faq = parse(dir, "faq.html", "faq", lastupdate, ParsedFaq.class);
    factbook.getFaqCategory().addAll(faq.getFaqCategory());
    ParsedDefinitions defs = parse(dir, "definitions.html", "defs", lastupdate, ParsedDefinitions.class);
    factbook.getDefinition().addAll(defs.getDefinition());
    for (char ltr = 'a'; ltr <= 'g'; ltr++) {
      ParsedAppendix appendix = parse(dir, "appendix-" + ltr + ".html", "appendix", lastupdate, ParsedAppendix.class);
      Factbook.Appendix a = obf.createFactbookAppendix();
      a.setLetter("" + ltr);
      a.setName(appendix.getName());
      a.setList(appendix.getList());
      a.getTable().addAll(appendix.getTable());
      factbook.getAppendix().add(a);
    }
    ;
    System.out.println("Writing out...");
    FileOutputStream fos = new FileOutputStream(new File(dir, "../factbook2.xml"));
    Marshaller m = ctx.createMarshaller();
View Full Code Here

Examples of factbookxml.converter.schema.Factbook

  private final Map<Integer, String> fieldIDs = new HashMap<Integer, String>();

  public SQLRoundtripParser(Connection conn, String version) {
    this.conn = conn;
    this.version = version;
    this.doc = new Factbook();
  }
View Full Code Here

Examples of factbookxml.converter.schema.Factbook

    long start = System.currentTimeMillis();
    JAXBContext ctx = JAXBContext.newInstance(factbookxml.converter.schema.ObjectFactory.class.getPackage().getName());
    marshaller = ctx.createMarshaller(); // no schema here!
    Unmarshaller u = ctx.createUnmarshaller();
    u.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(SQLBuilder.class.getResource("/factbook.xsd")));
    Factbook doc = (Factbook) u.unmarshal(new File(WORKPATH, "factbook.xml"));
    Properties props = new Properties();
    props.put("user", args[3]);
    props.put("password", args[4]);
    Connection conn = DriverManager.getConnection(args[2], props);
    SQLBuilder builder = new SQLBuilder(doc, conn);
    String version = builder.version;
    System.out.println("Version: " + version);
    builder.build();
    SQLRoundtripParser parser = new SQLRoundtripParser(conn, version);
    parser.parseBack(formatDate(doc.getLastupdate()));
    verify(Factbook.class, doc, parser.getFactbook());
    System.out.println("Finished: " + (System.currentTimeMillis() - start) + " ms.");
  }
View Full Code Here

Examples of factbookxml.converter.schema.Factbook

    WORKPATH=new File(args[1]);
    long start = System.currentTimeMillis();
    JAXBContext ctx = JAXBContext.newInstance(factbookxml.converter.schema.ObjectFactory.class.getPackage().getName());
    Unmarshaller u = ctx.createUnmarshaller();
    u.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(PDABuilder.class.getResource("/factbook.xsd")));
    Factbook doc = (Factbook) u.unmarshal(new File(WORKPATH, "factbook.xml"));
    new PDABuilder(doc, "ebook", "../graphics", false).build();
    buildMobi();
    new PDABuilder(doc, "offline", "../graphics", true).build();
    new PDABuilder(doc, "mobile", "https://www.cia.gov/library/publications/the-world-factbook/graphics", true).build();
    new PDABuilder(doc, null, "../graphics", false).build();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.