Search in sources :

Example 6 with MDRuntimeException

use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.

the class ViewPage method getVersion.

private String getVersion() {
    URL[] urls = { ViewPage.class.getProtectionDomain().getCodeSource().getLocation() };
    Manifest m = new Manifest();
    try (URLClassLoader urlClassLoader = new URLClassLoader(urls)) {
        try (InputStream in = urlClassLoader.getResourceAsStream("META-INF/MANIFEST.MF")) {
            m.read(in);
        }
    } catch (IOException ex) {
        throw new MDRuntimeException(ex);
    }
    Attributes infoAttributes = m.getAttributes("Info");
    return infoAttributes == null ? "DEV" : infoAttributes.getValue("Version");
}
Also used : InputStream(java.io.InputStream) URLClassLoader(java.net.URLClassLoader) Attributes(java.util.jar.Attributes) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) URL(java.net.URL)

Example 7 with MDRuntimeException

use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.

the class MangaPandaChapterList method getAvailabile.

@Override
public Collection<HosterListEntry> getAvailabile(final IndexerConfiguration conf) {
    Document doc;
    final URL baseUrl;
    try {
        baseUrl = new URL(getDetails().baseUrl());
        URL listUrl = new URL(baseUrl, "/alphabetical");
        doc = Utils.getDocument(listUrl, conf);
    } catch (IOException ex) {
        throw new MDRuntimeException(ex);
    }
    Elements elements = doc.select("div.series_col ul.series_alpha > li > a");
    Collection<HosterListEntry> entries = new TreeSet<>(HosterListEntry.NAME_COMPARATOR);
    for (Element element : elements) {
        HosterListEntry entry = new HosterListEntry();
        entry.setName(element.text());
        try {
            entry.setUrl(new URL(baseUrl, element.attr("href")).toExternalForm());
        } catch (MalformedURLException ex) {
            logger.catching(Level.DEBUG, ex);
        }
        entries.add(entry);
    }
    return entries;
}
Also used : MalformedURLException(java.net.MalformedURLException) TreeSet(java.util.TreeSet) Element(org.jsoup.nodes.Element) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) HosterListEntry(de.herrlock.manga.index.entity.HosterListEntry) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URL(java.net.URL)

Example 8 with MDRuntimeException

use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.

the class Hosters method loadResourcePaths.

private static Collection<URL> loadResourcePaths(final Iterable<String> lines) {
    Queue<URL> resourcePaths = new ArrayDeque<>();
    try {
        for (String line : lines) {
            String filename = line.substring(1, line.length() - 1);
            File nextFile = new File(filename);
            if (nextFile.exists()) {
                URL nextFileURL = nextFile.toURI().toURL();
                resourcePaths.add(nextFileURL);
            } else {
                logger.warn("The File \"{}\" does not exist", nextFile);
            }
        }
    } catch (MalformedURLException ex) {
        throw new MDRuntimeException(ex);
    }
    return resourcePaths;
}
Also used : MalformedURLException(java.net.MalformedURLException) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) File(java.io.File) URL(java.net.URL) ArrayDeque(java.util.ArrayDeque)

Example 9 with MDRuntimeException

use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.

the class Hosters method loadAdditionalHosters.

private static void loadAdditionalHosters(final Collection<String> lines) {
    logger.traceEntry("lines: {}", lines);
    final Predicate<String> isBracketLine = new Predicate<String>() {

        @Override
        public boolean apply(final String input) {
            return input != null && input.startsWith("[") && input.endsWith("]");
        }
    };
    Iterable<String> resourcesPathLines = Iterables.filter(lines, isBracketLine);
    Collection<URL> resourcePaths = loadResourcePaths(resourcesPathLines);
    URL[] resourcePathArray = resourcePaths.toArray(new URL[resourcePaths.size()]);
    try (URLClassLoader classLoader = new URLClassLoader(resourcePathArray, Hosters.class.getClassLoader())) {
        Iterable<String> otherLines = Iterables.filter(lines, Predicates.not(isBracketLine));
        for (String line : otherLines) {
            if (!line.trim().isEmpty() && !line.startsWith("#")) {
                loadExtraClass(classLoader, line);
            }
        }
    } catch (IOException ex) {
        throw new MDRuntimeException(ex);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) IOException(java.io.IOException) URL(java.net.URL) Predicate(com.google.common.base.Predicate)

Example 10 with MDRuntimeException

use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.

the class Main method startServer.

private static void startServer(final CommandLine commandline) {
    logger.traceEntry("Commandline: {}", commandline);
    logger.info("Starting Server:");
    try {
        if (commandline.hasOption("browser")) {
            logger.info("(and browser)");
            ServerMain.execute(true);
        } else {
            ServerMain.execute(false);
        }
    } catch (IOException | MDException | URISyntaxException ex) {
        throw new MDRuntimeException(ex);
    }
}
Also used : MDException(de.herrlock.manga.exceptions.MDException) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Aggregations

MDRuntimeException (de.herrlock.manga.exceptions.MDRuntimeException)13 IOException (java.io.IOException)11 URL (java.net.URL)6 InputStream (java.io.InputStream)4 MalformedURLException (java.net.MalformedURLException)3 HosterListEntry (de.herrlock.manga.index.entity.HosterListEntry)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 URLClassLoader (java.net.URLClassLoader)2 Path (java.nio.file.Path)2 Properties (java.util.Properties)2 TreeSet (java.util.TreeSet)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 Predicate (com.google.common.base.Predicate)1 MDException (de.herrlock.manga.exceptions.MDException)1 Index (de.herrlock.manga.index.entity.Index)1