Skip to content

Commit

Permalink
Merge pull request #2 from TheCoder4eu/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
jepsar authored Feb 9, 2018
2 parents f703aef + 56f1d07 commit 92b134c
Show file tree
Hide file tree
Showing 183 changed files with 28,395 additions and 23,721 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ download.xhtml
nbactions.xml
faces-config.NavData
nb-configuration.xml
.idea/
BootsFacesWeb.iml
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: 'war'

//webAppDirName = 'web'

sourceCompatibility = '1.7'
targetCompatibility = '1.7'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
mavenLocal()
Expand Down Expand Up @@ -39,7 +39,7 @@ compile files("${System.properties['java.home']}/../lib/tools.jar")

compile fileTree(dir: 'bsflib', include: '*.jar') //Required for messages/utils

compile "net.bootsfaces:bootsfaces:1.1.2-SNAPSHOT"
compile "net.bootsfaces:bootsfaces:1.2.0"
}

war.doFirst {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Apr 28 16:18:17 CEST 2017
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.bootsfaces</groupId>
<artifactId>BootsFacesWeb</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.1-SNAPSHOT</version>
<name>BootsFacesWeb</name>
<packaging>war</packaging>
<description>Documentation page of BootsFaces</description>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>net.bootsfaces</groupId>
<artifactId>bootsfaces</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.Arrays;
import java.util.List;

public class Admin {
private String id;

private List<AdminSkill> skills = Arrays.asList(new AdminSkill("sleep"), new AdminSkill("work"), new AdminSkill("drink coffee"));

public Admin(String id) {
this.id = id;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public List<AdminSkill> getSkills() {
return skills;
}

public void setSkills(List<AdminSkill> skills) {
this.skills = skills;
}
}
44 changes: 44 additions & 0 deletions src/main/java/AdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class AdminController implements Serializable {
private static final long serialVersionUID = 1L;

private List<Admin> admins = new ArrayList<>();

private Admin selectedAdmin = null;

public AdminController() {
admins.add(new Admin("Hugo"));
admins.add(new Admin("Erwin"));
admins.add(new Admin("Helga"));
}

public List<Admin> getAdmins() {
return admins;
}

public void setAdmins(List<Admin> admins) {
this.admins = admins;
}

public void onSelect(Admin admin) {
this.selectedAdmin = admin;
}

public List<AdminSkill> getAdminSkills() {
if (null == selectedAdmin) {
return new ArrayList<>();
}
return selectedAdmin.getSkills();
}

}


17 changes: 17 additions & 0 deletions src/main/java/AdminSkill.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

public class AdminSkill {
private String id;

public AdminSkill(String id) {
this.id = id;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

}
146 changes: 146 additions & 0 deletions src/main/java/Collector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Collector {

public static void main(String[] args) throws IOException {
scanFolder(new File("src/main/webapp"));
}

public static void scanFolder(File folder) throws IOException {
File[] files = folder.listFiles();
for (File file : files) {
if (file.isDirectory()) {
scanFolder(file);
} else if (file.getName().endsWith(".xhtml")) {
if (!file.getName().endsWith("Attributes.xhtml")) {
String newFile = readFile(file.getAbsolutePath());
if (newFile != null) {
writeFile(file.getAbsolutePath(), newFile);
//System.exit(1);
}
}
}
}
}

public static void writeFile(String filename, String content) throws IOException {
new File(filename).delete();
try (FileWriter fw = new FileWriter(filename); BufferedWriter bw = new BufferedWriter(fw)) {
bw.write(content);
}
}

public static String readFile(String filename) {
Map<String, String> chapters = new HashMap<>();
List<String> tags = new ArrayList<>();
StringBuilder result = new StringBuilder();
String previousLine = "";

try (FileReader fr = new FileReader(filename); BufferedReader br = new BufferedReader(fr)) {
String line;

while ((line = br.readLine()) != null) {
if (line.contains("<ui:define name=\"content-navigator\">")) {
return null;
}
while (line.contains("<h1") && (!line.contains("</h1>"))) {
line = line.trim() + br.readLine().trim();
}
line = examineLine(filename, chapters, tags, previousLine, line, "<h1>");
line = examineLine(filename, chapters, tags, previousLine, line, "<h2>");
line = examineLine(filename, chapters, tags, previousLine, line, "<h3>");
result.append(line);
result.append('\n');
}
} catch (IOException e) {
e.printStackTrace();
}
if (tags.size() > 1) {
int pos = result.indexOf("<ui:define name=\"content\">");
if (pos < 0) {
return null;
}
if (pos > 0) {
pos = result.lastIndexOf("\n", pos);
}
String start = result.substring(0, pos);
String end = result.substring(pos);
StringBuilder navigator = new StringBuilder();
navigator.append("\n\n<ui:define name=\"content-navigator\">\n");
navigator.append(" <b:listLinks>\n");
for (String tag : tags) {
navigator.append(" <b:navLink href=\"#" + tag + "\" value=\"" + chapters.get(tag) + "\" />\n");
}

navigator.append(" </b:listLinks>\n");
navigator.append("</ui:define>\n\n");
System.out.println(filename + ": " + tags.size());
return start + navigator.toString() + end;

}
return null;
}

private static String examineLine(String filename, Map<String, String> chapters, List<String> tags,
String previousLine, String line, String headerTag) {
String newHeaderTag = "<h2>";
if (headerTag.equals("<h1>")) {
newHeaderTag = "<h1>";
}
if (line.contains(headerTag)) {
if (line.contains("<a ")) {
int posh = line.indexOf(headerTag);
int posa = line.indexOf("<a");
if (posa < posh) {
System.out.println("Reorder!" + line);
}
} else if (previousLine.contains("<a ")) {
System.out.println("Previous line contains an anchor! " + line);
} else {
// add the anchor tag
int start = line.indexOf(headerTag) + 4;
int end = line.indexOf("<", start);
if (end < 0) {
System.out.println("Error: " + filename);
}
if (end < start) {
System.out.println("Weird!");
}
String innerText = line.substring(start, end).trim();
if (innerText.length() > 0) {
innerText = innerText.replace("(Virtually no)", "");
int end2 = 0;
while (end2 < innerText.length() && (Character.isLetter(innerText.charAt(end2))
|| Character.isWhitespace(innerText.charAt(end2)) || '&' == innerText.charAt(end2)
|| '/' == innerText.charAt(end2) || ';' == innerText.charAt(end2)
|| ':' == innerText.charAt(end2))) {
end2++;
}
String tag = innerText.substring(0, end2).replace("&lt;", "").replace("&gt;", "").replace(":", "_")
.replace("/", "").toLowerCase();
tag = tag.trim().replace(" ", "_");
if (tag.length() == 0) {
System.out.println("Empty tag?");
} else {
line = line.substring(0, line.indexOf(headerTag)) + newHeaderTag + "<a id=\"" + tag + "\">" + innerText
+ "</a>" + line.substring(end);
line = line.replace("</" + headerTag.substring(1), "</" + newHeaderTag.substring(1));
chapters.put(tag, innerText);
tags.add(tag);
newHeaderTag = "<h2>";
}
}
}
}
return line;
}
}
Loading

0 comments on commit 92b134c

Please sign in to comment.