Commit 39105d6b authored by Arthur Bogaart's avatar Arthur Bogaart Committed by Bert Leunis

CMS-11897 Add javadoc

(cherry picked from commit 9d0f7d8f)
parent ed8772d4
......@@ -19,10 +19,37 @@ import java.io.IOException;
import java.io.Serializable;
import java.util.List;
/**
* Processes HTML that is meant to be read from or written to the repository. It can be used to fix malformed HTML,
* remove unwanted elements and attributes, and transform elements into a representation needed by the CMS, e.g. images
* and internal links.
*
* The process applied is:
*
* 1. Parse HTML into DOM tree
* 2. Apply visitors to DOM tree
* 3. Serialize DOM tree as string
*/
public interface HtmlProcessor extends Serializable {
/**
* Process stored HTML.
*
* @param html The stored HTML
* @param visitors Visitors applied to the DOM tree
* @return Processed HTML
* @throws IOException when the DOM tree cannot be serialized
*/
String read(final String html, final List<TagVisitor> visitors) throws IOException;
/**
* Process HTML to store.
*
* @param html The HTML to be stored
* @param visitors Visitors applied to the DOM tree
* @return Processed HTML
* @throws IOException when the DOM tree cannot be serialized
*/
String write(final String html, final List<TagVisitor> visitors) throws IOException;
}
......@@ -17,11 +17,14 @@ package org.onehippo.cms7.services.htmlprocessor;
import org.onehippo.cms7.services.SingletonService;
/**
* Looks up {@link HtmlProcessor} instances.
*/
@SingletonService
public interface HtmlProcessorService {
/**
* Returns instance of HtmlProcessor or null if the configuration cannot be found
* Returns instance of {@link HtmlProcessor} or null if the configuration cannot be found
* @param id The HTML processor id
* @return Instance of HTML processor
*/
......
......@@ -15,6 +15,9 @@
*/
package org.onehippo.cms7.services.htmlprocessor;
/**
* Represents a DOM element, i.e. a node name with attributes.
*/
public interface Tag {
String getName();
......
......@@ -16,13 +16,31 @@
package org.onehippo.cms7.services.htmlprocessor;
import java.io.Serializable;
import java.util.List;
import javax.jcr.RepositoryException;
/**
* Visits {@link Tag}s that are part of a DOM tree.
*/
public interface TagVisitor extends Serializable {
/**
* Called by {@link HtmlProcessor#read(String, List)} for each {@link Tag} in the DOM tree.
*
* @param parent The parent of the tag parameter, or null if the tag is the root node of the DOM tree
* @param tag The visited tag
* @throws RepositoryException when an error occurred. Visiting will continue for the other tags.
*/
void onRead(Tag parent, Tag tag) throws RepositoryException;
/**
* Called by {@link HtmlProcessor#write(String, List)} for each {@link Tag} in the DOM tree.
*
* @param parent The parent of the tag parameter, or null if the tag is the root node of the DOM tree
* @param tag The visited tag
* @throws RepositoryException when an error occurred. Visiting will continue for the other tags.
*/
void onWrite(Tag parent, Tag tag) throws RepositoryException;
void release();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment