• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JDOMSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jdom2.transform.JDOMSource的典型用法代码示例。如果您正苦于以下问题:Java JDOMSource类的具体用法?Java JDOMSource怎么用?Java JDOMSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JDOMSource类属于org.jdom2.transform包,在下文中一共展示了JDOMSource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: test

import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Test
public void test() throws Exception {
	
	WebServiceTemplate template = new WebServiceTemplate();
	
	SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
	messageFactory.setSoapVersion(SoapVersion.SOAP_12);
	messageFactory.afterPropertiesSet();
	template.setMessageFactory(messageFactory);
	
	CryptoFactoryBean cryptoFactory = new CryptoFactoryBean();
	cryptoFactory.setKeyStoreLocation(new ClassPathResource("keystore.jks"));
	cryptoFactory.setKeyStorePassword("password");
	cryptoFactory.afterPropertiesSet();
	Crypto crypto = cryptoFactory.getObject();
	
	SAML2CallbackHandler samlCallbackHandler = new SAML2CallbackHandler(crypto, "selfsigned");
	
	SAMLIssuerImpl issuer = new SAMLIssuerImpl();
	issuer.setIssuerCrypto(crypto);
	issuer.setIssuerKeyName("selfsigned");
	issuer.setIssuerKeyPassword("password");
	issuer.setIssuerName("selfsigned");
	issuer.setSendKeyValue(false);
	issuer.setSignAssertion(true);
	issuer.setCallbackHandler(samlCallbackHandler);
	
	Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor();
	securityInterceptor.setSecurementActions("Timestamp SAMLTokenSigned");
	securityInterceptor.setSecurementSignatureCrypto(crypto);
	securityInterceptor.setSecurementUsername("selfsigned");
	securityInterceptor.setSecurementPassword("password");
	securityInterceptor.setSamlIssuer(issuer);
	securityInterceptor.afterPropertiesSet();
	
	template.setInterceptors(new ClientInterceptor[] {securityInterceptor});
	template.afterPropertiesSet();
	
	Element hello = new Element("Hello", "urn:jaminh:example");
	template.sendSourceAndReceiveToResult("http://localhost:8080/spring-saml-example-war", new JDOMSource(hello), new JDOMResult());
	template.sendSourceAndReceiveToResult("http://localhost:8080/spring-saml-example-war", new JDOMSource(hello), new JDOMResult());
	template.sendSourceAndReceiveToResult("http://localhost:8080/spring-saml-example-war", new JDOMSource(hello), new JDOMResult());
	
}
 
开发者ID:jaminh,项目名称:spring-saml-example-war,代码行数:45,代码来源:HelloTest.java


示例17: doWithMessage

import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
@Override
public void doWithMessage(WebServiceMessage message) throws IOException,
    TransformerException {
  sessionHolder.addSessionIdToSoapMessage((SoapMessage) message);
  transformer.transform(new JDOMSource(request), 
      message.getPayloadResult());
  
}
 
开发者ID:ceharris,项目名称:avaya-aes-demo,代码行数:9,代码来源:SystemManagementService.java


示例18: getRealmsSource

import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
/**
 * Returns the Realms JDOM document as a {@link Source} useful for transformation processes.
 */
