...
 
Commits (2)
......@@ -7,12 +7,22 @@ import j2html.TagCreator;
import j2html.tags.ContainerTag;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;
@RestController
@RequestMapping("/v1")
......@@ -36,7 +46,10 @@ public class Example {
TagCreator.title("Ezyness")),
TagCreator.body().
with(
TagCreator.p(new Ezyness().greetings()).
TagCreator.a(new Ezyness().greetings()).
withHref("/").
attr("target", "_blank").
attr("style",
"color:green;font-size:30px;")).
attr("style",
......@@ -49,19 +62,56 @@ public class Example {
@RequestMapping("/home")
public @ResponseBody ResponseEntity<String> home() {
String html = new ResourceFile("file:public/home.html").
getContent();
if (html == null) {
String html = null;
try {
html = new ResourceFile("/public/home.html").
getContent();
Document doc = Jsoup.parse(html);
Element bts = doc.getElementById("buildTimeStamp");
if (bts.hasText()) {
bts.text(mangle(bts.text()));
}
html = doc.toString();
} catch (Exception e) {
ContainerTag page = TagCreator.html().with(
TagCreator.head(),
TagCreator.body().with(
TagCreator.p("Can't find resource 'home.html'")));
TagCreator.p("ERROR 'home.html'")));
html = page.renderFormatted();
} else {
Document doc = Jsoup.parse(html);
}
System.out.println(html);
return new ResponseEntity<String>(html,
HttpStatus.OK); }
HttpStatus.OK);
}
@Autowired
private Environment env;
private String mangle(String text) {
StringBuffer buffer = new StringBuffer();
{
Scanner scanner = new Scanner(text);
final String delimiter = " ";
scanner.useDelimiter(delimiter);
Pattern pattern = Pattern.compile("%[A-Za-z]*");
while (scanner.hasNext()) {
if (scanner.hasNext(pattern)) {
String variable = scanner.next();
String value = env.getProperty(
variable.substring(1));
if (value == null) {
buffer.append(variable);
} else {
buffer.append(value);
}
} else {
String token = scanner.next();
buffer.append(token);
}
buffer.append(delimiter);
}
scanner.close();
}
return buffer.toString();
}
}
package application.rest.v1;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
......
management.endpoints.web.base-path=/
version=2.4
date=1st April
V2.4 snapshot 26/01-16h44
\ No newline at end of file
......@@ -14,14 +14,18 @@
<div class="cloud-header"></div>
<h1>Congratulations!</h1>
<center>
<embed
src="buildTimeStamp.txt">
<embed>
<text id="buildTimeStamp"
style="color:blue;font-style:italic;font-weight:bold">
%version Snapshot %date
</text>
</embed>
</center>
<h2>You are currently running a Spring server built for the IBM Cloud.</h2>
</header>
<main>
<ul>
<li>
<div class="right-arrow"></div>
<div>
......@@ -64,10 +68,9 @@
</div>
</li>
</ul>
<a target="_blank" href="/v1/ezyness">
<img style="display:block; margin-left:auto; margin-right:auto"
width="15%" height="auto" src="logoEzyness.png">
</ul>
<a target="_blank" href="/v1/ezyness">
<img style="display:block; margin-left:auto; margin-right:auto" width="15%" height="auto" src="/logoEzyness.png">
</a>
</main>
</body>
......
This diff is collapsed.