当前位置: 首页>>代码示例>>Java>>正文


Java JDOMSource类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:26,代码来源:MCRMetsResolver.java

示例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));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:26,代码来源:MCRURIResolver.java

示例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));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:31,代码来源:MCRXMLHelper.java

示例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();
    }
  }
}
 
开发者ID:calibre2opds,项目名称:calibre2opds,代码行数:28,代码来源:HtmlManager.java

示例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);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRMODSSorter.java

示例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);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:13,代码来源:MCREnrichmentResolver.java

示例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()));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:11,代码来源:MCRRealmResolver.java

示例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));
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCRRoleResolver.java

示例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);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:16,代码来源:MCRUserTransformer.java

示例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);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:16,代码来源:MCRRoleTransformer.java

示例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;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:16,代码来源:MCRUserAttributeMapper.java

示例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);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:11,代码来源:MCRLanguageResolver.java

示例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);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCRMailer.java

示例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);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRURIResolver.java

示例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;
    }
 
开发者ID:hagbeck,项目名称:task-processing-unit-for-dswarm,代码行数:40,代码来源:XmlTransformer.java


注:本文中的org.jdom2.transform.JDOMSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。