/** * Builds a jdom document containing the error parameter. * * @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)); }
public static boolean equivalent(DocType d1, DocType d2) { boolean equals = d1.getPublicID().equals(d2.getPublicID()) && d1.getSystemID().equals(d2.getSystemID()); if (!equals && LOGGER.isDebugEnabled()) { LOGGER.debug("DocType differs \"{}\"!=\"{}\"", d1, d2); } return equals; }
public static boolean equivalentContent(List<Content> l1, List<Content> l2) { if (l1.size() != l2.size()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Number of content list elements differ {}!={}", l1.size(), l2.size()); } return false; } boolean result = true; Iterator<Content> i1 = l1.iterator(); Iterator<Content> i2 = l2.iterator(); while (result && i1.hasNext() && i2.hasNext()) { Object o1 = i1.next(); Object o2 = i2.next(); if (o1 instanceof Element && o2 instanceof Element) { result = equivalent((Element) o1, (Element) o2); } else if (o1 instanceof Text && o2 instanceof Text) { result = equivalent((Text) o1, (Text) o2); } else if (o1 instanceof Comment && o2 instanceof Comment) { result = equivalent((Comment) o1, (Comment) o2); } else if (o1 instanceof ProcessingInstruction && o2 instanceof ProcessingInstruction) { result = equivalent((ProcessingInstruction) o1, (ProcessingInstruction) o2); } else if (o1 instanceof DocType && o2 instanceof DocType) { result = equivalent((DocType) o1, (DocType) o2); } else { result = false; } } return result; }
protected Document createDocument(Element root) { Document doc = new Document(root); DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType); return doc; }
private static File createConfigFile(Element project, String configXmlPath) throws IOException { //Create xml final String dtd = "Configuration.dtd"; final String encoding = "ISO-8859-1"; final String elName = "project"; DocType docType = new DocType(elName, dtd); Document doc = new Document(project, docType); XMLUtil.writeXML(doc, configXmlPath, encoding); return new File(configXmlPath); }
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final String name = rssRoot.getName(); final Attribute version = rssRoot.getAttribute("version"); final DocType docType = document.getDocType(); return name.equals(ELEMENT_NAME) && version != null && version.getValue().equals(getRSSVersion()) && docType != null && ELEMENT_NAME.equals(docType.getElementName()) && PUBLIC_ID.equals(docType.getPublicID()) && SYSTEM_ID.equals(docType.getSystemID()); }
@Override protected Document createDocument(final Element root) { final Document doc = new Document(root); final DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID); doc.setDocType(docType); return doc; }
public MyCoReWebPageProvider() { this.xml = new Document(); this.xml.setDocType(new DocType(XML_MYCORE_WEBPAGE)); this.xml.setRootElement(new Element(XML_MYCORE_WEBPAGE)); }
public void write(ChannelIF channel) throws IOException { if (writer == null) { throw new RuntimeException("No writer has been initialized."); } // 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); }
public static Document write(List<Identifier> identifiers, String title, List<Author> authors, TableOfContents tableOfContents) throws IllegalArgumentException, IllegalStateException, IOException { /* <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"> <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1"> */ Document ncxDocument = new Document(); DocType docType = new DocType("ncx", "-//NISO//DTD ncx 2005-1//EN", "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"); ncxDocument.setDocType(docType); Element root = new Element(NCXTags.ncx, NAMESPACE_NCX); root.setAttribute(NCXAttributes.version, NCXAttributeValues.version); ncxDocument.setRootElement(root); // serializer.writeNamespace("ncx", NAMESPACE_NCX); // serializer.attribute("xmlns", NAMESPACE_NCX); Element headElement = new Element(NCXTags.head, NAMESPACE_NCX); root.addContent(headElement); for (Identifier identifier : identifiers) { writeMetaElement(identifier.getScheme(), identifier.getValue(), headElement); } writeMetaElement("generator", Constants.EPUBLIB_GENERATOR_NAME, headElement); writeMetaElement("depth", String.valueOf(tableOfContents.calculateDepth()), headElement); writeMetaElement("totalPageCount", "0", headElement); writeMetaElement("maxPageNumber", "0", headElement); Element docTitleElement = new Element(NCXTags.docTitle, NAMESPACE_NCX); root.addContent(docTitleElement); Element textElement = new Element(NCXTags.text, NAMESPACE_NCX); docTitleElement.addContent(textElement); // write the first title textElement.setText(StringUtils.defaultString(title)); Element navMapElement = new Element(NCXTags.navMap, NAMESPACE_NCX); writeNavPoints(tableOfContents.getTocReferences(), 1, navMapElement); root.addContent(navMapElement); return ncxDocument; }
public void writeXML() throws IOException { DocType docType = new DocType("result"); XMLUtil.writeXML(new Document(root, docType), xmlPath); }