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();
}
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));
}
Aggregations