本文整理汇总了Java中org.jdom2.transform.JDOMSource类的典型用法代码示例。如果您正苦于以下问题:Java JDOMSource类的具体用法?Java JDOMSource怎么用?Java JDOMSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JDOMSource类属于org.jdom2.transform包,在下文中一共展示了JDOMSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Override
public Source resolve(String href, String base) throws TransformerException {
String id = href.substring(href.indexOf(":") + 1);
LOGGER.debug("Reading METS for ID {}", id);
MCRObjectID objId = MCRObjectID.getInstance(id);
if (!objId.getTypeId().equals("derivate")) {
String derivateID = getDerivateFromObject(id);
if (derivateID == null) {
return new JDOMSource(new Element("mets", Namespace.getNamespace("mets", "http://www.loc.gov/METS/")));
}
id = derivateID;
}
MCRPath metsPath = MCRPath.getPath(id, "/mets.xml");
try {
if (Files.exists(metsPath)) {
//TODO: generate new METS Output
//ignoreNodes.add(metsFile);
return new MCRPathContent(metsPath).getSource();
}
Document mets = MCRMETSGeneratorFactory.create(MCRPath.getPath(id, "/")).generate().asDocument();
return new JDOMSource(mets);
} catch (Exception e) {
throw new TransformerException(e);
}
}
示例2: resolve
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Override
public Source resolve(String href, String base) throws TransformerException {
String type = href.substring(href.indexOf(":") + 1);
String path = "/templates/" + type + "/";
LOGGER.debug("Reading templates from {}", path);
Set<String> resourcePaths = context.getResourcePaths(path);
ArrayList<String> templates = new ArrayList<>();
if (resourcePaths != null) {
for (String resourcePath : resourcePaths) {
if (!resourcePath.endsWith("/")) {
//only handle directories
continue;
}
String templateName = resourcePath.substring(path.length(), resourcePath.length() - 1);
LOGGER.debug("Checking if template: {}", templateName);
if (templateName.contains("/")) {
continue;
}
templates.add(templateName);
}
Collections.sort(templates);
}
LOGGER.info("Found theses templates: {}", templates);
return new JDOMSource(getStylesheets(templates));
}
示例3: validate
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
/**
* validates <code>doc</code> using XML Schema defined <code>schemaURI</code>
* @param doc document to be validated
* @param schemaURI URI of XML Schema document
* @throws SAXException if validation fails
* @throws IOException if resolving resources fails
*/
public static void validate(Document doc, String schemaURI) throws SAXException, IOException {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
sf.setResourceResolver(MCREntityResolver.instance());
Schema schema;
try {
schema = sf.newSchema(MCRURIResolver.instance().resolve(schemaURI, null));
} catch (TransformerException e) {
Throwable cause = e.getCause();
if (cause == null) {
throw new IOException(e);
}
if (cause instanceof SAXException) {
throw (SAXException) cause;
}
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw new IOException(e);
}
Validator validator = schema.newValidator();
validator.setResourceResolver(MCREntityResolver.instance());
validator.validate(new JDOMSource(doc));
}
示例4: generateIncludedHtml
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
/**
* This routine is sued to generate files that have no .xml file, but only a .xsl file.
* It is used for files included by other html files to avoid repreating the contents;
* - header.html
* - generated.html
*/
public static void generateIncludedHtml(Document document, File outputPath, String xslname) throws IOException {
if (ConfigurationManager.getCurrentProfile().getGenerateHtml()) {
FileOutputStream fos = null;
try {
JDOMSource source = new JDOMSource(document);
File htmlFile = new File(outputPath,getHtmlFilename(xslname));
fos = new FileOutputStream(htmlFile);
StreamResult streamResult = new StreamResult(fos);
try {
Transformer transformer;
transformer = JDOMManager.getIncludeTransformer(xslname);
transformer.transform(source, streamResult);
} catch (TransformerException e) {
logger.error(Localization.Main.getText("error.cannotTransform", xslname), e);
}
} finally {
if (fos != null)
fos.close();
}
}
}
示例5: resolve
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Override
public Source resolve(String href, String base) throws TransformerException {
href = href.substring(href.indexOf(":") + 1);
Element mods = MCRURIResolver.instance().resolve(href);
MCRMODSSorter.sort(mods);
return new JDOMSource(mods);
}
示例6: resolve
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Override
public Source resolve(String href, String base) throws TransformerException {
href = href.substring(href.indexOf(":") + 1);
String configID = href.substring(0, href.indexOf(':'));
href = href.substring(href.indexOf(":") + 1);
Element mods = MCRURIResolver.instance().resolve(href);
enrichPublication(mods, configID);
return new JDOMSource(mods);
}
示例7: resolve
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Override
public Source resolve(final String href, final String base) throws TransformerException {
String realmID = href.split(":")[1];
if ("all".equals(realmID)) {
return MCRRealmFactory.getRealmsSource();
} else if ("local".equals(realmID)) {
realmID = MCRRealmFactory.getLocalRealm().getID();
}
return new JDOMSource(getElement(MCRRealmFactory.getRealm(realmID).getID()));
}
示例8: resolve
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Override
public Source resolve(final String href, final String base) throws TransformerException {
final String target = href.substring(href.indexOf(":") + 1);
final String[] part = target.split(":");
final String method = part[0];
try {
if ("getAssignableGroupsForUser".equals(method)) {
return new JDOMSource(getAssignableGroupsForUser());
}
} catch (final MCRAccessException exc) {
throw new TransformerException(exc);
}
throw new TransformerException(new IllegalArgumentException("Unknown method " + method + " in uri " + href));
}
示例9: buildMCRUser
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
/**
* Builds an MCRUser instance from the given element.
* @param element as generated by {@link #buildExportableXML(MCRUser)}.
*/
public static MCRUser buildMCRUser(Element element) {
if (!element.getName().equals(USER_ELEMENT_NAME)) {
throw new IllegalArgumentException("Element is not a mycore user element.");
}
try {
Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
return (MCRUser) unmarshaller.unmarshal(new JDOMSource(element));
} catch (JAXBException e) {
throw new MCRException("Exception while transforming Element to MCRUser.", e);
}
}
示例10: buildMCRRole
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
/**
* Builds an MCRRole instance from the given element.
* @param element as generated by {@link #buildExportableXML(MCRRole)}.
*/
public static MCRRole buildMCRRole(Element element) {
if (!element.getName().equals(ROLE_ELEMENT_NAME)) {
throw new IllegalArgumentException("Element is not a mycore role element.");
}
try {
Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
return (MCRRole) unmarshaller.unmarshal(new JDOMSource(element));
} catch (JAXBException e) {
throw new MCRException("Exception while transforming Element to MCRUser.", e);
}
}
示例11: instance
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
public static MCRUserAttributeMapper instance(Element attributeMapping) {
try {
JAXBContext jaxb = JAXBContext.newInstance(Mappings.class.getPackage().getName(),
Mappings.class.getClassLoader());
Unmarshaller unmarshaller = jaxb.createUnmarshaller();
Mappings mappings = (Mappings) unmarshaller.unmarshal(new JDOMSource(attributeMapping));
MCRUserAttributeMapper uam = new MCRUserAttributeMapper();
uam.attributeMapping.putAll(mappings.getAttributeMap());
return uam;
} catch (Exception e) {
return null;
}
}
示例12: resolve
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
public Source resolve(String href, String base) throws TransformerException {
try {
String code = href.split(":")[1];
MCRLanguage language = MCRLanguageFactory.instance().getLanguage(code);
Document doc = new Document(buildXML(language));
return new JDOMSource(doc);
} catch (Exception ex) {
throw new TransformerException(ex);
}
}
示例13: parseXML
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
/**
* Parse a email from given {@link Element}.
*
* @param xml the email
* @return the {@link EMail} object
*/
public static EMail parseXML(final Element xml) {
try {
final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
return (EMail) unmarshaller.unmarshal(new JDOMSource(xml));
} catch (final JAXBException e) {
throw new MCRException("Exception while transforming Element to EMail.", e);
}
}
示例14: getSource
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
private Source getSource(MCRStoredMetadata retrieve) throws IOException {
Element e = new Element("versions");
Element v = new Element("version");
e.addContent(v);
v.setAttribute("date", MCRXMLFunctions.getISODate(retrieve.getLastModified(), null));
return new JDOMSource(e);
}
示例15: xmlOutputter
import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
public static String xmlOutputter(Document doc, String xslt, HashMap<String,String> params) throws IOException {
String result = null;
try {
Processor processor = new Processor(false);
XdmNode source = processor.newDocumentBuilder().build(new JDOMSource( doc ));
Serializer out = new Serializer();
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.INDENT, "yes");
StringWriter buffer = new StringWriter();
out.setOutputWriter(new PrintWriter( buffer ));
XsltCompiler xsltCompiler = processor.newXsltCompiler();
XsltExecutable exp = xsltCompiler.compile(new StreamSource(xslt));
XsltTransformer trans = exp.load();
trans.setInitialContextNode(source);
trans.setDestination(out);
if (params != null) {
for (String p : params.keySet()) {
trans.setParameter(new QName(p), new XdmAtomicValue(params.get(p)));
}
}
trans.transform();
result = buffer.toString();
} catch (SaxonApiException e) {
e.printStackTrace();
}
return result;
}