changeset 0:7682c04c63a8

First commit of the source code!
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Tue, 10 Mar 2015 14:50:41 +0100
parents
children 43f4cbe04ea1
files pom.xml src/main/java/de/mpiwg/gazetteer/bo/DBEntry.java src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java src/main/java/de/mpiwg/gazetteer/bo/LGFile.java src/main/java/de/mpiwg/gazetteer/bo/SearchRulesFile.java src/main/java/de/mpiwg/gazetteer/bo/Sequence.java src/main/java/de/mpiwg/gazetteer/dataverse/DVDataDepositAPI.java src/main/java/de/mpiwg/gazetteer/dataverse/DVFileAccessAPI.java src/main/java/de/mpiwg/gazetteer/dataverse/DVMetadataAPI.java src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java src/main/java/de/mpiwg/gazetteer/dataverse/bo/VDCUser.java src/main/java/de/mpiwg/gazetteer/db/DBBook.java src/main/java/de/mpiwg/gazetteer/db/DBSection.java src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java src/main/java/de/mpiwg/gazetteer/rest/GetFileText.java src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java src/main/java/de/mpiwg/gazetteer/rest/GetSectionText.java src/main/java/de/mpiwg/gazetteer/rest/GetUser.java src/main/java/de/mpiwg/gazetteer/rest/SaveNewText.java src/main/java/de/mpiwg/gazetteer/rest/SaveText.java src/main/java/de/mpiwg/gazetteer/rest/Servlet.java src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java src/main/java/de/mpiwg/gazetteer/utils/DBService.java src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java src/main/java/de/mpiwg/gazetteer/utils/FileManager.java src/main/java/de/mpiwg/gazetteer/utils/HTTPUtils.java src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java src/main/java/de/mpiwg/gazetteer/utils/JSONUtils.java src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java src/main/java/de/mpiwg/gazetteer/utils/SelectableObject.java src/main/java/de/mpiwg/gazetteer/utils/exceptions/GazetteerException.java src/main/java/de/mpiwg/gazetteer/utils/exceptions/NoAuthorizedException.java src/main/java/de/mpiwg/gazetteer/utils/exceptions/VersioningException.java src/main/java/de/mpiwg/web/AbstractBean.java src/main/java/de/mpiwg/web/ApplicationBean.java src/main/java/de/mpiwg/web/BranchEditor.java src/main/java/de/mpiwg/web/FileCreator.java src/main/java/de/mpiwg/web/SearchBean.java src/main/java/de/mpiwg/web/SessionBean.java src/main/java/de/mpiwg/web/jsf/PhaseTracker.java src/main/resources/config.properties src/main/resources/hibernate.cfg.xml src/main/resources/log4j.properties src/main/webapp/WEB-INF/faces-config.xml src/main/webapp/WEB-INF/web.xml src/main/webapp/home/branchEditor.xhtml src/main/webapp/home/createNewFile.xhtml src/main/webapp/home/mainPage.xhtml src/main/webapp/home/searchPage.xhtml src/main/webapp/home/test.html src/main/webapp/resources/css/style.css src/main/webapp/resources/images/branch_details_16.png src/main/webapp/resources/images/branch_details_32.png src/main/webapp/resources/images/edit_16.png src/main/webapp/resources/images/edit_32.png src/main/webapp/resources/images/edit_branch_16.png src/main/webapp/resources/images/edit_branch_32.png src/main/webapp/resources/images/new_branch_16.png src/main/webapp/resources/images/new_branch_32.png src/main/webapp/resources/images/publish_16.png src/main/webapp/resources/images/publish_32.png src/main/webapp/resources/images/search_16.png src/main/webapp/resources/images/search_32.png src/main/webapp/resources/images/search_64.png src/main/webapp/resources/images/show_16.png src/main/webapp/resources/images/show_32.png src/main/webapp/resources/js/general.js src/main/webapp/resources/js/jquery.steps.js src/main/webapp/templates/publicTemplate.xhtml
diffstat 69 files changed, 4998 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>de.mpiwg.gazetteer</groupId>
+	<artifactId>LGServer</artifactId>
+	<name>Local Gazetteers Server</name>
+	<version>1.0</version>
+	<packaging>war</packaging>
+
+
+	<properties>
+		<jetty.version>7.6.3.v20120416</jetty.version>
+		<tomcat.version>7.0.30</tomcat.version>
+		<jersey.version>2.15</jersey.version>
+		<!-- <hibernate.version>3.5.6-Final</hibernate.version> -->
+		<hibernate.version>4.3.8.Final</hibernate.version>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<repositories>
+     <repository>
+        <id>snapshots</id>
+        <url>http://anonsvn.icefaces.org/repo/maven2/releases/</url>
+     </repository>	
+	</repositories>
+	
+	<dependencies>
+	
+	    <dependency>
+            <groupId>cl.talca</groupId>
+            <artifactId>hashMapping</artifactId>
+            <version>1.0</version>
+        </dependency>		
+		<!-- ICEFACES -->
+		<dependency>
+			<groupId>org.icefaces</groupId>
+			<artifactId>icefaces-ace</artifactId>
+			<version>3.3.0</version>
+			<exclusions>
+				<exclusion>
+					<artifactId>jsp-api</artifactId>
+					<groupId>javax.servlet.jsp</groupId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+
+		<dependency>
+			<groupId>org.icefaces</groupId>
+			<artifactId>icefaces-compat</artifactId>
+			<version>3.3.0</version>
+		</dependency>
+		<!-- 
+		<dependency>
+			<groupId>org.icefaces</groupId>
+			<artifactId>icepush</artifactId>
+			<version>3.0.1</version>
+		</dependency>
+		 -->
+		<dependency>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-api</artifactId>
+			<version>2.2.5</version>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-impl</artifactId>
+			<version>2.2.5</version>
+		</dependency>
+		<!-- 
+		<dependency>
+			<groupId>org.apache.myfaces.core</groupId>
+			<artifactId>myfaces-api</artifactId>
+			<version>2.2.7</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.myfaces.core</groupId>
+			<artifactId>myfaces-impl</artifactId>
+			<version>2.2.7</version>
+		</dependency>
+				 -->
+		
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+			<version>1.6.4</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.17</version>
+		</dependency>
+		
+		<!-- REST API - jersey -->
+		
+		<dependency>
+			<groupId>org.apache.tomcat</groupId>
+			<artifactId>tomcat-servlet-api</artifactId>
+			<version>7.0.59</version>
+			<scope>provided</scope>
+		</dependency>
+		
+		<dependency>
+			<groupId>commons-fileupload</groupId>
+			<artifactId>commons-fileupload</artifactId>
+			<version>1.3.1</version>
+		</dependency>
+		
+		
+		
+		<!-- Rest -->
+		<!-- 
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-servlet-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.media</groupId>
+            <artifactId>jersey-media-moxy</artifactId>
+        </dependency>
+        
+		<dependency>
+			<groupId>org.glassfish.jersey.media</groupId>
+			<artifactId>jersey-media-multipart</artifactId>
+		</dependency>
+        
+        
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<version>3.0-alpha-1</version>
+			<scope>provided</scope>
+		</dependency>	
+		 -->
+		<!-- 
+		<dependency>
+		    <groupId>com.sun.jersey</groupId>
+		    <artifactId>jersey-server</artifactId>
+		    <version>${jersey.version}</version>
+		</dependency>
+		<dependency>
+		    <groupId>com.sun.jersey</groupId>
+		    <artifactId>jersey-core</artifactId>
+		    <version>${jersey.version}</version>
+		</dependency>
+		<dependency>
+		    <groupId>com.sun.jersey</groupId>
+		    <artifactId>jersey-servlet</artifactId>
+		    <version>${jersey.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey</groupId>
+			<artifactId>jersey-json</artifactId>
+		 	<version>${jersey.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey</groupId>
+			<artifactId>jersey-client</artifactId>
+		 	<version>${jersey.version}</version>
+		</dependency>
+		<dependency>
+            <groupId>com.sun.jersey.contribs</groupId>
+            <artifactId>jersey-multipart</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+		-->
+		<dependency>
+			<groupId>asm</groupId>
+			<artifactId>asm</artifactId>
+			<version>3.3.1</version>
+		</dependency>
+		<!-- Others -->		
+	
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.6</version>
+		</dependency>
+		<dependency>
+			<groupId>org.json</groupId>
+			<artifactId>json</artifactId>
+			<version>20090211</version>
+		</dependency>
+		<!-- hibernate -->
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-core</artifactId>
+			<version>4.3.8.Final</version>
+		</dependency>
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-entitymanager</artifactId>
+			<version>4.3.8.Final</version>
+		</dependency>
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-c3p0</artifactId>
+			<version>4.3.8.Final</version>
+		</dependency>
+		
+		
+		
+		<!-- 
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-core</artifactId>
+			<version>3.5.6-Final</version>
+		</dependency>
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-entitymanager</artifactId>
+			<version>3.5.6-Final</version>
+		</dependency>
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-c3p0</artifactId>
+			<version>3.5.6-Final</version>
+		</dependency>
+		-->
+		
+		<dependency>
+			<groupId>c3p0</groupId>
+			<artifactId>c3p0</artifactId>
+			<version>0.9.1.2</version>
+		</dependency>
+		
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>5.1.6</version>
+		</dependency>
+		<!-- XXX -->
+							
+	</dependencies>	
+	
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.glassfish.jersey</groupId>
+                <artifactId>jersey-bom</artifactId>
+                <version>${jersey.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>	
+  
+	<build>
+		<resources>
+			<resource>
+				<filtering>false</filtering>
+				<directory>src/main/resources</directory>
+			</resource>
+			<resource>
+				<filtering>false</filtering>
+				<directory>src/main/java</directory>
+				<includes>
+					<include>**</include>
+				</includes>
+				<excludes>
+					<exclude>**/*.java</exclude>
+				</excludes>
+			</resource>
+		</resources>
+
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.tomcat.maven</groupId>
+				<artifactId>tomcat7-maven-plugin</artifactId>
+				<version>2.2</version>
+			</plugin>
+
+			<plugin>
+				<groupId>org.mortbay.jetty</groupId>
+				<artifactId>maven-jetty-plugin</artifactId>
+				<version>6.1.10</version>
+				<configuration>
+					<scanIntervalSeconds>10</scanIntervalSeconds>
+					<stopKey>foo</stopKey>
+					<stopPort>9999</stopPort>
+				</configuration>
+				<executions>
+					<execution>
+						<id>start-jetty</id>
+						<phase>pre-integration-test</phase>
+						<goals>
+							<goal>run</goal>
+						</goals>
+						<configuration>
+							<scanIntervalSeconds>0</scanIntervalSeconds>
+							<daemon>true</daemon>
+						</configuration>
+					</execution>
+					<execution>
+						<id>stop-jetty</id>
+						<phase>post-integration-test</phase>
+						<goals>
+							<goal>stop</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+
+		</plugins>
+
+	</build>
+
+	<profiles>
+		<profile>
+			<id>jee6</id>
+			<build>
+				<plugins>
+					<plugin>
+						<artifactId>maven-war-plugin</artifactId>
+						<configuration>
+							<webappDirectory>${project.build.directory}/${project.build.finalName}-jee6</webappDirectory>
+							<classifier>jee6</classifier>
+						</configuration>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+</project>
--- /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
--- /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<Long> 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<Long>(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<Long> getContributorsList(){
+		if(contributorsList == null){
+			reloadContributorsList();
+		}
+		return contributorsList;
+	}
+	
+	public List<String> getContributorsNameList(){
+		List<String> list = new ArrayList<String>();
+		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<Long>();
+		try {
+			JSONArray array = new JSONArray(this.contributors);
+			for(int i=0; i<array.length(); i++){
+				this.contributorsList.add(array.getLong(i));
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public void addContributor(Long userId){
+		if(!getContributorsList().contains(userId)){
+			getContributorsList().add(userId);
+		}
+		upgradeContributors();
+	}
+	
+	public void removeContributor(Long userId){
+		if(getContributorsList().contains(userId)){
+			getContributorsList().remove(userId);
+			this.upgradeContributors();
+		}
+	}
+	
+	public void upgradeContributors(){
+		JSONArray array = new JSONArray(getContributorsList());
+		this.contributors = array.toString();
+	}
+	
+	
+	public Long getSectionId() {
+		return sectionId;
+	}
+
+	public void setSectionId(Long sectionId) {
+		this.sectionId = sectionId;
+	}
+
+	public Long getUserId() {
+		return userId;
+	}
+
+	public void setUserId(Long userId) {
+		this.userId = userId;
+	}
+
+	public String getContributors() {
+		return contributors;
+	}
+
+	public void setContributors(String contributors) {
+		this.contributors = contributors;
+	}
+	
+	public String getLabel() {
+		return label;
+	}
+
+	public void setLabel(String label) {
+		this.label = label;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}	
+
+	public Long getCurrentLastFileId() {
+		return currentLastFileId;
+	}
+
+	public void setCurrentLastFileId(Long currentLastFileId) {
+		this.currentLastFileId = currentLastFileId;
+	}
+
+	public DuplexKey<Long, Long> getKey(){
+		return new DuplexKey<Long, Long>(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<Long> 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;
+	}	
+}
--- /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<LGFile> {
+	
+	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<Long, Long> getKey(){
+		return new DuplexKey<Long, Long>(this.branchId, this.id);
+	}
+	
+	@Override
+	public String toString(){
+		return "LGFile [id=" + id + ", branchId=" + branchId + ", fileName=" + fileName + "]";
+	}
+}
--- /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<Long, Long> getKey(){
+		return new DuplexKey<Long, Long>(this.userId, this.id);
+	}
+}
--- /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 + "]";
+    }
+
+}
+
--- /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() {}
+	
+	
+}
--- /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;
+	}
+	
+}
--- /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();
+		}
+	}
+	
+}
--- /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<VDCUser> userList;
+	
+	static{
+		userList = new ArrayList<VDCUser>();
+		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<VDCUser> 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<VDCUser> getAllUsers() throws Exception{
+		List<VDCUser> list = new ArrayList<VDCUser>();
+		
+		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<userArray.length(); i++){
+					JSONObject userJson = userArray.getJSONObject(i);
+					VDCUser user = new VDCUser(userJson);
+					list.add(user);
+				}
+					
+			}
+			
+			
+		} catch (Exception e) {
+			if(response != null){
+				System.err.println(response.content);
+			}
+			e.printStackTrace();
+		}
+		
+		return list;	
+	}
+	
+	public static VDCUser login(String userName, String password) throws Exception{
+		
+		System.out.println("userName=" + userName + ", password=" + password);
+		
+		String query = PropertiesUtils.getPropValue("dvn_server") + "/getUser?user=" + userName + "&password=" + password;
+		
+		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")){
+				VDCUser user = new VDCUser(json.getJSONObject("user"));
+				return user;	
+			}
+			
+			
+		} catch (Exception e) {
+			if(response != null){
+				System.err.println(response.content);
+			}
+			e.printStackTrace();
+		}
+		
+		return null;
+	}
+
+	
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/dataverse/bo/VDCUser.java	Tue Mar 10 14:50:41 2015 +0100
@@ -0,0 +1,117 @@
+package de.mpiwg.gazetteer.dataverse.bo;
+
+import org.json.JSONObject;
+
+import de.mpiwg.gazetteer.utils.JSONUtils;
+
+/**
+ * See: edu.harvard.iq.dvn.core.admin.VDCUser
+ * @author jurzua
+ *
+ */
+public class VDCUser {
+
+	private String userName;
+    private String email;
+    private String firstName;
+    private String lastName;
+    private String institution;
+    private Long id;
+    private Long version;
+    private Long position;
+    
+    private String password;
+    public VDCUser(Long id, String userName, String password){
+    	this.id = id;
+    	this.userName = userName;
+    	this.password = password;
+    }
+    
+    public VDCUser(JSONObject json){
+    	
+    	this.email = JSONUtils.getString(json, "email");
+    	this.firstName = JSONUtils.getString(json, "firstName");
+    	this.userName = JSONUtils.getString(json, "userName");
+    	this.lastName = JSONUtils.getString(json, "lastName");
+    	this.institution = JSONUtils.getString(json, "institution");
+    	
+    	this.id = JSONUtils.getLong(json, "id");
+    	this.position = JSONUtils.getLong(json, "position");
+    	this.version = JSONUtils.getLong(json, "version");
+    }
+
+	public String getUserName() {
+		return userName;
+	}
+
+	public void setUserName(String userName) {
+		this.userName = userName;
+	}
+
+	public String getEmail() {
+		return email;
+	}
+
+	public void setEmail(String email) {
+		this.email = email;
+	}
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+
+	public String getInstitution() {
+		return institution;
+	}
+
+	public void setInstitution(String institution) {
+		this.institution = institution;
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getVersion() {
+		return version;
+	}
+
+	public void setVersion(Long version) {
+		this.version = version;
+	}
+
+	public Long getPosition() {
+		return position;
+	}
+
+	public void setPosition(Long position) {
+		this.position = position;
+	}
+
+	public String getPassword() {
+		return password;
+	}
+
+	public void setPassword(String password) {
+		this.password = password;
+	}    
+
+	
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/db/DBBook.java	Tue Mar 10 14:50:41 2015 +0100
@@ -0,0 +1,96 @@
+package de.mpiwg.gazetteer.db;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class DBBook {
+
+	private String id;
+	private String name;
+	private Integer line;
+	private String period;
+	//
+	private String author;
+	private String edition;
+	private String volume;
+	
+	public DBBook(ResultSet rs) throws SQLException{
+		this.name = rs.getString("name");
+		this.id = rs.getString("id");
+		this.line = rs.getInt("line");
+		this.period = rs.getString("period");
+		this.author = rs.getString("author");
+		this.edition = rs.getString("edition");
+		this.volume = rs.getString("volume");
+	}
+
+
+	public String getId() {
+		return id;
+	}
+
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+
+	public String getName() {
+		return name;
+	}
+
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+
+	public Integer getLine() {
+		return line;
+	}
+
+
+	public void setLine(Integer line) {
+		this.line = line;
+	}
+
+
+	public String getPeriod() {
+		return period;
+	}
+
+
+	public void setPeriod(String period) {
+		this.period = period;
+	}
+
+
+	public String getAuthor() {
+		return author;
+	}
+
+
+	public void setAuthor(String author) {
+		this.author = author;
+	}
+
+
+	public String getEdition() {
+		return edition;
+	}
+
+
+	public void setEdition(String edition) {
+		this.edition = edition;
+	}
+
+
+	public String getVolume() {
+		return volume;
+	}
+
+
+	public void setVolume(String volume) {
+		this.volume = volume;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/db/DBSection.java	Tue Mar 10 14:50:41 2015 +0100
@@ -0,0 +1,81 @@
+package de.mpiwg.gazetteer.db;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import de.mpiwg.gazetteer.bo.LGBranch;
+
+public class DBSection {
+
+	private Long id;
+	private String name;
+	private String text;
+	
+	private String bookId;
+	private DBBook book;
+	
+	private List<LGBranch> 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<LGBranch> getBranches() {
+		return branches;
+	}
+
+	public void setBranches(List<LGBranch> branches) {
+		this.branches = branches;
+	}
+}
--- /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;
+	}
+	
+}
--- /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();
+		}
+	}
+	
+}
--- /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();
+		}
+	}
+}
--- /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();
+		}
+	}
+	
+}
--- /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();
+	}
+}
--- /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();
+	}
+	
+}
--- /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();
+	}
+	
+}
--- /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];
+	}
+}
--- /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<LGBranch, Long, Long> branchMap = null;
+	
+	protected DuplexMap<LGBranch, Long, Long> getBranchMap(){
+		if(branchMap == null){
+			loadBranches();
+		}
+		return branchMap;
+	}
+	
+	public void loadBranches(){
+		List<LGBranch> list = DBService.getAllLGBranchFromDB();
+		this.branchMap = new DuplexMap<LGBranch, Long, Long>();
+		for(LGBranch item : list){
+			this.branchMap.put(item.getKey(), item);
+		}
+	}
+	
+	
+	private DuplexMap<LGFile, Long, Long> fileMap = null;
+	
+	protected DuplexMap<LGFile, Long, Long> getFileMap(){
+		if(fileMap == null){
+			loadFiles();
+		}
+		return fileMap;
+	}
+	
+	
+	private void loadFiles(){
+		List<LGFile> list = DBService.getAllLGFileFromDB();
+		this.fileMap = new DuplexMap<LGFile, Long, Long>();
+		for(LGFile file : list){
+			this.fileMap.put(file.getKey(), file);
+		}
+	}
+}
--- /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<DBSection> searchSection(List<String> termList) throws SQLException{
+		List<DBSection> list = new ArrayList<DBSection>();
+		
+		Connection conn = null;
+		Statement stmt = null;
+		
+		String query = "SELECT name, id, books_id FROM sections WHERE ";
+		for(int i=0; i<termList.size() ; i++){
+			String term = termList.get(i);
+			if(i>0){
+				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<String> suggestSectionName(String term) throws SQLException {
+		List<String> list = new ArrayList<String>();
+		
+		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<String> suggestSectionId(String input) throws SQLException {
+		List<String> list = new ArrayList<String>();
+		
+		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("<br>");
+	                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<LGFile> getAllLGFileFromDB(){
+		List<LGFile> 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<LGFile> getCurrentLGFilesFromDB(){
+		List<LGFile> 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<LGBranch> getAllLGBranchFromDB(){
+		List<LGBranch> 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"));
+	}
+	
+}
--- /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<SearchRulesFile> 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<LGFile> getAllFiles(Long branchId){
+		List<LGFile> list = getFileMap().getValuesByAKey(branchId);
+		return list;
+	}
+	
+	public List<LGBranch> getBranches(Long userId){
+		List<LGBranch> list = new ArrayList<LGBranch>();
+		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<LGFile> fileToDelete = getFileMap().getValuesByAKey(branch.getId());
+		
+		for(LGFile file : new ArrayList<LGFile>(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();
+		
+	}
+}
--- /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");
+	}
+	
+	
+}
--- /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;
+		}
+	}	
+	
+}
--- /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
--- /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;
+	}
+}
--- /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);
+	}
+	
+}
--- /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<N> 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;
+	}
+}
+
--- /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;
+	}
+	
+}
--- /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;
+	}
+	
+}
--- /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;
+	}
+}
--- /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<String>());
+		}
+		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();
+	}
+	
+}
--- /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; };";
+	}
+}
--- /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<LGFile> allFiles;
+	private String text;
+	private List<VDCUser> suggestionUserList;
+	private List<SelectableObject<VDCUser>> 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<SelectableObject<VDCUser>>();
+				for(Long userId : this.currentBranch.getContributorsList()){
+					VDCUser user = DataverseUtils.getUser(userId);
+					if(user != null){
+						this.contributors.add(new SelectableObject<VDCUser>(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<VDCUser>();
+		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<VDCUser> toDelete = new ArrayList<VDCUser>();
+		for(SelectableObject<VDCUser> so : new ArrayList<SelectableObject<VDCUser>>(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<LGFile> getAllFiles() {
+		return allFiles;
+	}
+
+	public void setAllFiles(List<LGFile> allFiles) {
+		this.allFiles = allFiles;
+	}
+
+	public String getText() {
+		return text;
+	}
+
+	public void setText(String text) {
+		this.text = text;
+	}
+
+	public List<VDCUser> getSuggestionUserList() {
+		return suggestionUserList;
+	}
+
+	public void setSuggestionUserList(List<VDCUser> suggestionUserList) {
+		this.suggestionUserList = suggestionUserList;
+	}
+
+	public List<SelectableObject<VDCUser>> getContributors() {
+		return contributors;
+	}
+
+	public void setContributors(List<SelectableObject<VDCUser>> contributors) {
+		this.contributors = contributors;
+	}	
+}
--- /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<SelectItem> 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<SelectItem>();
+		try {
+			List<String> 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<SelectItem> getSectionSuggestion() {
+		return sectionSuggestion;
+	}
+
+	public void setSectionSuggestion(List<SelectItem> sectionSuggestion) {
+		this.sectionSuggestion = sectionSuggestion;
+	}
+	
+	
+	
+}
--- /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<SelectItem> sectionSuggestion;
+	private List<DBSection> sectionList;
+	private String message;
+	private Map<Long, List<LGBranch>> branchesMap;
+	
+	public void changeSectionName(TextChangeEvent event){
+		logger.debug("changeSectionName");
+		logger.debug("key" + event.getKeyCode());
+		
+		String term = event.getNewValue().toString();
+		
+		this.sectionSuggestion = new ArrayList<SelectItem>();
+		
+		if(!term.contains(",")){
+			
+			try {
+				List<String> 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<String> 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<Long, List<LGBranch>>();
+		List<LGBranch> 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<LGBranch>());
+			}
+			this.branchesMap.get(branch.getSectionId()).add(branch);
+		}
+	}
+	
+	private List<String> splitTerms(){
+		List<String> rs = new ArrayList<String>();
+		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<SelectItem> getSectionSuggestion() {
+		return sectionSuggestion;
+	}
+
+	public void setSectionSuggestion(List<SelectItem> sectionSuggestion) {
+		this.sectionSuggestion = sectionSuggestion;
+	}
+
+	public List<DBSection> getSectionList() {
+		return sectionList;
+	}
+
+	public void setSectionList(List<DBSection> sectionList) {
+		this.sectionList = sectionList;
+	}
+
+	public String getMessage() {
+		return message;
+	}
+}
--- /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<String> msgList = new ArrayList<String>();
+	
+	private List<SelectableObject<LGBranch>> 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<String> getMsgList() {
+		return msgList;
+	}
+
+	public void setMsgList(List<String> 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<LGBranch> so : new ArrayList<SelectableObject<LGBranch>>(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<SelectableObject<LGBranch>>();
+		if(user != null){
+			for(LGBranch branch : DataProvider.getInstance().getBranches(this.user.getId())){
+				if(!branch.isTransientDataLoaded()){
+					branch.loadTransientData();
+				}	
+				this.branches.add(new SelectableObject<LGBranch>(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<SelectableObject<LGBranch>> getBranches() {
+		return branches;
+	}
+
+	public void setBranches(List<SelectableObject<LGBranch>> 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;
+	}
+	
+	
+}
--- /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<String, String> 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
--- /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
--- /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 @@
+<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+<hibernate-configuration>
+	<session-factory>
+
+		<!-- hibernate.cfg.xml -->
+		<property name="c3p0.min_size">5</property>
+		<property name="c3p0.max_size">20</property>
+		<property name="c3p0.timeout">1800</property>
+		<property name="c3p0.max_statements">50</property>
+		<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
+
+		<!-- Database connection settings -->
+		<!-- 
+		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
+		 -->
+		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
+        <property name="hibernate.connection.url">jdbc:mysql://localhost/LGServer?characterEncoding=UTF-8</property>
+        
+        <property name="hibernate.connection.username">root</property>
+		<property name="hibernate.connection.password">admin</property>
+		<property name="hibernate.connection.charSet">UTF-8</property>
+		
+		<!-- JDBC connection pool (use the built-in) -->
+		<property name="hibernate.connection.pool_size">1</property>
+
+		<!-- Enable Hibernate's automatic session context management -->
+		<property name="hibernate.current_session_context_class">thread</property>
+		<!-- Disable the second-level cache -->
+		<!-- 
+		<property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
+ 		-->
+		<!-- 
+		<property name="hibernate.show_sql">true</property> 
+		<property name="hibernate.hbm2ddl.auto">create</property> 
+	    
+		 -->
+	    <mapping class="de.mpiwg.gazetteer.bo.LGBranch"/>
+	    <mapping class="de.mpiwg.gazetteer.bo.LGFile"/>
+		<mapping class="de.mpiwg.gazetteer.bo.Sequence"/>	    
+	</session-factory>
+
+</hibernate-configuration>
--- /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
--- /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 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+         version="2.0">
+  	
+    <lifecycle>
+    	<phase-listener>de.mpiwg.web.jsf.PhaseTracker</phase-listener>
+    </lifecycle>   
+  
+    <managed-bean>
+      <managed-bean-name>sessionBean</managed-bean-name>
+      <managed-bean-class>de.mpiwg.web.SessionBean</managed-bean-class>
+      <managed-bean-scope>session</managed-bean-scope>
+    </managed-bean>
+    
+    <managed-bean>
+      <managed-bean-name>appBean</managed-bean-name>
+      <managed-bean-class>de.mpiwg.web.ApplicationBean</managed-bean-class>
+      <managed-bean-scope>application</managed-bean-scope>
+    </managed-bean>   
+    
+    <navigation-rule>
+    	<navigation-case>
+    		<from-outcome>branchEditor</from-outcome>
+    		<to-view-id>/home/branchEditor.xhtml</to-view-id>
+    		<redirect/>
+    	</navigation-case>  
+		<navigation-case>
+    		<from-outcome>searchPage</from-outcome>
+    		<to-view-id>/home/searchPage.xhtml</to-view-id>
+    		<redirect/>
+    	</navigation-case>      	
+    	<navigation-case>
+    		<from-outcome>fileCreator</from-outcome>
+    		<to-view-id>/home/createNewFile.xhtml</to-view-id>
+    		<redirect/>
+    	</navigation-case>    
+    	<navigation-case>
+    		<from-outcome>home</from-outcome>
+    		<to-view-id>/home/mainPage.xhtml</to-view-id>
+    		<redirect/>
+    	</navigation-case>  	
+    </navigation-rule>
+
+</faces-config>
--- /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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+	id="WebApp_ID" version="3.0">
+
+	<!-- REST API to connect to Extraction Interface -->
+	<!-- 
+	<servlet>
+		<servlet-name>Jersey REST Service</servlet-name>
+		<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+		<init-param>
+			<param-name>com.sun.jersey.config.property.packages</param-name>
+			<param-value>cl.doodoo.rest</param-value>
+		</init-param>
+		<init-param>
+			<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
+			<param-value>true</param-value>
+		</init-param>
+
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>Jersey REST Service</servlet-name>
+		<url-pattern>/rest/*</url-pattern>
+	</servlet-mapping>
+ 	-->
+ 	<!-- 
+     <servlet>
+        <servlet-name>servlet</servlet-name>
+        <servlet-class>de.mpiwg.gazetteer.rest.Servlet</servlet-class>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>servlet</servlet-name>
+        <url-pattern>/rest/*</url-pattern>
+    </servlet-mapping>
+ 	 -->
+ 	<!-- 
+	<servlet>
+        <servlet-name>Jersey Web Application</servlet-name>
+        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>jersey.config.server.provider.packages</param-name>
+            <param-value>de.mpiwg.gazetteer.rest</param-value>
+        </init-param>
+		<init-param>
+		    <param-name>jersey.config.server.provider.classnames</param-name>
+		    <param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
+		</init-param>        
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>Jersey Web Application</servlet-name>
+        <url-pattern>/rest/*</url-pattern>
+    </servlet-mapping>	
+    -->
+    <!-- 
+    <servlet>
+        <servlet-name>de.mpiwg.gazetteer.rest.RestApplication</servlet-name>
+        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>de.mpiwg.gazetteer.rest.RestApplication</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>de.mpiwg.gazetteer.rest.RestApplication</servlet-name>
+        <url-pattern>/rest/*</url-pattern>
+    </servlet-mapping>    
+	 -->	
+
+	<display-name>LGServer</display-name>
+	<welcome-file-list>
+		<!-- <welcome-file>management/companyForm.jsp</welcome-file> -->
+		<welcome-file>home/mainPage.xhtml</welcome-file>
+	</welcome-file-list>
+
+	<servlet-mapping>
+		<servlet-name>jsp</servlet-name>
+		<url-pattern>*.jsp</url-pattern>
+		<url-pattern>*.dcss</url-pattern>
+	</servlet-mapping>
+
+	<session-config> 
+		<session-timeout>60</session-timeout> 
+	</session-config>
+
+	<!-- Icefaces -->
+	<servlet>
+		<servlet-name>Faces Servlet</servlet-name>
+		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>Faces Servlet</servlet-name>
+		<url-pattern>*.xhtml</url-pattern>
+	</servlet-mapping>
+	<context-param>
+		<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
+		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+		<param-value>server</param-value>
+	</context-param>
+	<context-param>
+		<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
+		<param-value>resources.application</param-value>
+	</context-param>
+	<!-- 
+	javax.faces.FacesException: Cannot add the same component twice 
+	<listener>
+		<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
+	</listener>
+	-->
+	<context-param>
+		<param-name>javax.faces.PROJECT_STAGE</param-name>
+		<param-value>Development</param-value>
+	</context-param>
+	<context-param>
+		<param-name>org.icefaces.mandatoryResourceConfiguration</param-name>
+		<param-value></param-value>
+	</context-param>
+	<context-param>
+		<param-name>org.icefaces.ace.theme</param-name>
+		<param-value>none</param-value>
+	</context-param>
+	<context-param>
+		<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
+		<param-value>true</param-value>
+	</context-param>
+	<context-param>
+		<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
+		<param-value>false</param-value>
+	</context-param>
+	<context-param>
+		<description>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</description>
+		<param-name>com.icesoft.faces.gmapKey</param-name>
+		<param-value>ABQIAAAADlu0ZiSTam64EKaCQr9eTRTOTuQNzJNXRlYRLknj4cQ89tFfpxTEqxQnVWL4k55OPICgF5_SOZE06A</param-value>
+	</context-param>
+	<servlet>
+		<servlet-name>Resource Servlet</servlet-name>
+		<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>Resource Servlet</servlet-name>
+		<url-pattern>/xmlhttp/*</url-pattern>
+	</servlet-mapping>
+	<!-- Icefaces End -->
+	<!-- 
+	<mime-mapping>
+    	<extension>rest</extension>
+    	<mime-type>application/xml</mime-type>
+	</mime-mapping>
+	 -->
+</web-app>
\ No newline at end of file
--- /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 @@
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:c="http://java.sun.com/jsp/jstl/core"
+	xmlns:ace="http://www.icefaces.org/icefaces/components"
+	xmlns:ice="http://www.icesoft.com/icefaces/component"
+	xmlns:icecore="http://www.icefaces.org/icefaces/core"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:cl="http://java.sun.com/jsf/composite/jsf/cl"
+	template="../templates/publicTemplate.xhtml">
+	
+	<ui:define name="content">
+
+	<h:form>
+            
+	<ace:dialog id="dialog"
+		header="Message"
+		closable="false"
+		visible="#{!empty sessionBean.branchEditor.suggestionUserList}"
+		modal="true"
+		draggable="false">
+		<h:panelGrid columns="1">
+			<ace:dataTable value="#{sessionBean.branchEditor.suggestionUserList}" var="contributor">
+				<ace:column>
+					<h:commandLink value="#{contributor.userName}" actionListener="#{sessionBean.branchEditor.listenerAddContributor}"/>
+				</ace:column>
+			</ace:dataTable>
+			<h:commandButton 
+				value="Close" actionListener="#{sessionBean.branchEditor.listenerCloseContributorsDialog}" 
+				style="margin-left: auto;margin-right: auto; width:100%;"/>
+		</h:panelGrid>
+	</ace:dialog>
+	</h:form>
+
+		
+			<ice:form styleClass="content">
+			
+				<ice:outputLabel value="Branch Editor" styleClass="subTitle"/>
+				
+				<h:panelGrid columns="1">
+					<h:outputLabel value="No branch loaded!" rendered="#{sessionBean.branchEditor.currentBranch == null}"/>
+				</h:panelGrid>
+				
+				<h:panelGrid columns="2" rendered="#{sessionBean.branchEditor.currentBranch != null}">
+					
+					<h:outputLabel value="Branch" styleClass="subTitle"/>
+					<h:panelGrid columns="2" styleClass="tableComponent">
+						
+						<h:outputLabel value="Id"/>
+						<h:outputLabel value="#{sessionBean.branchEditor.currentBranch.id}"/>
+						
+						<h:outputLabel value="Label"/>
+						<h:panelGrid columns="2">
+							<h:inputText value="#{sessionBean.branchEditor.currentBranch.label}"/>
+							<h:commandButton value="Update" actionListener="#{sessionBean.branchEditor.listenerUpdateBranch}"/>
+						</h:panelGrid>
+						
+						<h:outputLabel value="Section Name"/>
+						<h:outputLabel value="#{sessionBean.branchEditor.currentBranch.sectionName}"/>
+						
+						<h:outputLabel value="Section Id"/>
+						<h:outputLabel value="#{sessionBean.branchEditor.currentBranch.sectionId}"/>
+						
+						<h:outputLabel value="Book Name"/>
+						<h:outputLabel value="#{sessionBean.branchEditor.currentBranch.book.name}"/>
+						
+						<h:outputLabel value="Book Id"/>
+						<h:outputLabel value="#{sessionBean.branchEditor.currentBranch.book.id}"/>
+						
+						<h:outputLabel value="Creator"/>
+						<h:outputLabel value="#{sessionBean.branchEditor.currentBranch.username}"/>
+						
+						<h:outputLabel value="Created"/>
+						<h:outputLabel value="#{sessionBean.branchEditor.currentBranch.fomattedCreation}"/>
+						
+						<h:outputLabel value="Contributors"/>
+						<h:panelGrid columns="2">
+							<ace:dataTable 
+								value="#{sessionBean.branchEditor.contributors}" 
+								var="soContributor">
+								<ace:column>
+							 		<h:outputLabel value="#{soContributor.obj.userName}"/>
+							 	</ace:column>
+							 	<ace:column>
+							 		<h:selectBooleanCheckbox value="#{soContributor.selected}"/>
+							 	</ace:column>
+							</ace:dataTable>
+							<h:panelGrid columns="1">
+								<h:commandButton 
+									value="Add Contributors" 
+									actionListener="#{sessionBean.branchEditor.listenerShowContributorsDialog}"/>
+								<h:commandButton 
+									value="Remove Contributors" 
+									actionListener="#{sessionBean.branchEditor.listenerRemoveContributor}"/>
+							</h:panelGrid>
+							
+						</h:panelGrid>
+						
+					</h:panelGrid>
+					
+					<h:outputLabel value="Current File"  styleClass="subTitle"/>
+					<h:panelGrid columns="2" styleClass="tableComponent">
+					
+						<h:outputLabel value="ID"/>
+						<h:outputText value="#{sessionBean.branchEditor.currentLastFile.id}"/>
+						
+						<h:outputLabel value="Version"/>
+						<h:outputText value="#{sessionBean.branchEditor.currentLastFile.version}"/>
+						
+						<h:outputLabel value="User"/>
+						<h:outputText value="#{sessionBean.branchEditor.currentLastFile.username}"/>
+						
+						<h:outputLabel value="File Name"/>
+						<h:outputText value="#{sessionBean.branchEditor.currentLastFile.fileName}"/>
+						
+						<h:outputLabel value="Created"/>
+						<h:outputText value="#{sessionBean.branchEditor.currentLastFile.fomattedCreation}"/>
+						
+						<h:outputText/>
+						<h:panelGrid columns="1">
+							<h:inputTextarea value="#{sessionBean.branchEditor.text}" style="width: 400px; height: 200px;'"/>
+							<h:commandButton value="Save Changes" actionListener="#{sessionBean.branchEditor.listenerSaveText}"/>						
+						</h:panelGrid>
+						
+					</h:panelGrid>
+					
+					
+					<h:outputLabel value="All files"  styleClass="subTitle"/>
+					<ace:dataTable value="#{sessionBean.branchEditor.allFiles}" var="file" styleClass="tableComponent">
+						<ace:column headerText="ID">
+							<h:outputText value="#{file.id}"/>
+						</ace:column>
+						<ace:column headerText="Version">
+							<h:outputText value="#{file.version}"/>
+						</ace:column>
+						<ace:column headerText="User">
+							<h:outputText value="#{file.username}"/>
+						</ace:column>
+						<ace:column headerText="Created">
+							<h:outputText value="#{file.fomattedCreation}"/>
+						</ace:column>
+						<ace:column headerText="Extraction Interface">
+							
+						</ace:column>
+						<ace:column headerText="Export Table">
+						
+						</ace:column>
+						<ace:column headerText="Text">
+							<h:outputLink 
+								value="#{appBean.rootServer}/rest/text/getFileText?fileId=#{file.id}"
+								target="_blank">
+								<h:graphicImage value="#{appBean.showImage}"/>
+							</h:outputLink>
+						</ace:column>
+					</ace:dataTable>
+								
+				</h:panelGrid>
+				
+
+			</ice:form>
+			
+	</ui:define>
+	
+		
+	
+</ui:composition>
\ No newline at end of file
--- /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 @@
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:c="http://java.sun.com/jsp/jstl/core"
+	xmlns:ace="http://www.icefaces.org/icefaces/components"
+	xmlns:ice="http://www.icesoft.com/icefaces/component"
+	xmlns:icecore="http://www.icefaces.org/icefaces/core"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:cl="http://java.sun.com/jsf/composite/jsf/cl"
+	template="../templates/publicTemplate.xhtml">
+	
+	<ui:define name="content">
+		
+			<ice:form styleClass="content">
+			
+				<ice:outputLabel value="Create New File (Branch)" styleClass="subTitle"/>
+			
+				<h:panelGrid columns="2">
+					
+					<h:outputLabel value="Label"/>
+					<h:inputText value="#{sessionBean.fileCreator.label}"/>
+					
+					
+					<h:outputLabel value="Section Id"/>
+					<h:panelGrid columns="2">
+						<ace:autoCompleteEntry
+							value="#{sessionBean.fileCreator.sectionId}"
+							textChangeListener="#{sessionBean.fileCreator.changeSectionInput}">
+							<f:selectItems value="#{sessionBean.fileCreator.sectionSuggestion}"/>
+						</ace:autoCompleteEntry>
+						<h:commandButton value="Load" actionListener="#{sessionBean.fileCreator.listenerLoadSection}"/>
+					</h:panelGrid>
+					
+					<h:outputText rendered="#{sessionBean.fileCreator.section != null}"/>
+					<h:panelGrid columns="2" rendered="#{sessionBean.fileCreator.section != null}">
+						<h:outputLabel value="Section Name"/>
+						<h:outputLabel value="#{sessionBean.fileCreator.section.name}"/>
+						
+						<h:outputLabel value="Book Id"/>
+						<h:outputLabel value="#{sessionBean.fileCreator.section.book.id}"/>
+						
+						<h:outputLabel value="Book Name"/>
+						<h:outputLabel value="#{sessionBean.fileCreator.section.book.name}"/>
+						
+						<h:outputLabel value="Text"/>
+						<h:inputTextarea value="#{sessionBean.fileCreator.section.text}" style="width: 500px; height: 200px;"/>
+						
+						<h:outputText/>
+						<h:panelGrid columns="2">
+							<h:commandButton value="Save" actionListener="#{sessionBean.fileCreator.listenerSaveNewFile}" onclick="#{appBean.JSConfirmationSave}"/>
+							<h:commandButton value="Reset" actionListener="#{sessionBean.fileCreator.listenerReset}"/>
+						</h:panelGrid>					
+					</h:panelGrid>
+					
+					
+
+					
+				</h:panelGrid>
+			
+				
+			</ice:form>
+			
+	</ui:define>
+	
+		
+	
+</ui:composition>
\ No newline at end of file
--- /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 @@
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:c="http://java.sun.com/jsp/jstl/core"
+	xmlns:ace="http://www.icefaces.org/icefaces/components"
+	xmlns:ice="http://www.icesoft.com/icefaces/component"
+	xmlns:icecore="http://www.icefaces.org/icefaces/core"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:cl="http://java.sun.com/jsf/composite/jsf/cl"
+	template="../templates/publicTemplate.xhtml">
+	
+	<ui:define name="content">
+		
+			<ice:form styleClass="content">
+				<ice:outputLabel value="User's Branches" styleClass="subTitle"/>
+				
+				<h:panelGrid columns="1">
+					
+					<h:commandButton value="Reload" actionListener="#{sessionBean.listenerReloadBranches}"/>
+					 
+					<h:panelGrid columns="1" rendered="#{!empty sessionBean.branches}">
+						<ace:dataTable value="#{sessionBean.branches}" var="soBranch">
+							 
+							 <ace:column headerText="ID">
+							 	<h:outputText value="#{soBranch.obj.id}"/>
+							 </ace:column>
+							 <ace:column headerText="Book ID">
+							 	<h:outputText value="#{soBranch.obj.book.id}"/>
+							 </ace:column>
+							 <ace:column headerText="Book Name">
+							 	<h:outputText value="#{soBranch.obj.book.name}"/>
+							 </ace:column>
+							 <ace:column headerText="Section ID">
+							 	<h:outputText value="#{soBranch.obj.sectionId}"/>
+							 </ace:column>
+							 <ace:column headerText="Section Name">
+							 	<h:outputText value="#{soBranch.obj.sectionName}"/>
+							 </ace:column>
+							 <ace:column headerText="Label">
+							 	<h:outputText value="#{soBranch.obj.label}"/>
+							 </ace:column>
+							 <ace:column headerText="Contributors">
+							 	<ace:dataTable value="#{soBranch.obj.contributorsNameList}" var="contributor">
+							 		<ace:column>
+							 			<h:outputLabel value="#{contributor}"/>
+							 		</ace:column>
+							 	</ace:dataTable>
+							 </ace:column>
+							 <ace:column headerText="Creation">
+							 	<h:outputText value="#{soBranch.obj.fomattedCreation}"/>
+							 </ace:column>
+							 <ace:column headerText="Las Change">
+							 	<h:outputText value="#{soBranch.obj.fomattedLastChange}"/>
+							 </ace:column>
+							 <ace:column headerText="Extraction Interface">
+							 	<h:commandButton value="Load" 
+									onclick="branchInExtractionInterface(#{soBranch.obj.id}, #{soBranch.obj.currentLastFileId}, #{soBranch.obj.sectionId}, '#{soBranch.obj.sectionName}', #{soBranch.obj.book.id}, '#{soBranch.obj.book.name}', #{sessionBean.user.id}, '#{appBean.extractionInterfaceUrl}');"
+									image="#{appBean.editBranchImage}"
+									title="Edit Branch in Extraction Interface"/>
+							 </ace:column>
+							 <ace:column headerText="Dataverse">
+							 	<h:commandButton value="Publish file" image="#{appBean.publishImage}"
+							 		title="Publish in Dataverse (TODO)"/>
+							 </ace:column>
+							 <ace:column headerText="Manage">
+								<h:outputLink 
+									value="#{appBean.rootServer}/home/branchEditor.xhtml?branchId=#{soBranch.obj.id}"
+									title="Manage Branch">
+									<h:graphicImage value="#{appBean.branchDetailsImage}"/>
+								</h:outputLink>
+							 </ace:column>
+							 <ace:column headerText="Select">
+							 	<h:selectBooleanCheckbox value="#{soBranch.selected}"/>
+							 </ace:column>
+						</ace:dataTable>	
+						<h:commandButton value="Delete" actionListener="#{sessionBean.listenerDeleteBranch}" onclick="#{appBean.JSConfirmationDelete}"/>
+					</h:panelGrid>
+				
+				</h:panelGrid>
+			
+				
+			</ice:form>
+			
+	</ui:define>
+	
+		
+	
+</ui:composition>
\ No newline at end of file
--- /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 @@
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:c="http://java.sun.com/jsp/jstl/core"
+	xmlns:ace="http://www.icefaces.org/icefaces/components"
+	xmlns:ice="http://www.icesoft.com/icefaces/component"
+	xmlns:icecore="http://www.icefaces.org/icefaces/core"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:cl="http://java.sun.com/jsf/composite/jsf/cl"
+	template="../templates/publicTemplate.xhtml">
+	
+	<ui:define name="content">
+	
+			<ice:form styleClass="content">
+			
+				<ice:outputLabel value="Search" styleClass="subTitle"/>
+					
+					<h:panelGrid columns="2" style="width: 300px; margin-left: auto;margin-right: auto;">
+						
+							<ace:autoCompleteEntry
+								id="searchTextInput"
+								value="#{sessionBean.searchPage.term}"
+								textChangeListener="#{sessionBean.searchPage.changeSectionName}" style="width: 300px;"
+								valueChangeListener="#{sessionBean.searchPage.changeSectionSearch}">
+								 <f:selectItems value="#{sessionBean.searchPage.sectionSuggestion}"/>
+							</ace:autoCompleteEntry>
+							
+						<h:commandButton 
+							value="Search"
+							title="Search Submit" 
+							actionListener="#{sessionBean.searchPage.listenerSearch}"
+							image="#{appBean.searchImage}"/>
+					</h:panelGrid>
+					
+					<h:outputLabel value="#{sessionBean.searchPage.message}"/>
+					
+					<h:panelGrid columns="1" rendered="#{!empty sessionBean.searchPage.sectionList}" style="width: 90%; margin-left: auto;margin-right: auto;">
+						<ace:dataTable var="section" value="#{sessionBean.searchPage.sectionList}">
+							 <ace:column headerText="Book Id">
+							 	<h:outputText value="#{section.book.id}"/>
+							 </ace:column>
+							 <ace:column headerText="Book Name">
+							 	<h:outputText value="#{section.book.name}"/>
+							 </ace:column>
+							 <ace:column headerText="Section Id">
+							 	<h:outputText value="#{section.id}"/>
+							 </ace:column>
+							 <ace:column headerText="Section Name">
+							 	<h:outputText value="#{section.name}"/>
+							 </ace:column>
+							 <ace:column headerText="Volume">
+							 	<h:outputText value="#{section.book.volume}"/>
+							 </ace:column>
+							 <ace:column headerText="Period">
+							 	<h:outputText value="#{section.book.period}"/>
+							 </ace:column>
+							 <ace:column headerText="Author">
+							 	<h:outputText value="#{section.book.author}"/>
+							 </ace:column>
+							 <ace:column headerText="Edition">
+							 	<h:outputText value="#{section.book.edition}"/>
+							 </ace:column>
+							 <ace:column headerText="Create Branch">
+							 	<h:commandButton 
+							 		value="Create Branch in Extraction Interface"
+							 		title="Create Branch in Extraction Interface" 
+							 		onclick="sectionInExtractionInterface(#{section.id}, '#{section.name}', #{section.book.id}, '#{section.book.name}', #{sessionBean.user.id}, '#{appBean.extractionInterfaceUrl}');"
+							 		image="#{appBean.newBranchImage}"/>
+							 </ace:column>								 
+							 <ace:column headerText="Existing Branches">
+							 	<ace:dataTable value="#{section.branches}" var="branch" rendered="#{!empty 	section.branches}">
+							 		<ace:column>
+							 			<h:outputLabel value="[#{branch.id}] #{branch.label}"/>
+							 		</ace:column>
+							 		<ace:column>
+							 			<h:commandButton value="Edit Branch in Extraction Interface" 
+											onclick="branchInExtractionInterface(#{branch.id}, #{branch.currentLastFileId}, #{branch.sectionId}, '#{branch.sectionName}', #{branch.book.id}, '#{branch.book.name}', #{sessionBean.user.id}, '#{appBean.extractionInterfaceUrl}');"
+											image="#{appBean.editBranchImage}" title="Edit Branch in Extraction Interface"
+											styleClass="iconLink"/>
+										<h:outputLink 
+											title="Manage Branch"
+											value="#{appBean.rootServer}/home/branchEditor.xhtml?branchId=#{branch.id}"
+											styleClass="iconLink">
+											<h:graphicImage value="#{appBean.branchDetailsImage}"/>
+										</h:outputLink>
+							 		</ace:column>
+							 	</ace:dataTable>
+							 </ace:column>
+						</ace:dataTable>
+					</h:panelGrid>
+					
+				
+			</ice:form>
+			
+	</ui:define>
+	
+		
+	
+</ui:composition>
\ No newline at end of file
--- /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 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta charset="utf-8">
+		<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
+		<script type="text/javascript" src="http://localhost:8080/gazetteer-server/resources/js/jquery.steps.js"></script>
+
+		
+	</head>
+	
+	 <body>
+		<script>
+            $("#wizard").steps();
+		</script>
+		<div id="wizard"></div>
+    </body>
+</html>
\ No newline at end of file
--- /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
Binary file src/main/webapp/resources/images/branch_details_16.png has changed
Binary file src/main/webapp/resources/images/branch_details_32.png has changed
Binary file src/main/webapp/resources/images/edit_16.png has changed
Binary file src/main/webapp/resources/images/edit_32.png has changed
Binary file src/main/webapp/resources/images/edit_branch_16.png has changed
Binary file src/main/webapp/resources/images/edit_branch_32.png has changed
Binary file src/main/webapp/resources/images/new_branch_16.png has changed
Binary file src/main/webapp/resources/images/new_branch_32.png has changed
Binary file src/main/webapp/resources/images/publish_16.png has changed
Binary file src/main/webapp/resources/images/publish_32.png has changed
Binary file src/main/webapp/resources/images/search_16.png has changed
Binary file src/main/webapp/resources/images/search_32.png has changed
Binary file src/main/webapp/resources/images/search_64.png has changed
Binary file src/main/webapp/resources/images/show_16.png has changed
Binary file src/main/webapp/resources/images/show_32.png has changed
--- /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
--- /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: "<strong>HTML code</strong>"
+});
\ No newline at end of file
--- /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 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:icecore="http://www.icefaces.org/icefaces/core"
+	xmlns:ace="http://www.icefaces.org/icefaces/components"
+	xmlns:ice="http://www.icesoft.com/icefaces/component">
+
+
+<h:head>
+	<title>Local Monographs Service</title>
+	<ice:outputStyle href="#{appBean.rootServer}/resources/css/style.css" />
+	<script type="text/javascript" src="#{appBean.rootServer}/resources/js/general.js"/>
+</h:head>
+
+<h:body>
+		
+	<h:form id="formDialog">
+	<ace:themeSelect value="cupertino"/>
+            
+	<ace:dialog id="dialog"
+		header="Message"
+		closable="false"
+		visible="#{!empty sessionBean.msgList}"
+		modal="true"
+		draggable="false">
+		<h:panelGrid columns="1">
+			<ace:dataTable value="#{sessionBean.msgList}" var="msg">
+				<ace:column>
+					<h:outputText value="#{msg}" />
+				</ace:column>
+			</ace:dataTable>
+			<h:commandButton value="Close" 
+				actionListener="#{sessionBean.listenerCloseMsgPopup}" 
+				style="margin-left: auto;margin-right: auto; width:100%;"
+				onclick="window.location.reload();">
+			</h:commandButton>
+		</h:panelGrid>
+	</ace:dialog>
+	</h:form>
+	
+	<div id="header">
+		<div id="logo">
+			<h1><a href="#"><ice:outputLabel value="Local Gazetter Server"/></a></h1>
+		</div>
+	</div>
+	
+	<div id="login">
+		<div id="loginContent">
+		
+			<ice:form id="loginForm">
+				
+				<h:panelGrid columns="5" rendered="#{sessionBean.user == null}">
+					<h:outputLink value="#{appBean.dvnRootServer}/faces/login/AddAccountPage.xhtml">Create Account</h:outputLink>
+					<ice:outputLabel value="Login"/>
+					<ice:inputText value="#{sessionBean.userName}"/>
+					<ice:inputSecret value="#{sessionBean.password}"
+						actionListener="#{sessionBean.listenerLogin}"/>
+					<ice:commandButton value="Submit" 
+						actionListener="#{sessionBean.listenerLogin}">
+					</ice:commandButton>
+				</h:panelGrid>
+				
+				<h:panelGrid columns="3" rendered="#{sessionBean.user != null}">
+					<h:outputText value="Logged in as: #{sessionBean.user.userName}"/>
+					<h:outputText value=" | "/>
+					<h:commandLink value="logout" actionListener="#{sessionBean.listenerLogout}"/>
+				</h:panelGrid>
+			</ice:form>		
+			
+		</div>
+	</div>
+	
+	<h:form>
+ 		<ace:menuBar autoSubmenuDisplay="true" style="margin: 0 auto; width: 80%;">
+			<ace:menuItem value="Home" 
+				url="#{appBean.rootServer}/home/mainPage.xhtml"/>
+			<ace:menuItem value="Manage Branch" 
+				url="#{appBean.rootServer}/home/branchEditor.xhtml" />
+			<ace:menuItem value="Create File"
+				url="#{appBean.rootServer}/home/createNewFile.xhtml" />
+			<ace:menuItem value="Search Section"
+				url="#{appBean.rootServer}/home/searchPage.xhtml" />	
+		</ace:menuBar>
+	</h:form>
+	
+	<div id="page">
+		<h:panelGrid rendered="#{sessionBean.user != null}" style="width:100%">
+			<ui:insert name="content"/>
+		</h:panelGrid>
+		<h:panelGrid rendered="#{sessionBean.user == null}" style="width:100%">
+			<h:outputLabel value="You must login!"/>
+		</h:panelGrid>
+
+	</div>
+</h:body>
+</html>