Package org.jdom.output

Examples of org.jdom.output.XMLOutputter


        }

        // create XML outputter with indent: 2 spaces, print new lines.
        Format format = Format.getPrettyFormat();
        format.setEncoding(encoding);
        XMLOutputter outputter = new XMLOutputter(format);
       
        Namespace dcNs = Namespace.getNamespace("dc", NS_DC);
        Namespace syNs = Namespace.getNamespace("sy", NS_SY);
        Namespace adminNs = Namespace.getNamespace("admin", NS_ADMIN);
        //Namespace rdfNs = Namespace.getNamespace("rdf", NS_RDF);

        Element rootElem = new Element("rss");
        rootElem.addNamespaceDeclaration(dcNs);
        rootElem.addNamespaceDeclaration(syNs);
        rootElem.addNamespaceDeclaration(adminNs);
        rootElem.setAttribute("version", RSS_VERSION);

        Element channelElem = new Element("channel");
        // rootElem.setAttribute("version");
        channelElem.addContent(new Element("title").setText(channel.getTitle()));
        if (channel.getSite() != null) {
            channelElem.addContent(new Element("link").setText(channel.getSite()
                    .toString()));
        }

        channelElem.addContent(new Element("description").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.getPubDate() != null) {
            channelElem.addContent(new Element("pubDate").setText(ParserUtils
                    .formatDate(channel.getPubDate())));
        }
        if (channel.getCategories() != null) {
            Collection categories = channel.getCategories();
            Iterator catIt = categories.iterator();
            while (catIt.hasNext()) {
                CategoryIF cat = (CategoryIF) catIt.next();
                channelElem = getCategoryElements(channelElem, cat, null);
            }
        }

        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");
          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());
        //     }
       
        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.getCategories() != null) {
                Collection categories = item.getCategories();
                Iterator catIt = categories.iterator();
                while (catIt.hasNext()) {
                    CategoryIF cat = (CategoryIF) catIt.next();
                    itemElem = getCategoryElements(itemElem, cat, null);
                }
            }
            if (item.getDate() != null) {
                itemElem.addContent(new Element("pubDate").setText(ParserUtils
                        .formatDate(item.getDate())));
            }
            if (item.getGuid() != null) {
                Element guid = new Element("guid").setText(item.getGuid().getLocation());
                guid.setAttribute("isPermaLink", Boolean.toString(item.getGuid().isPermaLink()));
                itemElem.addContent(guid);
            }
            if (item.getComments() != null) {
                itemElem.addContent(new Element("comments").setText(item.getComments()
                        .toString()));
            }
            channelElem.addContent(itemElem);
        }

        rootElem.addContent(channelElem);

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


      r.setApplicationShortcut(app, null);
      r.setSession(sessionInfo);
      p.setAttribute("value", r.replace(value));
    }

    XMLOutputter output = new XMLOutputter();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    output.output(element, out);

    String xml = new String(out.toByteArray());

    params = element.getChildren("parameter");
View Full Code Here

  }

  protected void sendDocument(Document doc,
                              HttpServletResponse response) throws IOException {
    response.setHeader("Content-type", "text/xml");
    XMLOutputter o = new XMLOutputter();
    o.output(doc, response.getOutputStream());
    response.getOutputStream().close();

  }
View Full Code Here

        }
      }
      p.setAttribute("value", replacer.replace(value));
    }

    XMLOutputter output = new XMLOutputter();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    output.output(element, out);
    String xml = new String(out.toByteArray());

    params = element.getChildren("parameter");

    Map<String, String> parameters = new HashMap<String, String>();
View Full Code Here

  public static String noteAsStr(Element element) {
    if(element == null) {
      return "";
    }
    StringWriter stream = new StringWriter();
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    try {
      out.output(element.getContent(), stream);
      stream.close();
    } catch (Exception e) {
      try {
        new ErrorLog("error in " + sos.util.SOSClassUtil.getMethodName() , e);
      } catch(Exception ee) {
View Full Code Here

          setLiveXmlAttribute(element,ele);
      
           aktEle.addContent(ele);
       }
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat() );
    erg = output.outputString(root);
      return erg;
    }
View Full Code Here

      try {
        // ---- Read XML file ----
        SAXBuilder builder = new SAXBuilder();
        doc = builder.build( xmlFile );
      
        XMLOutputter fmt = new XMLOutputter();
        fmt.setFormat( Format.getPrettyFormat() )// only for nicer formatting
        // fmt.output( doc, System.out );
      } catch( Exception ex ) {
        ex.printStackTrace();
      }
View Full Code Here

        reorderDOM(getDoc().getRootElement(), getNamespace());

        StringWriter stream = new StringWriter();
        // FileOutputStream stream = new FileOutputStream(new File(filename));

        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        out.output(getDoc(), stream);
        stream.close();
        String s = stream.toString();

        try {
            s = s.replaceAll("<pre space=\"preserve\">","<pre>");
View Full Code Here

    }


    public String noteAsStr(Element element) {
        StringWriter stream = new StringWriter();
        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        try {
            out.output(element.getContent(), stream);
            stream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
       
View Full Code Here

        reorderDOM(getDoc().getRootElement(), getNamespace());

        StringWriter stream = new StringWriter();
        // FileOutputStream stream = new FileOutputStream(new File(filename));

        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        out.output(getDoc(), stream);
        stream.close();
        String s = stream.toString();

        try {
            s = s.replaceAll("<pre space=\"preserve\">","<pre>");
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.