# HG changeset patch # User "jurzua " # Date 1425995441 -3600 # Node ID 7682c04c63a8839d748abdbe80df771bc777a476 First commit of the source code! diff -r 000000000000 -r 7682c04c63a8 pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,333 @@ + + + + 4.0.0 + de.mpiwg.gazetteer + LGServer + Local Gazetteers Server + 1.0 + war + + + + 7.6.3.v20120416 + 7.0.30 + 2.15 + + 4.3.8.Final + UTF-8 + + + + + snapshots + http://anonsvn.icefaces.org/repo/maven2/releases/ + + + + + + + cl.talca + hashMapping + 1.0 + + + + org.icefaces + icefaces-ace + 3.3.0 + + + jsp-api + javax.servlet.jsp + + + + + + org.icefaces + icefaces-compat + 3.3.0 + + + + com.sun.faces + jsf-api + 2.2.5 + + + com.sun.faces + jsf-impl + 2.2.5 + + + + + org.slf4j + slf4j-log4j12 + 1.6.4 + + + log4j + log4j + 1.2.17 + + + + + + org.apache.tomcat + tomcat-servlet-api + 7.0.59 + provided + + + + commons-fileupload + commons-fileupload + 1.3.1 + + + + + + + + + asm + asm + 3.3.1 + + + + + commons-lang + commons-lang + 2.6 + + + org.json + json + 20090211 + + + + org.hibernate + hibernate-core + 4.3.8.Final + + + org.hibernate + hibernate-entitymanager + 4.3.8.Final + + + org.hibernate + hibernate-c3p0 + 4.3.8.Final + + + + + + + + c3p0 + c3p0 + 0.9.1.2 + + + + mysql + mysql-connector-java + 5.1.6 + + + + + + + + + org.glassfish.jersey + jersey-bom + ${jersey.version} + pom + import + + + + + + + + false + src/main/resources + + + false + src/main/java + + ** + + + **/*.java + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.10 + + 10 + foo + 9999 + + + + start-jetty + pre-integration-test + + run + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + + + + + + + jee6 + + + + maven-war-plugin + + ${project.build.directory}/${project.build.finalName}-jee6 + jee6 + + + + + + + diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/bo/DBEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/DBEntry.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,119 @@ +package de.mpiwg.gazetteer.bo; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public abstract class DBEntry { + + private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy-HH:mm"); + + public DBEntry(){} + + @Id + @GeneratedValue(strategy = GenerationType.TABLE) + @Column(name="id") + protected Long id; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="creationDate") + private Date creationDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="lastChangeDate") + private Date lastChangeDate; + + public boolean isPersistent(){ + if(this.getId() == null){ + return false; + }else{ + return true; + } + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public Date getLastChangeDate() { + return lastChangeDate; + } + + public void setLastChangeDate(Date lastChangeDate) { + this.lastChangeDate = lastChangeDate; + } + + public String getFomattedLastChange(){ + if(this.lastChangeDate != null) + return DATE_FORMAT.format(this.lastChangeDate); + return null; + } + + public String getFomattedCreation(){ + if(this.creationDate != null) + return DATE_FORMAT.format(this.creationDate); + return null; + } + + + public String getInfo(){ + if(isPersistent()){ + StringBuilder sb = new StringBuilder("id=" + id); + + if(creationDate != null){ + sb.append(", creation date=" + creationDate); + } + + if(lastChangeDate != null){ + sb.append(", last change=" + lastChangeDate); + } + return sb.toString(); + } + return new String(); + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof DBEntry)) { + return false; + } + DBEntry other = (DBEntry) object; + + if(this.id != null && other.id != null && this.id.longValue() == other.id.longValue()) + return true; + + return false; + } + + @Override + public String toString(){ + StringBuilder sb = new StringBuilder(); + sb.append(this.getClass().toString()); + sb.append(" [id=" + this.id + "] "); + return sb.toString(); + } +} \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,240 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.json.JSONArray; +import org.json.JSONObject; + +import cl.maps.duplex.DuplexKey; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; + + +@Entity +@Table(name="Branch") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class LGBranch extends DBEntry implements Cloneable, Serializable { + private static final long serialVersionUID = 7805209462045170778L; + + + @Column(name="sectionId") + private Long sectionId; + + @Column(name="userId") + private Long userId; + + @Column(name="contributors") + private String contributors = "[]"; + + @Column(name="label") + private String label; + + @Column(name="description") + private String description; + + @Column(name="currentLastFileId") + private Long currentLastFileId; + + @Transient + private List contributorsList; + + @Transient + private String contributorsLabel; + + @Transient + private DBBook book; + + @Transient + private String sectionName; + + @Transient + private boolean transientDataLoaded = false; + + public void loadTransientData(){ + try { + DBSection section = DBService.getSectionWithContent(sectionId); + DBBook book = DBService.getBook(section.getBookId()); + this.sectionName = section.getName(); + this.book = book; + this.transientDataLoaded = true; + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public boolean isTransientDataLoaded() { + return transientDataLoaded; + } + + + + public Object clone() throws CloneNotSupportedException { + LGBranch clone = (LGBranch)super.clone(); + clone.setContributorsList(new ArrayList(clone.getContributorsList())); + clone.book = this.book; + return clone; + } + + + + public boolean hasContributor(Long userId){ + for(Long id : getContributorsList()){ + if(id.equals(userId)){ + return true; + } + } + return false; + } + + public List getContributorsList(){ + if(contributorsList == null){ + reloadContributorsList(); + } + return contributorsList; + } + + public List getContributorsNameList(){ + List list = new ArrayList(); + for(Long userId : getContributorsList()){ + list.add(DataverseUtils.getUsername(userId)); + } + return list; + } + + public String getUsername(){ + if(this.userId != null){ + return DataverseUtils.getUsername(this.userId); + } + return null; + } + + private void reloadContributorsList(){ + this.contributorsList = new ArrayList(); + try { + JSONArray array = new JSONArray(this.contributors); + for(int i=0; i getKey(){ + return new DuplexKey(this.userId, this.id); + } + + + @Override + public String toString(){ + return "LGBranch[label=" + label + ", id=" + id + ", sectionId=" + sectionId + "]"; + } + + public String getContributorsLabel() { + return contributorsLabel; + } + + public void setContributorsLabel(String contributorsLabel) { + this.contributorsLabel = contributorsLabel; + } + + public void setContributorsList(List contributorsList) { + this.contributorsList = contributorsList; + } + + public String getSectionName() { + return sectionName; + } + + public void setSectionName(String sectionName) { + this.sectionName = sectionName; + } + + public DBBook getBook() { + return book; + } + + public void setBook(DBBook book) { + this.book = book; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/bo/LGFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/LGFile.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,134 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Transient; + +import cl.maps.duplex.DuplexKey; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; + + +@Entity +@Table(name="File") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class LGFile extends DBEntry implements Cloneable, Serializable, Comparable { + + private static final long serialVersionUID = 1638482732212457961L; + + //many files can have the same fileId + @Column(name="branchId") + private Long branchId; + + //if this file has been exported to DV, here is saved the id. + @Column(name="dvId") + private Long dvId; + + @Column(name="version") + private Integer version = 0; + + @Column(name="fileName") + private String fileName; + + @Column(name="userId") + private Long userId; + + @Column(name="lastVersion") + private boolean lastVersion = true; + + + @Column(name="notes") + private String notes; + + @Transient + private String content; + + public Long getDvId() { + return dvId; + } + + public void setDvId(Long dvId) { + this.dvId = dvId; + } + + public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getUsername(){ + if(this.userId != null){ + return DataverseUtils.getUsername(this.userId); + } + return null; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public boolean isLastVersion() { + return lastVersion; + } + + public void setLastVersion(boolean lastVersion) { + this.lastVersion = lastVersion; + } + + public Long getBranchId() { + return branchId; + } + + public void setBranchId(Long branchId) { + this.branchId = branchId; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + @Override + public int compareTo(LGFile o) { + return getCreationDate().compareTo(o.getCreationDate()); + } + + public DuplexKey getKey(){ + return new DuplexKey(this.branchId, this.id); + } + + @Override + public String toString(){ + return "LGFile [id=" + id + ", branchId=" + branchId + ", fileName=" + fileName + "]"; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/bo/SearchRulesFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/SearchRulesFile.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,67 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; + +import cl.maps.duplex.DuplexKey; + +@Entity +@Table(name="SearchRulesFile.java") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class SearchRulesFile extends DBEntry implements Cloneable, Serializable { + + private static final long serialVersionUID = -3717062037374537162L; + + @Column(name="fileName") + private String fileName; + + @Column(name="description") + private String description; + + @Column(name="content") + private String content; + + @Column(name="userId") + private Long userId; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public DuplexKey getKey(){ + return new DuplexKey(this.userId, this.id); + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/bo/Sequence.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/Sequence.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,94 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * + * @author jurzua + */ +@Entity +@Table(name="row_sequence") +public class Sequence implements Serializable { + + private static final long serialVersionUID = 120128920808559599L; + + public Sequence(){} + + public Sequence(String name, Long value){ + this.lastValue = value; + this.name = name; + } + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Column(name="name") + private String name; + + @Column(name="last_value") + private Long lastValue; + + public Long generateId(){ + return this.lastValue++; + } + + public Long getLastValue() { + return lastValue; + } + + public void setLastValue(Long lastValue) { + this.lastValue = lastValue; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Sequence)) { + return false; + } + Sequence other = (Sequence) object; + if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "org.mpi.openmind.ontology.joins.Sequence[id=" + id + "]"; + } + +} + diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/dataverse/DVDataDepositAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DVDataDepositAPI.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,43 @@ +package de.mpiwg.gazetteer.dataverse; + +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse; + +/** + * Doc: http://thedata.harvard.edu/guides/dataverse-api-main.html#data-deposit-api + * @author jurzua + * + */ +public class DVDataDepositAPI { + + private static String user = "jurzua"; + private static String pwd = "221082"; + //curl https://jurzua:221082@thedata.harvard.edu/dvn/api/data-deposit/v1/swordv2/service-document + + + public static String retrieveSWORDServiceDocument(String user, String pwd) throws Exception{ + HttpStringResponse resp = + HTTPUtils.getStringResponse("https://" + user + ":" + pwd + "@thedata.harvard.edu/dvn/api/data-deposit/v1/swordv2/service-document"); + return resp.content; + } + + public static void createStudy(String xmlFile){ + //TODO + } + + public static void addFiles2Study(){ + + } + + public static void listStudies(){ + + } + + public static void deleteStudy(){} + + public static void deaccessStudy() {} + + public static void releaseStudy() {} + + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/dataverse/DVFileAccessAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DVFileAccessAPI.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,15 @@ +package de.mpiwg.gazetteer.dataverse; + +public class DVFileAccessAPI { + + ///dvn/api/downloadInfo/9956 + public String downloadInfo(){ + return ""; + } + + ///dvn/api/download/9956 + public Byte[] download(){ + return null; + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/dataverse/DVMetadataAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DVMetadataAPI.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,33 @@ +package de.mpiwg.gazetteer.dataverse; + +import java.io.IOException; + +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse; + +public class DVMetadataAPI { + + //public static String dataverseInstance = "https://thedata.harvard.edu/dvn/api/"; + public static String dataverseInstance = "https://localhost/dvn/api/"; + + public static String metadataSearchFields() throws Exception{ + HttpStringResponse res = HTTPUtils.getStringResponse(dataverseInstance + "metadataSearchFields"); + return res.content; + } + + public static void metadataSearch(){} + + public static void metadataFormatsAvailable(){} + + public static void metadata(){} + + + public static void main(String[] args){ + try { + System.out.println(DVMetadataAPI.metadataSearchFields()); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,134 @@ +package de.mpiwg.gazetteer.dataverse; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONArray; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse; +import de.mpiwg.gazetteer.utils.PropertiesUtils; + +public class DataverseUtils { + + private static List userList; + + static{ + userList = new ArrayList(); + userList.add(new VDCUser(new Long(10), "jurzua", "1234")); + userList.add(new VDCUser(new Long(11), "john", "1234")); + userList.add(new VDCUser(new Long(12), "zoe", "1234")); + userList.add(new VDCUser(new Long(13), "paul", "1234")); + } + + public static VDCUser login0(String userName, String password){ + for(VDCUser user : userList){ + if(StringUtils.equals(userName, user.getUserName()) && StringUtils.equals(password, user.getPassword())){ + return user; + } + } + return null; + } + + public static List getAllUsers0(){ + return userList; + } + + public static VDCUser getUser(Long id){ + try { + for(VDCUser user : getAllUsers()){ + if(user.getId().equals(id)){ + return user; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static String getUsername(Long id){ + try { + for(VDCUser user : getAllUsers()){ + if(user.getId().equals(id)){ + return user.getUserName(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return "user-no-found ("+ id +")"; + } + + public static List getAllUsers() throws Exception{ + List list = new ArrayList(); + + String query = PropertiesUtils.getPropValue("dvn_server") + "/getAllUsers"; + + System.out.println("************************************************"); + System.out.println("URL: " + query); + System.out.println("************************************************"); + + HttpStringResponse response = null; + try { + response = HTTPUtils.getStringResponse(query); + JSONObject json = new JSONObject(response.content); + if(StringUtils.equals(json.getString("state"), "ok")){ + + JSONArray userArray = json.getJSONArray("users"); + + for(int i=0; i branches; + + public DBSection(Long id){ + this.id = id; + } + + public DBSection(Long id, String name, String bookId){ + this.id = id; + this.name = name; + this.bookId = bookId; + } + + public DBSection(ResultSet rs) throws SQLException{ + this.name = rs.getString("name"); + this.id = rs.getLong("id"); + this.bookId = rs.getString("books_id"); + } + + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public String getBookId() { + return bookId; + } + + public void setBookId(String bookId) { + this.bookId = bookId; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public DBBook getBook() { + return book; + } + + public void setBook(DBBook book) { + this.book = book; + } + + public List getBranches() { + return branches; + } + + public void setBranches(List branches) { + this.branches = branches; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,105 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.Part; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + +import de.mpiwg.web.SessionBean; + +public abstract class AbstractServletMethod { + + private static Logger LOGGER = Logger.getLogger(AbstractServletMethod.class); + + + + protected static void writeError(HttpServletResponse response, String message){ + try { + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", message); + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected static Long getQueryLongParam(HttpServletRequest request, String paraName) { + String value = request.getParameter(paraName); + if (StringUtils.isNotEmpty(value)) { + try { + return Long.parseLong(value); + } catch (Exception e) { + } + } + return null; + } + + protected static Long getRequestLongPart(HttpServletRequest request, String partName) throws IOException, + IllegalStateException, ServletException { + + String value = getRequestPart(request, partName); + + try { + Long v = Long.parseLong(value); + return v; + } catch (Exception e) { + } + + return null; + + } + + protected static String getRequestPart(HttpServletRequest request, String partName) throws IOException, + IllegalStateException, ServletException { + + String partText = null; + final Part filePart = request.getPart(partName); + + if (filePart != null) { + OutputStream out = null; + InputStream filecontent = null; + + try { + out = new ByteArrayOutputStream(); + filecontent = filePart.getInputStream(); + + int read = 0; + final byte[] bytes = new byte[1024]; + + while ((read = filecontent.read(bytes)) != -1) { + out.write(bytes, 0, read); + } + + partText = out.toString(); + + } catch (FileNotFoundException fne) { + LOGGER.info("Problems during file upload. Error: " + fne.getMessage()); + } finally { + if (out != null) { + out.close(); + } + if (filecontent != null) { + filecontent.close(); + } + } + } + + return partText; + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/GetFileText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetFileText.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,54 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; + +public class GetFileText extends AbstractServletMethod { + + public static String name = "getFileText"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long fileId = getQueryLongParam(request, "fileId"); + + if(fileId != null){ + LGFile file = DataProvider.getInstance().getFile(fileId); + if(file != null){ + + String text = FileManager.getFile(file); + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain; charset=UTF-8"); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "File no found (" + fileId + ")"); + json.put("code", GazetteerException.CODE); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: fileId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,73 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; + +public class GetSectionMetadata extends AbstractServletMethod { + + public static String name = "getSectionMetadata"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long sectionId = getQueryLongParam(request, "sectionId"); + + if(sectionId != null){ + DBSection section = DBService.getSectionWithContent(sectionId); + if(section != null){ + DBBook book = DBService.getBook(section.getBookId()); + + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "ok"); + + + JSONObject sectionJson = new JSONObject(); + sectionJson.put("id", section.getId()); + sectionJson.put("name", section.getName()); + + JSONObject bookJson = new JSONObject(); + bookJson.put("id", book.getId()); + bookJson.put("author", book.getAuthor()); + bookJson.put("edition", book.getEdition()); + bookJson.put("line", book.getLine()); + bookJson.put("period", book.getPeriod()); + bookJson.put("volume", book.getVolume()); + + sectionJson.put("book", bookJson); + + + json.put("section", sectionJson); + + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Section no found (" + sectionId + ")"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: sectionId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/GetSectionText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetSectionText.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,50 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.utils.DBService; + +public class GetSectionText extends AbstractServletMethod { + + public static String name = "getSectionText"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long sectionId = getQueryLongParam(request, "sectionId"); + + if(sectionId != null){ + String text = DBService.getSectionWithContent(sectionId).getText(); + if(StringUtils.isNotEmpty(text)){ + + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain; charset=UTF-8"); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Section no found (" + sectionId + ")"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: sectionId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/GetUser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetUser.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,45 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +public class GetUser extends AbstractServletMethod{ + + public static String name = "getUser"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + response.setContentType("application/json"); + Long userId = getQueryLongParam(request, "userId"); + + JSONObject json = new JSONObject(); + + if(userId != null){ + //TODO + /* + VDCUser user = DataProvider.getInstance().get + if(file != null){ + + String text = FileManager.getFile(file.getFileName()); + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain"); + + }else{ + json.put("status", "error"); + json.put("message", "User not found (" + userId + ")"); + }*/ + }else{ + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: userId."); + } + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/SaveNewText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/SaveNewText.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,63 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.icefaces.apache.commons.fileupload.servlet.ServletFileUpload; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.JSONUtils; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; + +public class SaveNewText extends AbstractServletMethod{ + + public static String name = "saveNew"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + + if (ServletFileUpload.isMultipartContent(request)) { + String text = getRequestPart(request, "text"); + Long userId = getRequestLongPart(request, "userId"); + Long sectionId = getRequestLongPart(request, "sectionId"); + String label = getRequestPart(request, "label"); + + if(StringUtils.isNotEmpty(text) && userId != null && sectionId != null){ + Long branchId = DataProvider.getInstance().saveNewFile(text, label, sectionId, userId); + LGBranch branch = DataProvider.getInstance().getBranch(branchId); + LGFile file = DataProvider.getInstance().getFile(branch.getCurrentLastFileId()); + + JSONObject jsonBranch = JSONUtils.branch2JSON(branch); + JSONObject jsonFile = JSONUtils.file2JSON(file, true); + + json.put("branch", jsonBranch); + json.put("file", jsonFile); + json.put("status", "ok"); + + }else{ + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: text, userId, sectionId."); + json.put("code", GazetteerException.CODE); + } + + } else { + json.put("status", "error"); + json.put("message", "Content-type wrong. It should be: multipart/form-data"); + json.put("code", GazetteerException.CODE); + } + + + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/SaveText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/SaveText.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,81 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.icefaces.apache.commons.fileupload.servlet.ServletFileUpload; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.JSONUtils; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; +import de.mpiwg.gazetteer.utils.exceptions.VersioningException; + +public class SaveText extends AbstractServletMethod{ + + public static String name = "save"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + + if (ServletFileUpload.isMultipartContent(request)) { + String text = getRequestPart(request, "text"); + ;//getRequestPart(request, "text"); + Long userId = getRequestLongPart(request, "userId"); + Long branchId = getRequestLongPart(request, "branchId"); + Long userPreviousFileId = getRequestLongPart(request, "userPreviousFileId"); + + if(StringUtils.isNotEmpty(text) && userId != null && branchId != null && userPreviousFileId != null){ + //text = new String(text.getBytes("iso-8859-1"), "UTF-8"); + try { + LGFile file = DataProvider.getInstance().saveFile(branchId, text, userId, userPreviousFileId); + LGBranch branch = DataProvider.getInstance().getBranch(file.getBranchId()); + + JSONObject jsonBranch = JSONUtils.branch2JSON(branch); + JSONObject jsonFile = JSONUtils.file2JSON(file, true); + + json.put("branch", jsonBranch); + json.put("file", jsonFile); + json.put("status", "ok"); + } catch (GazetteerException e){ + json.put("status", "error"); + json.put("message", e.getMessage()); + json.put("code", e.getCode()); + if(e instanceof VersioningException){ + + JSONObject curentFile = JSONUtils.file2JSON(((VersioningException) e).getCurrentFile(), false); + JSONObject userFile = JSONUtils.file2JSON(((VersioningException) e).getUserFile(), false); + + json.put("currentFile", curentFile); + json.put("userFile", userFile); + } + } catch (Exception e) { + e.printStackTrace(); + json.put("status", "error"); + json.put("message", e.getMessage()); + json.put("code", GazetteerException.CODE); + } + + + }else{ + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: text, userId, branchId, userPreviousFileId."); + } + + } else { + json.put("status", "error"); + json.put("message", "Content-type wrong. It should be: multipart/form-data"); + } + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/rest/Servlet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/Servlet.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,88 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + +@WebServlet("/rest/text/*") +@MultipartConfig +public class Servlet extends HttpServlet { + + private static final long serialVersionUID = -8809504256505388787L; + + private final static Logger LOGGER = Logger.getLogger(Servlet.class.getCanonicalName()); + + @Override + public void init() throws ServletException { + + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { + + String method = getLastPathComponent(request); + request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); + + if(StringUtils.equals(SaveNewText.name, method)){ + SaveNewText.execute(request, response); + }else if(StringUtils.equals(SaveText.name, method)){ + SaveText.execute(request, response); + }else if(StringUtils.equals(GetFileText.name, method)){ + GetFileText.execute(request, response); + }else if(StringUtils.equals(GetUser.name, method)){ + GetUser.execute(request, response); + }else if(StringUtils.equals(GetSectionText.name, method)){ + GetSectionText.execute(request, response); + }else if(StringUtils.equals(GetSectionMetadata.name, method)){ + GetSectionMetadata.execute(request, response); + }else{ + writeError(response, "Content-type wrong. It should be: multipart/form-data"); + } + } + + private static void writeError(HttpServletResponse response, String message){ + try { + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", message); + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } catch (Exception e) { + LOGGER.error(e); + } + } + + public String getLastPathComponent(HttpServletRequest request){ + String uri = request.getRequestURI(); + String[] array = uri.split("/"); + return array[array.length-1]; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,50 @@ +package de.mpiwg.gazetteer.utils; + +import java.util.List; + +import cl.maps.duplex.DuplexMap; +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.SearchRulesFile; + +public class AbstractDataProvider { + + + //############################### + + private DuplexMap branchMap = null; + + protected DuplexMap getBranchMap(){ + if(branchMap == null){ + loadBranches(); + } + return branchMap; + } + + public void loadBranches(){ + List list = DBService.getAllLGBranchFromDB(); + this.branchMap = new DuplexMap(); + for(LGBranch item : list){ + this.branchMap.put(item.getKey(), item); + } + } + + + private DuplexMap fileMap = null; + + protected DuplexMap getFileMap(){ + if(fileMap == null){ + loadFiles(); + } + return fileMap; + } + + + private void loadFiles(){ + List list = DBService.getAllLGFileFromDB(); + this.fileMap = new DuplexMap(); + for(LGFile file : list){ + this.fileMap.put(file.getKey(), file); + } + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/DBService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,338 @@ + package de.mpiwg.gazetteer.utils; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; + +import de.mpiwg.gazetteer.bo.DBEntry; +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.SearchRulesFile; +import de.mpiwg.gazetteer.bo.Sequence; +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.web.SessionBean; + +public class DBService { + + private static Logger logger = Logger.getLogger(DBService.class); + + // JDBC driver name and database URL + static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + static final String DB_URL = "jdbc:mysql://localhost/"; + + public static List searchSection(List termList) throws SQLException{ + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + String query = "SELECT name, id, books_id FROM sections WHERE "; + for(int i=0; i0){ + query += " OR "; + } + query += "name like '" + term + "%' "; + } + query += " limit 50"; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + DBSection section = new DBSection(rs); + DBBook book = getBook0(conn, section.getBookId()); + section.setBook(book); + list.add(section); + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + + return list; + } + + public static List suggestSectionName(String term) throws SQLException { + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + String query = "SELECT name FROM sections WHERE name like '" + term + "%' limit 50"; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + String name = rs.getString("name"); + if(!list.contains(name)){ + list.add(name); + } + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + return list; + } + + + public static List suggestSectionId(String input) throws SQLException { + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + String query = "SELECT id FROM sections WHERE id like '" + input + "%' limit 50"; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + + String id = rs.getString("id"); + list.add(id); + + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + + + + return list; + } + + public static DBSection getSectionWithContent(Long sectionId) throws SQLException { + + Connection conn = null; + Statement stmt = null; + DBSection response = new DBSection(sectionId); + + String query = "SELECT * FROM sections WHERE id = '" + sectionId + "'"; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + + String bookId = rs.getString("books_id"); + int startPage = rs.getInt("start_page"); + int endPage = rs.getInt("end_page"); + String sectionName = rs.getString("name"); + + response.setBookId(bookId); + response.setName(sectionName); + + System.out.println("bookId=" + bookId + ", startPage=" + startPage + ", endPage=" + endPage); + String content = getContent(conn, bookId, startPage, endPage); + response.setText(content); + + DBBook book = getBook0(conn, bookId); + response.setBook(book); + + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + return response; + } + + public static String fixToNewline(String orig){ + char[] chars = orig.toCharArray(); + StringBuilder sb = new StringBuilder(100); + for(char c : chars){ + switch(c){ + case '\r': + case '\f': + break; + case '\n': + sb.append("
"); + break; + default: + sb.append(c); + } + } + return sb.toString(); + } + + //"SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d + private static String getContent(Connection conn, String bookId, Integer startLine, Integer endLine) throws Exception{ + + String query = "SELECT content, line FROM contents WHERE books_id = '" + bookId + "' AND line >= '" + startLine + "' AND line <= '" + endLine + "'"; + + logger.debug(query); + + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + + StringBuilder sb = new StringBuilder(); + while(rs.next()){ + String line = rs.getString("line"); + String content = rs.getString("content"); + sb.append("【" + line + "】" + content + "\n"); + } + + return sb.toString(); + } + + + public static DBBook getBook(String id) throws SQLException{ + Connection conn = null; + DBBook book = null; + + try { + Class.forName(JDBC_DRIVER); + + conn = getNewConnection(); + book = getBook0(conn, id); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + return book; + } + + private static DBBook getBook0(Connection conn, String id) throws SQLException{ + DBBook book = null; + + String query = "SELECT * FROM books WHERE id = '" + id + "'"; + logger.debug(query); + + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + + if(rs.next()){ + book = new DBBook(rs); + } + + return book; + } + + /** + * This method removed all files for a particular fileId. + * The elimination includes the current version as well as the old versions. + * @param fileId + * @return + */ + protected static int deleteBranchFromDB(Long branchId){ + logger.info("Deleting Branch by branchId=" + branchId); + + int modifiedFiles; + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + Query query = session.createQuery("delete LGBranch where id = :id"); + query.setLong("id", branchId); + modifiedFiles = query.executeUpdate(); + + Query query0 = session.createQuery("delete LGFile where branchId = :branchId"); + query0.setLong("branchId", branchId); + modifiedFiles += query0.executeUpdate(); + + session.getTransaction().commit(); + + return modifiedFiles; + } + + protected static List getAllLGFileFromDB(){ + List list = null; + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGFile"); + list = query.list(); + session.getTransaction().commit(); + + return list; + } + + protected static List getCurrentLGFilesFromDB(){ + List list = null; + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGFile where lastVersion = :lastVersion"); + query.setBoolean("lastVersion", true); + list = query.list(); + session.getTransaction().commit(); + + return list; + } + + protected static List getAllLGBranchFromDB(){ + List list = null; + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGBranch"); + list = query.list(); + session.getTransaction().commit(); + + return list; + } + + protected static void saveDBEntry(DBEntry entry, Date date){ + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + saveDBEntry0(session, entry, date); + + session.getTransaction().commit(); + } + + public static void saveDBEntry0(Session session, DBEntry entry, Date date){ + entry.setLastChangeDate(date); + if (entry.isPersistent()) { + session.update(entry); + } else { + entry.setCreationDate(date); + session.save(entry); + } + logger.info("saveDBEntry: " + entry.toString()); + } + + public static Connection getNewConnection() throws SQLException, IOException{ + return DriverManager.getConnection( + DB_URL + PropertiesUtils.getPropValue("db_gazetter_name") + "?useUnicode=yes&characterEncoding=UTF-8", + PropertiesUtils.getPropValue("db_gazetter_username"), + PropertiesUtils.getPropValue("db_gazetter_password")); + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,195 @@ +package de.mpiwg.gazetteer.utils; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.log4j.Logger; +import org.hibernate.Session; +import org.w3c.dom.ls.LSInput; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.SearchRulesFile; +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.exceptions.NoAuthorizedException; +import de.mpiwg.gazetteer.utils.exceptions.VersioningException; + +public class DataProvider extends AbstractDataProvider{ + + private static Logger logger = Logger.getLogger(DBService.class); + private static DataProvider instance; + + public static DataProvider getInstance(){ + if(instance == null) + instance = new DataProvider(); + return instance; + } + + public DataProvider(){ + logger.info("##### Starting DataProvider #####"); + } + + /* + public List getSearchRulesFiles(Long userId){ + return getSearchRulesFileMap().getValuesByAKey(userId); + } + + public void deleteSearchRulesFile(SearchRulesFile file){ + int modifiedFiles = DBService.deleteSearchRulesFile(file.getId()); + + DBService.saveDBEntry(file, date); + getSearchRulesFileMap().put(file.getKey(), file); + } + */ + + + //*********************************** + + public LGFile getFile(Long fileId){ + return getFileMap().getValuesByOwnKey(fileId); + } + + public List getAllFiles(Long branchId){ + List list = getFileMap().getValuesByAKey(branchId); + return list; + } + + public List getBranches(Long userId){ + List list = new ArrayList(); + for(LGBranch branch : getBranchMap().values()){ + if(branch.hasContributor(userId)){ + list.add(branch); + } + } + return list; + } + + public LGBranch getBranch(Long branchId){ + return getBranchMap().getValuesByOwnKey(branchId); + } + + public void deleteBranch(LGBranch branch){ + + int modifiedFiles = DBService.deleteBranchFromDB(branch.getId()); + List fileToDelete = getFileMap().getValuesByAKey(branch.getId()); + + for(LGFile file : new ArrayList(fileToDelete)){ + getFileMap().remove(file.getKey()); + } + getBranchMap().remove(branch.getKey()); + + logger.info(modifiedFiles + " items deleted by removing branch " + branch.toString()); + } + + public void updateBranch(LGBranch branch) throws Exception{ + if(!branch.isPersistent()){ + throw new Exception("Trying to update a branch that it is not persistent!"); + } + + Date date = new Date(); + DBService.saveDBEntry(branch, date); + this.getBranchMap().put(branch.getKey(), branch); + } + + public LGFile saveFile(Long branchId, String text, Long userId, Long userPreviousFileId) throws Exception{ + + Date date = new Date(); + + LGBranch branch = getBranchMap().getValuesByOwnKey(branchId); + + if(!branch.hasContributor(userId)){ + throw new NoAuthorizedException(userId, branchId); + } + + if(!branch.getCurrentLastFileId().equals(userPreviousFileId)){ + LGFile userPreviousFile = getFileMap().getValuesByOwnKey(userPreviousFileId); + LGFile currentLastFile = getFileMap().getValuesByOwnKey(branch.getCurrentLastFileId()); + + throw new VersioningException(userPreviousFile, currentLastFile); + } + + LGFile previousFile = getFileMap().getValuesByOwnKey(branch.getCurrentLastFileId()); + + LGFile file = new LGFile(); + file.setBranchId(branchId); + file.setVersion(previousFile.getVersion() + 1); + file.setUserId(userId); + file.setContent(text); + + //Saving into DB + //################################## + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + + file.setBranchId(branch.getId()); + DBService.saveDBEntry0(session, file, date); + + previousFile.setLastVersion(false); + DBService.saveDBEntry0(session, previousFile, date); + + branch.setCurrentLastFileId(file.getId()); + DBService.saveDBEntry0(session, branch, date); + + //Saving physical file in the operating system + String fileName = FileManager.saveFile(branch, file, date); + file.setFileName(fileName); + DBService.saveDBEntry0(session, file, date); + + session.getTransaction().commit(); + //################################## + + + //Saving into Cache + getBranchMap().put(branch.getKey(), branch); + getFileMap().put(file.getKey(), file); + getFileMap().put(previousFile.getKey(), previousFile); + + return file; + } + + public Long saveNewFile(String text, String label, Long sectionId, Long userId) throws Exception{ + + Date date = new Date(); + + LGBranch branch = new LGBranch(); + branch.setSectionId(sectionId); + branch.setUserId(userId); + branch.setLabel(label); + branch.addContributor(userId); + branch.loadTransientData(); + + LGFile file = new LGFile(); + file.setUserId(userId); + file.setContent(text); + + //Saving into DB + //################################## + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + DBService.saveDBEntry0(session, branch, date); + file.setBranchId(branch.getId()); + + DBService.saveDBEntry0(session, file, date); + branch.setCurrentLastFileId(file.getId()); + + //Saving physical file in the operating system + String fileName = FileManager.saveFile(branch, file, date); + file.setFileName(fileName); + DBService.saveDBEntry0(session, file, date); + + session.getTransaction().commit(); + //################################## + + + //Saving into Cache + getBranchMap().put(branch.getKey(), branch); + getFileMap().put(file.getKey(), file); + + return branch.getId(); + + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/FileManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,77 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.File; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; + +public class FileManager { + + private static Logger logger = Logger.getLogger(FileManager.class); + + private static DateFormat dfmt = new SimpleDateFormat( "yyyy.MM.dd_hh.mm.ss.SSS" ); + + + + private static String getRootPath() throws Exception{ + String base = PropertiesUtils.getPropValue("files_root"); + + if(StringUtils.isEmpty(base)){ + throw new Exception("Property files_root no found. The files can be stored without this property."); + } + + if(!base.endsWith("/")){ + base += "/"; + } + + logger.info("files_root=" + base); + + return base; + } + + public static String saveFile(LGBranch branch, LGFile file, Date date) throws Exception{ + + String absolutePath = getRootPath() + branch.getSectionId() + "/"; + String fileName = + branch.getSectionId() + "_" + + branch.getId() + "_" + + file.getId() + "_" + + dfmt.format(date) + + ".txt"; + + File folder = new File(absolutePath); + folder.mkdirs(); + + logger.info("Trying to save file " + absolutePath + fileName + "."); + + PrintWriter out = new PrintWriter(absolutePath + fileName); + out.println(file.getContent()); + out.close(); + + logger.info("The file " + fileName + " has been saved correctly."); + return fileName; + } + + public static String getFile(LGFile file) throws Exception{ + + LGBranch branch = DataProvider.getInstance().getBranch(file.getBranchId()); + + String absolutePath = getRootPath() + branch.getSectionId() + "/" + file.getFileName(); + System.out.println("Loading: " + absolutePath); + byte[] encoded = Files.readAllBytes(Paths.get(absolutePath)); + return new String(encoded, "UTF8"); + } + + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/HTTPUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/HTTPUtils.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,113 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; + +public class HTTPUtils { + + final static TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { + @Override + public void checkClientTrusted( final X509Certificate[] chain, final String authType ) { + } + @Override + public void checkServerTrusted( final X509Certificate[] chain, final String authType ) { + } + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + } }; + + public static HttpStringResponse getStringResponse(String link) throws IOException, KeyManagementException, NoSuchAlgorithmException{ + if(link.startsWith("https") || link.startsWith("HTTPS")) + return getHttpSSLStringResponse(link); + return getHttpStringResponse(link); + + } + + private static HttpStringResponse getHttpSSLStringResponse(String link) throws IOException, KeyManagementException, NoSuchAlgorithmException{ + + // Install the all-trusting trust manager + final SSLContext sslContext = SSLContext.getInstance( "SSL" ); + sslContext.init( null, trustAllCerts, new java.security.SecureRandom() ); + // Create an ssl socket factory with our all-trusting manager + final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); + + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection)url.openConnection(); + + ( (HttpsURLConnection) httpConn ).setSSLSocketFactory( sslSocketFactory ); + + + BufferedReader in = null; + if (httpConn.getResponseCode() >= 400) { + in = new BufferedReader( + new InputStreamReader( + httpConn.getErrorStream())); + } else { + in = new BufferedReader( + new InputStreamReader( + httpConn.getInputStream())); + } + + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + in.close(); + + return new HttpStringResponse(httpConn.getResponseCode(), sb.toString()); + } + + private static HttpStringResponse getHttpStringResponse(String link) throws IOException{ + + //System.out.println(link); + + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection)url.openConnection(); + + BufferedReader in = null; + if (httpConn.getResponseCode() >= 400) { + in = new BufferedReader( + new InputStreamReader( + httpConn.getErrorStream())); + } else { + in = new BufferedReader( + new InputStreamReader( + httpConn.getInputStream())); + } + + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + in.close(); + + return new HttpStringResponse(httpConn.getResponseCode(), sb.toString()); + } + + public static class HttpStringResponse{ + public int code; + public String content; + public HttpStringResponse(int code, String content){ + this.code = code; + this.content = content; + } + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,31 @@ +package de.mpiwg.gazetteer.utils; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AnnotationConfiguration; + + +public class HibernateUtil { + + private static final SessionFactory sessionFactory; + + static { + try { + // Create the SessionFactory from hibernate.cfg.xml + AnnotationConfiguration cfg = new AnnotationConfiguration().configure("hibernate.cfg.xml"); + if(System.getProperty("hibernate.hbm2ddl.auto") != null && System.getProperty("hibernate.hbm2ddl.auto").equals("create")){ + cfg.setProperty("hibernate.hbm2ddl.auto", "create"); + } + sessionFactory = cfg.buildSessionFactory(); + } catch (Throwable ex) { + // Make sure you log the exception, as it might be swallowed + System.err.println("Initial SessionFactory creation failed." + ex); + ex.printStackTrace(); + throw new ExceptionInInitializerError(ex); + } + } + + public static SessionFactory getSessionFactory() { + return sessionFactory; + } + +} \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/JSONUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/JSONUtils.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,66 @@ +package de.mpiwg.gazetteer.utils; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; + +public class JSONUtils { + + public static String getString(JSONObject json, String label){ + try { + return (json.has(label)) ? json.getString(label) : null; + } catch (Exception e) {} + return null; + } + + public static Long getLong(JSONObject json, String label){ + try { + return (json.has(label)) ? json.getLong(label) : null; + } catch (Exception e) {} + return null; + } + + public static JSONObject branch2JSON(LGBranch branch){ + JSONObject json = new JSONObject(); + + try { + + json.put("id", branch.getId()); + json.put("label", branch.getLabel()); + json.put("sectionId", branch.getSectionId()); + json.put("currentLastFileId", branch.getCurrentLastFileId()); + json.put("creatorId", branch.getUserId()); + json.put("creationDate", branch.getFomattedCreation()); + json.put("info", branch.getInfo()); + + } catch (Exception e) { + e.printStackTrace(); + } + + return json; + } + + public static JSONObject file2JSON(LGFile file, boolean includeText){ + JSONObject json = new JSONObject(); + + try { + + json.put("id", file.getId()); + json.put("version", file.getVersion()); + json.put("fileName", file.getFileName()); + json.put("info", file.getInfo()); + json.put("creatorId", file.getUserId()); + json.put("creationDate", file.getFomattedCreation()); + + if(includeText){ + json.put("text", file.getContent()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return json; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,53 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.Properties; + +import org.apache.log4j.Logger; + +import de.mpiwg.web.SessionBean; + +public class PropertiesUtils { + + private static Logger logger = Logger.getLogger(PropertiesUtils.class); + private static PropertiesUtils instance; + + + private static String PROP_FILENAME = "config.properties"; + private Properties prop; + + private PropertiesUtils() throws IOException{ + loadProperties(); + } + + + public void loadProperties() throws IOException { + + logger.info("##### Loading Propertis from " + PROP_FILENAME + " #####"); + + prop = new Properties(); + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(PROP_FILENAME); + + if (inputStream != null) { + prop.load(inputStream); + } else { + prop = null; + throw new FileNotFoundException("property file '" + PROP_FILENAME + "' not found in the classpath"); + + } + } + + public static String getPropValue(String key) throws IOException{ + if(instance == null){ + instance = new PropertiesUtils(); + } + if(instance.prop == null){ + instance.loadProperties(); + } + return instance.prop.getProperty(key); + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/SelectableObject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/SelectableObject.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,43 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.Serializable; + +public class SelectableObject implements Serializable{ + + private static final long serialVersionUID = 1L; + + private boolean selected; + private N obj; + private String label; + + public SelectableObject(N obj){ + this.obj = obj; + this.selected = false; + } + + public SelectableObject(N obj, String label){ + this.obj = obj; + this.selected = false; + this.label = label; + } + + public boolean isSelected() { + return selected; + } + public void setSelected(boolean selected) { + this.selected = selected; + } + public N getObj() { + return obj; + } + public void setObj(N obj) { + this.obj = obj; + } + public String getLabel() { + return label; + } + public void setLabel(String label) { + this.label = label; + } +} + diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/exceptions/GazetteerException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/exceptions/GazetteerException.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,13 @@ +package de.mpiwg.gazetteer.utils.exceptions; + +public abstract class GazetteerException extends Exception{ + + private static final long serialVersionUID = -7540131287577085722L; + + public static int CODE = 0; + + public int getCode(){ + return CODE; + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/exceptions/NoAuthorizedException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/exceptions/NoAuthorizedException.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,22 @@ +package de.mpiwg.gazetteer.utils.exceptions; + +public class NoAuthorizedException extends GazetteerException{ + private static final long serialVersionUID = 3483644794781830882L; + + private static int CODE = 2; + private Long userId; + private Long branchId; + + public NoAuthorizedException(Long userId, Long branchId){ + this.userId = userId; + this.branchId = branchId; + } + public String getMessage(){ + return "NoAuthorizedException: This user " + userId + " is not authorized to modify this branch (" + branchId + ")!"; + } + + public int getCode(){ + return CODE; + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/gazetteer/utils/exceptions/VersioningException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/exceptions/VersioningException.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,45 @@ +package de.mpiwg.gazetteer.utils.exceptions; + +import de.mpiwg.gazetteer.bo.LGFile; + +public class VersioningException extends GazetteerException{ + + private static final long serialVersionUID = 3686916552150745726L; + + private static int CODE = 1; + + public LGFile userFile; + public LGFile currentFile; + + public VersioningException(LGFile userFile, LGFile currentFile){ + this.userFile = userFile; + this.currentFile = currentFile; + } + + public String getMessage(){ + String msg = "VersioningException: In the between time, somebody else saved a new version of this file. "; + msg += " You modified the version " + this.userFile.getVersion() + ", however the current version is " + this.currentFile.getVersion() + "."; + return msg; + } + + + public LGFile getUserFile() { + return userFile; + } + + public void setUserFile(LGFile userFile) { + this.userFile = userFile; + } + + public LGFile getCurrentFile() { + return currentFile; + } + + public void setCurrentFile(LGFile currentFile) { + this.currentFile = currentFile; + } + + public int getCode(){ + return CODE; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/web/AbstractBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/AbstractBean.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,36 @@ +package de.mpiwg.web; + +import java.util.ArrayList; + +import javax.faces.context.FacesContext; + +public class AbstractBean { + + public Object getRequestBean(String name){ + return FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(name); + } + + public SessionBean getSessionBean(){ + return (SessionBean)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(SessionBean.BEAN_NAME); + } + + public void addMsg(String msg){ + if(getSessionBean().getMsgList() == null){ + getSessionBean().setMsgList(new ArrayList()); + } + if(!getSessionBean().getMsgList().contains(msg)){ + getSessionBean().getMsgList().add(msg); + } + } + + public void listenerCloseMsgPopup(){ + System.out.println("listenerCloseMsgPopup"); + getSessionBean().setMsgList(null); + } + + public void internalError(Exception e){ + addMsg("Internal Error: " + e.getMessage()); + e.printStackTrace(); + } + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/web/ApplicationBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/ApplicationBean.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,82 @@ +package de.mpiwg.web; + +import java.io.Serializable; + +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.utils.PropertiesUtils; + +public class ApplicationBean implements Serializable{ + + private static final long serialVersionUID = 804932192506497432L; + + private static Logger logger = Logger.getLogger(ApplicationBean.class); + + public static final String BEAN_NAME = "appBean"; + + public String getExtractionInterfaceUrl(){ + String value = null; + try { + value = PropertiesUtils.getPropValue("extraction_interface"); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + public String getRootServer(){ + String value = null; + try { + value = PropertiesUtils.getPropValue("root_server"); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + public String getDvnRootServer(){ + String value = null; + try { + value = PropertiesUtils.getPropValue("dvn_server"); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + public String getShowImage(){ + return getRootServer() + "/resources/images/show_16.png"; + } + + public String getEditImage(){ + return getRootServer() + "/resources/images/edit_16.png"; + } + + public String getPublishImage(){ + return getRootServer() + "/resources/images/publish_16.png"; + } + + public String getBranchDetailsImage(){ + return getRootServer() + "/resources/images/branch_details_16.png"; + } + + public String getNewBranchImage(){ + return getRootServer() + "/resources/images/new_branch_16.png"; + } + + public String getEditBranchImage(){ + return getRootServer() + "/resources/images/edit_branch_16.png"; + } + + public String getSearchImage(){ + return getRootServer() + "/resources/images/search_32.png"; + } + + public String getJSConfirmationDelete(){ + return "if(!confirm('Do you really want to delete this?')){ return false; };"; + } + + public String getJSConfirmationSave(){ + return "if(!confirm('Do you really want to save this?')){ return false; };"; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/web/BranchEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/BranchEditor.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,187 @@ +package de.mpiwg.web; + +import java.util.ArrayList; +import java.util.List; + +import javax.faces.event.ActionEvent; + +import org.apache.commons.lang.SerializationUtils; +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; +import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; +import de.mpiwg.gazetteer.utils.SelectableObject; + +public class BranchEditor extends AbstractBean{ + + + private static Logger logger = Logger.getLogger(BranchEditor.class); + + private LGBranch currentBranch; + private LGFile currentLastFile; + private List allFiles; + private String text; + private List suggestionUserList; + private List> contributors; + + public void loadBranch(Long branchId){ + LGBranch branch = DataProvider.getInstance().getBranch(branchId); + this.loadBranch(branch); + } + + public void loadBranch(LGBranch branch){ + logger.info("Loading Branch: " + branch.toString()); + this.reset(); + if(branch != null && branch.isPersistent()){ + + try { + this.currentBranch = (LGBranch)branch.clone(); + this.currentLastFile = DataProvider.getInstance().getFile(branch.getCurrentLastFileId()); + this.allFiles = DataProvider.getInstance().getAllFiles(branch.getId()); + this.text = FileManager.getFile(this.currentLastFile); + this.contributors = new ArrayList>(); + for(Long userId : this.currentBranch.getContributorsList()){ + VDCUser user = DataverseUtils.getUser(userId); + if(user != null){ + this.contributors.add(new SelectableObject(user)); + } + + } + //for(this.currentBranch.getContributorsList()) + } catch (Exception e) { + internalError(e); + } + + logger.info("allFiles.size=" + allFiles.size()); + } + } + + public void reset(){ + this.currentBranch = null; + this.currentLastFile = null; + this.allFiles = null; + } + + public void listenerShowContributorsDialog(ActionEvent event){ + this.suggestionUserList = new ArrayList(); + try { + for(VDCUser user : DataverseUtils.getAllUsers()){ + if(!currentBranch.hasContributor(user.getId())){ + this.suggestionUserList.add(user); + } + } + } catch (Exception e) { + internalError(e); + } + + + } + + public void listenerCloseContributorsDialog(ActionEvent event){ + this.suggestionUserList = null; + } + + public void listenerUpdateBranch(ActionEvent event){ + this.saveBranch0(); + } + + public void listenerAddContributor(ActionEvent event){ + VDCUser user = (VDCUser)getRequestBean("contributor"); + if(user != null){ + this.suggestionUserList = null; + this.currentBranch.addContributor(user.getId()); + } + + this.saveBranch0(); + } + + public void listenerRemoveContributor(ActionEvent event){ + List toDelete = new ArrayList(); + for(SelectableObject so : new ArrayList>(this.contributors)){ + if(so.isSelected()){ + toDelete.add(so.getObj()); + this.contributors.remove(so); + } + } + + for(VDCUser user : toDelete){ + this.currentBranch.removeContributor(user.getId()); + } + + this.saveBranch0(); + + } + + private void saveBranch0(){ + try { + DataProvider.getInstance().updateBranch(currentBranch); + this.loadBranch(currentBranch); + addMsg("The branch has been updated!"); + } catch (Exception e) { + internalError(e); + } + } + + public void listenerSaveText(ActionEvent event){ + try { + LGFile newFile = DataProvider.getInstance().saveFile(currentBranch.getId(), this.text, getSessionBean().getUser().getId(), this.currentLastFile.getId()); + LGBranch branch = DataProvider.getInstance().getBranch(newFile.getBranchId()); + this.loadBranch(branch); + addMsg("New File create " + newFile.getId()); + } catch (Exception e) { + internalError(e); + } + } + + public LGBranch getCurrentBranch() { + return currentBranch; + } + + public void setCurrentBranch(LGBranch currentBranch) { + this.currentBranch = currentBranch; + } + + public LGFile getCurrentLastFile() { + return currentLastFile; + } + + public void setCurrentLastFile(LGFile currentLastFile) { + this.currentLastFile = currentLastFile; + } + + public List getAllFiles() { + return allFiles; + } + + public void setAllFiles(List allFiles) { + this.allFiles = allFiles; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public List getSuggestionUserList() { + return suggestionUserList; + } + + public void setSuggestionUserList(List suggestionUserList) { + this.suggestionUserList = suggestionUserList; + } + + public List> getContributors() { + return contributors; + } + + public void setContributors(List> contributors) { + this.contributors = contributors; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/web/FileCreator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/FileCreator.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,121 @@ +package de.mpiwg.web; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.faces.event.ActionEvent; +import javax.faces.event.ValueChangeEvent; +import javax.faces.model.SelectItem; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.icefaces.ace.event.TextChangeEvent; + +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; +import de.mpiwg.gazetteer.utils.DataProvider; + +public class FileCreator extends AbstractBean{ + + private static Logger logger = Logger.getLogger(FileCreator.class); + + private DBSection section; + private String label; + private Long sectionId; + private List sectionSuggestion; + + + public FileCreator(){ + + } + + public void reset(){ + this.section = null; + this.label = null; + this.sectionId = null; + this.sectionSuggestion = null; + } + + public void listenerLoadSection(ActionEvent event){ + if(sectionId != null){ + try { + this.section = DBService.getSectionWithContent(sectionId); + } catch (SQLException e) { + internalError(e); + } + } + } + + public void listenerReset(ActionEvent event){ + this.reset(); + } + + public void changeSectionInput(TextChangeEvent event){ + String input = event.getNewValue().toString(); + this.sectionSuggestion = new ArrayList(); + try { + List list = DBService.suggestSectionId(input); + System.out.println(list.size()); + for(String s : list){ + this.sectionSuggestion.add(new SelectItem(s)); + } + } catch (SQLException e) { + internalError(e); + } + } + + public void listenerSaveNewFile(ActionEvent event){ + + if( section != null && + StringUtils.isNotEmpty(section.getText()) && + StringUtils.isNotEmpty(label)){ + try { + Long branchId = + DataProvider.getInstance().saveNewFile( + section.getText(), + label, + section.getId(), + getSessionBean().getUser().getId()); + addMsg("New branch created [id=" + branchId +"]"); + } catch (Exception e) { + internalError(e); + } + } + } + + public DBSection getSection() { + return section; + } + + public void setSection(DBSection section) { + this.section = section; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Long getSectionId() { + return sectionId; + } + + public void setSectionId(Long sectionId) { + this.sectionId = sectionId; + } + + public List getSectionSuggestion() { + return sectionSuggestion; + } + + public void setSectionSuggestion(List sectionSuggestion) { + this.sectionSuggestion = sectionSuggestion; + } + + + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/web/SearchBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/SearchBean.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,141 @@ +package de.mpiwg.web; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.faces.event.ActionEvent; +import javax.faces.event.ValueChangeEvent; +import javax.faces.model.SelectItem; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.icefaces.ace.event.TextChangeEvent; + +import com.icesoft.faces.component.jseventlistener.JSEventListener; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; +import de.mpiwg.gazetteer.utils.DataProvider; + +public class SearchBean extends AbstractBean{ + + private static Logger logger = Logger.getLogger(SearchBean.class); + + private String term; + private List sectionSuggestion; + private List sectionList; + private String message; + private Map> branchesMap; + + public void changeSectionName(TextChangeEvent event){ + logger.debug("changeSectionName"); + logger.debug("key" + event.getKeyCode()); + + String term = event.getNewValue().toString(); + + this.sectionSuggestion = new ArrayList(); + + if(!term.contains(",")){ + + try { + List list = DBService.suggestSectionName(term); + for(String s : list){ + this.sectionSuggestion.add(new SelectItem(s)); + } + } catch (SQLException e) { + internalError(e); + } + } + } + + public void changeSectionSearch(ValueChangeEvent event){ + this.term = (String)event.getNewValue(); + this.search(); + } + + public void listenerSearch(ActionEvent event){ + this.search(); + } + + private void search(){ + this.message = null; + if(StringUtils.isNotEmpty(this.term)){ + this.loadBranches(); + try { + List terms = splitTerms(); + this.sectionList = DBService.searchSection(terms); + + for(DBSection section : this.sectionList){ + section.setBranches(this.branchesMap.get(section.getId())); + } + + if(sectionList.size() > 0){ + this.message = sectionList.size() + " item(s) found for the term(s): " + this.term; + }else{ + this.message = "No items found for the term(s): " + this.term; + } + + } catch (Exception e) { + internalError(e); + } + } + + } + + private void loadBranches(){ + this.branchesMap = new HashMap>(); + List list = DataProvider.getInstance().getBranches(getSessionBean().getUser().getId()); + for(LGBranch branch : list){ + branch.loadTransientData(); + if(this.branchesMap.get(branch.getSectionId()) == null){ + this.branchesMap.put(branch.getSectionId(), new ArrayList()); + } + this.branchesMap.get(branch.getSectionId()).add(branch); + } + } + + private List splitTerms(){ + List rs = new ArrayList(); + String[] array = this.term.split(","); + + for(String tmp : array){ + tmp = tmp.replace(" ", ""); + if(StringUtils.isNotEmpty(tmp)){ + rs.add(tmp); + } + } + return rs; + } + + public String getTerm() { + return term; + } + + public void setTerm(String term) { + this.term = term; + } + + public List getSectionSuggestion() { + return sectionSuggestion; + } + + public void setSectionSuggestion(List sectionSuggestion) { + this.sectionSuggestion = sectionSuggestion; + } + + public List getSectionList() { + return sectionList; + } + + public void setSectionList(List sectionList) { + this.sectionList = sectionList; + } + + public String getMessage() { + return message; + } +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/web/SessionBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/SessionBean.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,186 @@ +package de.mpiwg.web; + +import java.util.ArrayList; +import java.util.List; + +import javax.faces.event.ActionEvent; +import javax.faces.event.AjaxBehaviorEvent; + +import org.apache.log4j.Logger; +import org.dom4j.Branch; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; +import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.utils.DBService; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.SelectableObject; + +public class SessionBean extends AbstractBean { + + private static Logger logger = Logger.getLogger(SessionBean.class); + public static final String BEAN_NAME = "sessionBean"; + + private List msgList = new ArrayList(); + + private List> branches; + + private VDCUser user; + private String userName; + private String password; + + private String currentSectionId = "5190882"; + + private FileCreator fileCreator = new FileCreator(); + private BranchEditor branchEditor = new BranchEditor(); + private SearchBean searchPage = new SearchBean(); + + public SessionBean(){ + logger.info("#### SessionBean #####"); + } + + public void reset(){ + this.user = null; + this.branches = null; + this.fileCreator = new FileCreator(); + this.branchEditor = new BranchEditor(); + this.searchPage = new SearchBean(); + } + + public List getMsgList() { + return msgList; + } + + public void setMsgList(List msgList) { + this.msgList = msgList; + } + + public void listenerCloseMsgPopup(ActionEvent event){ + getSessionBean().setMsgList(null); + } + + public void listenerReloadBranches(ActionEvent event){ + this.reloadBranches(); + } + + public void listenerLogin(ActionEvent event){ + login0(); + } + + public void ajaxLogin(AjaxBehaviorEvent event){ + login0(); + } + + private void login0(){ + try { + this.user = DataverseUtils.login(userName, password); + if(user != null){ + reloadBranches(); + + }else{ + addMsg("User account no found or userName and password do not match!"); + } + + } catch (Exception e) { + internalError(e); + } + } + + public void listenerDeleteBranch(ActionEvent event){ + System.out.println("listenerDeleteBranch"); + try { + for(SelectableObject so : new ArrayList>(this.branches)){ + if(so.isSelected()){ + this.branches.remove(so); + DataProvider.getInstance().deleteBranch(so.getObj()); + } + } + + } catch (Exception e) { + internalError(e); + } + } + + public void reloadBranches(){ + this.branches = new ArrayList>(); + if(user != null){ + for(LGBranch branch : DataProvider.getInstance().getBranches(this.user.getId())){ + if(!branch.isTransientDataLoaded()){ + branch.loadTransientData(); + } + this.branches.add(new SelectableObject(branch)); + } + } + } + + public void listenerLogout(ActionEvent event){ + this.reset(); + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public VDCUser getUser() { + return user; + } + + public void setUser(VDCUser user) { + this.user = user; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public List> getBranches() { + return branches; + } + + public void setBranches(List> branches) { + this.branches = branches; + } + + public String getCurrentSectionId() { + return currentSectionId; + } + + public void setCurrentSectionId(String currentSectionId) { + this.currentSectionId = currentSectionId; + } + + public FileCreator getFileCreator() { + return fileCreator; + } + + public void setFileCreator(FileCreator fileCreator) { + this.fileCreator = fileCreator; + } + + public BranchEditor getBranchEditor() { + return branchEditor; + } + + public void setBranchEditor(BranchEditor branchEditor) { + this.branchEditor = branchEditor; + } + + public SearchBean getSearchPage() { + return searchPage; + } + + public void setSearchPage(SearchBean searchPage) { + this.searchPage = searchPage; + } + + +} diff -r 000000000000 -r 7682c04c63a8 src/main/java/de/mpiwg/web/jsf/PhaseTracker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsf/PhaseTracker.java Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,71 @@ +package de.mpiwg.web.jsf; + +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; +import javax.faces.event.PhaseEvent; +import javax.faces.event.PhaseId; +import javax.faces.event.PhaseListener; + +import org.apache.commons.lang.StringUtils; + +import de.mpiwg.web.SessionBean; + +public class PhaseTracker implements PhaseListener { + + private static final long serialVersionUID = 312014196782070515L; + + @Override + public void beforePhase(PhaseEvent event) { + + Map params = event.getFacesContext().getExternalContext().getRequestParameterMap(); + String servletPath = event.getFacesContext().getExternalContext().getRequestServletPath(); + + if(StringUtils.isNotEmpty(servletPath) && event.getPhaseId() == PhaseId.RESTORE_VIEW){ + + if(servletPath.equals("/home/mainPage.xhtml")){ + SessionBean session = getSessionBean(event.getFacesContext()); + if(session != null){ + session.reloadBranches(); + } + }else if(servletPath.equals("/home/branchEditor.xhtml") && true){ + String branchId = params.get("branchId"); + SessionBean session = getSessionBean(event.getFacesContext()); + if(StringUtils.isNotEmpty(branchId) && session != null){ + try { + Long id = Long.parseLong(branchId); + session.getBranchEditor().loadBranch(id); + } catch (Exception e) { + e.printStackTrace(); + } + } + }else if(servletPath.equals("/home/createNewFile.xhtml")){ + /* + SessionBean session = getSessionBean(event.getFacesContext()); + session.getFileCreator().reset(); + */ + } + + } + } + private SessionBean getSessionBean(FacesContext context){ + SessionBean bean = (SessionBean)context.getExternalContext().getSessionMap().get(SessionBean.BEAN_NAME); + if(bean == null){ + bean = new SessionBean(); + context.getExternalContext().getSessionMap().put(SessionBean.BEAN_NAME, bean); + } + return bean; + } + + @Override + public void afterPhase(PhaseEvent event) { + + } + + @Override + public PhaseId getPhaseId() { + return PhaseId.ANY_PHASE; + } + +} \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/resources/config.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/config.properties Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,10 @@ +db_gazetter_username=root +db_gazetter_password=admin +db_gazetter_name=Gazetteer +files_root=/gazetteer-server/data +#extraction_interface=http://141.14.239.50:1080/localmonographs +extraction_interface=http://localgazetteers-dev/extraction-interface +dvn_server=http://localgazetteers-dev:8081/dvn +#root_server=http://localgazetteers.mpiwg-berlin.mpg.de:8080/gazetteer-server +root_server=http://localhost:8080/LGServer +#root_server=http://localgazetteers-dev:8080/LGServer diff -r 000000000000 -r 7682c04c63a8 src/main/resources/hibernate.cfg.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/hibernate.cfg.xml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,42 @@ + + + + + + 5 + 20 + 1800 + 50 + org.hibernate.connection.C3P0ConnectionProvider + + + + com.mysql.jdbc.Driver + jdbc:mysql://localhost/LGServer?characterEncoding=UTF-8 + + root + admin + UTF-8 + + + 1 + + + thread + + + + + + + + + diff -r 000000000000 -r 7682c04c63a8 src/main/resources/log4j.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/log4j.properties Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,31 @@ +### direct log messages to stdout ### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %5p %c{1}:%L - %m%n + +### set log levels - for more verbose logging change 'info' to 'debug' ## + +log4j.rootLogger=info, stdout + +log4j.logger.de.mpiwg=debug, file + +#log4j.logger.cl.dialectic=info, stdout + +#log4j.logger.net.sf.hibernate=debug, stdout +#Hibernate +#log4j.logger.org.hibernate.cfg=debug, file +#log4j.logger.org.hibernate.cfg.annotations.Version=info, stdout +#log4j.logger.org.hibernate.cfg.Environment=info, stdout +#log4j.logger.org.hibernate.cfg.AnnotationBinder=info, stdout + + +### enable the following line if you want to track down connection ### +### leakages when using DriverManagerConnectionProvider ### +#log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace + +### log JDBC bind parameters ### +#log4j.logger.net.sf.hibernate.type=debug + +### log prepared statement cache activity ### +#log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=debug diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/WEB-INF/faces-config.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/WEB-INF/faces-config.xml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,46 @@ + + + + + de.mpiwg.web.jsf.PhaseTracker + + + + sessionBean + de.mpiwg.web.SessionBean + session + + + + appBean + de.mpiwg.web.ApplicationBean + application + + + + + branchEditor + /home/branchEditor.xhtml + + + + searchPage + /home/searchPage.xhtml + + + + fileCreator + /home/createNewFile.xhtml + + + + home + /home/mainPage.xhtml + + + + + diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/WEB-INF/web.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/WEB-INF/web.xml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,157 @@ + + + + + + + + + + LGServer + + + home/mainPage.xhtml + + + + jsp + *.jsp + *.dcss + + + + 60 + + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.xhtml + + + State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2 + javax.faces.STATE_SAVING_METHOD + server + + + javax.servlet.jsp.jstl.fmt.localizationContext + resources.application + + + + javax.faces.PROJECT_STAGE + Development + + + org.icefaces.mandatoryResourceConfiguration + + + + org.icefaces.ace.theme + none + + + javax.faces.FACELETS_SKIP_COMMENTS + true + + + javax.faces.VALIDATE_EMPTY_FIELDS + false + + + Google Maps API key is required if gMap component is used. Sign up for an API key from http://code.google.com/apis/maps/signup.html + com.icesoft.faces.gmapKey + ABQIAAAADlu0ZiSTam64EKaCQr9eTRTOTuQNzJNXRlYRLknj4cQ89tFfpxTEqxQnVWL4k55OPICgF5_SOZE06A + + + Resource Servlet + com.icesoft.faces.webapp.CompatResourceServlet + 1 + + + Resource Servlet + /xmlhttp/* + + + + \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/home/branchEditor.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/home/branchEditor.xhtml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/home/createNewFile.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/home/createNewFile.xhtml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/home/mainPage.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/home/mainPage.xhtml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/home/searchPage.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/home/searchPage.xhtml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/home/test.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/home/test.html Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,17 @@ + + + + + + + + + + + + +
+ + \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/css/style.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/resources/css/style.css Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,134 @@ +body { + margin: 0; + padding: 0; + font-family: Verdana, Arial, sans-serif; + background-color: #FCF2DF ; + font-size: 12px; +} + +.tableComponent{ + margin-top: 10px; + padding-top: 10px; + width: 300px; + border-top: 5px solid #ABABCC; + width: 100%; +} + +.tableComponent table{ + width: 100%; +} + +#header { + background-color: #fcf2df; + box-shadow: 0 0 5px 3px #d0d0d0; + height: 100px; + margin: 0 auto; + width: 80%; +} + +#page { + background-color: #fcf2df; + box-shadow: 0 0 5px 3px #d0d0d0; + margin: 0 auto; + padding-bottom: 50px; + width: 80%; +} + +.inputSearch{ + margin: 0; + outline: medium none; + padding: 4px; + box-shadow: inset 0 2px 2px #d3d3d3; + color: #555555; + border-radius: 4px/*{cornerRadius}*/; + font-family: Verdana,Arial,sans-serif/*{ffDefault}*/; + font-size: 1.1em/*{fsDefault}*/; + letter-spacing: normal; + font: normal normal normal 13.3333330154419px/normal Arial; + text-rendering: auto; + word-spacing: normal; + text-transform: none; + text-indent: 0px; + text-shadow: none; + display: inline-block; + +} + +.content{ + color: #3b4186; + margin-left: auto; + margin-right: auto; + text-align: center; + width: 100%; + padding-left: 10px; + padding-right: 10px; +} + +.content table, td{ + text-align: left; +} + +.iceOutLbl { + color: #485297; + font-family: Verdana,Arial,sans-serif; + padding: 2px 0; +} + +.subTitle{ + display: inline-block; + font-size: x-large; + padding: 10px 0; +} + +.iconLink{ + padding: 0 10px; +} + +/* Logo */ + +#logo { + width: 920px; + height: 40px; + margin: 0; + padding: 20px 45px 0px 40px; + /*color: #000000;*/ +} + +#logo h1, #logo p { + margin: 0px; + padding: 0px; + //text-transform: uppercase; +} + +#logo h1 { + font-family: Verdana, Verdana, Arial, sans-serif; + font-size: x-large; +} + +#logo p { + font-size: 12px; + font-weight: bold; + color: #FFFFFF; +} + +#logo a { + border: none; + background: none; + text-decoration: none; + color: #FFFFFF; +} + +#login { + background-color: #fcf2df; + color: black; + font-size: 11px; + height: 25px; + margin: 0 auto; + padding-bottom: 2px; + width: 80%; +} + +#loginContent { + float: right; + width: 600px; +} \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/branch_details_16.png Binary file src/main/webapp/resources/images/branch_details_16.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/branch_details_32.png Binary file src/main/webapp/resources/images/branch_details_32.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/edit_16.png Binary file src/main/webapp/resources/images/edit_16.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/edit_32.png Binary file src/main/webapp/resources/images/edit_32.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/edit_branch_16.png Binary file src/main/webapp/resources/images/edit_branch_16.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/edit_branch_32.png Binary file src/main/webapp/resources/images/edit_branch_32.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/new_branch_16.png Binary file src/main/webapp/resources/images/new_branch_16.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/new_branch_32.png Binary file src/main/webapp/resources/images/new_branch_32.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/publish_16.png Binary file src/main/webapp/resources/images/publish_16.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/publish_32.png Binary file src/main/webapp/resources/images/publish_32.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/search_16.png Binary file src/main/webapp/resources/images/search_16.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/search_32.png Binary file src/main/webapp/resources/images/search_32.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/search_64.png Binary file src/main/webapp/resources/images/search_64.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/show_16.png Binary file src/main/webapp/resources/images/show_16.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/images/show_32.png Binary file src/main/webapp/resources/images/show_32.png has changed diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/js/general.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/resources/js/general.js Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,99 @@ +function branchInExtractionInterface( + branchId, fileId, + sectionId, + sectionName, + bookId, + bookName, + userId, extractionInterfaceUrl){ + + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", extractionInterfaceUrl + "/develop/Extractapp/TaggingText"); // hand to controller + form.setAttribute("target", "_blank"); + + + var hiddenField0 = document.createElement("input"); + hiddenField0.setAttribute("name", "branchId"); + hiddenField0.setAttribute("value", branchId); + form.appendChild(hiddenField0); + + var hiddenField1 = document.createElement("input"); + hiddenField1.setAttribute("name", "fileId"); + hiddenField1.setAttribute("value", fileId); + form.appendChild(hiddenField1); + + var hiddenField2 = document.createElement("input"); + hiddenField2.setAttribute("name", "userId"); + hiddenField2.setAttribute("value", userId); + form.appendChild(hiddenField2); + + var hiddenField3 = document.createElement("input"); + hiddenField3.setAttribute("name", "sectionId"); + hiddenField3.setAttribute("value", sectionId); + form.appendChild(hiddenField3); + + + var hiddenField4 = document.createElement("input"); + hiddenField4.setAttribute("name", "sectionName"); + hiddenField4.setAttribute("value", sectionName); + form.appendChild(hiddenField4); + + var hiddenField5 = document.createElement("input"); + hiddenField5.setAttribute("name", "bookId"); + hiddenField5.setAttribute("value", bookId); + form.appendChild(hiddenField5); + + var hiddenField6 = document.createElement("input"); + hiddenField6.setAttribute("name", "bookName"); + hiddenField6.setAttribute("value", bookName); + form.appendChild(hiddenField6); + + if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { + document.body.appendChild(form); + form.submit(); + document.body.removeChild(form); + } else { + form.submit(); // works under IE and Chrome, but not FF + } +} + +function sectionInExtractionInterface(sectionId, sectionName, bookId, bookName, userId, extractionInterfaceUrl){ + + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", extractionInterfaceUrl + "/develop/Extractapp/TaggingText"); // hand to controller + form.setAttribute("target", "_blank"); + + var hiddenField2 = document.createElement("input"); + hiddenField2.setAttribute("name", "userId"); + hiddenField2.setAttribute("value", userId); + form.appendChild(hiddenField2); + + var hiddenField3 = document.createElement("input"); + hiddenField3.setAttribute("name", "sectionId"); + hiddenField3.setAttribute("value", sectionId); + form.appendChild(hiddenField3); + + var hiddenField4 = document.createElement("input"); + hiddenField4.setAttribute("name", "sectionName"); + hiddenField4.setAttribute("value", sectionName); + form.appendChild(hiddenField4); + + var hiddenField5 = document.createElement("input"); + hiddenField5.setAttribute("name", "bookId"); + hiddenField5.setAttribute("value", bookId); + form.appendChild(hiddenField5); + + var hiddenField6 = document.createElement("input"); + hiddenField6.setAttribute("name", "bookName"); + hiddenField6.setAttribute("value", bookName); + form.appendChild(hiddenField6); + + if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { + document.body.appendChild(form); + form.submit(); + document.body.removeChild(form); + } else { + form.submit(); // works under IE and Chrome, but not FF + } +} \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/resources/js/jquery.steps.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/resources/js/jquery.steps.js Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,8 @@ +// Initialize wizard +var wizard = $("#wizard").steps(); + +// Add step +wizard.steps("add", { + title: "HTML code", + content: "HTML code" +}); \ No newline at end of file diff -r 000000000000 -r 7682c04c63a8 src/main/webapp/templates/publicTemplate.xhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/templates/publicTemplate.xhtml Tue Mar 10 14:50:41 2015 +0100 @@ -0,0 +1,99 @@ + + + + + + + Local Monographs Service + +