本文整理汇总了Java中org.jdom2.Document.setRootElement方法的典型用法代码示例。如果您正苦于以下问题:Java Document.setRootElement方法的具体用法?Java Document.setRootElement怎么用?Java Document.setRootElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.Document
的用法示例。
在下文中一共展示了Document.setRootElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAbbyyToAlto
import org.jdom2.Document; //导入方法依赖的package包/类
/**
* Extracts page width and height attributes from the given ABBYY XML file and converts the document to ALTO.
*
* @param file
* @return
* @throws FileNotFoundException
* @throws IOException
* @throws JDOMException
* @throws XMLStreamException
* @throws FatalIndexerException
* @should convert to ALTO correctly
* @should throw IOException given wrong document format
*/
public static Map<String, Object> readAbbyyToAlto(File file) throws FileNotFoundException, IOException, XMLStreamException,
FatalIndexerException {
logger.trace("readAbbyy: {}", file.getAbsolutePath());
if (!FileFormat.ABBYYXML.equals(JDomXP.determineFileFormat(file))) {
throw new IOException(file.getAbsolutePath() + " is not a valid ABBYY XML document.");
}
Map<String, Object> ret = new HashMap<>();
// Convert to ALTO
Element alto = new ConvertAbbyyToAltoStaX().convert(file, new Date(file.lastModified()));
if (alto != null) {
Document altoDoc = new Document();
altoDoc.setRootElement(alto);
ret = readAltoDoc(altoDoc, file.getAbsolutePath());
logger.debug("Converted ABBYY XML to ALTO: {}", file.getName());
}
return ret;
}
示例2: wrongSchema
import org.jdom2.Document; //导入方法依赖的package包/类
/**
* @param response
* @param string
* @throws IOException
*/
private static void wrongSchema(HttpServletResponse response, String parameter) throws IOException {
Element searchRetrieveResponse = new Element("searchRetrieveResponse", SRU_NAMESPACE);
Element version = new Element("version", SRU_NAMESPACE);
version.setText("1.2");
searchRetrieveResponse.addContent(version);
Element diagnostic = new Element("diagnostic", SRU_NAMESPACE);
searchRetrieveResponse.addContent(diagnostic);
Element uri = new Element("uri", DIAG_NAMESPACE);
uri.setText("info:srw/diagnostic/1/66");
diagnostic.addContent(uri);
Element details = new Element("details", DIAG_NAMESPACE);
details.setText(" Unknown schema for retrieval");
diagnostic.addContent(details);
Element message = new Element("message", DIAG_NAMESPACE);
message.setText("Unknown schema for retrieval / " + parameter);
diagnostic.addContent(message);
Document doc = new Document();
doc.setRootElement(searchRetrieveResponse);
Format format = Format.getPrettyFormat();
format.setEncoding("utf-8");
XMLOutputter xmlOut = new XMLOutputter(format);
xmlOut.output(doc, response.getOutputStream());
}
示例3: missingArgument
import org.jdom2.Document; //导入方法依赖的package包/类
private static void missingArgument(HttpServletResponse response, String parameter) throws IOException {
Element searchRetrieveResponse = new Element("searchRetrieveResponse", SRU_NAMESPACE);
Element version = new Element("version", SRU_NAMESPACE);
version.setText("1.2");
searchRetrieveResponse.addContent(version);
Element diagnostic = new Element("diagnostic", SRU_NAMESPACE);
searchRetrieveResponse.addContent(diagnostic);
Element uri = new Element("uri", DIAG_NAMESPACE);
uri.setText("info:srw/diagnostic/1/7");
diagnostic.addContent(uri);
Element details = new Element("details", DIAG_NAMESPACE);
details.setText("Mandatory parameter not supplied");
diagnostic.addContent(details);
Element message = new Element("message", DIAG_NAMESPACE);
message.setText("Mandatory parameter not supplied / " + parameter);
diagnostic.addContent(message);
Document doc = new Document();
doc.setRootElement(searchRetrieveResponse);
Format format = Format.getPrettyFormat();
format.setEncoding("utf-8");
XMLOutputter xmlOut = new XMLOutputter(format);
xmlOut.output(doc, response.getOutputStream());
}
示例4: unsupportedOperation
import org.jdom2.Document; //导入方法依赖的package包/类
private static void unsupportedOperation(HttpServletResponse response, String parameter) throws IOException {
Element searchRetrieveResponse = new Element("searchRetrieveResponse", SRU_NAMESPACE);
Element version = new Element("version", SRU_NAMESPACE);
version.setText("1.2");
searchRetrieveResponse.addContent(version);
Element diagnostic = new Element("diagnostic", SRU_NAMESPACE);
searchRetrieveResponse.addContent(diagnostic);
Element uri = new Element("uri", DIAG_NAMESPACE);
uri.setText("info:srw/diagnostic/1/4");
diagnostic.addContent(uri);
Element details = new Element("details", DIAG_NAMESPACE);
details.setText("Unsupported operation");
diagnostic.addContent(details);
Element message = new Element("message", DIAG_NAMESPACE);
message.setText("Unsupported operation / " + parameter);
diagnostic.addContent(message);
Document doc = new Document();
doc.setRootElement(searchRetrieveResponse);
Format format = Format.getPrettyFormat();
format.setEncoding("utf-8");
XMLOutputter xmlOut = new XMLOutputter(format);
xmlOut.output(doc, response.getOutputStream());
}
示例5: readTeiToAlto
import org.jdom2.Document; //导入方法依赖的package包/类
/**
* Converts the document from the given TEI file to ALTO.
*
* @param file
* @return
* @throws FileNotFoundException
* @throws IOException
* @throws JDOMException
* @throws FatalIndexerException
* @should convert to ALTO correctly
* @should throw IOException given wrong document format
*/
public static Map<String, Object> readTeiToAlto(File file) throws FileNotFoundException, IOException, JDOMException, FatalIndexerException {
logger.info("readTei: {}", file.getAbsolutePath());
if (!file.exists()) {
throw new FileNotFoundException("File not found: " + file.getAbsolutePath());
}
if (!FileFormat.TEI.equals(JDomXP.determineFileFormat(file))) {
throw new IOException(file.getAbsolutePath() + " is not a valid TEI document.");
}
Map<String, Object> ret = new HashMap<>();
// Convert to ALTO
try {
Element alto = new ConvertTeiToAlto().convert(file.toPath());
if (alto != null) {
Document altoDoc = new Document();
altoDoc.setRootElement(alto);
ret = readAltoDoc(altoDoc, file.getAbsolutePath());
logger.info("Converted TEI to ALTO: {}", file.getName());
} else {
logger.warn("Could not convert TEI to ALTO: {}", file.getName());
}
} catch (XMLStreamException e) {
throw new IOException(e);
}
return ret;
}
示例6: doGetPost
import org.jdom2.Document; //导入方法依赖的package包/类
@Override
public void doGetPost(MCRServletJob job) throws Exception {
//prepare request
HttpServletRequest req = job.getRequest();
//get doi from URL
String doi = getParameter(req, "id");
//send request to CrossRef API
Document crossRefDocument = xmlFromDOICrossRef(doi);
Element crossRefExport = crossRefDocument.getRootElement().clone();
Element crossRefElement = new Element("crossref-export");
crossRefElement.addContent(crossRefExport);
//send request to Scopus API
Document scopusDocument = xmlFromDOIScopus(doi);
Element scopusExport = scopusDocument.getRootElement().clone();
Element scopusElement = new Element("scopus-export");
scopusElement.addContent(scopusExport);
System.out.println(scopusElement.getName());
// check, if the scopus-export contains multiple results
if(potentialScopusResult(scopusElement)) {
ExportComparator comp = new ExportComparator();
Element fittingElement = comp.getFittingElement(scopusElement, crossRefElement);
Element newScopusElement = fittingElement
.getChild("extension", modsNS).clone();
scopusElement.removeContent();
scopusElement.setContent(newScopusElement);
}
//build document
Document fullDoc = new Document();
Element rootElement = new Element("api-retrieval");
rootElement.addContent(crossRefElement);
rootElement.addContent(scopusElement);
fullDoc.setRootElement(rootElement);
XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
xmlOutput.output(fullDoc, new FileWriter("AllExport_DOI_mods.xml"));
scopusConnection.close();
crossRefConnection.close();
}