Ejemplo n.º 1
0
  /**
   * @param handler content handler
   * @param pkgDto package info dto object
   * @throws SAXException
   */
  protected static void addPackageBoilerplate(SimpleContentHandler handler, PackageDto pkgDto)
      throws SAXException {
    long pkgId = pkgDto.getId().longValue();
    SimpleAttributesImpl attr = new SimpleAttributesImpl();
    attr.addAttribute("pkgid", sanitize(pkgId, pkgDto.getChecksum()));
    attr.addAttribute("name", sanitize(pkgId, pkgDto.getName()));
    attr.addAttribute("arch", sanitize(pkgId, pkgDto.getArchLabel()));
    handler.startElement("package", attr);

    attr.clear();
    attr.addAttribute("ver", sanitize(pkgId, pkgDto.getVersion()));
    attr.addAttribute("rel", sanitize(pkgId, pkgDto.getRelease()));
    attr.addAttribute("epoch", sanitize(pkgId, getPackageEpoch(pkgDto.getEpoch())));
    handler.startElement("version", attr);
    handler.endElement("version");
  }
Ejemplo n.º 2
0
  /**
   * Constructor takes in a writer
   *
   * @param writer content writer
   * @param shouldEscape says whether write output shall be escaped
   */
  public RepomdWriter(Writer writer, boolean shouldEscape) {

    OutputFormat of = new OutputFormat();
    of.setPreserveSpace(true);
    XMLSerializer serializer = null;

    if (shouldEscape) {
      // XMLSerializer used to escape chars like < >
      serializer = new XMLSerializer(writer, of);
    } else {
      // UnescapingXmlSerializer doesn't escape anything,
      // input shall already be escaped
      serializer = new UnescapingXmlSerializer(writer, of);
    }

    try {
      handler = new SimpleContentHandler(serializer.asContentHandler());
    } catch (IOException e) {
      // XXX fatal error
    }
    try {
      handler.startDocument();
    } catch (SAXException e) {
      // XXX fatal error
    }
  }