🚀 DAY 1 OF LAUNCH WEEK: Reachability for Ruby Now in Beta.Learn more
Socket
Book a DemoInstallSign in
Socket

com.github.vedenin.atoms:atoms-htmlparser

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.vedenin.atoms:atoms-htmlparser

Project provide implementation of Atom pattern for html parser using jsop

Source
mavenMaven
Version
0.1-jsoup-draft
Version published
Maintainers
1
Source

Atom pattern (draft, in progress)

Atom pattern is combination of Proxy/Facade/Wrapper pattern. Main idea of Atom pattern reduce complexity of third party libraries in your business code.

Main problem of common Java project

  • Difficult to change one third party library to other library in big project,

  • Some of third party libraries is very complicated (it have a lot of type, class and method), but you need only small part of this in your project,

  • Difficult to add logging, debugging, change methods of third party libraries and so on,

  • High coupling between your code and third party libraries

  • You can't use Dependency injection with a third party library (if library author is not provide DI support)

Main idea

Do not use third party libraries directly, but add to your project some Proxy/Atoms (in separate module or package) and call only Atom from your project.

Common approach:

common way

Atom-pattern approach:

atom way

Small example

 @Atom(Document.class)
 @Molecule({ElementAtom.class, ListAtom.class})
 @Contract("Provide information about HTML pages")
 public class DocumentAtom {
     private final Document original;

     @Contract("Should returns elements according this CSS Query")
     public ListAtom<ElementAtom> select(String cssQuery) {
         ListAtom<ElementAtom> result = ListAtom.create();
         result.addAll(original.select(cssQuery).stream().original(ElementAtom::getAtom).collect(ListAtom.getCollector()));
         return result;
     }

     // -------------- Just boilerplate code for Atom -----------------
     @BoilerPlate
     private DocumentAtom(Document original) {
         this.original = original;
     }

     @BoilerPlate
     static DocumentAtom getAtom(Document original) {
         return new DocumentAtom(original);
     }

 }

Possible Atom types

1. Atom with Exceptions proxy

atom way

Description: All Exceptions (checked or unchecked) from a third party libraries classes catch in Atoms and throw as AtomException.

For example:

 public boolean createNewFile() {
     try {
         return original.createNewFile();
     } catch (IOException exp) {
         throw new IOAtomException(exp);
     }
 }
 

Usage:

  • Easy debug business logic in your application, because you can split exceptions in your own classes and exceptions from a third party libraries,

  • Reduce code to catch checked exception in your business (if you need),

3. Atoms-Facade

4. Atoms with one Entry point (Molecule)

In progress

In progress

6. Polymorphic Atom

In progress

7. Join Atom

In progress

8. Repeat-Join Atom

In progress

FAQs

Package last updated on 01 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts