| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
package net.sourceforge.pebble.event.blogentry; |
| 33 |
|
|
| 34 |
|
import net.sourceforge.pebble.domain.BlogEntry; |
| 35 |
|
import net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent; |
| 36 |
|
import org.apache.commons.logging.Log; |
| 37 |
|
import org.apache.commons.logging.LogFactory; |
| 38 |
|
import org.w3c.dom.Document; |
| 39 |
|
import org.w3c.tidy.Tidy; |
| 40 |
|
|
| 41 |
|
import java.beans.PropertyChangeEvent; |
| 42 |
|
import java.util.Iterator; |
| 43 |
|
import java.util.List; |
| 44 |
|
import java.io.ByteArrayInputStream; |
| 45 |
|
import java.io.ByteArrayOutputStream; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@author |
| 52 |
|
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 9 |
Complexity Density: 0,32 |
|
| 53 |
|
public class TidyListener extends BlogEntryListenerSupport { |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
private static final Log log = LogFactory.getLog(TidyListener.class); |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@param |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 63 |
0
|
public void blogEntryAdded(BlogEntryEvent event) {... |
| 64 |
0
|
tidy(event.getBlogEntry()); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
@param |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0,57 |
|
| 72 |
0
|
public void blogEntryChanged(BlogEntryEvent event) {... |
| 73 |
0
|
List propertyChangeEvents = event.getPropertyChangeEvents(); |
| 74 |
0
|
Iterator it = propertyChangeEvents.iterator(); |
| 75 |
0
|
while (it.hasNext()) { |
| 76 |
0
|
PropertyChangeEvent pce = (PropertyChangeEvent)it.next(); |
| 77 |
0
|
String property = pce.getPropertyName(); |
| 78 |
0
|
if (property.equals(BlogEntry.EXCERPT_PROPERTY) || |
| 79 |
|
property.equals(BlogEntry.BODY_PROPERTY)) { |
| 80 |
0
|
tidy(event.getBlogEntry()); |
| 81 |
|
} |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 85 |
0
|
private void tidy(BlogEntry blogEntry) {... |
| 86 |
0
|
blogEntry.setExcerpt(tidy(blogEntry.getExcerpt())); |
| 87 |
0
|
blogEntry.setBody(tidy(blogEntry.getBody())); |
| 88 |
|
} |
| 89 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0,17 |
|
| 90 |
0
|
private String tidy(String s) {... |
| 91 |
0
|
if (s != null && s.length() > 0) { |
| 92 |
0
|
s = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + |
| 93 |
|
"<html xmlns=\"http://www.w3.org/1999/xhtml\"><title></title><body>" + s + "</body></html>"; |
| 94 |
0
|
ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes()); |
| 95 |
0
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 96 |
0
|
Tidy tidy = new Tidy(); |
| 97 |
0
|
tidy.setXHTML(true); |
| 98 |
0
|
tidy.setDocType("\"-//W3C//DTD XHTML 1.0 Transitional//EN\""); |
| 99 |
0
|
tidy.setQuiet(true); |
| 100 |
0
|
tidy.setShowWarnings(false); |
| 101 |
0
|
tidy.setIndentContent(false); |
| 102 |
0
|
tidy.setSmartIndent(false); |
| 103 |
0
|
tidy.setIndentAttributes(false); |
| 104 |
0
|
tidy.setWraplen(0); |
| 105 |
0
|
Document doc = tidy.parseDOM(in, null); |
| 106 |
0
|
tidy.pprint(doc, out); |
| 107 |
|
|
| 108 |
0
|
String tidied = new String(out.toByteArray()); |
| 109 |
0
|
return tidied.substring(tidied.indexOf("<body>")+"<body>".length(), tidied.indexOf("</body>")).trim(); |
| 110 |
|
} else { |
| 111 |
0
|
return ""; |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
} |