List of usage examples for org.jdom2 Namespace XML_NAMESPACE
Namespace XML_NAMESPACE
To view the source code for org.jdom2 Namespace XML_NAMESPACE.
Click Source Link
Namespace
for the standard xml prefix. From source file:org.mycore.datamodel.language.MCRLanguageXML.java
License:Open Source License
/** * Returns the language of the given XML element, by inspecting the xml:lang or lang attribute. * If neither exists, the default language is returned. */// w w w. j a va 2s.c o m public static MCRLanguage getLanguage(Element element) { String code = element.getAttributeValue("lang", Namespace.XML_NAMESPACE); if ((code == null) || code.isEmpty()) code = element.getAttributeValue("lang"); if ((code == null) || code.isEmpty()) return MCRLanguageFactory.instance().getDefaultLanguage(); else return MCRLanguageFactory.instance().getLanguage(code); }
From source file:org.mycore.datamodel.metadata.MCRMetaDefault.java
License:Open Source License
/** * This method read the XML input stream part from a DOM part for the * metadata of the document./* w ww . j a va2 s.c o m*/ * * @param element * a relevant DOM element for the metadata * @exception MCRException * if the set_subtag value is null or empty */ public void setFromDOM(org.jdom2.Element element) throws MCRException { if (element == null) { return; } String temp_subtag = element.getName(); if (temp_subtag == null || (temp_subtag = temp_subtag.trim()).length() == 0) { throw new MCRException("The subtag is null or empty."); } subtag = temp_subtag; String temp_lang = element.getAttributeValue("lang", org.jdom2.Namespace.XML_NAMESPACE); if (temp_lang != null && (temp_lang = temp_lang.trim()).length() != 0) { lang = temp_lang; } String temp_type = element.getAttributeValue("type"); if (temp_type != null && (temp_type = temp_type.trim()).length() != 0) { type = temp_type; } String temp_herit = element.getAttributeValue("inherited"); if (temp_herit != null && (temp_herit = temp_herit.trim()).length() != 0) { try { inherited = Integer.parseInt(temp_herit); } catch (NumberFormatException e) { inherited = 0; } } }
From source file:org.mycore.datamodel.metadata.MCRMetaDefault.java
License:Open Source License
/** * This abstract method create a XML stream for all data in this class, * defined by the MyCoRe XML MCRMeta... definition for the given subtag. * /* w ww. j a v a 2s .c o m*/ * @exception MCRException * if the content of this class is not valid * @return a JDOM Element with the XML MCRMeta... part */ public Element createXML() throws MCRException { try { validate(); } catch (MCRException exc) { debug(); throw exc; } Element elm = new Element(subtag); if (getLang() != null && getLang().length() > 0) elm.setAttribute("lang", getLang(), Namespace.XML_NAMESPACE); if (getType() != null && getType().length() > 0) { elm.setAttribute("type", getType()); } elm.setAttribute("inherited", Integer.toString(getInherited())); return elm; }
From source file:org.mycore.datamodel.metadata.MCRMetaHistoryDate.java
License:Open Source License
/** * This method reads the XML input stream part from a DOM part for the * metadata of the document./*from www . java 2 s. c o m*/ * * @param element * a relevant JDOM element for the metadata */ @Override public void setFromDOM(org.jdom2.Element element) { super.setFromDOM(element); texts.clear(); // clear for (Element textElement : (Collection<Element>) element.getChildren("text")) { String text = textElement.getText(); String lang = textElement.getAttributeValue("lang", Namespace.XML_NAMESPACE); if (lang != null) { setText(text, lang); } else { setText(text); } } setCalendar(element.getChildTextTrim("calendar")); setVonDate(element.getChildTextTrim("von"), calendar); setBisDate(element.getChildTextTrim("bis"), calendar); }
From source file:org.mycore.datamodel.metadata.MCRMetaHistoryDate.java
License:Open Source License
/** * This method creates a XML stream for all data in this class, defined by * the MyCoRe XML MCRMetaHistoryDate definition for the given subtag. * // w w w . j ava 2 s .co m * @exception MCRException * if the content of this class is not valid * @return a JDOM Element with the XML MCRMetaHistoryDate part */ @Override public org.jdom2.Element createXML() throws MCRException { Element elm = super.createXML(); for (MCRMetaHistoryDateText text : texts) { Element elmt = new Element("text"); elmt.addContent(text.getText()); elmt.setAttribute("lang", text.getLang(), Namespace.XML_NAMESPACE); elm.addContent(elmt); } /** use gregorian for claendar string; wrong output; ToDo : get function for calendar string */ elm.addContent(new org.jdom2.Element("calendar").addContent(calendar)); elm.addContent(new org.jdom2.Element("ivon").addContent(Integer.toString(ivon))); elm.addContent(new org.jdom2.Element("von").addContent(getVonToString())); elm.addContent(new org.jdom2.Element("ibis").addContent(Integer.toString(ibis))); elm.addContent(new org.jdom2.Element("bis").addContent(getBisToString())); return elm; }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
/** * Stores the list of additional namespaces declared in the components * element of the editor definition. These namespaces and its prefixes can * be used in editor variable paths (var attributes of cells). *//*from w w w .j av a 2 s .com*/ @SuppressWarnings("unchecked") private void setAdditionalNamespaces(Element editor) { Element components = editor.getChild("components"); List<Namespace> namespaces = components.getAdditionalNamespaces(); for (Namespace ns : namespaces) { nsMap.put(ns.getPrefix(), ns); } nsMap.put("xml", Namespace.XML_NAMESPACE); for (Namespace ns : MCRConstants.getStandardNamespaces()) { setNamespaceIfUndefined(ns); } }
From source file:org.mycore.frontend.servlets.MCRErrorServlet.java
License:Open Source License
/** * Builds a jdom document containing the error parameter. * //from ww w . ja v a2s. c o m * @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.restapi.v1.MCRRestAPIClassifications.java
License:Open Source License
/** * Output xml// w w w . ja v a 2 s . com * @param eRoot - the root element * @param lang - the language which should be filtered or null for no filter * @return a string representation of the XML * @throws IOException */ private static String writeXML(Element eRoot, String lang) throws IOException { StringWriter sw = new StringWriter(); if (lang != null) { // <label xml:lang="en" text="part" /> XPathExpression<Element> xpE = XPathFactory.instance().compile("//label[@xml:lang!='" + lang + "']", Filters.element(), null, Namespace.XML_NAMESPACE); for (Element e : xpE.evaluate(eRoot)) { e.getParentElement().removeContent(e); } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); Document docOut = new Document(eRoot.detach()); xout.output(docOut, sw); return sw.toString(); }
From source file:org.mycore.restapi.v1.MCRRestAPIClassifications.java
License:Open Source License
/** * Output JSON/* w ww. j av a2 s . com*/ * @param eRoot - the category element * @param lang - the language to be filtered for or null if all languages should be displayed * @param style - the style * @return a string representation of a JSON object * @throws IOException */ private String writeJSON(Element eRoot, String lang, String style) throws IOException { StringWriter sw = new StringWriter(); JsonWriter writer = new JsonWriter(sw); writer.setIndent(" "); if (style.contains("checkboxtree")) { if (lang == null) { lang = "de"; } writer.beginObject(); writer.name("identifier").value(eRoot.getAttributeValue("ID")); for (Element eLabel : eRoot.getChildren("label")) { if (lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) { writer.name("label").value(eLabel.getAttributeValue("text")); } } writer.name("items"); writeChildrenAsJSONCBTree(eRoot = eRoot.getChild("categories"), writer, lang, style.contains("checked")); writer.endObject(); } else if (style.contains("jstree")) { if (lang == null) { lang = "de"; } writeChildrenAsJSONJSTree(eRoot = eRoot.getChild("categories"), writer, lang, style.contains("opened"), style.contains("disabled"), style.contains("selected")); } else { writer.beginObject(); // { writer.name("ID").value(eRoot.getAttributeValue("ID")); writer.name("label"); writer.beginArray(); for (Element eLabel : eRoot.getChildren("label")) { if (lang == null || lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) { writer.beginObject(); writer.name("lang").value(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE)); writer.name("text").value(eLabel.getAttributeValue("text")); if (eLabel.getAttributeValue("description") != null) { writer.name("description").value(eLabel.getAttributeValue("description")); } writer.endObject(); } } writer.endArray(); if (eRoot.equals(eRoot.getDocument().getRootElement())) { writeChildrenAsJSON(eRoot.getChild("categories"), writer, lang); } else { writeChildrenAsJSON(eRoot, writer, lang); } writer.endObject(); } writer.close(); return sw.toString(); }
From source file:org.mycore.restapi.v1.MCRRestAPIClassifications.java
License:Open Source License
/** * output categories in JSON format/*from w w w . jav a 2 s.c o m*/ * @param eParent - the parent xml element * @param writer - the JSON writer * @param lang - the language to be filtered or null if all languages should be displayed * * @throws IOException */ private static void writeChildrenAsJSON(Element eParent, JsonWriter writer, String lang) throws IOException { if (eParent.getChildren("category").size() == 0) return; writer.name("categories"); writer.beginArray(); for (Element e : eParent.getChildren("category")) { writer.beginObject(); writer.name("ID").value(e.getAttributeValue("ID")); writer.name("labels").beginArray(); for (Element eLabel : e.getChildren("label")) { if (lang == null || lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) { writer.beginObject(); writer.name("lang").value(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE)); writer.name("text").value(eLabel.getAttributeValue("text")); if (eLabel.getAttributeValue("description") != null) { writer.name("description").value(eLabel.getAttributeValue("description")); } writer.endObject(); } } writer.endArray(); if (e.getChildren("category").size() > 0) { writeChildrenAsJSON(e, writer, lang); } writer.endObject(); } writer.endArray(); }