Search in sources :

Example 1 with MCRURLContent

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);
    }
}
Also used : MCRFileContent(org.mycore.common.content.MCRFileContent) MCRURLContent(org.mycore.common.content.MCRURLContent) IOException(java.io.IOException) File(java.io.File) MCRContent(org.mycore.common.content.MCRContent) URL(java.net.URL)

Example 2 with MCRURLContent

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()));
}
Also used : MCRURLContent(org.mycore.common.content.MCRURLContent) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 3 with MCRURLContent

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);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) MCRSolrURL(org.mycore.solr.search.MCRSolrURL) MCRURLContent(org.mycore.common.content.MCRURLContent) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

Example 4 with MCRURLContent

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);
    }
}
Also used : MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRURLContent(org.mycore.common.content.MCRURLContent) Document(org.jdom2.Document) URL(java.net.URL) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 5 with MCRURLContent

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;
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) MCRURLContent(org.mycore.common.content.MCRURLContent) URL(java.net.URL)

Aggregations

MCRURLContent (org.mycore.common.content.MCRURLContent)11 URL (java.net.URL)8 Document (org.jdom2.Document)5 Test (org.junit.Test)4 MCRCategory (org.mycore.datamodel.classifications2.MCRCategory)4 IOException (java.io.IOException)3 File (java.io.File)2 MCRContent (org.mycore.common.content.MCRContent)2 MCRFileContent (org.mycore.common.content.MCRFileContent)2 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)2 JsonElement (com.google.gson.JsonElement)1 MalformedURLException (java.net.MalformedURLException)1 EntityManager (javax.persistence.EntityManager)1 TransformerException (javax.xml.transform.TransformerException)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)1 Element (org.jdom2.Element)1 MCRCategoryID (org.mycore.datamodel.classifications2.MCRCategoryID)1 MCRFile (org.mycore.datamodel.ifs.MCRFile)1 MCRSolrURL (org.mycore.solr.search.MCRSolrURL)1