diff --git a/.gradle/5.4.1/fileChanges/last-build.bin b/.gradle/5.4.1/fileChanges/last-build.bin new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d Binary files /dev/null and b/.gradle/5.4.1/fileChanges/last-build.bin differ diff --git a/.gradle/5.4.1/fileHashes/fileHashes.lock b/.gradle/5.4.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000000000000000000000000000000000000..c0bfcbe3bc122f38fefe12be500f959e40f35b42 Binary files /dev/null and b/.gradle/5.4.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/5.4.1/gc.properties b/.gradle/5.4.1/gc.properties new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.gradle/7.3.1/checksums/checksums.lock b/.gradle/7.3.1/checksums/checksums.lock new file mode 100644 index 0000000000000000000000000000000000000000..55a30675bc5db1a51d5a132dac4f204c2179c758 Binary files /dev/null and b/.gradle/7.3.1/checksums/checksums.lock differ diff --git a/.gradle/7.3.1/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.3.1/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000000000000000000000000000000000000..6d464c756f44452c334b6de70be3b21ba2a779b6 Binary files /dev/null and b/.gradle/7.3.1/dependencies-accessors/dependencies-accessors.lock differ diff --git a/.gradle/7.3.1/dependencies-accessors/gc.properties b/.gradle/7.3.1/dependencies-accessors/gc.properties new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.gradle/7.3.1/fileChanges/last-build.bin b/.gradle/7.3.1/fileChanges/last-build.bin new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d Binary files /dev/null and b/.gradle/7.3.1/fileChanges/last-build.bin differ diff --git a/.gradle/7.3.1/fileHashes/fileHashes.lock b/.gradle/7.3.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000000000000000000000000000000000000..5b0f623fbd28f7343334f10d73967371605654e2 Binary files /dev/null and b/.gradle/7.3.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.1/gc.properties b/.gradle/7.3.1/gc.properties new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000000000000000000000000000000000000..aedd17d8c71ea8d6c41a0fefafa75b1c6cfcd4db Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000000000000000000000000000000000000..b2f59e1106954f904906c190e4e8bfec93e8865b --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Mon Mar 28 08:21:54 CEST 2022 +gradle.version=7.3.1 diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..776bf9262555b22b686214070487a9aec576accd --- /dev/null +++ b/build.gradle @@ -0,0 +1,34 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'java' +apply plugin: 'application' + +mainClassName='com.uca.StartServer' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.freemarker:freemarker:2.3.30' + implementation 'com.sparkjava:spark-core:2.9.3' + implementation 'com.h2database:h2:1.4.200' + compile 'io.jsonwebtoken:jjwt-api:0.11.2' + runtime 'io.jsonwebtoken:jjwt-impl:0.11.2', 'io.jsonwebtoken:jjwt-jackson:0.11.2' + compile 'org.mindrot:jbcrypt:0.4' + compile 'com.fasterxml.jackson.core:jackson-databind:2.11.1' + compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1' +} +test { + useJUnitPlatform() +} + +jar { + manifest { + attributes 'Implementation-Title': 'Gradle Quickstart', + 'Implementation-Version': '1.0.0', + 'Main-Class': 'com.uca.StartServer' + } +} + +sourceSets.main.java.srcDirs = ['src'] +sourceSets.test.java.srcDirs = ['src'] \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..f6b961fd5a86aa5fbfe90f707c3138408be7c718 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..3c0715e704a092397037f1f0a0af3635b014ae22 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Mar 28 08:21:48 CEST 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000000000000000000000000000000000..cccdd3d517fc5249beaefa600691cf150f2fa3e6 --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100755 index 0000000000000000000000000000000000000000..e95643d6a2ca62258464e83c72f5156dc941c609 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/com/uca/StartServer.java b/src/com/uca/StartServer.java new file mode 100644 index 0000000000000000000000000000000000000000..fd9233b2fe6e2199b0eed1341b4670e8a0a37157 --- /dev/null +++ b/src/com/uca/StartServer.java @@ -0,0 +1,23 @@ +package com.uca; + +import com.uca.dao._Initializer; +import com.uca.gui.*; + +import static spark.Spark.*; + +public class StartServer { + + public static void main(String[] args) { + //Configure Spark + staticFiles.location("/static/"); + port(8081); + + + _Initializer.Init(); + + //Defining our routes + get("/users", (req, res) -> { + return UserGUI.getAllUsers(); + }); + } +} \ No newline at end of file diff --git a/src/com/uca/core/UserCore.java b/src/com/uca/core/UserCore.java new file mode 100644 index 0000000000000000000000000000000000000000..7b222bd56a23b8dd18bae481404bf81a02865e39 --- /dev/null +++ b/src/com/uca/core/UserCore.java @@ -0,0 +1,14 @@ +package com.uca.core; + +import com.uca.dao.UserDAO; +import com.uca.entity.UserEntity; + +import java.util.ArrayList; + +public class UserCore { + + public static ArrayList<UserEntity> getAllUsers() { + return new UserDAO().getAllUsers(); + } + +} diff --git a/src/com/uca/dao/UserDAO.java b/src/com/uca/dao/UserDAO.java new file mode 100644 index 0000000000000000000000000000000000000000..9a711b7f445b012591426fd2ed47beabcb5c75e4 --- /dev/null +++ b/src/com/uca/dao/UserDAO.java @@ -0,0 +1,40 @@ +package com.uca.dao; + +import com.uca.entity.UserEntity; + +import java.sql.*; +import java.util.ArrayList; + +public class UserDAO extends _Generic<UserEntity> { + + public ArrayList<UserEntity> getAllUsers() { + ArrayList<UserEntity> entities = new ArrayList<>(); + try { + PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM users ORDER BY id ASC;"); + ResultSet resultSet = preparedStatement.executeQuery(); + while (resultSet.next()) { + UserEntity entity = new UserEntity(); + entity.setId(resultSet.getInt("id")); + entity.setFirstName(resultSet.getString("firstname")); + entity.setLastName(resultSet.getString("lastname")); + + entities.add(entity); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return entities; + } + + @Override + public UserEntity create(UserEntity obj) { + //TODO ! + return null; + } + + @Override + public void delete(UserEntity obj) { + //TODO ! + } +} diff --git a/src/com/uca/dao/_Connector.java b/src/com/uca/dao/_Connector.java new file mode 100644 index 0000000000000000000000000000000000000000..af8ce51ffa035d8562e60dffd51359e44e9c64e2 --- /dev/null +++ b/src/com/uca/dao/_Connector.java @@ -0,0 +1,29 @@ +package com.uca.dao; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class _Connector { + + private static String url = "jdbc:h2:~/test"; + + private static String user = "sa"; + + private static String passwd = ""; + + private static Connection connect; + + public static Connection getInstance(){ + if(connect == null){ + try { + connect = DriverManager.getConnection(url, user, passwd); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return connect; + } + + +} diff --git a/src/com/uca/dao/_Generic.java b/src/com/uca/dao/_Generic.java new file mode 100644 index 0000000000000000000000000000000000000000..3f19e2e3605698a0ab0ba68c42b48abf826e2651 --- /dev/null +++ b/src/com/uca/dao/_Generic.java @@ -0,0 +1,22 @@ +package com.uca.dao; + +import java.sql.Connection; + +public abstract class _Generic<T> { + + public Connection connect = _Connector.getInstance(); + + /** + * Permet de créer une entrée dans la base de données + * par rapport à un objet + * @param obj + */ + public abstract T create(T obj); + + /** + * Permet la suppression d'une entrée de la base + * @param obj + */ + public abstract void delete(T obj); + +} diff --git a/src/com/uca/dao/_Initializer.java b/src/com/uca/dao/_Initializer.java new file mode 100644 index 0000000000000000000000000000000000000000..84fe9861ae5189cc5c438228524b5a5a12d97c2d --- /dev/null +++ b/src/com/uca/dao/_Initializer.java @@ -0,0 +1,28 @@ +package com.uca.dao; + +import java.sql.*; + +public class _Initializer { + + public static void Init(){ + Connection connection = _Connector.getInstance(); + + try { + PreparedStatement statement; + + //Init articles table + statement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS users (id int primary key auto_increment, firstname varchar(100), lastname varchar(100)); "); + statement.executeUpdate(); + + //Todo Remove me ! + statement = connection.prepareStatement("INSERT INTO users(firstname, lastname) VALUES(?, ?);"); + statement.setString(1, "Theodore"); + statement.setString(2, "Muillerez"); + statement.executeUpdate(); + + } catch (Exception e){ + System.out.println(e.toString()); + throw new RuntimeException("could not create database !"); + } + } +} diff --git a/src/com/uca/entity/Eleve.java b/src/com/uca/entity/Eleve.java new file mode 100644 index 0000000000000000000000000000000000000000..155dbc683ccab75dfd4be6eee9e6e95ff3da3b33 --- /dev/null +++ b/src/com/uca/entity/Eleve.java @@ -0,0 +1,6 @@ +package com.uca.entity; + +public class Eleve extends UserEntity +{ + +} diff --git a/src/com/uca/entity/Gomette.java b/src/com/uca/entity/Gomette.java new file mode 100644 index 0000000000000000000000000000000000000000..a8497832815bf904bde1854c46d5a05ef3d5be46 --- /dev/null +++ b/src/com/uca/entity/Gomette.java @@ -0,0 +1,33 @@ +package com.uca.entity; + +import java.sql.Timestamp; + + +public class Gomette +{ + public enum Couleur { Verte, Rouge, Blanc, ArcEnCiel } + + private Couleur couleur; + public Couleur couleur() { return couleur; } + + private String description; + public String description() { return description; } + + private Eleve recipiendaire; + public Eleve recipiendaire() { return recipiendaire; } + + private Prof attribuant; + public Prof attribuant() { return attribuant; } + + private Date date; + public Date date() { return date; } + + public Gomette(Couleur couleur, String description, Eleve recipiendaire, Prof attribuant, Date date) + { + this.couleur = couleur; + this.description = description; + this.recipiendaire = recipiendaire; + this.attribuant = attribuant; + this.date = date; + } +} diff --git a/src/com/uca/entity/Prof.java b/src/com/uca/entity/Prof.java new file mode 100644 index 0000000000000000000000000000000000000000..6e6ee2ea6515af95dd4784d88bf70c878cbe2bac --- /dev/null +++ b/src/com/uca/entity/Prof.java @@ -0,0 +1,6 @@ +package com.uca.entity; + +public class Prof : UserEntity +{ + +} diff --git a/src/com/uca/entity/UserEntity.java b/src/com/uca/entity/UserEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..d68d040e90feb0db956949a74bb92d019866e958 --- /dev/null +++ b/src/com/uca/entity/UserEntity.java @@ -0,0 +1,50 @@ +package com.uca.entity; + +import java.sql.Timestamp; +import java.util.*; + +public class UserEntity { + private String firstName; + private String lastName; + private int id; + private Set<Gomette> gomettes; + + public UserEntity() { + //Ignored ! + load(); + } + + private void load() + { + gomettes = new HashSet<Gomette>(); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public boolean ajouterGomette(Gomette g) + { + return gomettes.add(g); + } +} diff --git a/src/com/uca/gui/UserGUI.java b/src/com/uca/gui/UserGUI.java new file mode 100644 index 0000000000000000000000000000000000000000..86ec18416978fc756e5df2c7678bdcb44ad80689 --- /dev/null +++ b/src/com/uca/gui/UserGUI.java @@ -0,0 +1,30 @@ +package com.uca.gui; + +import com.uca.core.UserCore; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +public class UserGUI { + + public static String getAllUsers() throws IOException, TemplateException { + Configuration configuration = _FreeMarkerInitializer.getContext(); + + Map<String, Object> input = new HashMap<>(); + + input.put("users", UserCore.getAllUsers()); + + Writer output = new StringWriter(); + Template template = configuration.getTemplate("users/users.ftl"); + template.setOutputEncoding("UTF-8"); + template.process(input, output); + + return output.toString(); + } +} diff --git a/src/com/uca/gui/_FreeMarkerInitializer.java b/src/com/uca/gui/_FreeMarkerInitializer.java new file mode 100644 index 0000000000000000000000000000000000000000..10915e46f5c1f53ea1ec21db4dced730cc6e4433 --- /dev/null +++ b/src/com/uca/gui/_FreeMarkerInitializer.java @@ -0,0 +1,21 @@ +package com.uca.gui; + +import com.uca.StartServer; +import freemarker.template.Configuration; +import freemarker.template.TemplateExceptionHandler; + +import java.util.Locale; + +public class _FreeMarkerInitializer { + + public static Configuration getContext() { + //Configure FreeMarker + Configuration configuration = new Configuration(Configuration.VERSION_2_3_30); + configuration.setClassForTemplateLoading(StartServer.class, "/views"); + configuration.setDefaultEncoding("UTF-8"); + configuration.setLocale(Locale.FRANCE); + configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + + return configuration; + } +} diff --git a/src/main/resources/static/style.css b/src/main/resources/static/style.css new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/main/resources/views/users/users.ftl b/src/main/resources/views/users/users.ftl new file mode 100644 index 0000000000000000000000000000000000000000..57c8eb73066d9fdc7676a2dbe5ec057a5be93f5f --- /dev/null +++ b/src/main/resources/views/users/users.ftl @@ -0,0 +1,13 @@ +<#ftl encoding="utf-8"> + +<body xmlns="http://www.w3.org/1999/html"> + +<ul> + <#list users as user> + <li>${user.id} - ${user.firstName} ${user.lastName}</li> + </#list> +</ul> + +</body> + +</html>