Search in sources :

Example 11 with MCRFileContent

use of org.mycore.common.content.MCRFileContent in project mycore by MyCoRe-Org.

the class MCRConfigurationInputStream method getPropertyStream.

private static InputStream getPropertyStream(String filename) throws IOException {
    File mycoreProperties = new File(filename);
    MCRContent input = null;
    if (mycoreProperties.canRead()) {
        input = new MCRFileContent(mycoreProperties);
    } else {
        URL url = MCRConfigurationInputStream.class.getClassLoader().getResource(filename);
        if (url != null) {
            input = new MCRURLContent(url);
        }
    }
    return input == null ? null : input.getInputStream();
}
Also used : MCRFileContent(org.mycore.common.content.MCRFileContent) MCRURLContent(org.mycore.common.content.MCRURLContent) File(java.io.File) MCRContent(org.mycore.common.content.MCRContent) URL(java.net.URL)

Example 12 with MCRFileContent

use of org.mycore.common.content.MCRFileContent in project mycore by MyCoRe-Org.

the class MCRGoogleSitemapServlet method doGetPost.

/**
 * This method implement the doGetPost method of MCRServlet. It build a XML
 * file for the Google search engine.
 *
 * @param job
 *            a MCRServletJob instance
 */
public void doGetPost(MCRServletJob job) throws Exception {
    File baseDir = MCRFrontendUtil.getWebAppBaseDir(getServletContext()).orElseGet(() -> new File(MCRConfiguration.instance().getString("MCR.WebApplication.basedir")));
    MCRGoogleSitemapCommon common = new MCRGoogleSitemapCommon(MCRFrontendUtil.getBaseURL(job.getRequest()), baseDir);
    int number = common.checkSitemapFile();
    LOGGER.debug("Build Google number of URL files {}.", Integer.toString(number));
    Document jdom = null;
    // check if sitemap_google.xml exist
    String fnsm = common.getFileName(1, true);
    LOGGER.debug("Build Google check file {}", fnsm);
    File fi = new File(fnsm);
    if (fi.isFile()) {
        jdom = MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRFileContent(fi));
        if (jdom == null) {
            if (number == 1) {
                jdom = common.buildSingleSitemap();
            } else {
                jdom = common.buildSitemapIndex(number);
            }
        }
        // send XML output
        getLayoutService().doLayout(job.getRequest(), job.getResponse(), new MCRJDOMContent(jdom));
        return;
    }
    // remove old files
    common.removeSitemapFiles();
    // build new return and URL files
    if (number == 1) {
        jdom = common.buildSingleSitemap();
    } else {
        for (int i = 0; i < number; i++) {
            String fn = common.getFileName(i + 2, true);
            File xml = new File(fn);
            jdom = common.buildPartSitemap(i);
            LOGGER.info("Write Google sitemap file {}.", fn);
            new MCRJDOMContent(jdom).sendTo(xml);
        }
        jdom = common.buildSitemapIndex(number);
    }
    // send XML output
    getLayoutService().doLayout(job.getRequest(), job.getResponse(), new MCRJDOMContent(jdom));
}
Also used : MCRFileContent(org.mycore.common.content.MCRFileContent) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) File(java.io.File)

Aggregations

MCRFileContent (org.mycore.common.content.MCRFileContent)12 File (java.io.File)8 Document (org.jdom2.Document)6 Element (org.jdom2.Element)4 MCRContent (org.mycore.common.content.MCRContent)3 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)3 FileOutputStream (java.io.FileOutputStream)2 URL (java.net.URL)2 Test (org.junit.Test)2 MCRException (org.mycore.common.MCRException)2 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)2 MCRURLContent (org.mycore.common.content.MCRURLContent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 MCRAccessInterface (org.mycore.access.MCRAccessInterface)1 MCRSourceContent (org.mycore.common.content.MCRSourceContent)1