Browse code

initial import

bcolombi authored on 25/01/2016 11:27:31
Showing 16 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
1
+/target/
2
+/.settings/
0 3
\ No newline at end of file
1 4
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+# Source code
2
+
3
+The MIT License (MIT)
4
+
5
+Copyright (c) 2016 devnewton <devnewton@bci.im>
6
+
7
+Permission is hereby granted, free of charge, to any person obtaining a copy
8
+of this software and associated documentation files (the "Software"), to deal
9
+in the Software without restriction, including without limitation the rights
10
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+copies of the Software, and to permit persons to whom the Software is
12
+furnished to do so, subject to the following conditions:
13
+
14
+The above copyright notice and this permission notice shall be included in
15
+all copies or substantial portions of the Software.
16
+
17
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+THE SOFTWARE.
24
+
25
+# Data
26
+
27
+## favicon.png
28
+
29
+License: this is a free work, you can copy, distribute, and modify it under the terms of the Free Art License 1.3 (FAL1.3.txt file).
30
+Authors: Geeky Goblin Productions (http://geekygoblin.org/), devnewton <devnewton@bci.im>
0 31
\ No newline at end of file
1 32
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+# a2html
2
+
3
+a2html is a KISS converter from text to ascii html powered by java and spring boot.
4
+
5
+## Build, run and deploy manually
6
+
7
+### Skill check
8
+
9
+Please note that a thorough knowledge of Java web application development and hosting is required.
10
+
11
+### Requirements
12
+
13
+- JDK 7+
14
+- Maven 3+
15
+
16
+### Build
17
+
18
+    mvn package
19
+
20
+### Run locally
21
+
22
+Run:
23
+
24
+    java -jar target/a2html-*.jar
25
+
26
+The frontend is now accessible on [locahost:8080](http://localhost:8080).
27
+
28
+### Deploy and hosting on a production server
29
+
30
+There is several options to deploy and host a2html. Here is one that requires:
31
+
32
+- a domain name (example: mydomain.me).
33
+- a web server with http proxy capabilities (example [Cherokee](http://cherokee-project.com/)).
34
+
35
+#### Deployment
36
+
37
+1. Build and launch a2html on the server.
38
+2. Configure your web server to act as reverse proxy on http://localhost:8080
0 39
new file mode 100644
... ...
@@ -0,0 +1,66 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+	<parent>
6
+		<groupId>org.springframework.boot</groupId>
7
+		<artifactId>spring-boot-starter-parent</artifactId>
8
+		<version>1.3.1.RELEASE</version>
9
+	</parent>
10
+	<artifactId>a2html</artifactId>
11
+	<groupId>im.bci</groupId>
12
+	<name>a2html</name>
13
+	<description>convert text to ascii html</description>
14
+	<version>1.0-SNAPSHOT</version>
15
+	<url>http://devnewton.bci.im</url>
16
+	<properties>
17
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
19
+	</properties>
20
+	<dependencies>
21
+		<dependency>
22
+			<groupId>org.springframework.boot</groupId>
23
+			<artifactId>spring-boot-starter</artifactId>
24
+		</dependency>
25
+		<dependency>
26
+			<groupId>pl.allegro.tech.boot</groupId>
27
+			<artifactId>handlebars-spring-boot-starter</artifactId>
28
+			<version>0.2.8</version>
29
+		</dependency>
30
+		<dependency>
31
+			<groupId>org.jsoup</groupId>
32
+			<artifactId>jsoup</artifactId>
33
+			<version>1.8.3</version>
34
+		</dependency>
35
+		<dependency>
36
+			<groupId>org.webjars</groupId>
37
+			<artifactId>jquery</artifactId>
38
+			<version>3.0.0-alpha1</version>
39
+		</dependency>
40
+	</dependencies>
41
+	<build>
42
+		<resources>
43
+			<resource>
44
+				<directory>src/main/resources</directory>
45
+				<filtering>false</filtering>
46
+				<includes>
47
+					<include>**/*.html</include>
48
+					<include>**/*.properties</include>
49
+					<include>**/*.xml</include>
50
+					<include>**/*.js</include>
51
+					<include>**/*.css</include>
52
+					<include>**/*.png</include>
53
+				</includes>
54
+			</resource>
55
+		</resources>
56
+		<plugins>
57
+			<plugin>
58
+				<groupId>org.springframework.boot</groupId>
59
+				<artifactId>spring-boot-maven-plugin</artifactId>
60
+				<configuration>
61
+					<mainClass>im.bci.a2html.A2htmlApplication</mainClass>
62
+				</configuration>
63
+			</plugin>
64
+		</plugins>
65
+	</build>
66
+</project>
0 67
new file mode 100644
... ...
@@ -0,0 +1,32 @@
1
+package im.bci.a2html;
2
+
3
+import org.springframework.boot.CommandLineRunner;
4
+import org.springframework.boot.SpringApplication;
5
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
6
+import org.springframework.context.annotation.Bean;
7
+import org.springframework.context.annotation.ComponentScan;
8
+import org.springframework.context.annotation.Configuration;
9
+import org.springframework.web.filter.CharacterEncodingFilter;
10
+
11
+@Configuration
12
+@EnableAutoConfiguration
13
+@ComponentScan
14
+public class A2htmlApplication implements CommandLineRunner {
15
+
16
+    @Override
17
+    public void run(String... args) throws Exception {
18
+        System.out.println("Launch passgrid.");
19
+    }
20
+
21
+    @Bean
22
+    CharacterEncodingFilter characterEncodingFilter() {
23
+        CharacterEncodingFilter filter = new CharacterEncodingFilter();
24
+        filter.setEncoding("UTF-8");
25
+        filter.setForceEncoding(true);
26
+        return filter;
27
+    }
28
+
29
+    public static void main(String[] args) throws Exception {
30
+        SpringApplication.run(A2htmlApplication.class, args);
31
+    }
32
+}
0 33
new file mode 100644
... ...
@@ -0,0 +1,27 @@
1
+package im.bci.a2html.controllers;
2
+
3
+import org.jsoup.Jsoup;
4
+import org.jsoup.nodes.Document.OutputSettings;
5
+import org.jsoup.nodes.Entities.EscapeMode;
6
+import org.jsoup.safety.Whitelist;
7
+import org.springframework.ui.Model;
8
+import org.springframework.web.bind.annotation.RequestMapping;
9
+import org.springframework.web.bind.annotation.RequestMethod;
10
+import org.springframework.web.bind.annotation.RestController;
11
+
12
+import im.bci.a2html.frontend.ConvertMV;
13
+import im.bci.a2html.frontend.ConvertRQ;
14
+
15
+@RestController
16
+@RequestMapping("/ajax")
17
+public class A2htmlAjaxController {
18
+
19
+    @RequestMapping(value = "/convert", method = RequestMethod.POST)
20
+    public ConvertMV convert(ConvertRQ rq, Model model) {
21
+        ConvertMV mv = new ConvertMV();
22
+        String cleaned = Jsoup.clean(rq.getText(), "", Whitelist.basic(), new OutputSettings().prettyPrint(false).escapeMode(EscapeMode.extended).charset("ASCII"));
23
+        mv.setConvertedText(cleaned);
24
+        return mv;
25
+    }
26
+
27
+}
0 28
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+package im.bci.a2html.controllers;
2
+
3
+import org.springframework.stereotype.Controller;
4
+import org.springframework.ui.Model;
5
+import org.springframework.web.bind.annotation.RequestMapping;
6
+
7
+@Controller
8
+@RequestMapping("/")
9
+public class A2htmlController {
10
+
11
+    @RequestMapping("")
12
+    public String index(Model model) {
13
+        return "index";
14
+    }
15
+}
0 16
new file mode 100644
... ...
@@ -0,0 +1,47 @@
1
+package im.bci.a2html.controllers;
2
+
3
+import java.util.Map;
4
+import javax.servlet.http.HttpServletRequest;
5
+import javax.servlet.http.HttpServletResponse;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.boot.autoconfigure.web.ErrorAttributes;
8
+import org.springframework.boot.autoconfigure.web.ErrorController;
9
+import org.springframework.stereotype.Controller;
10
+import org.springframework.ui.Model;
11
+import org.springframework.web.bind.annotation.RequestMapping;
12
+import org.springframework.web.context.request.RequestAttributes;
13
+import org.springframework.web.context.request.ServletRequestAttributes;
14
+
15
+import im.bci.a2html.frontend.ErrorMV;
16
+
17
+/**
18
+ *
19
+ * @author devnewton
20
+ */
21
+@Controller
22
+public class CustomErrorController implements ErrorController {
23
+    
24
+    @Autowired
25
+    private ErrorAttributes errorAttributes;
26
+
27
+    @RequestMapping(value = "/error")
28
+    public String error(Model model, HttpServletRequest request, HttpServletResponse response) {
29
+        model.addAttribute("error", buildErrorMV(request, response));
30
+        return "error";
31
+    }
32
+
33
+    public ErrorMV buildErrorMV(HttpServletRequest request, HttpServletResponse response) {
34
+        return new ErrorMV(response.getStatus(), getErrorAttributes(request, true));
35
+    }
36
+
37
+    private Map<String, Object> getErrorAttributes(HttpServletRequest request, boolean includeStackTrace) {
38
+        RequestAttributes requestAttributes = new ServletRequestAttributes(request);
39
+        return errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace);
40
+    }
41
+
42
+    @Override
43
+    public String getErrorPath() {
44
+        return "error";
45
+    }
46
+
47
+}
0 48
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+package im.bci.a2html.frontend;
2
+
3
+import java.io.Serializable;
4
+
5
+public class ConvertMV implements Serializable{
6
+
7
+    private static final long serialVersionUID = 1L;
8
+
9
+    private String convertedText;
10
+
11
+    public String getConvertedText() {
12
+        return convertedText;
13
+    }
14
+
15
+    public void setConvertedText(String convertedText) {
16
+        this.convertedText = convertedText;
17
+    }
18
+}
0 19
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+package im.bci.a2html.frontend;
2
+
3
+import java.io.Serializable;
4
+
5
+public class ConvertRQ implements Serializable {
6
+
7
+    private static final long serialVersionUID = 1L;
8
+    private String text;
9
+
10
+    public String getText() {
11
+        return text;
12
+    }
13
+
14
+    public void setText(String text) {
15
+        this.text = text;
16
+    }
17
+
18
+}
0 19
new file mode 100644
... ...
@@ -0,0 +1,68 @@
1
+package im.bci.a2html.frontend;
2
+
3
+import java.util.Map;
4
+
5
+/**
6
+ *
7
+ * @author devnewton
8
+ */
9
+public class ErrorMV {
10
+
11
+    public Integer status;
12
+    public String error;
13
+    public String message;
14
+    public String timeStamp;
15
+    public String trace;
16
+
17
+    public ErrorMV(int status, Map<String, Object> errorAttributes) {
18
+        this.status = status;
19
+        this.error = (String) errorAttributes.get("error");
20
+        this.message = (String) errorAttributes.get("message");
21
+        this.timeStamp = errorAttributes.get("timestamp").toString();
22
+        this.trace = (String) errorAttributes.get("trace");
23
+    }
24
+
25
+    public ErrorMV() {
26
+    }
27
+
28
+    public Integer getStatus() {
29
+        return status;
30
+    }
31
+
32
+    public void setStatus(Integer status) {
33
+        this.status = status;
34
+    }
35
+
36
+    public String getError() {
37
+        return error;
38
+    }
39
+
40
+    public void setError(String error) {
41
+        this.error = error;
42
+    }
43
+
44
+    public String getMessage() {
45
+        return message;
46
+    }
47
+
48
+    public void setMessage(String message) {
49
+        this.message = message;
50
+    }
51
+
52
+    public String getTimeStamp() {
53
+        return timeStamp;
54
+    }
55
+
56
+    public void setTimeStamp(String timeStamp) {
57
+        this.timeStamp = timeStamp;
58
+    }
59
+
60
+    public String getTrace() {
61
+        return trace;
62
+    }
63
+
64
+    public void setTrace(String trace) {
65
+        this.trace = trace;
66
+    }
67
+
68
+}
0 69
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+handlebars.suffix=.html
2
+handlebars.failOnMissingFile=true
3
+handlebars.prettyPrint=true
4
+handlebars.cache=false
5
+
6
+server.port = 361501
7
+
8
+error.whitelabel.enabled=false
9
+
10
+logging.level.org.springframework.web: DEBUG
0 11
\ No newline at end of file
1 12
new file mode 100644
... ...
@@ -0,0 +1,9 @@
1
+$("#convert").click(function() {
2
+	$.ajax({
3
+		url : "/ajax/convert",
4
+		method: "POST",
5
+		data: { text : $("#input").val() }
6
+	}).done(function(data) {
7
+		$("#output").val(data.convertedText);
8
+	})
9
+})
0 10
\ No newline at end of file
1 11
new file mode 100644
2 12
Binary files /dev/null and b/src/main/resources/static/favicon.png differ
3 13
new file mode 100644
... ...
@@ -0,0 +1,39 @@
1
+.passgrid {
2
+    font-family: monospace;
3
+    width: 8cm;
4
+    height: 6cm;
5
+    border-collapse: collapse;
6
+    border: 1px solid black;
7
+    float: left;
8
+    page-break-inside : avoid;
9
+    margin: 2mm;
10
+}
11
+.passgrid th {
12
+    background-color: #CCCCFF;
13
+    font-size: 0.8em;
14
+}
15
+
16
+.passgrid td {
17
+    text-align: center;
18
+    vertical-align: middle;
19
+    border-bottom: dotted 1px black;
20
+}
21
+
22
+.passgrid tbody tr:nth-child(odd) td:nth-child(odd) {
23
+    background-color: #CCCCCC;
24
+}
25
+.passgrid tbody tr:nth-child(even) td:nth-child(even) {
26
+    background-color: #CCCCCC;
27
+}
28
+
29
+nav ul {
30
+    list-style-type: none;;
31
+    display: flex;
32
+    padding: 0;
33
+    margin: 8px;
34
+}
35
+
36
+header {
37
+    display: flex;
38
+    align-items: center;
39
+}
0 40
\ No newline at end of file
1 41
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+<title>a2html</title>
5
+<meta charset="UTF-8">
6
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+<meta name="robots" content="noindex,nofollow">
8
+<link rel="icon" type="image/png" href="/favicon.png">
9
+</head>
10
+<body>
11
+	<label for="input">Input:</label>
12
+	<textarea id="input" rows="20" cols="80"></textarea>
13
+	<input id="convert" type="button" value="Convert">
14
+	<label for="output">Input:</label>
15
+	<textarea id="output" rows="20" cols="80"></textarea>
16
+	<script src="/webjars/jquery/3.0.0-alpha1/jquery.js" defer></script>
17
+	<script src="/a2html.js" defer></script>
18
+</body>
19
+</html>
0 20
\ No newline at end of file