MCPcopy Create free account
hub / github.com/Fedict/dcattools / writeLiteral

Method writeLiteral

tools/src/main/java/be/gov/data/tools/EDP.java:168–196  ·  view source on GitHub ↗

Write literal (date, anyURI, string...) to XML file @param w XML writer @param el element name @param val value @throws XMLStreamException

(XMLStreamWriter w, String el, Value val)

Source from the content-addressed store, hash-verified

166 * @throws XMLStreamException
167 */
168 private static void writeLiteral(XMLStreamWriter w, String el, Value val)
169 throws XMLStreamException {
170 if (val instanceof Literal) {
171 w.writeStartElement(el);
172 // write language or datatype
173 String lang = ((Literal) val).getLanguage().orElse("");
174 if (!lang.isEmpty()) {
175 w.writeAttribute("xml:lang", lang);
176 } else {
177 IRI dtype = ((Literal) val).getDatatype();
178 if ((dtype != null) && !dtype.equals(XSD.STRING)) {
179 w.writeAttribute("rdf:datatype", dtype.toString());
180 }
181 }
182 String str = val.stringValue();
183 if (str.contains("<")) {
184 w.writeCData(str);
185 } else {
186 w.writeCharacters(str);
187 }
188 w.writeEndElement();
189 }
190 if (val instanceof IRI) {
191 w.writeStartElement(el);
192 w.writeAttribute("rdf:datatype", ANYURI);
193 w.writeCharacters(val.stringValue());
194 w.writeEndElement();
195 }
196 }
197
198 /**
199 * Write generic info on (nested) elements

Callers 2

writeLiteralsMethod · 0.95
writeLocationsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected