Fix bug on empty html body
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115920 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e8a2253fe8
commit
c768d40496
@ -34,8 +34,8 @@ import org.dom4j.Node;
|
|||||||
* A simple bean for converting a HTML document into an XDoc compliant XML
|
* A simple bean for converting a HTML document into an XDoc compliant XML
|
||||||
* document.
|
* document.
|
||||||
* This could be done via XSLT but is a little more complex than it might first
|
* This could be done via XSLT but is a little more complex than it might first
|
||||||
* appear so its done via Java code instead.
|
* appear so its done via Java code instead.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
|
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
|
||||||
*/
|
*/
|
||||||
public class Html2XdocBean {
|
public class Html2XdocBean {
|
||||||
@ -75,7 +75,7 @@ public class Html2XdocBean {
|
|||||||
/**
|
/**
|
||||||
* Converts the given HTML document into the corresponding XDoc format
|
* Converts the given HTML document into the corresponding XDoc format
|
||||||
* of XML
|
* of XML
|
||||||
*
|
*
|
||||||
* @param html the input html document
|
* @param html the input html document
|
||||||
* @return Document
|
* @return Document
|
||||||
*/
|
*/
|
||||||
@ -100,9 +100,9 @@ public class Html2XdocBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterates thorugh the given body looking for h1, h2, h3 nodes and
|
* Iterates thorugh the given body looking for h1, h2, h3 nodes and
|
||||||
* creating the associated section elements. Any text nodes
|
* creating the associated section elements. Any text nodes
|
||||||
* contained inside the body are wrapped in a <p> element
|
* contained inside the body are wrapped in a <p> element
|
||||||
*
|
*
|
||||||
* @param output the output destination
|
* @param output the output destination
|
||||||
* @param body the block of HTML markup to convert
|
* @param body the block of HTML markup to convert
|
||||||
*/
|
*/
|
||||||
@ -140,10 +140,10 @@ public class Html2XdocBean {
|
|||||||
/**
|
/**
|
||||||
* Specifies whether the node is a text modifying construct that should be
|
* Specifies whether the node is a text modifying construct that should be
|
||||||
* passed as is to the resultant html. Such as an anchor '<a>'.
|
* passed as is to the resultant html. Such as an anchor '<a>'.
|
||||||
*
|
*
|
||||||
* @param node the node to check
|
* @param node the node to check
|
||||||
* @return true if the node is used to modify the formatting of the
|
* @return true if the node is used to modify the formatting of the
|
||||||
* text; otherwise, false
|
* text; otherwise, false
|
||||||
*/
|
*/
|
||||||
protected boolean isTextFormatting(Node node) {
|
protected boolean isTextFormatting(Node node) {
|
||||||
// Ultimately this needs bold, italic, and so on
|
// Ultimately this needs bold, italic, and so on
|
||||||
@ -151,9 +151,9 @@ public class Html2XdocBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether the node is character data and should be passed as
|
* Specifies whether the node is character data and should be passed as
|
||||||
* straight text to the resultant html.
|
* straight text to the resultant html.
|
||||||
*
|
*
|
||||||
* @param node the node to check
|
* @param node the node to check
|
||||||
* @return true if the node is a text node; otherwise, false.
|
* @return true if the node is a text node; otherwise, false.
|
||||||
*/
|
*/
|
||||||
@ -164,7 +164,7 @@ public class Html2XdocBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether the node is a heading node.
|
* Specifies whether the node is a heading node.
|
||||||
*
|
*
|
||||||
* @param node the node to check
|
* @param node the node to check
|
||||||
* @return true if the given node is a heading element
|
* @return true if the given node is a heading element
|
||||||
* (h1, h2, h3 etc); otherwise, false
|
* (h1, h2, h3 etc); otherwise, false
|
||||||
@ -176,7 +176,7 @@ public class Html2XdocBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the heading level of the node.
|
* Determines the heading level of the node.
|
||||||
*
|
*
|
||||||
* @param node the node to check
|
* @param node the node to check
|
||||||
* @return the integer level of the heading
|
* @return the integer level of the heading
|
||||||
*/
|
*/
|
||||||
@ -192,7 +192,7 @@ public class Html2XdocBean {
|
|||||||
/**
|
/**
|
||||||
* Creates a section or subsection as necessary based on the node
|
* Creates a section or subsection as necessary based on the node
|
||||||
* for the output document.
|
* for the output document.
|
||||||
*
|
*
|
||||||
* @param output the output document to attach the section
|
* @param output the output document to attach the section
|
||||||
* @param node the node to base making a section on
|
* @param node the node to base making a section on
|
||||||
*/
|
*/
|
||||||
@ -233,7 +233,7 @@ public class Html2XdocBean {
|
|||||||
* Determines if a new section is needed which is based on whether
|
* Determines if a new section is needed which is based on whether
|
||||||
* the node's a heading level and equal to or less than the current
|
* the node's a heading level and equal to or less than the current
|
||||||
* section's heading level.
|
* section's heading level.
|
||||||
*
|
*
|
||||||
* @param node the node to check
|
* @param node the node to check
|
||||||
* @return true if the current node's information means for a new
|
* @return true if the current node's information means for a new
|
||||||
* section; otherwise, false
|
* section; otherwise, false
|
||||||
@ -314,7 +314,7 @@ public class Html2XdocBean {
|
|||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
protected List getBodyContent(List content) {
|
protected List getBodyContent(List content) {
|
||||||
// lets turn <pre> into <source> and concatenate consective entries
|
// lets turn <pre> into <source> and concatenate consective entries
|
||||||
Element lastPre = null;
|
Element lastPre = null;
|
||||||
LinkedList list = new LinkedList();
|
LinkedList list = new LinkedList();
|
||||||
boolean lastWasElement = true;
|
boolean lastWasElement = true;
|
||||||
@ -342,6 +342,8 @@ public class Html2XdocBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (list.size() == 0) return list;
|
||||||
|
|
||||||
// now lets remove any whitespace text nodes at the beginning and end
|
// now lets remove any whitespace text nodes at the beginning and end
|
||||||
while (true) {
|
while (true) {
|
||||||
Node node = (Node) list.getFirst();
|
Node node = (Node) list.getFirst();
|
||||||
@ -376,7 +378,7 @@ public class Html2XdocBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param node the node to check
|
* @param node the node to check
|
||||||
* @return true if the given node is a whitespace text node
|
* @return true if the given node is a whitespace text node
|
||||||
*/
|
*/
|
||||||
protected boolean isWhitespace(Node node) {
|
protected boolean isWhitespace(Node node) {
|
||||||
if (node instanceof CharacterData) {
|
if (node instanceof CharacterData) {
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<body>
|
<body>
|
||||||
<release version="1.3.1-SNAPSHOT" date="in CVS">
|
<release version="1.3.1-SNAPSHOT" date="in CVS">
|
||||||
|
<action dev="dion" type="fix">Fix crash with an empty html body element.</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="1.3" date="2004-05-15">
|
<release version="1.3" date="2004-05-15">
|
||||||
<action dev="dion" type="fix">Fix issues with DOM classes and jdk1.3</action>
|
<action dev="dion" type="fix">Fix issues with DOM classes and jdk1.3</action>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user