use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRFieldBaseValue method buildXML.
/**
* Builds a XML representation of this field's value
*
* @return a 'field' element with attribute 'name' and the value as element
* content
*/
public Element buildXML() {
Element eField = new Element("field", MCRConstants.MCR_NAMESPACE);
eField.setAttribute("name", getFieldName());
eField.addContent(value);
return eField;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRSolrTransformerInputDocumentFactory method getDocument.
/* (non-Javadoc)
* @see org.mycore.solr.index.document.MCRSolrInputDocumentFactory#getDocument(org.mycore.datamodel.metadata.MCRObjectID, org.mycore.common.content.MCRContent)
*/
@Override
public SolrInputDocument getDocument(MCRObjectID id, MCRContent content) throws SAXException, IOException {
// we need no parameter for searchfields - hopefully
try {
SolrInputDocument document;
if (isJAXBTransformer) {
MCRParameterCollector param = new MCRParameterCollector();
@SuppressWarnings("unchecked") MCRXSL2JAXBTransformer<MCRSolrInputDocumentList> jaxbTransformer = (MCRXSL2JAXBTransformer<MCRSolrInputDocumentList>) transformer;
MCRSolrInputDocumentList input = jaxbTransformer.getJAXBObject(content, param);
document = MCRSolrInputDocumentGenerator.getSolrInputDocument(input.getDoc().iterator().next());
} else {
MCRContent result = transformer.transform(content);
document = MCRSolrInputDocumentGenerator.getSolrInputDocument(result.asXML().getRootElement());
}
return document;
} catch (TransformerConfigurationException | JAXBException | JDOMException | ParserConfigurationException e) {
throw new IOException(e);
}
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRXSL2XMLTransformer method getDocument.
private Document getDocument(JDOMResult result) {
Document resultDoc = result.getDocument();
if (resultDoc == null) {
// Sometimes a transformation produces whitespace strings
// JDOM would produce a empty document if it detects those
// So we remove them, if they exists.
List<Content> transformResult = result.getResult();
int origSize = transformResult.size();
Iterator<Content> iterator = transformResult.iterator();
while (iterator.hasNext()) {
Content content = iterator.next();
if (content instanceof Text) {
String trimmedText = ((Text) content).getTextTrim();
if (trimmedText.length() == 0) {
iterator.remove();
}
}
}
if (transformResult.size() < origSize) {
JDOMFactory f = result.getFactory();
if (f == null) {
f = new DefaultJDOMFactory();
}
resultDoc = f.document(null);
resultDoc.setContent(transformResult);
}
}
return resultDoc;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRToPrettyXML method transform.
@Override
public MCRContent transform(MCRContent source) throws IOException {
MCRXMLContent content;
try {
content = (source instanceof MCRXMLContent ? (MCRXMLContent) source : new MCRJDOMContent(source.asXML()));
} catch (JDOMException | SAXException e) {
throw new IOException(e);
}
if (content != source) {
content.setName(source.getName());
content.setLastModified(source.lastModified());
}
content.setFormat(Format.getPrettyFormat().setEncoding(getEncoding()));
return content;
}
use of org.jdom2.Content in project mycore by MyCoRe-Org.
the class MCRTransferPackage method getContent.
/**
* Returns the content for this transfer package. You have to call {@link #build()}
* before you can retrieve this data.
*
* @return a map where key = filename; value = MCRContent
*/
public Map<String, MCRContent> getContent() throws IOException {
Map<String, MCRContent> content = new HashMap<>();
// config
content.put(IMPORT_CONFIG_FILENAME, new MCRJDOMContent(buildImportConfiguration()));
// objects
for (MCRObject object : this.objects) {
String fileName = CONTENT_PATH + object.getId() + ".xml";
Document xml = object.createXML();
content.put(fileName, new MCRJDOMContent(xml));
}
// file containers
for (MCRTransferPackageFileContainer fc : this.fileContainers) {
// derivate
MCRObjectID derivateId = fc.getDerivateId();
MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateId);
Document derivateXML = derivate.createXML();
String folder = CONTENT_PATH + fc.getName();
String derivateFileName = folder + "/" + fc.getName() + ".xml";
content.put(derivateFileName, new MCRJDOMContent(derivateXML));
// files of derivate
for (MCRFile file : fc.getFiles()) {
content.put(folder + file.getAbsolutePath(), file.getContent());
}
}
// classifications
for (String classId : this.classifications) {
Document classification = MCRClassificationUtils.asDocument(classId);
String path = CLASS_PATH + classId + ".xml";
content.put(path, new MCRJDOMContent(classification));
}
return content;
}
Aggregations