diff --git a/nb-configuration.xml b/nb-configuration.xml index 2f562e55..a9f9041e 100644 --- a/nb-configuration.xml +++ b/nb-configuration.xml @@ -6,6 +6,7 @@ The configuration is intended to be shared among all the users of project and therefore it is assumed to be part of version control checkout. Without this configuration present, some functionality in the IDE may be limited or fail altogether. --> + + @@ -164,8 +169,8 @@ maven-compiler-plugin 3.13.0 - 1.8 - 1.8 + 11 + 11 -Djava.endorsed.dirs=${endorsed.dir} @@ -298,7 +303,7 @@ - + maven-surefire-plugin 2.22.2 diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/db/AbstractBase.java b/src/main/java/de/uni_tuebingen/ub/nppm/db/AbstractBase.java index 42e5d911..9934d90c 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/db/AbstractBase.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/db/AbstractBase.java @@ -92,6 +92,10 @@ protected static SessionFactory getSessionFactory() throws Exception { settings.put("hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.EhCacheRegionFactory"); settings.put("hibernate.cache.ehcache.missing_cache_strategy", "create"); + // Avoid FetchType.EAGER, automatically create session with FetchType.LAZY if there is none + // Note: This can lead to Performance problems (N+1) + settings.put("hibernate.enable_lazy_load_no_trans", "true"); + configuration.setProperties(settings); // Add all model classes dynamically @@ -127,7 +131,7 @@ protected static Map initTableNameToEntityMap() throws RuntimeExc } public static T getById(int id, Class class_) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { return (T) session.get(class_, id); } } @@ -155,12 +159,12 @@ protected static String getDatabaseName() throws Exception { // For now, we open a new session each time this method is called. // Later, we might try to use a static session similar to the static SessionFactory. - protected static Session getSession() throws Exception { + protected static Session getSession() throws Exception { return getSessionFactory().openSession(); } protected static List getList(Class c, CriteriaQuery criteria) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); if (criteria == null) { criteria = builder.createQuery(c); @@ -175,21 +179,33 @@ protected static List getList(Class c) throws Exception { return getList(c, null); } - public static void remove(Class class_, int id) throws Exception { - try ( Session session = getSession()) { - Transaction transaction = session.getTransaction(); - transaction.begin(); - //Load - Object obj = session.load(class_, id); - //Remove - session.remove(obj); - //Commit - transaction.commit(); + + + protected static void removeHelper(Class class_, int id, Session session) throws Exception { + Object obj = session.load(class_, id); + session.remove(obj); + } + + public static void remove(Class class_, int id) throws Exception { + remove(class_, id, null); + } + + public static void remove(Class class_, int id, Session session) throws Exception { + if (session == null) { + try (Session session2 = getSession()) { + Transaction transaction = session2.getTransaction(); + transaction.begin(); + removeHelper(class_, id, session2); + transaction.commit(); + } + } else { + removeHelper(class_, id, session); } } + public static List getListNative(String sql) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { NativeQuery sqlQuery = session.createNativeQuery(sql); List rows = sqlQuery.getResultList(); return rows; @@ -209,7 +225,7 @@ public static Integer getIntNative(String sql) throws Exception { // This function is needed because if we use getRowNative or getListNative // we will have problems to cast a BigInteger to an Object, so we cast to // Int instead. - try ( Session session = getSession()) { + try (Session session = getSession()) { NativeQuery sqlQuery = session.createNativeQuery(sql); //sqlQuery.setMaxResults(1); List rows = sqlQuery.getResultList(); @@ -222,7 +238,7 @@ public static Integer getIntNative(String sql) throws Exception { } public static String getStringNative(String sql) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { NativeQuery sqlQuery = session.createNativeQuery(sql); //sqlQuery.setMaxResults(1); List rows = sqlQuery.getResultList(); @@ -235,7 +251,7 @@ public static String getStringNative(String sql) throws Exception { } public static List getStringListNative(String sql) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { NativeQuery sqlQuery = session.createNativeQuery(sql); List rows = sqlQuery.getResultList(); return rows; @@ -243,7 +259,7 @@ public static List getStringListNative(String sql) throws Exception { } public static Timestamp getTimestampNative(String sql) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { NativeQuery sqlQuery = session.createNativeQuery(sql); //sqlQuery.setMaxResults(1); List rows = sqlQuery.getResultList(); @@ -295,7 +311,7 @@ protected static void registerParameters(Map conditions, NativeQ } public static void update(String table, Map attributesAndValues, Map andConditions, List specialColumns) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { session.getTransaction().begin(); String sql = "UPDATE " + table + " SET "; @@ -323,7 +339,7 @@ public static void update(String table, Map attributesAndValues, } public static void update(String table, String attribute, String value, Map andConditions) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { session.getTransaction().begin(); String sql = "UPDATE " + table + " SET " + attribute + "= :value"; sql += buildAndConditions(andConditions); @@ -351,7 +367,7 @@ public static String getSingleField(String zielAttribut, String zieltabelle, int } protected static void insertOrUpdate(String sql) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { session.getTransaction().begin(); NativeQuery query = session.createNativeQuery(sql); query.executeUpdate(); @@ -384,7 +400,7 @@ public static List getMappedListString(String query) throws Exception { // Note: If you wanna use this function properly and your query // contains a JOIN, please make sure to provide aliases (using AS) // to be able to access the result columns by key. - try ( Session session = getSession()) { + try (Session session = getSession()) { return getMappedListString(session.createNativeQuery(query)); } } @@ -396,7 +412,7 @@ protected static List getMappedList(Query query) throws Exception { } protected static List getMappedList(CriteriaQuery criteria) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { return getMappedList(session.createQuery(criteria)); } } @@ -405,7 +421,7 @@ public static List getMappedList(String query) throws Exception { // Note: If you wanna use this function properly and your query // contains a JOIN, please make sure to provide aliases (using AS) // to be able to access the result columns by key. - try ( Session session = getSession()) { + try (Session session = getSession()) { return getMappedList(session.createNativeQuery(query)); } } @@ -422,7 +438,7 @@ protected static Map getMappedRow(Query query) throws Exception { } public static Map getMappedRow(String query) throws Exception { - try ( Session session = getSession()) { + try (Session session = getSession()) { return getMappedRow(session.createNativeQuery(query)); } } @@ -476,4 +492,4 @@ public static void verifyDynamicColumn(String column) throws SqlInjectionExcepti throw new SqlInjectionException("Invalid column name: " + column); } } -} +} \ No newline at end of file diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/db/ContentDB.java b/src/main/java/de/uni_tuebingen/ub/nppm/db/ContentDB.java index 4a5d7bd0..428cddbe 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/db/ContentDB.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/db/ContentDB.java @@ -9,29 +9,55 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; import org.hibernate.Session; public class ContentDB extends AbstractBase { - public static void putToDatabase(Content imageContent) throws Exception { - try (Session session = getSession()) { + public static void createHtmlFile(String fileName, Content.Context context, String language) throws Exception { + String htmlTemplate = "Empty HTML"; + byte[] contentBytes = htmlTemplate.getBytes("UTF-8"); + Content content = new Content(fileName, "text/html", contentBytes, context, language); + putToDatabase(content); + + } + + public static void updateHtmlFile(Content content, String newHtmlContent) throws Exception { + String htmlTemplate = newHtmlContent; + byte[] contentBytes = htmlTemplate.getBytes("UTF-8"); + content.setContent(contentBytes); + saveOrUpdate(content); + } + + public static void putToDatabase(Content dataContent) throws Exception { + try ( Session session = getSession()) { session.beginTransaction(); - session.save(imageContent); + session.save(dataContent); session.getTransaction().commit(); } } public static void saveFile(String path, String name, String content_Type, Context context) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { byte[] contentBytes = readBytesFromFile(path); Content content = new Content(name, content_Type, contentBytes, context); putToDatabase(content); } } + //überladet nur zur zeit + public static void saveFile(String path, String name, String content_Type, Context context, String language) throws Exception { + try ( Session session = getSession()) { + byte[] contentBytes = readBytesFromFile(path); + Content content = new Content(name, content_Type, contentBytes, context, language); + putToDatabase(content); + } + } + public static byte[] readBytesFromFile(String filePath) throws Exception { File inputFile = new File(filePath); - try (FileInputStream inputStream = new FileInputStream(inputFile)) { + try ( FileInputStream inputStream = new FileInputStream(inputFile)) { byte[] fileBytes = new byte[(int) inputFile.length()]; inputStream.read(fileBytes); return fileBytes; @@ -43,63 +69,105 @@ public static Content getById(int id) throws Exception { } public static Content getByName(String name) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { + CriteriaBuilder builder = session.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(Content.class); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); + criteria.where(builder.equal(myContent.get(Content_.NAME), name)); + Content content = session.createQuery(criteria).getSingleResult(); + return content; + } + } + + public static Content getFirstResultByName(String name) throws Exception { + try ( Session session = getSession()) { + CriteriaBuilder builder = session.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(Content.class); + Root root = criteria.from(Content.class); + criteria.select(root); + criteria.where(builder.equal(root.get(Content_.NAME), name)); + + List resultList = session.createQuery(criteria).getResultList(); + + if (resultList.isEmpty()) { + return null; + } else if (resultList.size() > 1) { + //Return first result + return resultList.get(0); + } else { + return resultList.get(0); + } + } + } + + public static Content getByNameAndLanguage(String name, String language) throws Exception { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root myImage = criteria.from(Content.class); - criteria.select(myImage); - criteria.where(builder.equal(myImage.get(Content_.NAME), name)); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); + criteria.where( + builder.and( + builder.equal(myContent.get(Content_.NAME), name), + builder.equal(myContent.get(Content_.LANGUAGE), language) + ) + ); + Content content = session.createQuery(criteria).getSingleResult(); return content; } } public static List getList() throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root myImage = criteria.from(Content.class); + Root myContent = criteria.from(Content.class); criteria.getOrderList(); - List images = (List) session.createQuery(criteria).list(); - return images; + List contents = (List) session.createQuery(criteria).list(); + return contents; } } public static List getList(String context) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root myImage = criteria.from(Content.class); - criteria.select(myImage); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); // Filter hinzufügen basierend auf dem übergebenen Kontext if (context != null && !context.isEmpty()) { - criteria.where(builder.equal(myImage.get("context"), Context.valueOf(context))); + criteria.where(builder.equal(myContent.get("context"), Context.valueOf(context))); } - List images = session.createQuery(criteria).getResultList(); - return images; + List contents = session.createQuery(criteria).getResultList(); + return contents; } } - public static void copyPicturesFromDatabaseTableToTempFolder(String outputDirectory) throws Exception { - List pictures = ContentDB.getList(); - for (Content ic : pictures) { + + + // unused function for future use ... + public static void copyContentFromDatabaseTableToTempFolder(String outputDirectory) throws Exception { + List contents = ContentDB.getList(); + for (Content ic : contents) { String name = ic.getName(); String filePathToSave = outputDirectory + name; - byte[] photoBytes = ic.getContent(); - saveBytesToFile(filePathToSave, photoBytes); + byte[] contentBytes = ic.getContent(); + saveBytesToFile(filePathToSave, contentBytes); } } // unused function for future use ... public static void copyHTMLFromDatabaseTableToTempFolder(String outputDirectory, String name) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root myImage = criteria.from(Content.class); - criteria.select(myImage); - criteria.where(builder.equal(myImage.get(Content_.NAME), name)); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); + criteria.where(builder.equal(myContent.get(Content_.NAME), name)); Content content = session.createQuery(criteria).getSingleResult(); String filePathToSave = outputDirectory + name; byte[] HtmlBytes = content.getContent(); @@ -107,72 +175,125 @@ public static void copyHTMLFromDatabaseTableToTempFolder(String outputDirectory, } } + + private static void saveBytesToFile(String filePath, byte[] fileBytes) throws Exception { - try (FileOutputStream outputStream = new FileOutputStream(filePath)) { + try ( FileOutputStream outputStream = new FileOutputStream(filePath)) { outputStream.write(fileBytes); } } public static void deleteById(Integer id) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root myImage = criteria.from(Content.class); - criteria.select(myImage); - criteria.where(builder.equal(myImage.get(Content_.ID), id)); - Content image = session.createQuery(criteria).getSingleResult(); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); + criteria.where(builder.equal(myContent.get(Content_.ID), id)); + Content content = session.createQuery(criteria).getSingleResult(); session.beginTransaction(); - session.delete(image); + session.delete(content); session.getTransaction().commit(); session.close(); } } public static void deleteByName(String name) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root myImage = criteria.from(Content.class); - criteria.select(myImage); - criteria.where(builder.equal(myImage.get(Content_.NAME), name)); - Content image = session.createQuery(criteria).getSingleResult(); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); + criteria.where(builder.equal(myContent.get(Content_.NAME), name)); + Content content = session.createQuery(criteria).getSingleResult(); session.beginTransaction(); - session.delete(image); + session.delete(content); + session.getTransaction().commit(); + } + } + + public static void deleteByNameAndLanguage(String name, String language) throws Exception { + try ( Session session = getSession()) { + CriteriaBuilder builder = session.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(Content.class); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); + criteria.where( + builder.and( + builder.equal(myContent.get(Content_.NAME), name), + builder.equal(myContent.get(Content_.LANGUAGE), language) + ) + ); + Content content = session.createQuery(criteria).getSingleResult(); + session.beginTransaction(); + session.delete(content); session.getTransaction().commit(); } } //Search if name exists in database public static boolean searchName(String name) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { + CriteriaBuilder builder = session.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(Content.class); + Root myContent = criteria.from(Content.class); + criteria.select(myContent); + criteria.where(builder.equal(myContent.get(Content_.NAME), name)); + List contents = (List) session.createQuery(criteria).list(); + return !contents.isEmpty(); + } + } + + //Search if name and language exists in database + public static boolean searchNameAndLanguage(String name, String language) throws Exception { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root picture = criteria.from(Content.class); - criteria.select(picture); - criteria.where(builder.equal(picture.get(Content_.NAME), name)); - List pictures = (List) session.createQuery(criteria).list(); - return !pictures.isEmpty(); + Root content = criteria.from(Content.class); + criteria.select(content); + criteria.where( + builder.and( + builder.equal(content.get(Content_.NAME), name), + builder.equal(content.get(Content_.LANGUAGE), language) + ) + ); + List contents = session.createQuery(criteria).getResultList(); + return !contents.isEmpty(); } } //Search if ID exists in database public static boolean searchId(int id) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Content.class); - Root picture = criteria.from(Content.class); - criteria.select(picture); - criteria.where(builder.equal(picture.get(Content_.ID), id)); - List pictures = (List) session.createQuery(criteria).list(); - return !pictures.isEmpty(); + Root content = criteria.from(Content.class); + criteria.select(content); + criteria.where(builder.equal(content.get(Content_.ID), id)); + List contents = (List) session.createQuery(criteria).list(); + return !contents.isEmpty(); } } public static void saveOrUpdate(Content content) throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { session.getTransaction().begin(); session.saveOrUpdate(content); session.getTransaction().commit(); } } + + public static String getCookieLanguage(HttpServletRequest request) { + Cookie[] cookies = request.getCookies(); + String selectedLanguage = "dontDelete"; // Standardwert, wenn kein Cookie gesetzt ist + if (cookies != null) { + for (Cookie cookie : cookies) { + if (cookie.getName().equals("selectedLanguage")) { + selectedLanguage = cookie.getValue(); + break; + } + } + } + return selectedLanguage; + } } diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/db/EinzelbelegDB.java b/src/main/java/de/uni_tuebingen/ub/nppm/db/EinzelbelegDB.java index 4ed63a8e..641289ea 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/db/EinzelbelegDB.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/db/EinzelbelegDB.java @@ -1,11 +1,18 @@ package de.uni_tuebingen.ub.nppm.db; +import static de.uni_tuebingen.ub.nppm.db.AbstractBase.getSession; import java.util.List; import de.uni_tuebingen.ub.nppm.model.*; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; import org.hibernate.Session; +import org.hibernate.query.NativeQuery; import org.hibernate.query.Query; -public class EinzelbelegDB extends AbstractBase { +public class EinzelbelegDB extends AbstractBase{ public static Einzelbeleg getById(int id) throws Exception { return AbstractBase.getById(id, Einzelbeleg.class); @@ -24,7 +31,7 @@ public static List getListTextKritik() throws Exception { } public static Einzelbeleg getFirstPublicEinzelbeleg() throws Exception { - try (Session session = getSession()) { + try ( Session session = getSession()) { String HQL = "FROM Einzelbeleg WHERE QuelleID IN (SELECT id FROM Quelle WHERE ZuVeroeffentlichen=1) ORDER BY id ASC"; Query query = session.createQuery(HQL).setMaxResults(1); Einzelbeleg einzelbeleg = (Einzelbeleg) query.getSingleResult(); @@ -35,4 +42,32 @@ public static Einzelbeleg getFirstPublicEinzelbeleg() throws Exception { public static void insertBySql(String sql) throws Exception { insertOrUpdate(sql); } + + //gibt eine Liste von Einzelbelege die die gleiche Belegform haben + public static List getListByBelegform(String belegform) { + try ( Session session = getSession()) { + CriteriaBuilder builder = session.getCriteriaBuilder(); + CriteriaQuery criteria = builder.createQuery(Einzelbeleg.class); + Root root = criteria.from(Einzelbeleg.class); + + criteria.select(root) + .where(builder.equal(root.get("belegform"), belegform)); + + Query query = session.createQuery(criteria); + return query.getResultList(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Error retrieving Einzelbeleg list by belegform: " + belegform, e); + } + } + + public static void insertLemma(String einzelbelegId, String mghLemmaId) throws Exception { + String sql = "INSERT INTO einzelbeleg_hatmghlemma(EinzelbelegID, MGHLemmaID) VALUES(" + einzelbelegId + ", " + mghLemmaId + ")"; + insertOrUpdate(sql); + } + + public static void insertNamenkommentar(String einzelbelegId, String namenkommentarId) throws Exception { + String sql = "INSERT INTO einzelbeleg_hatnamenkommentar(EinzelbelegID, NamenkommentarID) VALUES(" + einzelbelegId + ", " + namenkommentarId + ")"; + insertOrUpdate(sql); + } } diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/model/Content.java b/src/main/java/de/uni_tuebingen/ub/nppm/model/Content.java index 8e14ef07..75eb254b 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/model/Content.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/model/Content.java @@ -16,10 +16,10 @@ public class Content { public enum Context { - HILFE, NAMENKOMMENTAR, QUELLENKOMMENTAR, - UEBERLIEFERUNGSKOMMENTAR + UEBERLIEFERUNGSKOMMENTAR, + CMS } @Id @@ -42,6 +42,9 @@ public enum Context { @Column(name = "context", nullable = false) private Context context; + @Column(name = "language", length = 255) + String language; + //Constructors //Default Constructor is neccessary !!! - don delete public Content() { @@ -54,6 +57,15 @@ public Content(String name, String content_Type, byte[] content, Context context this.context = context; } + public Content(String name, String content_Type, byte[] content, Context context, String language) { + this.ID = ID; + this.name = name; + this.content_Type = content_Type; + this.content = content; + this.context = context; + this.language = language; + } + public int getID() { return ID; } @@ -93,4 +105,13 @@ public Context getContext() { public void setContext(Context context) { this.context = context; } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + }//end Class diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/model/Einzelbeleg.java b/src/main/java/de/uni_tuebingen/ub/nppm/model/Einzelbeleg.java index f9282303..2cac30a2 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/model/Einzelbeleg.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/model/Einzelbeleg.java @@ -1,7 +1,12 @@ package de.uni_tuebingen.ub.nppm.model; + import javax.persistence.*; import java.util.*; +import javax.persistence.criteria.*; +import org.hibernate.Session; +import de.uni_tuebingen.ub.nppm.model.*; +import org.hibernate.query.NativeQuery; @Entity @Table(name = "einzelbeleg") @@ -269,6 +274,16 @@ public class Einzelbeleg { ) Set areal = new HashSet<>(); + @ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}) + @JoinTable( + name = "einzelbeleg_hatareal", + joinColumns = { + @JoinColumn(name = "EinzelbelegID")}, + inverseJoinColumns = { + @JoinColumn(name = "ArealTypID")} + ) + Set arealTyp = new HashSet<>(); + @ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}) @JoinTable( name = "einzelbeleg_hatfunktion", @@ -945,6 +960,24 @@ public void removeTitelKritik(int id) { this.getTitelKritiken().removeIf(e -> e.getId() == id); } + public Set getArealTyp() { + return arealTyp; + } + + public void setArealTyp(Set arealTyp) { + this.arealTyp = arealTyp; + } + + public void addArealTyp(SelektionArealTyp selektionArealTyp) { + if (selektionArealTyp != null) { + this.getArealTyp().add(selektionArealTyp); + } + } + + public void removeArealTyp(int id) { + this.getArealTyp().removeIf(e -> e.getId() == id); + } + public Integer getKritikId() { return kritikId; } diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/model/EinzelbelegHatAreal_MM.java b/src/main/java/de/uni_tuebingen/ub/nppm/model/EinzelbelegHatAreal_MM.java new file mode 100644 index 00000000..f0217b80 --- /dev/null +++ b/src/main/java/de/uni_tuebingen/ub/nppm/model/EinzelbelegHatAreal_MM.java @@ -0,0 +1,43 @@ +package de.uni_tuebingen.ub.nppm.model; + +import javax.persistence.*; + +@Entity +@Table(name = "einzelbeleg_hatareal") +public class EinzelbelegHatAreal_MM { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID") + private Integer id; + + @ManyToOne(targetEntity = Einzelbeleg.class) + @JoinColumn(name = "EinzelbelegID", referencedColumnName = "ID") + private Einzelbeleg einzelbeleg; + + @ManyToOne(targetEntity = SelektionAreal.class) + @JoinColumn(name = "ArealID", referencedColumnName = "ID") + private SelektionAreal areal; + + public Integer getId() { + return id; + } + + public Einzelbeleg getEinzelbeleg() { + return einzelbeleg; + } + + public void setEinzelbeleg(Einzelbeleg einzelbeleg) { + this.einzelbeleg = einzelbeleg; + } + + public SelektionAreal getAreal() { + return areal; + } + + public void setAreal(SelektionAreal areal) { + this.areal = areal; + } + + +} diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/model/SelektionArealTyp.java b/src/main/java/de/uni_tuebingen/ub/nppm/model/SelektionArealTyp.java new file mode 100644 index 00000000..a754fba8 --- /dev/null +++ b/src/main/java/de/uni_tuebingen/ub/nppm/model/SelektionArealTyp.java @@ -0,0 +1,23 @@ +package de.uni_tuebingen.ub.nppm.model; + +import javax.persistence.*; +import java.util.*; + +@Entity +@Table(name = "selektion_arealtyp") +public class SelektionArealTyp extends SelektionBezeichnung { + @ManyToMany(mappedBy = "arealTyp") + private Set einzelbelege = new HashSet<>(); + + public void addEinzelbeleg(Einzelbeleg beleg) { + this.getEinzelbelege().add(beleg); + } + + public void removeEinzelbeleg(int id) { + this.getEinzelbelege().removeIf(e -> e.getId() != null && e.getId().equals(id)); + } + + public Set getEinzelbelege() { + return einzelbelege; + } +} diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AbstractServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AbstractServlet.java index 210d4a23..96a49295 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AbstractServlet.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AbstractServlet.java @@ -13,6 +13,9 @@ public abstract class AbstractServlet extends HttpServlet { + protected HttpServletRequest currentRequest; + protected HttpServletResponse currentResponse; + protected void initRequest(HttpServletRequest request) throws Exception { Language.setLanguage(request); } @@ -54,6 +57,11 @@ protected List getAdditionalJavaScript() { abstract protected String getTitle(); + // Methode mit Parametern benoetigt für dynamische Titel angabe bei sharedHtmlServlet + protected String getTitle(HttpServletRequest request, HttpServletResponse response) { + return getTitle(); + } + protected String getNavigationTitle() { return ""; } @@ -65,6 +73,9 @@ protected String getNavigationTitle() { abstract protected String getFooterTemplate(); protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { + + this.currentRequest = request; + this.currentResponse = response; // Since the header is very large using the UB navigation, // we need to increase the buffer size so no packages will be sent // during rendering the navigation. Else it would not be possible to @@ -99,4 +110,4 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doHelper(request, response); } -} +} \ No newline at end of file diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AjaxServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AjaxServlet.java index 1800131f..16eb35fd 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AjaxServlet.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/AjaxServlet.java @@ -1,15 +1,25 @@ package de.uni_tuebingen.ub.nppm.servlet; import de.uni_tuebingen.ub.nppm.db.*; +import de.uni_tuebingen.ub.nppm.model.Einzelbeleg; +import de.uni_tuebingen.ub.nppm.model.EinzelbelegMghLemma_MM; +import de.uni_tuebingen.ub.nppm.model.EinzelbelegNamenkommentar_MM; +import de.uni_tuebingen.ub.nppm.model.MghLemma; +import de.uni_tuebingen.ub.nppm.model.NamenKommentar; +import de.uni_tuebingen.ub.nppm.util.Language; import org.json.*; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class AjaxServlet extends HttpServlet { + protected void autocomplete(HttpServletRequest request, HttpServletResponse response) { try { String query = request.getParameter("query"); @@ -35,6 +45,235 @@ protected void autocomplete(HttpServletRequest request, HttpServletResponse resp } } + protected void detectZusatzNamenKommentar(HttpServletRequest request, HttpServletResponse response) { + try { + String EinzelbelegID = request.getParameter("EinzelbelegID"); + if (EinzelbelegID == null) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + } else { + ArrayList outputList = new ArrayList<>(); + Einzelbeleg lastEinzelbeleg = EinzelbelegDB.getById(Integer.parseInt(EinzelbelegID)); + String belegform = lastEinzelbeleg.getBelegform(); + + List einzelbelege = EinzelbelegDB.getListByBelegform(belegform); + + Map> namenkommentarIdToEinzelbelegIdsMap = new HashMap<>(); + Map namenkommentarIdToPlemmaMap = new HashMap<>(); + + for (Einzelbeleg eb : einzelbelege) { + int einzelbelegId = eb.getId(); + + for (NamenKommentar namenKommentar : eb.getNamenKommentar()) { + if (namenKommentar != null) { + int namenkommentarID = namenKommentar.getId(); + String plemma = namenKommentar.getpLemma(); + + if (!namenkommentarIdToEinzelbelegIdsMap.containsKey(namenkommentarID)) { + namenkommentarIdToEinzelbelegIdsMap.put(namenkommentarID, new ArrayList<>()); + } + namenkommentarIdToEinzelbelegIdsMap.get(namenkommentarID).add(einzelbelegId); + + if (!namenkommentarIdToPlemmaMap.containsKey(namenkommentarID)) { + namenkommentarIdToPlemmaMap.put(namenkommentarID, plemma); + } + } + } + } + + if (!namenkommentarIdToEinzelbelegIdsMap.isEmpty()) { + String language = Language.getLanguage(request); + StringBuilder sb = new StringBuilder(); + int save_namenkommentarID = -1; + + for (Map.Entry> entry : namenkommentarIdToEinzelbelegIdsMap.entrySet()) { + int namenkommentarID = entry.getKey(); + List einzelbelegIDs = entry.getValue(); + String plemma = namenkommentarIdToPlemmaMap.get(namenkommentarID); + + String einzelbelegIDsString = einzelbelegIDs.toString(); + + String s = DatenbankDB.getLabel(language, "einzelbeleg", "foundZusatznamenkommentar"); + + String result = String.format(s, belegform, plemma, String.valueOf(namenkommentarID), einzelbelegIDsString); + + sb.append(result).append("\n\n"); + + if (namenkommentarIdToEinzelbelegIdsMap.size() == 1) { + save_namenkommentarID = namenkommentarID; + } + } + + if (namenkommentarIdToEinzelbelegIdsMap.size() == 1) { + sb.append(DatenbankDB.getLabel(language, "einzelbeleg", "replaceZusatznamenkommentar")); + } else { + sb.append(DatenbankDB.getLabel(language, "einzelbeleg", "cleanData")); + } + + outputList.add(sb.toString()); + + response.setContentType("application/json; charset=UTF-8"); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("EinzelbelegID", EinzelbelegID); + jsonObject.put("outputListZ", outputList); + + if (save_namenkommentarID != -1) { + jsonObject.put("namenkommentarID", save_namenkommentarID); + } + + response.getWriter().print(jsonObject.toString()); + } else { + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + } + } + } catch (Exception e) { + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } + + protected void confirmZusatzNamenKommentar(HttpServletRequest request, HttpServletResponse response) { + try { + String EinzelbelegID = request.getParameter("EinzelbelegID"); + String namenkommentarID = request.getParameter("namenkommentarID"); + + if (EinzelbelegID == null || namenkommentarID == null) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + } else { + // Logik zum Speichern des Zusatznamen-Kommentars + EinzelbelegDB.insertNamenkommentar(EinzelbelegID, namenkommentarID); + + response.setContentType("application/json; charset=UTF-8"); + JSONObject jsonObject = new JSONObject(); + response.getWriter().print(jsonObject.toString()); + } + } catch (Exception e) { + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } + + protected void detectLemma(HttpServletRequest request, HttpServletResponse response) { + try { + String EinzelbelegID = request.getParameter("EinzelbelegID"); + if (EinzelbelegID == null) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + } else { + ArrayList outputList = new ArrayList<>(); + Einzelbeleg lastEinzelbeleg = EinzelbelegDB.getById(Integer.parseInt(EinzelbelegID)); + String belegform = lastEinzelbeleg.getBelegform(); + + List einzelbelege = EinzelbelegDB.getListByBelegform(belegform); + + Map> lemmaIdToEinzelbelegIdsMap = new HashMap<>(); + Map lemmaIdToLemmaMap = new HashMap<>(); + + for (Einzelbeleg eb : einzelbelege) { + int einzelbelegId = eb.getId(); + + // 5. Überprüfe, ob Einträge gefunden wurden + for (MghLemma lemmakommentar : eb.getMghLemma()) { + if (lemmakommentar != null) { + int lemmaID = lemmakommentar.getId(); + String plemma = lemmakommentar.getMghLemma(); + + // Füge EinzelbelegID zur entsprechenden Liste in der Map hinzu + if (!lemmaIdToEinzelbelegIdsMap.containsKey(lemmaID)) { + lemmaIdToEinzelbelegIdsMap.put(lemmaID, new ArrayList<>()); + } + lemmaIdToEinzelbelegIdsMap.get(lemmaID).add(einzelbelegId); + + // Speichere die plemma-Strings in der Map + if (!lemmaIdToLemmaMap.containsKey(lemmaID)) { + lemmaIdToLemmaMap.put(lemmaID, plemma); + } + } + } + + } + + if (!lemmaIdToEinzelbelegIdsMap.isEmpty()) { + String language = Language.getLanguage(request); + StringBuilder sb = new StringBuilder(); + int save_lemmaID = -1; + + for (Map.Entry> entry : lemmaIdToEinzelbelegIdsMap.entrySet()) { + int lemmaID = entry.getKey(); + List einzelbelegIDs = entry.getValue(); + String lemma = lemmaIdToLemmaMap.get(lemmaID); + + String einzelbelegIDsString = einzelbelegIDs.toString(); + + String s = DatenbankDB.getLabel(language, "einzelbeleg", "foundLemma"); + + String result = String.format(s, belegform, lemma, String.valueOf(lemmaID), einzelbelegIDsString); + + sb.append(result).append("\n\n"); + + if (lemmaIdToEinzelbelegIdsMap.size() == 1) { + save_lemmaID = lemmaID; + } + } + + if (lemmaIdToEinzelbelegIdsMap.size() == 1) { + sb.append(DatenbankDB.getLabel(language, "einzelbeleg", "replaceLemma")); + } else { + sb.append(DatenbankDB.getLabel(language, "einzelbeleg", "cleanData")); + } + + outputList.add(sb.toString()); + + response.setContentType("application/json; charset=UTF-8"); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("EinzelbelegID", EinzelbelegID); + jsonObject.put("outputListL", outputList); + + if (save_lemmaID != -1) { + jsonObject.put("lemmaID", save_lemmaID); + } + + response.getWriter().print(jsonObject.toString()); + } else { + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + } + } + } catch (Exception e) { + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } + + protected void confirmLemma(HttpServletRequest request, HttpServletResponse response) { + try { + String EinzelbelegID = request.getParameter("EinzelbelegID"); + String lemmaID = request.getParameter("lemmaID"); + + if (EinzelbelegID == null || lemmaID == null) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + } else { + // Logik zum Speichern des Zusatznamen-Kommentars + // EinzelbelegDB.insertFunktion(EinzelbelegID, lemmaID); + EinzelbelegDB.insertLemma(EinzelbelegID, lemmaID); + + response.setContentType("application/json; charset=UTF-8"); + JSONObject jsonObject = new JSONObject(); + response.getWriter().print(jsonObject.toString()); + } + } catch (Exception e) { + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String action = request.getParameter("action"); + if ("confirmLemma".equals(action)) { + confirmLemma(request, response); + } else if ("confirmZusatzNamenKommentar".equals(action)) { + confirmZusatzNamenKommentar(request, response); + } else { + // Andere Aktionen + } + } + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -43,6 +282,10 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) if (action != null) { if (action.equals("autocomplete")) { autocomplete(request, response); + } else if (action.equals("detectZusatzNamenKommentar")) { + detectZusatzNamenKommentar(request, response); + } else if (action.equals("detectLemma")) { + detectLemma(request, response); } else { response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); } @@ -51,5 +294,4 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); } - } diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/ShowContentServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/ShowContentServlet.java new file mode 100644 index 00000000..e8a416f6 --- /dev/null +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/ShowContentServlet.java @@ -0,0 +1,66 @@ +package de.uni_tuebingen.ub.nppm.servlet; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import de.uni_tuebingen.ub.nppm.db.*; +import de.uni_tuebingen.ub.nppm.model.*; +import java.io.OutputStream; +import javax.persistence.NoResultException; +import javax.servlet.http.Cookie; + +public class ShowContentServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String name = req.getParameter("name"); + + Cookie[] cookies = req.getCookies(); + String selectedLanguage = "null"; //Standardwert wenn kein Cookie gesetzt worden ist + if (cookies != null) { + for (Cookie cookie : cookies) { + if (cookie.getName().equals("selectedLanguage")) { + selectedLanguage = cookie.getValue(); + break; + } + } + } + + try { + Content content = null; + try { + content = ContentDB.getByNameAndLanguage(name, selectedLanguage); + } catch (NoResultException e) { + // Falls keine Datei für die angegebene Sprache gefunden wird, die Standarddatei abrufen + content = ContentDB.getByName(name); + } + + if (content != null) { + // Setzen der Zeichenkodierung + resp.setCharacterEncoding("UTF-8"); + + // Setzen des Content-Type Headers mit Zeichensatz + resp.setContentType(content.getContent_Type() + "; charset=UTF-8"); + + if (content.getContent_Type().startsWith("text/plain") || content.getContent_Type().startsWith("application/vnd.oasis.opendocument.text") + || content.getContent_Type().startsWith("application/msword") + || content.getContent_Type().startsWith("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) { + // Set Content-Disposition header to specify the filename + resp.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\""); + } + + OutputStream os = resp.getOutputStream(); + byte[] photoBytes = content.getContent(); + os.write(photoBytes); + os.flush(); + os.close(); + } else { + resp.sendRedirect("file?context=CMS"); + } + } catch (Exception e) { + resp.sendRedirect("file?context=CMS"); + } + } +} diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/backend/BerechneDateiSpracheServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/backend/BerechneDateiSpracheServlet.java new file mode 100644 index 00000000..815664cd --- /dev/null +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/backend/BerechneDateiSpracheServlet.java @@ -0,0 +1,53 @@ +package de.uni_tuebingen.ub.nppm.servlet.backend; + +import de.uni_tuebingen.ub.nppm.db.ContentDB; +import java.io.IOException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + + + +/** + * + * @author root + */ +public class BerechneDateiSpracheServlet extends HttpServlet { + + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + String fileName = request.getParameter("param1"); + String fileLanguage = request.getParameter("param2"); + + // Überprüfen, ob fileName und fileLanguage nicht null und nicht leer sind + if (fileName != null && !fileName.equals("") && fileLanguage != null && !fileLanguage.equals("")) { + try { + // Suchen Sie in der Datenbank nach der Datei basierend auf dem Namen und der Sprache + boolean fileExist = ContentDB.searchNameAndLanguage(fileName, fileLanguage); + + // Setzen des Antwortinhalts + response.setContentType("text/plain"); + response.setCharacterEncoding("UTF-8"); + + // Senden der Antwort basierend auf dem Ergebnis der Suche + if (fileExist) { + response.getWriter().write("true"); + } else { + response.getWriter().write("false"); + } + } catch (Exception ex) { + // Fehlerbehandlung bei auftretenden Ausnahmen + ex.printStackTrace(); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); // Setzen des HTTP-Statuscodes für interne Serverfehler + response.getWriter().write("Error occurred: " + ex.getMessage()); // Senden einer Fehlermeldung als Antwort + } + } else { + // Senden einer Fehlermeldung, wenn fileName oder fileLanguage null oder leer sind + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); // Setzen des HTTP-Statuscodes für eine ungültige Anfrage + response.getWriter().write("Both fileName and fileLanguage parameters are required."); + } + } + +} diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/backend/ContentServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/backend/ContentServlet.java index 65779b40..318c2d81 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/backend/ContentServlet.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/backend/ContentServlet.java @@ -2,6 +2,7 @@ import de.uni_tuebingen.ub.nppm.db.*; import de.uni_tuebingen.ub.nppm.model.*; +import de.uni_tuebingen.ub.nppm.util.Language; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -9,9 +10,14 @@ import java.io.InputStream; import java.io.PrintWriter; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.servlet.RequestDispatcher; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.jsp.JspWriter; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.FileUploadException; @@ -30,54 +36,129 @@ protected boolean isAdminRequired() { protected void generatePage(HttpServletRequest request, HttpServletResponse response) throws Exception { PrintWriter out = response.getWriter(); - // show TinyMCE - if (request.getParameter("loadFile") != null) { - RequestDispatcher rd = request.getRequestDispatcher("tinyMce.jsp"); - rd.include(request, response); - } else { - //show fileManagement - out.println("
"); - out.println(" "); - out.println(" "); - out.println(" "); - out.println(" "); - out.println("
"); - out.println("

Inhalt bearbeiten"); - out.println("

"); - out.println("
"); - out.println("
"); - out.println("
"); - out.println("

Html Dateien & Bilder verwalten

"); - out.println("

Wenn sie eine Datei löschen, dann ist auch jede Verknüpfung im Programm gelöscht, auch wenn Sie

"); - out.println("

die Datei mit gleichem Namen hochladen.

"); - out.println("

Wenn sie aber Ersetzen wählen, dann bleiben die Verknüpfungen im Programm bestehen.

"); - // Actions: - String fileAccess = request.getParameter("fileAccess"); - if (fileAccess != null) { - - //Action (Delete) - if (fileAccess.equals("fileDelete")) { + try { + // show TinyMCE + if (request.getParameter("loadFile") != null) { + RequestDispatcher rd = request.getRequestDispatcher("tinyMce.jsp"); + rd.include(request, response); + } else if ("HtmlSaveToDatabase".equals(request.getParameter("htmlFileAccess"))) { + String fileName = request.getParameter("tinyFileName"); + String language = request.getParameter("tinyLanguage"); + String newHtmlContent = request.getParameter("htmlContent"); + + try { + Content content = ContentDB.getByNameAndLanguage(fileName, language); + if (content != null) { + ContentDB.updateHtmlFile(content, newHtmlContent); + // Redirect to the tinyMce.jsp page after saving + response.sendRedirect("edit?loadFile=" + fileName); + return; // Important to return after redirect to stop further execution + } + } catch (Exception e) { + e.printStackTrace(); + } + } else if (request.getParameter("loadFile") == null && !"HtmlSaveToDatabase".equals(request.getParameter("htmlFileAccess"))) { + //show fileManagement + + HttpSession session = request.getSession(); + String myLanguage = Language.getLanguage(request); + + out.println("
"); + out.println(" "); + out.println(" "); + out.println(" "); + out.println(" "); + out.println("
"); + out.println("

"); + Language.printTextfield(out, session, "inhaltBearbeiten", "Titel"); + out.println("

"); + out.println("
"); + out.println("
"); + out.println("
"); + out.println("

"); + Language.printTextfield(out, session, "contentServlet", "h2"); + out.println("

"); + out.println("

"); + Language.printTextfield(out, session, "contentServlet", "p1"); + out.println("

"); + out.println("

"); + Language.printTextfield(out, session, "contentServlet", "p2"); + out.println("

"); + out.println("

"); + Language.printTextfield(out, session, "contentServlet", "p3"); + out.println("

"); + + // Actions: + String fileAccess = request.getParameter("fileAccess"); + if (fileAccess != null) { + String messageStart = ""; + String messageEnd = ""; + String selectedLanguage = getCookieLanguage(request, response); + Content content = null; if (request.getParameter("id") != null) { - Content content = ContentDB.getById(Integer.parseInt(request.getParameter("id"))); - out.println("Datei " + content.getName() + " wurde gelöscht"); - deleteFile(request.getParameter("id")); + content = ContentDB.getById(Integer.parseInt(request.getParameter("id"))); + } - } else { - out.println("Error: Datei kann nicht gelöscht werden"); + boolean isHtml = false; + if (content != null && content.getContext() != null && content.getContent_Type().equals("text/html")) { + isHtml = true; } - // Action (upload OR replace/update) - } else if (fileAccess.equals("fileUpload")) { - uploadFile(request, response); - } else if (fileAccess.equals("fileReplace")) { - if (request.getParameter("id") != null) { - replaceFile(request, response, request.getParameter("id")); - } else { - out.println("Error: Datei kann nicht ersetzt werden"); + //Action (Delete) + if (fileAccess.equals("fileDelete")) { + if (request.getParameter("id") != null) { + + messageStart = Language.getTextfield(session, "contentServlet", "Datei") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "BeenDeleted"); + + if (isHtml) { + deleteFileByNameAndLanguage(content.getName(), selectedLanguage); + out.println(messageStart + content.getName() + " (" + selectedLanguage + ") " + messageEnd); + } else { + deleteFile(request.getParameter("id")); + out.println(messageStart + content.getName() + messageEnd); + } + + } else { + messageEnd = Language.getTextfield(session, "contentServlet", "FileNotDeleted"); + out.println("Error: " + messageEnd); + } + // Action (upload OR replace/update) + } else if (fileAccess.equals("fileUpload")) { + uploadFile(request, response); + } else if (fileAccess.equals("fileReplace")) { + + if (request.getParameter("id") != null) { //hier != null + replaceFile(request, response); + } else { + messageEnd = Language.getTextfield(session, "contentServlet", "FileNotReplaced"); + if (isHtml) { + out.println("Error: " + content.getName() + " (" + selectedLanguage + ") " + messageEnd); + } else { + out.println("Error: " + content.getName() + " " + messageEnd); + } + } + } else if (fileAccess.equals("HtmlFileCreate")) { + String createFileName = request.getParameter("CreateHTMLFileName"); + String contextParam = request.getParameter("HtmlContext"); + Content.Context context = Content.Context.valueOf(contextParam); + + if (createFileName != null && context != null && selectedLanguage != null) { + ContentDB.createHtmlFile(createFileName, context, selectedLanguage); + + messageStart = Language.getTextfield(session, "contentServlet", "Datei") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "FileCreated"); + out.println(messageStart + createFileName + " (" + selectedLanguage + ") " + messageEnd); + } } } + // show list (e.g. help, name comment or blank page) + RequestDispatcher rd = request.getRequestDispatcher("fileManagement.jsp"); + rd.include(request, response); + } - // show list (e.g. help, name comment or blank page) + } catch (Exception e) { + // out.println("An error occurred mein Freund: " + e.getMessage()); RequestDispatcher rd = request.getRequestDispatcher("fileManagement.jsp"); rd.include(request, response); } @@ -109,65 +190,108 @@ public void deleteFile(String fileId) throws IOException, Exception { ContentDB.deleteById(id); }//end function - public void replaceFile(HttpServletRequest request, HttpServletResponse response, String fileId) throws IOException, FileUploadException, Exception { + public void deleteFileByNameAndLanguage(String fileName, String selectedLanguage) throws IOException, Exception { - PrintWriter out = response.getWriter(); + if (!selectedLanguage.equals("dontDelete")) { - String context = request.getParameter("context"); - Content.Context contextEnum = Content.Context.valueOf(context); + try { + Content content = ContentDB.getByNameAndLanguage(fileName, selectedLanguage); + if (content != null) { + ContentDB.deleteByNameAndLanguage(fileName, selectedLanguage); + } + } catch (javax.persistence.NoResultException e) { + // Kein Eintrag gefunden, nichts zu löschen - // Create a new file upload handler - ServletFileUpload upload = new ServletFileUpload(); + } + } + }//end function - // Parse the request - FileItemIterator iter = upload.getItemIterator(request); + public void replaceFile(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException, Exception { - while (iter.hasNext()) { + try { + PrintWriter out = response.getWriter(); - FileItemStream item = iter.next(); - String contentType = item.getContentType(); - String errorFileName = item.getName(); + String context = request.getParameter("context"); + Content.Context contextEnum = Content.Context.valueOf(context); - if (!item.isFormField()) { + // Create a new file upload handler + ServletFileUpload upload = new ServletFileUpload(); - if (item.getName() == null || item.getName().isEmpty() || item.getName().equals("")) { - out.println("Error: Sie haben keine Datei ausgewählt!"); - } else if (item.getContentType().startsWith("text/html") || item.getContentType().startsWith("text/plain") || item.getContentType().startsWith("application/vnd.oasis.opendocument.text") - || item.getContentType().startsWith("image") || item.getContentType().startsWith("application/vnd.openxmlformats-officedocument.wordprocessingml.document") - || item.getContentType().startsWith("application/msword")) { + // Parse the request + FileItemIterator iter = upload.getItemIterator(request); - String fileName = item.getName(); + String messageStart = ""; + String messageEnd = ""; + HttpSession session = request.getSession(); - boolean fileExists = ContentDB.searchName(fileName); - boolean sameFileName = false; - Content content = ContentDB.getById(Integer.parseInt(request.getParameter("id"))); - if (fileName.equals(content.getName())) //The file name to be uploaded should match the one in the database - { - sameFileName = true; - } + while (iter.hasNext()) { - String pathname = writeItemToTempFile(item); + FileItemStream item = iter.next(); + String contentType = item.getContentType(); + String errorFileName = item.getName(); + + if (!item.isFormField()) { + + if (item.getName() == null || item.getName().isEmpty() || item.getName().equals("")) { + messageEnd = " " + Language.getTextfield(session, "contentServlet", "NoFile"); + out.println("Error: " + messageEnd); + } else if (item.getContentType().startsWith("text/html") || item.getContentType().startsWith("text/plain") || item.getContentType().startsWith("application/vnd.oasis.opendocument.text") + || item.getContentType().startsWith("image") || item.getContentType().startsWith("application/vnd.openxmlformats-officedocument.wordprocessingml.document") + || item.getContentType().startsWith("application/msword")) { + + String fileName = item.getName(); + + boolean fileExists = ContentDB.searchName(fileName); + boolean sameFileName = false; + Content content = null; + String selectedLanguage = getCookieLanguage(request, response); + + if (contentType.equals("text/html")) { + content = ContentDB.getByNameAndLanguage(fileName, selectedLanguage); + } else { + content = ContentDB.getById(Integer.parseInt(request.getParameter("id"))); + } + + if (fileName.equals(content.getName())) //The file name to be uploaded should match the one in the database + { + sameFileName = true; + } + + String pathname = writeItemToTempFile(item); - if (fileExists == true && sameFileName == true) { + if (fileExists == true && sameFileName == true) { - byte[] bytes = ContentDB.readBytesFromFile(pathname); - content.setContent(bytes); - ContentDB.saveOrUpdate(content); - out.println("Datei " + fileName + " wurde aktualisiert!"); + byte[] bytes = ContentDB.readBytesFromFile(pathname); + content.setContent(bytes); + ContentDB.saveOrUpdate(content); + messageStart = Language.getTextfield(session, "contentServlet", "Datei") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "FileUpdate"); + if (contentType.equals("text/html")) { + out.println(messageStart + fileName + " (" + selectedLanguage + ")" + messageEnd); + } else { + out.println(messageStart + fileName + messageEnd); + } + } else { + messageStart = Language.getTextfield(session, "contentServlet", "FilesDontMatch") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "Und") + " "; + out.println("Error: " + messageStart + content.getName() + messageEnd + fileName); + out.println("
"); + } + + //Now delete the temporary file again + File myObj = new File(pathname); + myObj.delete(); } else { - out.println("Error: Datei Namen stimmen nicht überein: " + content.getName() + " und " + fileName); + messageStart = Language.getTextfield(session, "contentServlet", "Datei") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "FileNotAllowed"); + out.println("Error: " + messageStart + errorFileName + ":" + messageEnd); out.println("
"); } - - //Now delete the temporary file again - File myObj = new File(pathname); - myObj.delete(); - } else { - out.println("Error: Datei " + errorFileName + " Dateityp nicht erlaubt. Bitte wenden Sie sich an den Administrator"); - out.println("
"); } } + } catch (Exception e) { + } } @@ -176,12 +300,18 @@ public void uploadFile(HttpServletRequest request, HttpServletResponse response) String context = request.getParameter("context"); Content.Context contextEnum = Content.Context.valueOf(context); + String selectedLanguage = getCookieLanguage(request, response); + // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(); // Parse the request FileItemIterator iter = upload.getItemIterator(request); + String messageStart = ""; + String messageEnd = ""; + HttpSession session = request.getSession(); + while (iter.hasNext()) { FileItemStream item = iter.next(); @@ -191,27 +321,48 @@ public void uploadFile(HttpServletRequest request, HttpServletResponse response) if (!item.isFormField()) { if (item.getName() == null || item.getName().isEmpty() || item.getName().equals("")) { - out.println("Error: Sie haben keine Datei ausgewählt!"); + messageEnd = " " + Language.getTextfield(session, "contentServlet", "NoFile"); + out.println("Error: " + messageEnd); } else if (item.getContentType().startsWith("text/html") || item.getContentType().startsWith("text/plain") || item.getContentType().startsWith("application/vnd.oasis.opendocument.text") || item.getContentType().startsWith("image") || item.getContentType().startsWith("application/vnd.openxmlformats-officedocument.wordprocessingml.document") || item.getContentType().startsWith("application/msword")) { String fileName = item.getName(); - boolean fileExists = ContentDB.searchName(fileName); + boolean fileExists = true; + + if (contentType.equals("text/html")) { + fileExists = ContentDB.searchNameAndLanguage(fileName, selectedLanguage); + } else { + fileExists = ContentDB.searchName(fileName); + } + String pathname = writeItemToTempFile(item); if (fileExists == true) { //search file - Context of existing file - String existingFileContext = ContentDB.getByName(fileName).getContext().toString(); - - out.println("Error: Datei " + fileName + " existiert bereits im Context: " + existingFileContext); + String existingFileContext = ""; + messageStart = Language.getTextfield(session, "contentServlet", "Datei") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "FileExist") + " "; + if (contentType.equals("text/html")) { + existingFileContext = ContentDB.getByNameAndLanguage(fileName, selectedLanguage).getContext().toString(); + out.println("Error: " + messageStart + fileName + " (" + selectedLanguage + ")" + messageEnd + existingFileContext); + } else { + existingFileContext = ContentDB.getByName(fileName).getContext().toString(); + out.println("Error: " + messageStart + fileName + messageEnd + existingFileContext); + } out.println("
"); - } else { - ContentDB.saveFile(pathname, fileName, contentType, contextEnum); - out.println("Datei " + fileName + " erfolgreich hochgeladen!"); + messageStart = Language.getTextfield(session, "contentServlet", "Datei") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "FileSuccess"); + if (contentType.equals("text/html")) { + ContentDB.saveFile(pathname, fileName, contentType, contextEnum, selectedLanguage); + out.println(messageStart + fileName + "(" + selectedLanguage + ")" + messageEnd); + } else { + ContentDB.saveFile(pathname, fileName, contentType, contextEnum); + out.println(messageStart + fileName + messageEnd); + } out.println("
"); } @@ -219,7 +370,9 @@ public void uploadFile(HttpServletRequest request, HttpServletResponse response) File myObj = new File(pathname); myObj.delete(); } else { - out.println("Error: Datei " + errorFileName + " Dateityp nicht erlaubt. Bitte wenden Sie sich an den Administrator"); + messageStart = Language.getTextfield(session, "contentServlet", "Datei") + " "; + messageEnd = " " + Language.getTextfield(session, "contentServlet", "FileNotAllowed"); + out.println("Error: " + messageStart + errorFileName + ":" + messageEnd); out.println("
"); } } @@ -241,7 +394,22 @@ protected String writeItemToTempFile(FileItemStream item) throws FileNotFoundExc @Override protected String getTitle() { - return null; + return "fileManagement"; + } + + public String getCookieLanguage(HttpServletRequest request, HttpServletResponse response) { + Cookie[] cookies = request.getCookies(); + String selectedLanguage = "dontDelete"; //Standardwert wenn kein Cookie gesetzt worden ist + if (cookies != null) { + for (Cookie cookie : cookies) { + if (cookie.getName().equals("selectedLanguage")) { + selectedLanguage = cookie.getValue(); + break; + } + } + } + return selectedLanguage; } }//end class + diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/HilfeServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/HilfeServlet.java deleted file mode 100644 index bf0c8135..00000000 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/HilfeServlet.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.uni_tuebingen.ub.nppm.servlet.gast; - -import java.util.List; -import javax.servlet.RequestDispatcher; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class HilfeServlet extends AbstractGastServlet { - - @Override - protected List getAdditionalCss() { - List css = super.getAdditionalCss(); - css.add("layout/help.css"); - return css; - } - - @Override - protected String getTitle() { - return "freie_suche"; - } - - @Override - protected void generatePage(HttpServletRequest request, HttpServletResponse response) throws Exception { - RequestDispatcher rd = request.getRequestDispatcher("hilfe.jsp"); - rd.include(request, response); - } -} diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/ImpressumServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/ImpressumServlet.java deleted file mode 100644 index 940907bf..00000000 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/ImpressumServlet.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.uni_tuebingen.ub.nppm.servlet.gast; - -import javax.servlet.RequestDispatcher; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - - -public class ImpressumServlet extends AbstractGastServlet { - @Override - protected String getTitle() { - return "freie_suche"; // "Impressum" does not yet exist in DB - } - - @Override - protected void generatePage(HttpServletRequest request, HttpServletResponse response) throws Exception { - RequestDispatcher rd = request.getRequestDispatcher("impressum.jsp"); - rd.include(request, response); - } -} diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/SharedHtmlServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/SharedHtmlServlet.java new file mode 100644 index 00000000..3582fe3b --- /dev/null +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/SharedHtmlServlet.java @@ -0,0 +1,73 @@ +package de.uni_tuebingen.ub.nppm.servlet.gast; + +import de.uni_tuebingen.ub.nppm.db.ContentDB; +import de.uni_tuebingen.ub.nppm.model.Content; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; + +public class SharedHtmlServlet extends AbstractGastServlet { + + @Override + protected String getTitle() { + return setTitel(currentRequest, currentResponse); + } + + private String setTitel(HttpServletRequest request, HttpServletResponse response) { + if (request != null) { + String myFile = request.getParameter("sharedHtml"); + return myFile != null ? myFile : ""; + } + return ""; + } + + @Override + protected void generatePage(HttpServletRequest request, HttpServletResponse response) throws Exception { + + // Überprüfen, ob eine neue Sprache ausgewählt wurde und in der Session speichern + String newLanguage = request.getParameter("language"); + if (newLanguage != null && !newLanguage.isEmpty()) { + request.getSession().setAttribute("Sprache", newLanguage); + } + + // Sprache aus der Session holen + String selectedLanguage = (String) request.getSession().getAttribute("Sprache"); + + // Wenn keine Sprache in der Session gespeichert ist, eine Standardsprache setzen + if (selectedLanguage == null) { + selectedLanguage = "de"; // Standard: Deutsch + request.getSession().setAttribute("Sprache", selectedLanguage); + } + + // HTML-Dateiname aus der Anfrage holen und .html anhängen, wenn nötig + String myFile = request.getParameter("sharedHtml"); + if (myFile != null && !myFile.endsWith(".html")) { + myFile += ".html"; + } + + try { + // Inhalt aus der Datenbank basierend auf dem Dateinamen und der Sprache holen + Content content = ContentDB.getByNameAndLanguage(myFile, selectedLanguage); + + if (content != null) { + response.setContentType("text/html; charset=UTF-8"); + + // Inhalt senden + PrintWriter writer = response.getWriter(); + byte[] htmlBytes = content.getContent(); + writer.write(new String(htmlBytes, "UTF-8")); + writer.flush(); + } + + } catch (Exception e) { + // Fehlerbehandlung benutze Standard Sprache Deutsch, da für nicht alle wie Hilfe.html eine Englische Version vorhanden ist + Content content = ContentDB.getByNameAndLanguage(myFile, "de"); + + response.setContentType("text/html; charset=UTF-8"); + PrintWriter writer = response.getWriter(); + byte[] htmlBytes = content.getContent(); + writer.write(new String(htmlBytes, "UTF-8")); + writer.flush(); + } + } +} \ No newline at end of file diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/ShowContentServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/ShowContentServlet.java deleted file mode 100644 index 2ebe969c..00000000 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/ShowContentServlet.java +++ /dev/null @@ -1,36 +0,0 @@ -package de.uni_tuebingen.ub.nppm.servlet.gast; - -import java.io.IOException; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import de.uni_tuebingen.ub.nppm.db.*; -import de.uni_tuebingen.ub.nppm.model.*; -import java.io.OutputStream; - -public class ShowContentServlet extends HttpServlet { - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - String name = req.getParameter("name"); - try { - Content content = ContentDB.getByName(name); - resp.setContentType(content.getContent_Type()); - - if (content.getContent_Type().startsWith("text/plain") || content.getContent_Type().startsWith("application/vnd.oasis.opendocument.text") - || content.getContent_Type().startsWith("application/msword") - || content.getContent_Type().startsWith("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) { - // Set Content-Disposition header to specify the filename - resp.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\""); - } - - OutputStream os = resp.getOutputStream(); - byte[] photoBytes = content.getContent(); - os.write(photoBytes); - os.flush(); - os.close(); - } catch (Exception e) { - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/StartseiteServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/StartseiteServlet.java index 87e8ef1f..37e3b45e 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/StartseiteServlet.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/StartseiteServlet.java @@ -13,7 +13,7 @@ protected String getNavigationTitle() { @Override protected String getTitle() { - return "Startseite"; + return "startseite"; } @Override diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/SucheServlet.java b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/SucheServlet.java index bc2eff27..89fe8ff8 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/SucheServlet.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/servlet/gast/SucheServlet.java @@ -7,6 +7,11 @@ public class SucheServlet extends AbstractGastServlet { + @Override + protected String getNavigationTitle() { + return "einfaches_ergebnis"; + } + @Override protected String getTitle() { return "einfaches_ergebnis"; diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/util/DeleteHelper.java b/src/main/java/de/uni_tuebingen/ub/nppm/util/DeleteHelper.java index 95a24798..3dc8a622 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/util/DeleteHelper.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/util/DeleteHelper.java @@ -25,6 +25,9 @@ public static boolean deleteEntity(HttpServletRequest request, HttpServletRespon case "einzelbeleg_hatamtweihe": EinzelbelegDB.remove(EinzelbelegHatAmtWeihe_MM.class, id); break; + case "einzelbeleg_hatareal": + EinzelbelegDB.remove(EinzelbelegHatAreal_MM.class, id); + break; case "einzelbeleg_hatangabe": //Das hier Kommt neu dazu "einzelbeleg_hatangabe": EinzelbelegDB.remove(EinzelbelegHatAngabe.class, id); break; diff --git a/src/main/java/de/uni_tuebingen/ub/nppm/util/Language.java b/src/main/java/de/uni_tuebingen/ub/nppm/util/Language.java index 8a2f41ba..9a57af06 100644 --- a/src/main/java/de/uni_tuebingen/ub/nppm/util/Language.java +++ b/src/main/java/de/uni_tuebingen/ub/nppm/util/Language.java @@ -2,7 +2,9 @@ import javax.servlet.http.*; import de.uni_tuebingen.ub.nppm.db.DatenbankDB; +import java.io.PrintWriter; import javax.servlet.jsp.JspWriter; + public class Language { public static String getLanguage(HttpServletRequest request) { @@ -11,7 +13,7 @@ public static String getLanguage(HttpServletRequest request) { // Usually setLanguage() is called before getLanguage() // so we prioritize the session over the request. if (session.getAttribute("Sprache") != null) { - return (String)session.getAttribute("Sprache"); + return (String) session.getAttribute("Sprache"); } else if (request.getParameter("language") != null) { return request.getParameter("language"); } else { @@ -42,46 +44,52 @@ public static void setLanguage(HttpServletRequest request) { } } - public static void printDatafield(JspWriter out,HttpSession session, String formular, String datenfeld) throws Exception{ + public static void printDatafield(JspWriter out, HttpSession session, String formular, String datenfeld) throws Exception { String lang = getLanguage(session); String[] langArray = {lang, Constants.DEFAULT_LANG}; boolean isSet = false; - out.print("