Example #1
0
 public MBTrack(Element e) {
   try {
     number = Integer.parseInt(e.getChild("number", e.getNamespace()).getValue());
   } catch (Exception ex) {
   }
   ;
   try {
     position = Integer.parseInt(e.getChild("position", e.getNamespace()).getValue());
   } catch (Exception ex) {
   }
   ;
   try {
     title = e.getChild("title", e.getNamespace()).getValue();
   } catch (Exception ex) {
   }
   ;
   try {
     length = Integer.parseInt(e.getChild("length", e.getNamespace()).getValue());
   } catch (Exception ex) {
   }
   ;
   try {
     recording = new MBRecording(e.getChild("recording", e.getNamespace()));
   } catch (Exception ex) {
   }
   ;
 }
Example #2
0
  public void parseDoc(File file) throws Exception {
    adjustFile(file);
    start = -1;
    end = -1;
    prevValue = -1;
    ocrAl = new ArrayList<>(1000);
    outFileName =
        file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4) + "ngt.xml";
    builder = new SAXBuilder();
    doc = builder.build(file);
    root = doc.getRootElement();
    xmlns = root.getNamespace();
    xpath =
        XPathFactory.instance()
            .compile(
                "//ns:span[@class='ocr_word']",
                Filters.element(),
                null,
                Namespace.getNamespace("ns", "http://www.w3.org/1999/xhtml"));
    List<Element> elements = xpath.evaluate(root);
    for (Element element : elements) {
      parseOcrWord(element);
    }

    ocrAl.add("%%%");
    ocrAl.add("%%%");
    findAnchors();
    writeFragment(start, end);
  }
  private Content parseContent(Element e) {
    String value = null;
    String type = getAttributeValue(e, "type");
    type = (type != null) ? type : "text/plain";
    String mode = getAttributeValue(e, "mode");
    if (mode == null) {
      mode = Content.XML; // default to xml content
    }
    if (mode.equals(Content.ESCAPED)) {
      // do nothing XML Parser took care of this
      value = e.getText();
    } else if (mode.equals(Content.BASE64)) {
      value = Base64.decode(e.getText());
    } else if (mode.equals(Content.XML)) {
      XMLOutputter outputter = new XMLOutputter();
      List<org.jdom2.Content> eContent = e.getContent();
      Iterator<org.jdom2.Content> i = eContent.iterator();
      while (i.hasNext()) {
        org.jdom2.Content c = i.next();
        if (c instanceof Element) {
          Element eC = (Element) c;
          if (eC.getNamespace().equals(getAtomNamespace())) {
            ((Element) c).setNamespace(Namespace.NO_NAMESPACE);
          }
        }
      }
      value = outputter.outputString(eContent);
    }

    Content content = new Content();
    content.setType(type);
    content.setMode(mode);
    content.setValue(value);
    return content;
  }
Example #4
0
  public String formatAsXHTML(String xhtml) throws IOException, JDOMException {
    DocType doctype =
        new DocType(
            "html", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd");
    Namespace namespace = Namespace.getNamespace("http://www.w3.org/1999/xhtml");

    org.jdom2.Document document = XHTMLUtils.parseXHTMLDocument(xhtml);

    org.jdom2.Element root = document.getRootElement();
    root.setNamespace(namespace);
    root.addNamespaceDeclaration(namespace);
    IteratorIterable<org.jdom2.Element> elements = root.getDescendants(Filters.element());
    for (org.jdom2.Element element : elements) {
      if (element.getNamespace() == null) {
        element.setNamespace(Constants.NAMESPACE_XHTML);
      }
    }
    document.setDocType(doctype);

    XMLOutputter outputter = new XMLOutputter();
    Format xmlFormat = Format.getPrettyFormat();
    outputter.setFormat(xmlFormat);
    outputter.setXMLOutputProcessor(new XHTMLOutputProcessor());
    String result = outputter.outputString(document);
    return result;
  }
Example #5
0
 private String parseTextConstructToString(final Element e) {
   String value = null;
   String type = getAttributeValue(e, "type");
   if (type == null) {
     type = Content.TEXT;
   }
   if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) {
     // XHTML content needs special handling
     final XMLOutputter outputter = new XMLOutputter();
     final List<org.jdom2.Content> eContent = e.getContent();
     final Iterator<org.jdom2.Content> i = eContent.iterator();
     while (i.hasNext()) {
       final org.jdom2.Content c = i.next();
       if (c instanceof Element) {
         final Element eC = (Element) c;
         if (eC.getNamespace().equals(getAtomNamespace())) {
           ((Element) c).setNamespace(Namespace.NO_NAMESPACE);
         }
       }
     }
     value = outputter.outputString(eContent);
   } else {
     // Everything else comes in verbatim
     value = e.getText();
   }
   return value;
 }
Example #6
0
  /**
   * Gets maps that are not installed, but may be downloaded.
   *
   * @return set of all maps available for download
   */
  public static Set<AutoRefMap> getRemoteMaps() {
    // check the cache first, we might want to just use the cached value
    long time = ManagementFactory.getRuntimeMXBean().getUptime() - _cachedRemoteMapsTime;
    if (_cachedRemoteMaps != null && time < AutoRefMap.REMOTE_MAP_CACHE_LENGTH)
      return _cachedRemoteMaps;

    Set<AutoRefMap> maps = Sets.newHashSet();
    String repo = AutoRefMatch.getMapRepo();

    try {
      Map<String, String> params = Maps.newHashMap();
      params.put("prefix", "maps/");

      for (; ; ) {
        String url = String.format("%s?%s", repo, QueryUtil.prepareParams(params));
        Element listing = new SAXBuilder().build(new URL(url)).getRootElement();
        assert "ListBucketResult".equals(listing.getName()) : "Unexpected response";
        Namespace ns = listing.getNamespace();

        String lastkey = null;
        for (Element entry : listing.getChildren("Contents", ns)) {
          lastkey = entry.getChildTextTrim("Key", ns);
          if (!lastkey.endsWith(".zip")) continue;

          String[] keyparts = lastkey.split("/");
          String mapfile = keyparts[keyparts.length - 1];

          String mapslug = mapfile.substring(0, mapfile.length() - 4);
          String slugparts[] = mapslug.split("-v");

          if (slugparts.length < 2) {
            AutoReferee.log("Invalid map filename: " + mapfile, Level.WARNING);
            AutoReferee.log("Map files should be of the form \"MapName-vX.X.zip\"", Level.WARNING);
          } else {
            String etag = entry.getChildTextTrim("ETag", ns);
            maps.add(
                new AutoRefMap(
                    slugparts[0], slugparts[1], lastkey, etag.substring(1, etag.length() - 1)));
          }
        }

        // stop looping if the result says that it hasn't been truncated (no more results)
        if (!Boolean.parseBoolean(listing.getChildText("IsTruncated", ns))) break;

        // use the last key as a marker for the next pass
        if (lastkey != null) params.put("marker", lastkey);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } catch (JDOMException e) {
      e.printStackTrace();
    }

    _cachedRemoteMapsTime = ManagementFactory.getRuntimeMXBean().getUptime();
    return _cachedRemoteMaps = maps;
  }
Example #7
0
 /**
  * @param controller Receives the lines when the are parsed
  * @param PATH Path to the XML-file of the play
  */
 public XMLParser(DBCInterface controller, final String PATH) {
   this.controller = controller;
   try {
     doc = new SAXBuilder().build(PATH);
     root = doc.getRootElement();
     ns = root.getNamespace();
     body = root.getChild("text", ns).getChild("body", ns);
   } catch (IOException | JDOMException e) {
     e.printStackTrace();
   }
   acts = new ArrayList<Element>(body.getChildren("div1", ns));
 }
  /**
   * tds radar dataset collection factory
   *
   * @param desc _more_
   * @param dsc_location _more_
   * @param errlog _more_
   * @return dataset collection
   * @throws IOException _more_
   */
  public static TDSRadarDatasetCollection factory(
      String desc, String dsc_location, StringBuffer errlog) throws IOException {
    // super();
    SAXBuilder builder;
    Document doc = null;
    XMLEntityResolver jaxp = new XMLEntityResolver(true);
    builder = jaxp.getSAXBuilder();

    try {
      doc = builder.build(dsc_location);
    } catch (JDOMException e) {
      errlog.append(e.toString());
    }

    Element qcElem = doc.getRootElement();
    Namespace ns = qcElem.getNamespace();

    return new TDSRadarDatasetCollection(desc, dsc_location, qcElem, ns, errlog);
  }
Example #9
0
  public Element save(Element parent) {
    Element e = super.save(parent);
    // e.setName("DeliverReq");

    if (sender != null) {
      Element sa = new Element("Sender", e.getNamespace());
      e.addContent(sa);

      /*
      if (sender.getAddressType() != null) {
      	sa.addContent(sender.save(sa));
      } else {
      	sa.addContent(sender.getAddress());
      }
      */

      sa.addContent(sender.getAddress());
    }

    if (linkedId != null) {
      e.addContent(new Element("LinkedID", e.getNamespace()).setText(linkedId));
    }
    if (senderSPI != null) {
      e.addContent(new Element("SenderSPI", e.getNamespace()).setText(senderSPI));
    }
    if (recipientSPI != null) {
      e.addContent(new Element("RecipientSPI", e.getNamespace()).setText(recipientSPI));
    }
    if (replyChargingId != null) {
      e.addContent(new Element("ReplyChargingID", e.getNamespace()).setText(replyChargingId));
    }
    if (Subject != null) {
      e.addContent(new Element("Subject", e.getNamespace()).setText(Subject));
    }
    if (applicId != null) {
      e.addContent(new Element("ApplicID", e.getNamespace()).setText(applicId));
    }
    if (replyApplicId != null) {
      e.addContent(new Element("ReplyApplicID", e.getNamespace()).setText(replyApplicId));
    }
    if (auxApplicInfo != null) {
      e.addContent(new Element("AuxApplicInfo", e.getNamespace()).setText(auxApplicInfo));
    }
    if (priority != null) {
      e.addContent(new Element("Priority", e.getNamespace()).setText(priority.toString()));
    }
    if (timeStamp != null) {
      e.addContent(
          new Element("TimeStamp", e.getNamespace())
              .setText(new RelativeDate(timeStamp).toString()));
    }
    if (content != null) {
      Element c = new Element("Content", e.getNamespace());
      c.setAttribute("href", "cid:mm7-content");
      e.addContent(c);
    }

    return e;
  }
 public boolean isMyType(Document document) {
   Element rssRoot = document.getRootElement();
   Namespace defaultNS = rssRoot.getNamespace();
   return (defaultNS != null) && defaultNS.equals(getAtomNamespace());
 }
Example #11
0
 /**
  * Returns the Namespace corresponding to an element and a prefix.
  *
  * @param element the element.
  * @param prefix the prefix.
  * @return the Namespace.
  */
 private static Namespace getNamespace(final Element element, final String prefix) {
   Namespace namespace =
       (prefix == null) ? element.getNamespace("") : element.getNamespace(prefix);
   return (namespace == null) ? Namespace.NO_NAMESPACE : namespace;
 }
Example #12
0
 @Override
 public boolean isMyType(final Document document) {
   final Element rssRoot = document.getRootElement();
   final Namespace defaultNS = rssRoot.getNamespace();
   return defaultNS != null && defaultNS.equals(getAtomNamespace());
 }