Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
String csv = "...";
|
||||
// Use Collectors.joining(...) for streaming, otherwise StringJoiner
|
||||
StringBuilder html = new StringBuilder("<table>\n");
|
||||
Collector collector = Collectors.joining("</td><td>", " <tr><td>", "</td></tr>\n");
|
||||
for (String row : csv.split("\n") ) {
|
||||
html.append(Arrays.stream(row.split(",")).collect(collector));
|
||||
}
|
||||
html.append("</table>\n");
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
|
||||
class Csv2Html {
|
||||
|
||||
public static String escapeChars(String lineIn) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int lineLength = lineIn.length();
|
||||
for (int i = 0; i < lineLength; i++) {
|
||||
char c = lineIn.charAt(i);
|
||||
switch (c) {
|
||||
case '"':
|
||||
sb.append(""");
|
||||
break;
|
||||
case '&':
|
||||
sb.append("&");
|
||||
break;
|
||||
case '\'':
|
||||
sb.append("'");
|
||||
break;
|
||||
case '<':
|
||||
sb.append("<");
|
||||
break;
|
||||
case '>':
|
||||
sb.append(">");
|
||||
break;
|
||||
default: sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void tableHeader(PrintStream ps, String[] columns) {
|
||||
ps.print("<tr>");
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
ps.print("<th>");
|
||||
ps.print(columns[i]);
|
||||
ps.print("</th>");
|
||||
}
|
||||
ps.println("</tr>");
|
||||
}
|
||||
|
||||
public static void tableRow(PrintStream ps, String[] columns) {
|
||||
ps.print("<tr>");
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
ps.print("<td>");
|
||||
ps.print(columns[i]);
|
||||
ps.print("</td>");
|
||||
}
|
||||
ps.println("</tr>");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
boolean withTableHeader = (args.length != 0);
|
||||
|
||||
InputStreamReader isr = new InputStreamReader(System.in);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
PrintStream stdout = System.out;
|
||||
|
||||
stdout.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
|
||||
stdout.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
|
||||
stdout.println("<head><meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\"/>");
|
||||
stdout.println("<title>Csv2Html</title>");
|
||||
stdout.println("<style type=\"text/css\">");
|
||||
stdout.println("body{background-color:#FFF;color:#000;font-family:OpenSans,sans-serif;font-size:10px;}");
|
||||
stdout.println("table{border:0.2em solid #2F6FAB;border-collapse:collapse;}");
|
||||
stdout.println("th{border:0.15em solid #2F6FAB;padding:0.5em;background-color:#E9E9E9;}");
|
||||
stdout.println("td{border:0.1em solid #2F6FAB;padding:0.5em;background-color:#F9F9F9;}</style>");
|
||||
stdout.println("</head><body><h1>Csv2Html</h1>");
|
||||
|
||||
stdout.println("<table>");
|
||||
String stdinLine;
|
||||
boolean firstLine = true;
|
||||
while ((stdinLine = br.readLine()) != null) {
|
||||
String[] columns = escapeChars(stdinLine).split(",");
|
||||
if (withTableHeader == true && firstLine == true) {
|
||||
tableHeader(stdout, columns);
|
||||
firstLine = false;
|
||||
} else {
|
||||
tableRow(stdout, columns);
|
||||
}
|
||||
}
|
||||
stdout.println("</table></body></html>");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
|
||||
<title>Csv2Html</title>
|
||||
<style type="text/css">
|
||||
body{background-color:#FFF;color:#000;font-family:OpenSans,sans-serif;font-size:10px;}
|
||||
table{border:0.2em solid #2F6FAB;border-collapse:collapse;}
|
||||
th{border:0.15em solid #2F6FAB;padding:0.5em;background-color:#E9E9E9;}
|
||||
td{border:0.1em solid #2F6FAB;padding:0.5em;background-color:#F9F9F9;}</style>
|
||||
</head><body><h1>Csv2Html</h1>
|
||||
<table>
|
||||
<tr><td>Character</td><td>Speech</td></tr>
|
||||
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
|
||||
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
|
||||
<tr><td>The multitude</td><td>Who are you?</td></tr>
|
||||
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
|
||||
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
|
||||
</table></body></html>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
|
||||
<title>Csv2Html</title>
|
||||
<style type="text/css">
|
||||
body{background-color:#FFF;color:#000;font-family:OpenSans,sans-serif;font-size:10px;}
|
||||
table{border:0.2em solid #2F6FAB;border-collapse:collapse;}
|
||||
th{border:0.15em solid #2F6FAB;padding:0.5em;background-color:#E9E9E9;}
|
||||
td{border:0.1em solid #2F6FAB;padding:0.5em;background-color:#F9F9F9;}</style>
|
||||
</head><body><h1>Csv2Html</h1>
|
||||
<table>
|
||||
<tr><th>Character</th><th>Speech</th></tr>
|
||||
<tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr>
|
||||
<tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr>
|
||||
<tr><td>The multitude</td><td>Who are you?</td></tr>
|
||||
<tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr>
|
||||
<tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr>
|
||||
</table></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue