use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.
the class MCRDefaultConfigurationLoader method loadFromFile.
/**
* Loads configuration properties from a specified properties file and adds
* them to the properties currently set. This method scans the <CODE>
* CLASSPATH</CODE> for the properties file, it may be a plain file, but
* may also be located in a zip or jar file. If the properties file contains
* a property called <CODE>MCR.Configuration.Include</CODE>, the files
* specified in that property will also be read. Multiple include files have
* to be separated by spaces or colons.
*
* @param filename
* the properties file to be loaded
* @throws MCRConfigurationException
* if the file can not be loaded
*/
private void loadFromFile(String filename) {
File mycoreProperties = new File(filename);
MCRContent input = null;
try {
if (mycoreProperties.canRead()) {
input = new MCRFileContent(mycoreProperties);
} else {
URL url = this.getClass().getResource("/" + filename);
if (url == null) {
throw new MCRConfigurationException("Could not find file or resource:" + filename);
}
input = new MCRURLContent(url);
}
loadFromContent(input);
} catch (IOException e) {
String name = input == null ? filename : input.getSystemId();
throw new MCRConfigurationException("Could not load configuration from: " + name, e);
}
}
use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.
the class MCRXMLParserTest method testInvalidXML.
@Test
public void testInvalidXML() throws SAXParseException, IOException {
try {
MCRXMLParserFactory.getValidatingParser().parseXML(new MCRURLContent(xmlResourceInvalid));
fail("MCRParserXerces accepts invalid XML content when validation is requested");
} catch (Exception e) {
}
MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRURLContent(xmlResourceInvalid));
MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRURLContent(xmlFileInvalid.toUri().toURL()));
}
use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.
the class MCRSolrQueryResolver method resolve.
@Override
public Source resolve(String href, String base) throws TransformerException {
String urlQuery = href.substring(href.indexOf(":") + 1);
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
MCRSolrURL solrURL = new MCRSolrURL((HttpSolrClient) solrClient, urlQuery);
try {
MCRURLContent result = new MCRURLContent(solrURL.getUrl());
return result.getSource();
} catch (IOException e) {
throw new TransformerException("Unable to get input stream from solr: " + solrURL.getUrl(), e);
}
}
use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method updateFromURL.
@MCRCommand(syntax = "update classification from url {0}", help = "The command updates a classification from URL {0} to the system.", order = 25)
public static void updateFromURL(String fileURL) throws SAXParseException, MalformedURLException, URISyntaxException {
Document xml = MCRXMLParserFactory.getParser().parseXML(new MCRURLContent(new URL(fileURL)));
MCRCategory category = MCRXMLTransformer.getCategory(xml);
if (DAO.exist(category.getId())) {
DAO.replaceCategory(category);
} else {
// add if classification does not exist
DAO.addCategory(null, category);
}
}
use of org.mycore.common.content.MCRURLContent in project mycore by MyCoRe-Org.
the class MCRAVExtRealHelix method getPlayerStarter.
@Override
public MCRContent getPlayerStarter(String startPos, String stopPos) throws IOException {
MCRURLContent content = new MCRURLContent(new URL(getURL(startPos, stopPos)));
content.setMimeType(getPlayerStarterContentType());
if (file instanceof MCRFile) {
content.setName(file.getName() + startPos + "-" + stopPos);
}
return content;
}
Aggregations