mertakdut / EpubParser

Parses .epub files, provides seperation page by page.
Apache License 2.0
118 stars 27 forks source link

javax.xml.parsers.ParserConfigurationException #16

Open mfissehaye opened 7 years ago

mfissehaye commented 7 years ago

I tried to use the library according to the guideline on the GitHub page The first problem I got is that there is no class called Book.

The fifth line of code in the Usage section tries to create a Book object from reader.readSection. I thought maybe you meant to say BookSectionso I replaced it.

And further into the code reader.setFullContent(epubFilePath); throws the following exception. (I have put the complete stack trace)

What I understood while debugging is that the DocumentBuilderFactoryImplclass throws ParserConfigurationException if instance of DocumentBuilderFactoryImpl calls setFeature with names different from http://xml.org/sax/features/namespaces and http://xml.org/sax/features/validation

Is there a problem with my android depedencies?

javax.xml.parsers.ParserConfigurationException: http://apache.org/xml/features/nonvalidating/load-dtd-grammar
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setFeature(DocumentBuilderFactoryImpl.java:101)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.github.mertakdut.Reader.fillContent(Reader.java:98)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.github.mertakdut.Reader.setFullContent(Reader.java:39)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.a360ground.lomibooksrecycler.BookReaderActivity.onCreate(BookReaderActivity.java:31)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.Activity.performCreate(Activity.java:6178)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.access$900(ActivityThread.java:177)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.os.Looper.loop(Looper.java:135)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5910)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
mertakdut commented 7 years ago

Hello,

mertakdut commented 7 years ago

Android sdk (api-23) uses this method for setFeature:

`@Override
public void setFeature(String name, boolean value)
        throws ParserConfigurationException {
    if (name == null) {
        throw new NullPointerException("name == null");
    }

    if (NAMESPACES.equals(name)) {
        setNamespaceAware(value);
    } else if (VALIDATION.equals(name)) {
        setValidating(value);
    } else {
        throw new ParserConfigurationException(name);
    }
}`

As this states, android throws exception for all other features other than namespace and validation.

lvs-coding commented 7 years ago

Same problem here. Get a ParserConfigurationException on reader.setFullContent(epubFilePath). The Exception doesn't break the operation and I can get the ebook content with bookSection.getSectionContent().

I'm getting the same error with the sample app provided EpubParser-Sample-Android-Application.

lvs-coding commented 7 years ago

It looks like Android SDK DocumentBuilderFactory cannot support these two features factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);

As these features are used for document validation maybe they are not mandatory ? anyway they are not supported on API 25. docs here and here