-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathhtml_2_text.sql
More file actions
87 lines (73 loc) · 2.82 KB
/
html_2_text.sql
File metadata and controls
87 lines (73 loc) · 2.82 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-- select pkg_html.to_text(testo) from api_msg_messages
-- where user_id = '1122530'
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED HTML as import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import java.io.*;
import java.io.File;
import java.security.AccessControlException;
import java.sql.*;
import oracle.sql.driver.*;
import oracle.sql.*;
public class HTML extends Object
{
private static CLOB outCLOB;
private static String retVal;
private static int i;
private static String p_in;
public static CLOB to_text(CLOB p_ins)
throws IOException, BadLocationException, AccessControlException, SQLException {
if (p_ins == null)
{
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
outCLOB = CLOB.createTemporary((oracle.jdbc.OracleConnectionWrapper) conn, true, CLOB.DURATION_SESSION);
i = outCLOB.setString(1, "");
return outCLOB;
}
p_in = clobToString(p_ins).trim();
if (p_in != null) {
HTMLEditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
kit.read(new StringReader(p_in), doc, 0);
retVal = doc.getText(0, doc.getLength());
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
outCLOB = CLOB.createTemporary((oracle.jdbc.OracleConnectionWrapper) conn, true, CLOB.DURATION_SESSION);
i = outCLOB.setString(1, retVal);
return outCLOB;
} else
{
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
outCLOB = CLOB.createTemporary((oracle.jdbc.OracleConnectionWrapper) conn, true, CLOB.DURATION_SESSION);
i = outCLOB.setString(1, "");
return outCLOB;
}
}
static private String clobToString(java.sql.Clob data) {
final StringBuilder sb = new StringBuilder();
try {
final Reader reader = data.getCharacterStream();
final BufferedReader br = new BufferedReader(reader);
int b;
while (-1 != (b = br.read())) {
sb.append((char) b);
}
br.close();
} catch (SQLException e) {
return e.toString();
} catch (IOException e) {
return e.toString();
}
return sb.toString();
}
}
/
CREATE OR REPLACE PACKAGE pkg_html
IS
FUNCTION to_text ( html_in IN CLOB )
RETURN CLOB
IS
language java
name 'HTML.to_text( oracle.sql.CLOB ) return oracle.sql.CLOB';
END pkg_html;
/