ENML4j
Simple utility classes to handle ENML (Evernote Markup Language) in Java.
Overview
ENML4j provide a convenient way to:
- Convert a
NoteENML content to an HTML file referencingResources as configurable URL - Convert a
NoteENML content to an HTML file with inlineResources as Data URI - Replace
Resourcereferences inNoteENML content with newResources - Delete
Resourcereferences inNoteENML content - Add
Resourcereferences inNoteENML content
ENML4j is design to be simple, customizable and to produce valid XHTML. ENML4j uses stAX to parse ENML and write XHTML.
Getting started
Converting a Notes ENML content to XHTML is as simple as:
ENMLProcessor = new ENMLProcessor();
FileOutputStream fos = new FileOutputStream("/path/to/file.html");
ENMLProcessor.noteToInlineHTML(note, fos);
The best way to start is to look at enml4j-sample
Including the SDK in your project
The easiest way to incorporate the SDK into your Java project is to use Maven. If you're using Maven already, simply add a new dependency to your pom.xml:
<dependency>
<groupId>com.syncthemall</groupId>
<artifactId>enml4j</artifactId>
<version>1.1.0</version>
</dependency>
If you'd prefer to build the jar yourself, it's as simple as running
$ mvn package
You'll find enml4j-1.1.0.jar in the target directory after the build completes. This single JAR contains everything needed to use the API.
Dependencies
You'll also need to be sure to include in your classpath a stAX implementation and evernote-sdk-java
User Guide
ENMLProcessor
This is the entry point of ENML4j. This class should be instantiated and kept in reference (as a static for example) for better performances. When converting a Note to HTML the Evernote DTD has to be parsed the first time, then stays in memory. Parsing the DTD the first time is time-consuming.
This class rely on stAX to convert ENML to HTML. ENML4j will uses the default stAX implementation on the platform. Implementation can be easily chosen : [StAX Factory Classes] (http://docs.oracle.com/javaee/5/tutorial/doc/bnbem.html#bnbeo)
This class is thread-safe as long as the stAX implementation of XMLInputFactory, XMLOutputFactory, XMLEventFactory are thread-safe. Almost all implementation of this classes are thread-safe.
Customize the conversion
ENML4j rely on Converters classes to convert specifics ENML tags to an HTML equivalent. Default Converters are provided and instantiated by default.
DefaultNoteTagConverterDefaultInlineMediaTagConverterDefaultTodoTagConverterDefaultCryptTagConverterDefaultInlineMediaTagConverter
For specifics needs BaseConverter and MediaConverter can be implemented and set with ENMLProcessor#setConverters(BaseConverter, MediaConverter, BaseConverter, BaseConverter) and ENMLProcessor#setInlineConverters(BaseConverter, MediaConverter, BaseConverter, BaseConverter).
For more information on ENML see Understanding the Evernote Markup Language
Development
Any bug reported properly will be fixed. Any features request will be taken under consideration.
Potential future features:
- Convert ENML to PDF with Flying Saucer
- Convert ENML to Plain text
- Convert valid XHTML to ENML
- Convert "street HTML" to ENML (very unlikely considering the lack of Java HTML renderer)
Change log
1.1.0
- Bug fixes
- added method addNoteResources
- Evernote DTD and it's dependencies are now embedded in the library
1.0.0
- Bug fixes
- Updated to Evernote SDK to version 1.25.1
0.2.1
- New methods to update
Resources inNoteENML content, based on their hash value - Minor code improvements
0.2.0
- New methods to delete
Resources fromNoteENML content - Methods to update
ResourceinNoENML can now also delete - Minor code improvements
0.1.1
- Mapping of external resources path now uses
Stringinstead ofURL - Methods returning
voidnow return the variable in parameter
License
MIT
Free Software, Fuck Yeah!
