Package factbookxml.converter.schema

Examples of factbookxml.converter.schema.ObjectFactory


    return parseHypertextType(html, null);
  }

  public static HypertextType parseHypertextType(String htmlOrig, ParsePosition pp) {
    String html = htmlOrig;
    ObjectFactory of = new ObjectFactory();
    HypertextType result = of.createHypertextType();
    int pos = html.indexOf('<');
    while (pos != -1) {
      if (pos != 0)
        result.getContent().add(parseHTML(html.substring(0, pos)));
      html = html.substring(pos);
      if (html.startsWith("<i>") || html.startsWith("<b>")) {
        ParsePosition ppp = new ParsePosition(0);
        HypertextType inner = parseHypertextType(html.substring(3), ppp);
        if (!html.substring(ppp.getIndex() + 3, ppp.getIndex() + 7).equals("</" + html.substring(1, 3)))
          throw new RuntimeException("Start " + html.substring(0, 3) + " was closed by " + html.substring(ppp.getIndex() + 3, ppp.getIndex() + 7));
        if (html.startsWith("<b>")) {
          result.getContent().add(of.createHypertextTypeBold(inner));
        } else {
          result.getContent().add(of.createHypertextTypeItalic(inner));
        }
        html = html.substring(ppp.getIndex() + 7);
      } else if (html.startsWith("<br />")) {
        result.getContent().add(of.createHypertextTypeNewLine(new EmptyType()));
        html = html.substring(6);
      } else if (html.startsWith("</") && pp != null) {
        pp.setIndex(htmlOrig.length() - html.length());
        return result;
      } else {
View Full Code Here


  private static String parseHTML(String html) {
    return html.replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("&amp;", "&");
  }

  public static FieldContentType parseFieldContentType(String ref, String html) {
    ObjectFactory of = new ObjectFactory();
    FieldContentType result = new FieldContentType();
    result.setRef(ref);
    int pos = html.indexOf('<');
    while (pos != -1) {
      if (pos != 0)
        result.getContent().add(parseHTML(html.substring(0, pos)));
      html = html.substring(pos);
      if (html.startsWith("<br /><")) {
        html = html.substring(6);
      } else if (html.startsWith("<br />")) {
        result.getContent().add(of.createFieldContentTypeUnnamedsubfield(of.createEmptyType()));
        html = html.substring(6);
      } else if (html.startsWith("<i><b>")) {
        pos = html.indexOf("</b> </i>");
        FieldContentType.Subfield sf = of.createFieldContentTypeSubfield();
        sf.setEmph((short) 1);
        sf.setName(parseHTML(html.substring(6, pos)));
        result.getContent().add(of.createFieldContentTypeSubfield(sf));
        html = html.substring(pos + 9);
      } else if (html.startsWith("<i>")) {
        pos = html.indexOf(" </i>");
        FieldContentType.Subfield sf = of.createFieldContentTypeSubfield();
        sf.setName(parseHTML(html.substring(3, pos)));
        result.getContent().add(of.createFieldContentTypeSubfield(sf));
        html = html.substring(pos + 5);
      } else if (html.startsWith("<a href=\"https://www.cia.gov/library/publications/the-world-factbook/graphics/ref_maps/")) {
        html = html.substring("<a href=\"https://www.cia.gov/library/publications/the-world-factbook/graphics/ref_maps/".length());
        FieldContentType.Refmap refmap = of.createFieldContentTypeRefmap();
        pos = html.indexOf("\">");
        String file = html.substring(0, pos);
        if (file.startsWith("pdf/")) {
          file = file.substring(4);
        } else {
          file =":"+file.replace("/pdf/", "/");
        }
        refmap.setFile(file);
        html = html.substring(pos + 2);
        pos = html.indexOf("</a>");
        refmap.setName(parseHTML(html.substring(0, pos)));
        html = html.substring(pos + 4);
        result.getContent().add(of.createFieldContentTypeRefmap(refmap));
      } else {
        throw new RuntimeException("Unparsable: " + html);
      }
      pos = html.indexOf('<');
    }
View Full Code Here

      result.getContent().add(parseHTML(html));
    return result;
  }

  public static DefinitionType parseDefinitionType(String name, String html) {
    ObjectFactory of = new ObjectFactory();
    DefinitionType result = new DefinitionType();
    result.setName(name);
    int pos = html.indexOf('<');
    while (pos != -1) {
      if (pos != 0)
        result.getContent().add(parseHTML(html.substring(0, pos)));
      html = html.substring(pos);
      if (html.startsWith("<i>") || html.startsWith("<b>")) {
        ParsePosition pp = new ParsePosition(0);
        HypertextType inner = parseHypertextType(html.substring(3), pp);
        if (!html.substring(pp.getIndex() + 3, pp.getIndex() + 7).equals("</" + html.substring(1, 3)))
          throw new RuntimeException("Start " + html.substring(0, 3) + " was closed by " + html.substring(pp.getIndex() + 3, pp.getIndex() + 7));
        if (html.startsWith("<b>")) {
          result.getContent().add(of.createDefinitionTypeBold(inner));
        } else {
          result.getContent().add(of.createDefinitionTypeItalic(inner));
        }
        html = html.substring(pp.getIndex() + 7);
      } else if (html.startsWith("<br />")) {
        result.getContent().add(of.createDefinitionTypeNewLine(of.createEmptyType()));
        html = html.substring(6);
      } else if (html.startsWith("<a href=\"appendix-") && html.startsWith(".html\">", "<a href=\"appendix-".length() + 1)) {
        html = html.substring("<a href=\"appendix-".length());
        DefinitionType.AppendixReference app = of.createDefinitionTypeAppendixReference();
        app.setLetter(html.substring(0, 1));
        html = html.substring(".html\">".length() + 1);
        pos = html.indexOf("</a>");
        app.setTitle(parseHTML(html.substring(0, pos)));
        html = html.substring(pos + 4);
        result.getContent().add(of.createDefinitionTypeAppendixReference(app));
      } else {
        throw new RuntimeException("Unparsable: " + html);
      }
      pos = html.indexOf('<');
    }
View Full Code Here

      result.getContent().add(parseHTML(html));
    return result;
  }

  public static AppendixList.Entry.Value parseAppendixListEntryValue(String html) {
    ObjectFactory of = new ObjectFactory();
    AppendixList.Entry.Value result = new AppendixList.Entry.Value();
    int pos = html.indexOf('<');
    while (pos != -1) {
      if (pos != 0)
        result.getContent().add(parseHTML(html.substring(0, pos)));
      html = html.substring(pos);

      if (html.startsWith("<br /><i>")) {
        html = html.substring(6);
      } else if (html.startsWith("<br />")) {
        result.getContent().add(of.createAppendixListEntryValueUnnamedsubfield(of.createEmptyType()));
        html = html.substring(6);
      } else if (html.startsWith("<i>")) {
        pos = html.indexOf("</i>");
        AppendixList.Entry.Value.Subfield sf = of.createAppendixListEntryValueSubfield();
        sf.setName(parseHTML(html.substring(3, pos)));
        result.getContent().add(of.createAppendixListEntryValueSubfield(sf));
        html = html.substring(pos + 4);
      } else {
        throw new RuntimeException("Unparsable: " + html);
      }
      pos = html.indexOf('<');
View Full Code Here

TOP

Related Classes of factbookxml.converter.schema.ObjectFactory

Copyright © 2018 www.massapicom. 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.