static Source getRealmsSource() {
    reInitIfNeeded();
    return new JDOMSource(realmsDocument);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRRealmFactory.java


示例19: exportMCRObject

import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
/**
 * The method read a MCRObject and use the transformer to write the data to a file. They are any steps to handel
 * errors and save the damaged data.
 * <ul>
 * <li>Read data for object ID in the MCRObject, add ACL's and store it as checked and transformed XML. Return true.
 * </li>
 * <li>If it can't find a transformer instance (no script file found) it store the checked data with ACL's native in
 * the file. Warning and return true.</li>
 * <li>If it get an exception while build the MCRObject, it try to read the XML blob and stor it without check and
 * ACL's to the file. Warning and return true.</li>
 * <li>If it get an exception while store the native data without check, ACÖ's and transformation it return a
 * warning and false.</li>
 * </ul>
 *
 * @param dir
 *            the file instance to store
 * @param trans
 *            the XML transformer
 * @param nid
 *            the MCRObjectID
 * @return true if the store was okay (see description), else return false
 * @throws TransformerException
 * @throws IOException
 * @throws MCRException
 * @throws SAXParseException
 */
private static boolean exportMCRObject(File dir, Transformer trans, String nid)
    throws TransformerException, IOException, MCRException, SAXParseException {
    MCRContent content;
    try {
        // if object do'snt exist - no exception is catched!
        content = MCRXMLMetadataManager.instance().retrieveContent(MCRObjectID.getInstance(nid));
    } catch (MCRException ex) {
        return false;
    }

    File xmlOutput = new File(dir, nid + ".xml");

    if (trans != null) {
        FileOutputStream out = new FileOutputStream(xmlOutput);
        StreamResult sr = new StreamResult(out);
        Document doc = MCRXMLParserFactory.getNonValidatingParser().parseXML(content);
        trans.transform(new org.jdom2.transform.JDOMSource(doc), sr);
    } else {
        content.sendTo(xmlOutput);
    }
    LOGGER.info("Object {} saved to {}.", nid, xmlOutput.getCanonicalPath());
    return true;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:50,代码来源:MCRObjectCommands.java


示例20: xslt

import org.jdom2.transform.JDOMSource; //导入依赖的package包/类
private static void xslt(String objectId, String xslFilePath, boolean force) throws IOException, JDOMException, SAXException,
        URISyntaxException, TransformerException, MCRPersistenceException, MCRAccessException {
    File xslFile = new File(xslFilePath);
    URL xslURL;
    if (!xslFile.exists()) {
        try {
            xslURL = new URL(xslFilePath);
        } catch (MalformedURLException e) {
            LOGGER.error("XSL parameter is not a file or URL: {}", xslFilePath);
            return;
        }
    } else {
        xslURL = xslFile.toURI().toURL();
    }
    MCRObjectID mcrId = MCRObjectID.getInstance(objectId);
    Document document = MCRXMLMetadataManager.instance().retrieveXML(mcrId);
    // do XSL transform
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformerFactory.setErrorListener(MCRErrorListener.getInstance());
    transformerFactory.setURIResolver(MCRURIResolver.instance());
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    xmlReader.setEntityResolver(MCREntityResolver.instance());
    SAXSource styleSource = new SAXSource(xmlReader, new InputSource(xslURL.toURI().toString()));
    Transformer transformer = transformerFactory.newTransformer(styleSource);
    for (Entry<String, String> property : MCRConfiguration.instance().getPropertiesMap().entrySet()) {
        transformer.setParameter(property.getKey(), property.getValue());
    }
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    transformer.setOutputProperty(OutputKeys.INDENT, "no");
    JDOMResult result = new JDOMResult();
    transformer.transform(new JDOMSource(document), result);
    Document resultDocument = Objects.requireNonNull(result.getDocument(), "Could not get transformation result");

    String originalName = document.getRootElement().getName();
    String resultName = resultDocument.getRootElement().getName();
    if (!force && !originalName.equals(resultName)) {
        LOGGER.error("{}: root name '{}' does not match result name '{}'.", objectId, originalName, resultName);
        return;
    }

    // update on diff
    if (MCRXMLHelper.deepEqual(document, resultDocument)) {
        return;
    }
    if(resultName.equals(MCRObject.ROOT_NAME)) {
        MCRMetadataManager.update(new MCRObject(resultDocument));
    } else if(resultName.equals(MCRDerivate.ROOT_NAME)) {
        MCRMetadataManager.update(new MCRDerivate(resultDocument));
    } else {
        LOGGER.error("Unable to transform '{}' because unknown result root name '{}'.", objectId, resultName);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:53,代码来源:MCRObjectCommands.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TextChangedEvent类代码示例发布时间:2022-05-23
下一篇:
Java OIDCTokenResponse类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap