Package org.jdom.output

Examples of org.jdom.output.XMLOutputter


  public void write(Writer writer) throws IOException
  {
    // build document from registry data structures
    Document document = buildDocument();
   
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.setFormat(Format.getPrettyFormat());

    xmlOutputter.output(document, writer);
  }
View Full Code Here


        Element contentChild = (Element) iter.next();
        String name = contentChild.getName();

        /* Expected DIV Child */
        if ("div".equals(name)) { //$NON-NLS-1$
          XMLOutputter out = new XMLOutputter();
          StringWriter writer = new StringWriter();

          try {
            out.output(contentChild.getContent(), writer);
            writer.close();
          } catch (IOException e) {
            /* This should not happen */
          }

View Full Code Here

            }
            if (isValid == false) {
              String errorMsg = outDoc.getRootElement().getName() +
                " document is not valid after TransRoute modifications.  Can't forward message.";
              logger.fatal(errorMsg);
              XMLOutputter xmlOut = new XMLOutputter();
              logger.fatal("Document content is: \n" + xmlOut.outputString(outDoc));

              ArrayList errors = new ArrayList();
              errors.add(buildError("system", "OpenEAI_ROUTER-2007", errorMsg));
              publishSyncError(eControlArea, errors);
              continue;
View Full Code Here

                applicationsElement.addContent(applicationElement);
            }

            doc.setRootElement(rootElement);
            /* write to the disc */
            XMLOutputter writer = new XMLOutputter();
            writer.output(doc, new FileOutputStream(ConfigConstants.DEFAULT_CONFIG_FILE_NAME));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

        Element contentChild = (Element) iter.next();
        String name = contentChild.getName();

        /* Expected DIV Child */
        if ("div".equals(name)) { //$NON-NLS-1$
          XMLOutputter out = new XMLOutputter();
          StringWriter writer = new StringWriter();

          try {
            out.output(contentChild.getContent(), writer);
            writer.close();
          } catch (IOException e) {
            /* This should not happen */
          }

View Full Code Here

   */
  public void write(Writer writer) throws IOException {
    // build document from registry data structures
    Document document = buildDocument();
   
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.setFormat(Format.getPrettyFormat());

    xmlOutputter.output(document, writer);
  }
View Full Code Here

   * java.util.Collection, java.util.Set)
   */
  public void exportTo(File destination, Collection<? extends IFolderChild> elements, Set<Options> options) throws InterpreterException {
    Format format = Format.getPrettyFormat();
    format.setEncoding(UTF_8);
    XMLOutputter output = new XMLOutputter(format);
    DateFormat dateFormat = DateFormat.getDateInstance();

    Document document = new Document();
    Element root = new Element(Tag.OPML.get());
    root.setAttribute(Attributes.VERSION.get(), "1.1"); //$NON-NLS-1$
    root.addNamespaceDeclaration(RSSOWL_NS);
    document.setRootElement(root);

    /* Head */
    Element head = new Element(Tag.HEAD.get());
    root.addContent(head);

    Element title = new Element(Tag.TITLE.get());
    title.setText(Messages.OPMLExporter_RSSOWL_SUBSCRIPTIONS);
    head.addContent(title);

    Element dateModified = new Element(Tag.DATE_MODIFIED.get());
    dateModified.setText(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z").format(new Date())); //$NON-NLS-1$
    head.addContent(dateModified);

    /* Body */
    Element body = new Element(Tag.BODY.get());
    root.addContent(body);

    boolean exportPreferences = (options != null && options.contains(Options.EXPORT_PREFERENCES));

    /* Export Folder Childs */
    if (elements != null && !elements.isEmpty()) {
      Map<IFolder, Element> mapFolderToElement = new HashMap<IFolder, Element>();
      mapFolderToElement.put(null, body);

      /* Ensure that all Parent Elements exist */
      repairHierarchy(mapFolderToElement, elements, exportPreferences);

      /* Now export Elements */
      exportFolderChilds(mapFolderToElement, elements, exportPreferences, dateFormat);
    }

    /* Export Labels */
    if (options != null && options.contains(Options.EXPORT_LABELS))
      exportLabels(body);

    /* Export Filters */
    if (options != null && options.contains(Options.EXPORT_FILTERS))
      exportFilters(body, dateFormat);

    /* Export Preferences */
    if (exportPreferences)
      exportPreferences(body);

    /* Write to File */
    FileOutputStream out = null;
    try {
      out = new FileOutputStream(destination);
      output.output(document, out);
      out.close();
    } catch (FileNotFoundException e) {
      throw new InterpreterException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
    } catch (IOException e) {
      throw new InterpreterException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
View Full Code Here

                }
                rootElement.addContent(userElement);
            }
            doc.setRootElement(rootElement);
            /* write to the disc */
            XMLOutputter writer = new XMLOutputter();
            writer.output(doc, new FileOutputStream(AuthConstants.USER_CONFIG_FILE_NAME));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

    }

    // create XML outputter with indent: 2 spaces, print new lines.
    Format format = Format.getPrettyFormat();
    format.setEncoding(encoding);
    XMLOutputter outputter = new XMLOutputter(format);
   
    // ----
    Element rootElem = new Element("rss");
    rootElem.setAttribute("version", RSS_VERSION);
    Element channelElem = new Element("channel");
           
    channelElem.addContent(new Element("title").setText(channel.getTitle()));
   
    channelElem.addContent(new Element("description")
                           .setText(channel.getDescription()));
    if (channel.getSite() != null) {
      channelElem.addContent(new Element("link")
                             .setText(channel.getSite().toString()));
    }
    if (channel.getLanguage() != null) {
      channelElem.addContent(new Element("language")
                             .setText(channel.getLanguage()));
    }

    Collection items = channel.getItems();
    Iterator it = items.iterator();
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      Element itemElem = new Element("item");
      itemElem.addContent(new Element("title").setText(item.getTitle()));
      if (item.getLink() != null) {
        itemElem.addContent(new Element("link")
                            .setText(item.getLink().toString()));
      }
      if (item.getDescription() != null) {
        itemElem.addContent(new Element("description")
                            .setText(item.getDescription()));
      }
      if (item.getDate() != null) {
        itemElem.addContent(new Element("pubDate")
                            .setText(ParserUtils.formatDate(item.getDate())));
      }
      channelElem.addContent(itemElem);
    }

    // export channel image           
    if (channel.getImage() != null) {
      Element imgElem = new Element("image");
      imgElem.addContent(new Element("title")
                         .setText(channel.getImage().getTitle()));
      imgElem.addContent(new Element("url")
                         .setText(channel.getImage().getLocation().toString()));
      imgElem.addContent(new Element("link")
                         .setText(channel.getImage().getLink().toString()));
      imgElem.addContent(new Element("height")
                         .setText("" + channel.getImage().getHeight()));
      imgElem.addContent(new Element("width")
                         .setText("" + channel.getImage().getWidth()));
      imgElem.addContent(new Element("description")
                         .setText(channel.getImage().getDescription()));
      channelElem.addContent(imgElem);
    }
    
    // TODO: add exporting textinput field
    //     if (channel.getTextInput() != null) {
    //       channelElem.addContent(channel.getTextInput().getElement());
    //     }

    if (channel.getCopyright() != null) {
      channelElem.addContent(new Element("copyright")
                             .setText(channel.getCopyright()));
    }

    // we have all together for the channel definition
    rootElem.addContent(channelElem);
    // ---
    DocType docType = new DocType("rss", PUBLIC_ID, SYSTEM_ID);
    Document doc = new Document(rootElem, docType);
    outputter.output(doc, writer);
  }
View Full Code Here

    }

    // create XML outputter with indent: 2 spaces, print new lines.
    Format format = Format.getPrettyFormat();
    format.setEncoding(encoding);
    XMLOutputter outputter = new XMLOutputter(format);

    Namespace defNs = Namespace.getNamespace(NS_DEFAULT);
    Namespace rdfNs = Namespace.getNamespace("rdf", NS_RDF);
    Namespace dcNs = Namespace.getNamespace("dc", NS_DC);
    Namespace syNs = Namespace.getNamespace("sy", NS_SY);
   
    // ----
    Element rootElem = new Element("RDF", rdfNs);
    rootElem.addNamespaceDeclaration(defNs);
    rootElem.addNamespaceDeclaration(dcNs);
    rootElem.addNamespaceDeclaration(syNs);
    // rootElem.setAttribute("version");
    Element channelElem = new Element("channel", defNs);
    if (channel.getLocation() != null) {
      channelElem.setAttribute("about",
                               channel.getLocation().toString(), rdfNs);
    }
    channelElem.addContent(new Element("title", defNs)
                           .setText(channel.getTitle()));
    if (channel.getSite() != null) {
      channelElem.addContent(new Element("link", defNs)
                             .setText(channel.getSite().toString()));
      channelElem.addContent(new Element("source", dcNs)
                             .setAttribute("resource",
                                           channel.getSite().toString()));
    }

    channelElem.addContent(new Element("description", defNs)
                           .setText(channel.getDescription()));
    if (channel.getLanguage() != null) {
      channelElem.addContent(new Element("language", dcNs)
                             .setText(channel.getLanguage()));
    }
    if (channel.getCopyright() != null) {
      channelElem.addContent(new Element("copyright", dcNs)
                             .setText(channel.getCopyright()));
    }
    if (channel.getUpdateBase() != null) {
      channelElem.addContent(new Element("updateBase", syNs)
                             .setText(df.format(channel.getUpdateBase())));
    }
    if (channel.getUpdatePeriod() != null) {
      // don't put out frequency without specifying period
      channelElem.addContent(new Element("updateFrequency", syNs)
                             .setText((new Integer(channel.getUpdateFrequency())).toString()));
      channelElem.addContent(new Element("updatePeriod", syNs)
                             .setText(channel.getUpdatePeriod().toString()));
    }
    // export channel image           
    if (channel.getImage() != null) {
      Element imgElem = new Element("image", defNs);
      imgElem.addContent(new Element("title", defNs)
                         .setText(channel.getImage().getTitle()));
      imgElem.addContent(new Element("url", defNs)
                         .setText(channel.getImage().getLocation().toString()));
      imgElem.addContent(new Element("link", defNs)
                         .setText(channel.getImage().getLink().toString()));
      imgElem.addContent(new Element("height", defNs)
                         .setText("" + channel.getImage().getHeight()));
      imgElem.addContent(new Element("width", defNs)
                         .setText("" + channel.getImage().getWidth()));
      imgElem.addContent(new Element("description", defNs)
                         .setText(channel.getImage().getDescription()));
      channelElem.addContent(imgElem);
    }
    
    // TODO: add exporting textinput field
    //     if (channel.getTextInput() != null) {
    //       channelElem.addContent(channel.getTextInput().getElement());
    //     }

    // ===========================================
    Element itemsElem = new Element("items", defNs);
    Element seqElem = new Element("Seq", rdfNs);
    Collection items = channel.getItems();
    Iterator it = items.iterator();
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      Element itemElem = new Element("li", rdfNs);
      if (item.getLink() != null) {
        itemElem.setAttribute("resource", item.getLink().toString());
      }
      seqElem.addContent(itemElem);
    }
    itemsElem.addContent(seqElem);
    channelElem.addContent(itemsElem);
    rootElem.addContent(channelElem);

    // item-by-item en detail
    items = channel.getItems();
    it = items.iterator();
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      Element itemElem = new Element("item", defNs);
      if (item.getLink() != null) {
        itemElem.setAttribute("about",
                              item.getLink().toString(), rdfNs);
      }
      itemElem.addContent(new Element("title", defNs).setText(item.getTitle()));
      if (item.getLink() != null) {
        itemElem.addContent(new Element("link", defNs)
                            .setText(item.getLink().toString()));
      }
      if (item.getDescription() != null) {
        itemElem.addContent(new Element("description", dcNs)
                            .setText(item.getDescription()));
      }
      if (item.getDate() != null) {
        itemElem.addContent(new Element("date", dcNs)
                            .setText(ParserUtils.formatDate(item.getDate())));
      }
                         
      rootElem.addContent(itemElem);
    }

    // ---
    Document doc = new Document(rootElem);
    outputter.output(doc, writer);
    // ---
    writer.close();
  }
View Full Code Here

TOP

Related Classes of org.jdom.output.XMLOutputter

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.