List of usage examples for org.jdom2 Document Document
public Document(Element rootElement, DocType docType)
Document
, with the supplied Element
as the root element and the supplied DocType
declaration. From source file:de.nava.informa.exporters.RSS_0_91_Exporter.java
License:Open Source License
public void write(ChannelIF channel) throws IOException { if (writer == null) { throw new RuntimeException("No writer has been initialized."); }/* w w w . j a v a2 s .c om*/ // 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()) { channelElem.addContent(getItemElement((ItemIF) it.next())); } // 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); }
From source file:org.mycore.frontend.servlets.MCRErrorServlet.java
License:Open Source License
/** * Builds a jdom document containing the error parameter. * /*from ww w . j a va 2 s . com*/ * @param msg the message of the error * @param statusCode the http status code * @param requestURI the uri of the request * @param exceptionType type of the exception * @param source source of the error * @param ex exception which is occured * * @return jdom document containing all error parameter */ public static Document buildErrorPage(String msg, Integer statusCode, String requestURI, Class<? extends Throwable> exceptionType, String source, Throwable ex) { String rootname = MCRConfiguration.instance().getString("MCR.Frontend.ErrorPage", "mcr_error"); Element root = new Element(rootname); root.setAttribute("errorServlet", Boolean.TRUE.toString()); root.setAttribute("space", "preserve", Namespace.XML_NAMESPACE); if (msg != null) { root.setText(msg); } if (statusCode != null) { root.setAttribute("HttpError", statusCode.toString()); } if (requestURI != null) { root.setAttribute("requestURI", requestURI); } if (exceptionType != null) { root.setAttribute("exceptionType", exceptionType.getName()); } if (source != null) { root.setAttribute("source", source); } while (ex != null) { Element exception = new Element("exception"); exception.setAttribute("type", ex.getClass().getName()); Element trace = new Element("trace"); Element message = new Element("message"); trace.setText(MCRException.getStackTraceAsString(ex)); message.setText(ex.getMessage()); exception.addContent(message).addContent(trace); root.addContent(exception); ex = ex.getCause(); } return new Document(root, new DocType(rootname)); }
From source file:org.mycore.frontend.servlets.MCRServlet.java
License:Open Source License
/** * @deprecated use {@link HttpServletResponse#sendError(int, String)} instead or throw Exception *//*from w w w.j a v a2 s.c om*/ @Deprecated() protected void generateErrorPage(HttpServletRequest request, HttpServletResponse response, int error, String msg, Exception ex, boolean xmlstyle) throws IOException, TransformerException, SAXException { LOGGER.error( getClass().getName() + ": Error " + error + " occured. The following message was given: " + msg, ex); String rootname = "mcr_error"; String style = getProperty(request, "XSL.Style"); if (style == null || !style.equals("xml")) { style = "default"; } Element root = new Element(rootname); root.setAttribute("HttpError", Integer.toString(error)).setText(msg); Document errorDoc = new Document(root, new DocType(rootname)); while (ex != null) { Element exception = new Element("exception"); exception.setAttribute("type", ex.getClass().getName()); Element trace = new Element("trace"); Element message = new Element("message"); trace.setText(MCRException.getStackTraceAsString(ex)); message.setText(ex.getMessage()); exception.addContent(message).addContent(trace); root.addContent(exception); if (ex instanceof MCRException) { if (ex.getCause() instanceof Exception) { ex = (Exception) ex.getCause(); } } else { ex = null; } } request.setAttribute("XSL.Style", style); final String requestAttr = "MCRServlet.generateErrorPage"; if (!response.isCommitted() && request.getAttribute(requestAttr) == null) { response.setStatus(error); request.setAttribute(requestAttr, msg); LAYOUT_SERVICE.doLayout(request, response, new MCRJDOMContent(errorDoc)); return; } else { if (request.getAttribute(requestAttr) != null) { LOGGER.warn("Could not send error page. Generating error page failed. The original message:\n" + request.getAttribute(requestAttr)); } else { LOGGER.warn( "Could not send error page. Response allready commited. The following message was given:\n" + msg); } } }
From source file:org.olanto.myterm.export.ExportTBXFromDB.java
License:Open Source License
public static void doIt(JTextArea _logArea, String _outFileName, String _resourceName, boolean show) { resourceName = _resourceName;/*from w w w . jav a 2 s . c o m*/ outFileName = _outFileName; logArea = _logArea; // init("C:\\MYTERM\\prog\\CoreDBTerm\\src\\org\\olanto\\myterm\\export\\export.properties"); msg("File Generation TBX\n"); msg("TBX version: " + dtdName); msg("rootName: " + rootName); msg("exported file: " + outFileName + "\n"); initRoot(rootName); racine = getRacine(); DocType doctype = new DocType("TBXBasiccoreStructV02.dtd"); document = new Document(racine, doctype); resource = Queries.getResourceID(resourceName, TermEnum.AutoCreate.NO); JdomUtilities.msg("start exporting :"); racine.addContent(GenerateTBXHeader.setHeader(dtdName, rootName)); racine.addContent(GenerateEntries.getTermsFromDB()); if (show) showXML(document); saveXML(document, outFileName); msg("\n end of export"); }