diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3a4c97a --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + org.tinystruct + tinystruct + 2.0.0-SNAPSHOT + + + org.tinystruct + tinystruct2.0 + 1.0.0 + system + ${basedir}/WEB-INF/lib/struct-2.0.jar + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + UTF-8 + 1.8 + 1.8 + + + ${basedir}/src/main/java + ${basedir}/WEB-INF/classes + + + org.apache.maven.plugins + maven-compiler-plugin + + + + \ No newline at end of file diff --git a/src/ApplicationGenerator.java b/src/main/java/ApplicationGenerator.java similarity index 96% rename from src/ApplicationGenerator.java rename to src/main/java/ApplicationGenerator.java index 7030402..0caee55 100755 --- a/src/ApplicationGenerator.java +++ b/src/main/java/ApplicationGenerator.java @@ -1,30 +1,30 @@ - -import org.tinystruct.ApplicationException; -import org.tinystruct.data.tools.Generator; -import org.tinystruct.data.tools.MySQLGenerator; - -public class ApplicationGenerator { - public static void main(String[]arguments) - { - System.out.println("Please type the command like this:ApplicationGenerator className tableName"); - - try { - String[] list=new String[]{"book"}; -// String[] list=new String[]{"Member","User","Rights","Role"}; - for(String className:list) - { - Generator generator=new MySQLGenerator(); - generator.setFileName("src/custom/objects/"); - generator.setPackageName("custom.objects"); - generator.importPackages("java.util.Date"); - generator.create(className,className); - System.out.println("class:"+className+" table:"+className); - } - } catch (ApplicationException e) { - e.printStackTrace(); - } - - System.out.println("OK!"); - System.out.close(); - } + +import org.tinystruct.ApplicationException; +import org.tinystruct.data.tools.Generator; +import org.tinystruct.data.tools.MySQLGenerator; + +public class ApplicationGenerator { + public static void main(String[]arguments) + { + System.out.println("Please type the command like this:ApplicationGenerator className tableName"); + + try { + String[] list=new String[]{"book"}; +// String[] list=new String[]{"Member","User","Rights","Role"}; + for(String className:list) + { + Generator generator=new MySQLGenerator(); + generator.setFileName("src/custom/objects/"); + generator.setPackageName("custom.objects"); + generator.importPackages("java.util.Date"); + generator.create(className,className); + System.out.println("class:"+className+" table:"+className); + } + } catch (ApplicationException e) { + e.printStackTrace(); + } + + System.out.println("OK!"); + System.out.close(); + } } \ No newline at end of file diff --git a/src/application.properties b/src/main/java/application.properties similarity index 100% rename from src/application.properties rename to src/main/java/application.properties diff --git a/src/custom/objects/User.java b/src/main/java/custom/objects/User.java similarity index 96% rename from src/custom/objects/User.java rename to src/main/java/custom/objects/User.java index 6a6e549..7492346 100644 --- a/src/custom/objects/User.java +++ b/src/main/java/custom/objects/User.java @@ -1,251 +1,251 @@ -package custom.objects; - -import java.util.Date; - -import org.tinystruct.data.component.Row; -import org.tinystruct.data.component.AbstractData; - -public class User extends AbstractData { - private String email; - private String username; - private String password; - private String nickname; - private String introduce; - private int gender; - private String firstName; - private String lastName; - private String country; - private String city; - private String telephone; - private String postcode; - private String lastloginIP; - private Date lastloginTime; - private Date registrationTime; - private String logo; - private boolean status; - - public String getId() - { - return String.valueOf(this.Id); - } - - public void setEmail(String email) - { - this.email=this.setFieldAsString("email",email); - } - - public String getEmail() - { - return this.email; - } - - public void setUsername(String username) - { - this.username=this.setFieldAsString("username",username); - } - - public String getUsername() - { - return this.username; - } - - public void setPassword(String password) - { - this.password=this.setFieldAsString("password",password); - } - - public String getPassword() - { - return this.password; - } - - public void setNickname(String nickname) - { - this.nickname=this.setFieldAsString("nickname",nickname); - } - - public String getNickname() - { - return this.nickname; - } - - public void setIntroduce(String introduce) - { - this.introduce=this.setFieldAsString("introduce",introduce); - } - - public String getIntroduce() - { - return this.introduce; - } - - public void setGender(int gender) - { - this.gender=this.setFieldAsInt("gender",gender); - } - - public int getGender() - { - return this.gender; - } - - public void setFirstName(String firstName) - { - this.firstName=this.setFieldAsString("firstName",firstName); - } - - public String getFirstName() - { - return this.firstName; - } - - public void setLastName(String lastName) - { - this.lastName=this.setFieldAsString("lastName",lastName); - } - - public String getLastName() - { - return this.lastName; - } - - public void setCountry(String country) - { - this.country=this.setFieldAsString("country",country); - } - - public String getCountry() - { - return this.country; - } - - public void setCity(String city) - { - this.city=this.setFieldAsString("city",city); - } - - public String getCity() - { - return this.city; - } - - public void setTelephone(String telephone) - { - this.telephone=this.setFieldAsString("telephone",telephone); - } - - public String getTelephone() - { - return this.telephone; - } - - public void setPostcode(String postcode) - { - this.postcode=this.setFieldAsString("postcode",postcode); - } - - public String getPostcode() - { - return this.postcode; - } - - public void setLastloginIP(String lastloginIP) - { - this.lastloginIP=this.setFieldAsString("lastloginIP",lastloginIP); - } - - public String getLastloginIP() - { - return this.lastloginIP; - } - - public void setLastloginTime(Date lastloginTime) - { - this.lastloginTime=this.setFieldAsDate("lastloginTime",lastloginTime); - } - - public Date getLastloginTime() - { - return this.lastloginTime; - } - - public void setRegistrationTime(Date registrationTime) - { - this.registrationTime=this.setFieldAsDate("registrationTime",registrationTime); - } - - public Date getRegistrationTime() - { - return this.registrationTime; - } - - public void setLogo(String logo) - { - this.logo=this.setFieldAsString("logo",logo); - } - - public String getLogo() - { - return this.logo; - } - - public void setStatus(boolean status) - { - this.status=this.setFieldAsBoolean("status",status); - } - - public boolean getStatus() - { - return this.status; - } - - - @Override - public void setData(Row row) { - if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").stringValue()); - if(row.getFieldInfo("email")!=null) this.setEmail(row.getFieldInfo("email").stringValue()); - if(row.getFieldInfo("username")!=null) this.setUsername(row.getFieldInfo("username").stringValue()); - if(row.getFieldInfo("password")!=null) this.setPassword(row.getFieldInfo("password").stringValue()); - if(row.getFieldInfo("nickname")!=null) this.setNickname(row.getFieldInfo("nickname").stringValue()); - if(row.getFieldInfo("introduce")!=null) this.setIntroduce(row.getFieldInfo("introduce").stringValue()); - if(row.getFieldInfo("gender")!=null) this.setGender(row.getFieldInfo("gender").intValue()); - if(row.getFieldInfo("first_name")!=null) this.setFirstName(row.getFieldInfo("first_name").stringValue()); - if(row.getFieldInfo("last_name")!=null) this.setLastName(row.getFieldInfo("last_name").stringValue()); - if(row.getFieldInfo("country")!=null) this.setCountry(row.getFieldInfo("country").stringValue()); - if(row.getFieldInfo("city")!=null) this.setCity(row.getFieldInfo("city").stringValue()); - if(row.getFieldInfo("telephone")!=null) this.setTelephone(row.getFieldInfo("telephone").stringValue()); - if(row.getFieldInfo("postcode")!=null) this.setPostcode(row.getFieldInfo("postcode").stringValue()); - if(row.getFieldInfo("lastlogin_IP")!=null) this.setLastloginIP(row.getFieldInfo("lastlogin_IP").stringValue()); - if(row.getFieldInfo("lastlogin_time")!=null) this.setLastloginTime(row.getFieldInfo("lastlogin_time").dateValue()); - if(row.getFieldInfo("registration_time")!=null) this.setRegistrationTime(row.getFieldInfo("registration_time").dateValue()); - if(row.getFieldInfo("logo")!=null) this.setLogo(row.getFieldInfo("logo").stringValue()); - if(row.getFieldInfo("status")!=null) this.setStatus(row.getFieldInfo("status").booleanValue()); - } - - @Override - public String toString() { - StringBuffer buffer=new StringBuffer(); - buffer.append("{"); - buffer.append("\"Id\":\""+this.getId()+"\""); - buffer.append(",\"email\":\""+this.getEmail()+"\""); - buffer.append(",\"username\":\""+this.getUsername()+"\""); - buffer.append(",\"password\":\""+this.getPassword()+"\""); - buffer.append(",\"nickname\":\""+this.getNickname()+"\""); - buffer.append(",\"introduce\":\""+this.getIntroduce()+"\""); - buffer.append(",\"gender\":"+this.getGender()); - buffer.append(",\"firstName\":\""+this.getFirstName()+"\""); - buffer.append(",\"lastName\":\""+this.getLastName()+"\""); - buffer.append(",\"country\":\""+this.getCountry()+"\""); - buffer.append(",\"city\":\""+this.getCity()+"\""); - buffer.append(",\"telephone\":\""+this.getTelephone()+"\""); - buffer.append(",\"postcode\":\""+this.getPostcode()+"\""); - buffer.append(",\"lastloginIP\":\""+this.getLastloginIP()+"\""); - buffer.append(",\"lastloginTime\":\""+this.getLastloginTime()+"\""); - buffer.append(",\"registrationTime\":\""+this.getRegistrationTime()+"\""); - buffer.append(",\"logo\":\""+this.getLogo()+"\""); - buffer.append(",\"status\":"+this.getStatus()); - buffer.append("}"); - return buffer.toString(); - } - +package custom.objects; + +import java.util.Date; + +import org.tinystruct.data.component.Row; +import org.tinystruct.data.component.AbstractData; + +public class User extends AbstractData { + private String email; + private String username; + private String password; + private String nickname; + private String introduce; + private int gender; + private String firstName; + private String lastName; + private String country; + private String city; + private String telephone; + private String postcode; + private String lastloginIP; + private Date lastloginTime; + private Date registrationTime; + private String logo; + private boolean status; + + public String getId() + { + return String.valueOf(this.Id); + } + + public void setEmail(String email) + { + this.email=this.setFieldAsString("email",email); + } + + public String getEmail() + { + return this.email; + } + + public void setUsername(String username) + { + this.username=this.setFieldAsString("username",username); + } + + public String getUsername() + { + return this.username; + } + + public void setPassword(String password) + { + this.password=this.setFieldAsString("password",password); + } + + public String getPassword() + { + return this.password; + } + + public void setNickname(String nickname) + { + this.nickname=this.setFieldAsString("nickname",nickname); + } + + public String getNickname() + { + return this.nickname; + } + + public void setIntroduce(String introduce) + { + this.introduce=this.setFieldAsString("introduce",introduce); + } + + public String getIntroduce() + { + return this.introduce; + } + + public void setGender(int gender) + { + this.gender=this.setFieldAsInt("gender",gender); + } + + public int getGender() + { + return this.gender; + } + + public void setFirstName(String firstName) + { + this.firstName=this.setFieldAsString("firstName",firstName); + } + + public String getFirstName() + { + return this.firstName; + } + + public void setLastName(String lastName) + { + this.lastName=this.setFieldAsString("lastName",lastName); + } + + public String getLastName() + { + return this.lastName; + } + + public void setCountry(String country) + { + this.country=this.setFieldAsString("country",country); + } + + public String getCountry() + { + return this.country; + } + + public void setCity(String city) + { + this.city=this.setFieldAsString("city",city); + } + + public String getCity() + { + return this.city; + } + + public void setTelephone(String telephone) + { + this.telephone=this.setFieldAsString("telephone",telephone); + } + + public String getTelephone() + { + return this.telephone; + } + + public void setPostcode(String postcode) + { + this.postcode=this.setFieldAsString("postcode",postcode); + } + + public String getPostcode() + { + return this.postcode; + } + + public void setLastloginIP(String lastloginIP) + { + this.lastloginIP=this.setFieldAsString("lastloginIP",lastloginIP); + } + + public String getLastloginIP() + { + return this.lastloginIP; + } + + public void setLastloginTime(Date lastloginTime) + { + this.lastloginTime=this.setFieldAsDate("lastloginTime",lastloginTime); + } + + public Date getLastloginTime() + { + return this.lastloginTime; + } + + public void setRegistrationTime(Date registrationTime) + { + this.registrationTime=this.setFieldAsDate("registrationTime",registrationTime); + } + + public Date getRegistrationTime() + { + return this.registrationTime; + } + + public void setLogo(String logo) + { + this.logo=this.setFieldAsString("logo",logo); + } + + public String getLogo() + { + return this.logo; + } + + public void setStatus(boolean status) + { + this.status=this.setFieldAsBoolean("status",status); + } + + public boolean getStatus() + { + return this.status; + } + + + @Override + public void setData(Row row) { + if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").stringValue()); + if(row.getFieldInfo("email")!=null) this.setEmail(row.getFieldInfo("email").stringValue()); + if(row.getFieldInfo("username")!=null) this.setUsername(row.getFieldInfo("username").stringValue()); + if(row.getFieldInfo("password")!=null) this.setPassword(row.getFieldInfo("password").stringValue()); + if(row.getFieldInfo("nickname")!=null) this.setNickname(row.getFieldInfo("nickname").stringValue()); + if(row.getFieldInfo("introduce")!=null) this.setIntroduce(row.getFieldInfo("introduce").stringValue()); + if(row.getFieldInfo("gender")!=null) this.setGender(row.getFieldInfo("gender").intValue()); + if(row.getFieldInfo("first_name")!=null) this.setFirstName(row.getFieldInfo("first_name").stringValue()); + if(row.getFieldInfo("last_name")!=null) this.setLastName(row.getFieldInfo("last_name").stringValue()); + if(row.getFieldInfo("country")!=null) this.setCountry(row.getFieldInfo("country").stringValue()); + if(row.getFieldInfo("city")!=null) this.setCity(row.getFieldInfo("city").stringValue()); + if(row.getFieldInfo("telephone")!=null) this.setTelephone(row.getFieldInfo("telephone").stringValue()); + if(row.getFieldInfo("postcode")!=null) this.setPostcode(row.getFieldInfo("postcode").stringValue()); + if(row.getFieldInfo("lastlogin_IP")!=null) this.setLastloginIP(row.getFieldInfo("lastlogin_IP").stringValue()); + if(row.getFieldInfo("lastlogin_time")!=null) this.setLastloginTime(row.getFieldInfo("lastlogin_time").dateValue()); + if(row.getFieldInfo("registration_time")!=null) this.setRegistrationTime(row.getFieldInfo("registration_time").dateValue()); + if(row.getFieldInfo("logo")!=null) this.setLogo(row.getFieldInfo("logo").stringValue()); + if(row.getFieldInfo("status")!=null) this.setStatus(row.getFieldInfo("status").booleanValue()); + } + + @Override + public String toString() { + StringBuffer buffer=new StringBuffer(); + buffer.append("{"); + buffer.append("\"Id\":\""+this.getId()+"\""); + buffer.append(",\"email\":\""+this.getEmail()+"\""); + buffer.append(",\"username\":\""+this.getUsername()+"\""); + buffer.append(",\"password\":\""+this.getPassword()+"\""); + buffer.append(",\"nickname\":\""+this.getNickname()+"\""); + buffer.append(",\"introduce\":\""+this.getIntroduce()+"\""); + buffer.append(",\"gender\":"+this.getGender()); + buffer.append(",\"firstName\":\""+this.getFirstName()+"\""); + buffer.append(",\"lastName\":\""+this.getLastName()+"\""); + buffer.append(",\"country\":\""+this.getCountry()+"\""); + buffer.append(",\"city\":\""+this.getCity()+"\""); + buffer.append(",\"telephone\":\""+this.getTelephone()+"\""); + buffer.append(",\"postcode\":\""+this.getPostcode()+"\""); + buffer.append(",\"lastloginIP\":\""+this.getLastloginIP()+"\""); + buffer.append(",\"lastloginTime\":\""+this.getLastloginTime()+"\""); + buffer.append(",\"registrationTime\":\""+this.getRegistrationTime()+"\""); + buffer.append(",\"logo\":\""+this.getLogo()+"\""); + buffer.append(",\"status\":"+this.getStatus()); + buffer.append("}"); + return buffer.toString(); + } + } \ No newline at end of file diff --git a/src/custom/objects/User.map.xml b/src/main/java/custom/objects/User.map.xml similarity index 98% rename from src/custom/objects/User.map.xml rename to src/main/java/custom/objects/User.map.xml index 8808171..17f8572 100644 --- a/src/custom/objects/User.map.xml +++ b/src/main/java/custom/objects/User.map.xml @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/custom/objects/article.java b/src/main/java/custom/objects/article.java similarity index 96% rename from src/custom/objects/article.java rename to src/main/java/custom/objects/article.java index d5d7c08..e915131 100755 --- a/src/custom/objects/article.java +++ b/src/main/java/custom/objects/article.java @@ -1,80 +1,80 @@ -package custom.objects; - -import org.tinystruct.data.component.AbstractData; -import org.tinystruct.data.component.Row; - -public class article extends AbstractData { - private String bookId; - private int chapterId; - private int sectionId; - private String content; - - public Integer getId() - { - return Integer.parseInt(this.Id.toString()); - } - - public void setBookId(String bookId) - { - this.bookId=this.setFieldAsString("bookId",bookId); - } - - public String getBookId() - { - return this.bookId; - } - - public void setChapterId(int chapterId) - { - this.chapterId=this.setFieldAsInt("chapterId",chapterId); - } - - public int getChapterId() - { - return this.chapterId; - } - - public void setSectionId(int sectionId) - { - this.sectionId=this.setFieldAsInt("sectionId",sectionId); - } - - public int getSectionId() - { - return this.sectionId; - } - - public void setContent(String content) - { - this.content=this.setFieldAsString("content",content); - } - - public String getContent() - { - return this.content; - } - - - @Override - public void setData(Row row) { - if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").intValue()); - if(row.getFieldInfo("book_id")!=null) this.setBookId(row.getFieldInfo("book_id").stringValue()); - if(row.getFieldInfo("chapter_id")!=null) this.setChapterId(row.getFieldInfo("chapter_id").intValue()); - if(row.getFieldInfo("section_id")!=null) this.setSectionId(row.getFieldInfo("section_id").intValue()); - if(row.getFieldInfo("content")!=null) this.setContent(row.getFieldInfo("content").stringValue()); - } - - @Override - public String toString() { - StringBuffer buffer=new StringBuffer(); - buffer.append("{"); - buffer.append("\"Id\":"+this.getId()); - buffer.append(",\"bookId\":\""+this.getBookId()+"\""); - buffer.append(",\"chapterId\":"+this.getChapterId()); - buffer.append(",\"sectionId\":"+this.getSectionId()); - buffer.append(",\"content\":\""+this.getContent()+"\""); - buffer.append("}"); - return buffer.toString(); - } - +package custom.objects; + +import org.tinystruct.data.component.AbstractData; +import org.tinystruct.data.component.Row; + +public class article extends AbstractData { + private String bookId; + private int chapterId; + private int sectionId; + private String content; + + public Integer getId() + { + return Integer.parseInt(this.Id.toString()); + } + + public void setBookId(String bookId) + { + this.bookId=this.setFieldAsString("bookId",bookId); + } + + public String getBookId() + { + return this.bookId; + } + + public void setChapterId(int chapterId) + { + this.chapterId=this.setFieldAsInt("chapterId",chapterId); + } + + public int getChapterId() + { + return this.chapterId; + } + + public void setSectionId(int sectionId) + { + this.sectionId=this.setFieldAsInt("sectionId",sectionId); + } + + public int getSectionId() + { + return this.sectionId; + } + + public void setContent(String content) + { + this.content=this.setFieldAsString("content",content); + } + + public String getContent() + { + return this.content; + } + + + @Override + public void setData(Row row) { + if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").intValue()); + if(row.getFieldInfo("book_id")!=null) this.setBookId(row.getFieldInfo("book_id").stringValue()); + if(row.getFieldInfo("chapter_id")!=null) this.setChapterId(row.getFieldInfo("chapter_id").intValue()); + if(row.getFieldInfo("section_id")!=null) this.setSectionId(row.getFieldInfo("section_id").intValue()); + if(row.getFieldInfo("content")!=null) this.setContent(row.getFieldInfo("content").stringValue()); + } + + @Override + public String toString() { + StringBuffer buffer=new StringBuffer(); + buffer.append("{"); + buffer.append("\"Id\":"+this.getId()); + buffer.append(",\"bookId\":\""+this.getBookId()+"\""); + buffer.append(",\"chapterId\":"+this.getChapterId()); + buffer.append(",\"sectionId\":"+this.getSectionId()); + buffer.append(",\"content\":\""+this.getContent()+"\""); + buffer.append("}"); + return buffer.toString(); + } + } \ No newline at end of file diff --git a/src/custom/objects/article.map.xml b/src/main/java/custom/objects/article.map.xml similarity index 98% rename from src/custom/objects/article.map.xml rename to src/main/java/custom/objects/article.map.xml index f1a136c..0fd000a 100755 --- a/src/custom/objects/article.map.xml +++ b/src/main/java/custom/objects/article.map.xml @@ -1,11 +1,11 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/src/custom/objects/book.java b/src/main/java/custom/objects/book.java similarity index 96% rename from src/custom/objects/book.java rename to src/main/java/custom/objects/book.java index 8b83779..bafae91 100755 --- a/src/custom/objects/book.java +++ b/src/main/java/custom/objects/book.java @@ -1,121 +1,121 @@ -package custom.objects; - -import java.util.Date; - -import org.tinystruct.data.component.Row; -import org.tinystruct.data.component.AbstractData; - -public class book extends AbstractData { - private String name; - private String cover; - private String author; - private String translator; - private String publisher; - private Date publishDate; - private String language; - - public String getId() - { - return String.valueOf(this.Id); - } - - public void setName(String name) - { - this.name=this.setFieldAsString("name",name); - } - - public String getName() - { - return this.name; - } - - public void setCover(String cover) - { - this.cover=this.setFieldAsString("cover",cover); - } - - public String getCover() - { - return this.cover; - } - - public void setAuthor(String author) - { - this.author=this.setFieldAsString("author",author); - } - - public String getAuthor() - { - return this.author; - } - - public void setTranslator(String translator) - { - this.translator=this.setFieldAsString("translator",translator); - } - - public String getTranslator() - { - return this.translator; - } - - public void setPublisher(String publisher) - { - this.publisher=this.setFieldAsString("publisher",publisher); - } - - public String getPublisher() - { - return this.publisher; - } - - public void setPublishDate(Date publishDate) - { - this.publishDate=this.setFieldAsDate("publishDate",publishDate); - } - - public Date getPublishDate() - { - return this.publishDate; - } - - public void setLanguage(String language) - { - this.language=this.setFieldAsString("language",language); - } - - public String getLanguage() - { - return this.language; - } - - - @Override - public void setData(Row row) { - if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").stringValue()); - if(row.getFieldInfo("name")!=null) this.setName(row.getFieldInfo("name").stringValue()); - if(row.getFieldInfo("cover")!=null) this.setCover(row.getFieldInfo("cover").stringValue()); - if(row.getFieldInfo("author")!=null) this.setAuthor(row.getFieldInfo("author").stringValue()); - if(row.getFieldInfo("translator")!=null) this.setTranslator(row.getFieldInfo("translator").stringValue()); - if(row.getFieldInfo("publisher")!=null) this.setPublisher(row.getFieldInfo("publisher").stringValue()); - if(row.getFieldInfo("publish_date")!=null) this.setPublishDate(row.getFieldInfo("publish_date").dateValue()); - if(row.getFieldInfo("language")!=null) this.setLanguage(row.getFieldInfo("language").stringValue()); - } - - @Override - public String toString() { - StringBuffer buffer=new StringBuffer(); - buffer.append("{"); - buffer.append("\"Id\":\""+this.getId()+"\""); - buffer.append(",\"name\":\""+this.getName()+"\""); - buffer.append(",\"cover\":\""+this.getCover()+"\""); - buffer.append(",\"author\":\""+this.getAuthor()+"\""); - buffer.append(",\"translator\":\""+this.getTranslator()+"\""); - buffer.append(",\"publisher\":\""+this.getPublisher()+"\""); - buffer.append(",\"publishDate\":\""+this.getPublishDate()+"\""); - buffer.append(",\"language\":\""+this.getLanguage()+"\""); - buffer.append("}"); - return buffer.toString(); - } - +package custom.objects; + +import java.util.Date; + +import org.tinystruct.data.component.Row; +import org.tinystruct.data.component.AbstractData; + +public class book extends AbstractData { + private String name; + private String cover; + private String author; + private String translator; + private String publisher; + private Date publishDate; + private String language; + + public String getId() + { + return String.valueOf(this.Id); + } + + public void setName(String name) + { + this.name=this.setFieldAsString("name",name); + } + + public String getName() + { + return this.name; + } + + public void setCover(String cover) + { + this.cover=this.setFieldAsString("cover",cover); + } + + public String getCover() + { + return this.cover; + } + + public void setAuthor(String author) + { + this.author=this.setFieldAsString("author",author); + } + + public String getAuthor() + { + return this.author; + } + + public void setTranslator(String translator) + { + this.translator=this.setFieldAsString("translator",translator); + } + + public String getTranslator() + { + return this.translator; + } + + public void setPublisher(String publisher) + { + this.publisher=this.setFieldAsString("publisher",publisher); + } + + public String getPublisher() + { + return this.publisher; + } + + public void setPublishDate(Date publishDate) + { + this.publishDate=this.setFieldAsDate("publishDate",publishDate); + } + + public Date getPublishDate() + { + return this.publishDate; + } + + public void setLanguage(String language) + { + this.language=this.setFieldAsString("language",language); + } + + public String getLanguage() + { + return this.language; + } + + + @Override + public void setData(Row row) { + if(row.getFieldInfo("id")!=null) this.setId(row.getFieldInfo("id").stringValue()); + if(row.getFieldInfo("name")!=null) this.setName(row.getFieldInfo("name").stringValue()); + if(row.getFieldInfo("cover")!=null) this.setCover(row.getFieldInfo("cover").stringValue()); + if(row.getFieldInfo("author")!=null) this.setAuthor(row.getFieldInfo("author").stringValue()); + if(row.getFieldInfo("translator")!=null) this.setTranslator(row.getFieldInfo("translator").stringValue()); + if(row.getFieldInfo("publisher")!=null) this.setPublisher(row.getFieldInfo("publisher").stringValue()); + if(row.getFieldInfo("publish_date")!=null) this.setPublishDate(row.getFieldInfo("publish_date").dateValue()); + if(row.getFieldInfo("language")!=null) this.setLanguage(row.getFieldInfo("language").stringValue()); + } + + @Override + public String toString() { + StringBuffer buffer=new StringBuffer(); + buffer.append("{"); + buffer.append("\"Id\":\""+this.getId()+"\""); + buffer.append(",\"name\":\""+this.getName()+"\""); + buffer.append(",\"cover\":\""+this.getCover()+"\""); + buffer.append(",\"author\":\""+this.getAuthor()+"\""); + buffer.append(",\"translator\":\""+this.getTranslator()+"\""); + buffer.append(",\"publisher\":\""+this.getPublisher()+"\""); + buffer.append(",\"publishDate\":\""+this.getPublishDate()+"\""); + buffer.append(",\"language\":\""+this.getLanguage()+"\""); + buffer.append("}"); + return buffer.toString(); + } + } \ No newline at end of file diff --git a/src/custom/objects/book.map.xml b/src/main/java/custom/objects/book.map.xml similarity index 98% rename from src/custom/objects/book.map.xml rename to src/main/java/custom/objects/book.map.xml index aa8c83d..166b335 100755 --- a/src/custom/objects/book.map.xml +++ b/src/main/java/custom/objects/book.map.xml @@ -1,14 +1,14 @@ - - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/src/themes/hello.view b/src/main/java/themes/hello.view similarity index 95% rename from src/themes/hello.view rename to src/main/java/themes/hello.view index a33f7fc..f951894 100644 --- a/src/themes/hello.view +++ b/src/main/java/themes/hello.view @@ -1,35 +1,35 @@ - - - -Hello - - -

-:) -

-
-
-//5?Array(i).join('  '): Array(10 - i).join('  ')) + String.fromCharCode(96+i));\n\
-}\n\
-");
-
-println('What the result will be? see the below result.');
-println(Array(10).join('--'));
-for(var i=1;i<10;i++) {
-	println((i>5?Array(i).join('  '): Array(10 - i).join('  ')) + String.fromCharCode(96+i));
-}
-println(Array(10).join('--'));
-
- //]]>
-
-
- - + + + +Hello + + +

+:) +

+
+
+//5?Array(i).join('  '): Array(10 - i).join('  ')) + String.fromCharCode(96+i));\n\
+}\n\
+");
+
+println('What the result will be? see the below result.');
+println(Array(10).join('--'));
+for(var i=1;i<10;i++) {
+	println((i>5?Array(i).join('  '): Array(10 - i).join('  ')) + String.fromCharCode(96+i));
+}
+println(Array(10).join('--'));
+
+ //]]>
+
+
+ + diff --git a/src/themes/reading.view b/src/main/java/themes/reading.view similarity index 97% rename from src/themes/reading.view rename to src/main/java/themes/reading.view index c5c86f0..d379469 100644 --- a/src/themes/reading.view +++ b/src/main/java/themes/reading.view @@ -1,121 +1,121 @@ - - - - - - - - - - - - - {%book.name%} - - - - - - - - - - - - - - - - - - -
- -

{%book.name%}

-
[%book.info%]
- - -
{%content%}
- - -
- -
-
-

© 2015

-
-
- - - - - - - - + + + + + + + + + + + + + {%book.name%} + + + + + + + + + + + + + + + + + + +
+ +

{%book.name%}

+
[%book.info%]
+ + +
{%content%}
+ + +
+ +
+
+

© 2015

+
+
+ + + + + + + + diff --git a/src/themes/smalltalk.view b/src/main/java/themes/smalltalk.view similarity index 96% rename from src/themes/smalltalk.view rename to src/main/java/themes/smalltalk.view index cb34fd2..b0a7ca9 100644 --- a/src/themes/smalltalk.view +++ b/src/main/java/themes/smalltalk.view @@ -1,729 +1,729 @@ - - - - - - - - - - Small Talk - - - - - - - - - - - - - - - - - - - - -
- -

Welcome to use smalltalk application!

-

{%topic%}

-
-
    -
    -
    -
    Share the link to invite others join this conversation: [%LINK:talk/join%]/{%meeting_code%}
    -
    -
    - - - - -
    - - -
    - - -
    -
    - - - - - - -
    -
    -

    © 2017

    -
    -
    - - - - - - - - + + + + + + + + + + Small Talk + + + + + + + + + + + + + + + + + + + + +
    + +

    Welcome to use smalltalk application!

    +

    {%topic%}

    +
    +
      +
      +
      +
      Share the link to invite others join this conversation: [%LINK:talk/join%]/{%meeting_code%}
      +
      +
      + + + + +
      + + +
      + + +
      +
      + + + + + + +
      +
      +

      © 2017

      +
      +
      + + + + + + + + diff --git a/src/themes/startup.view b/src/main/java/themes/startup.view similarity index 96% rename from src/themes/startup.view rename to src/main/java/themes/startup.view index a02f76a..ea4e040 100644 --- a/src/themes/startup.view +++ b/src/main/java/themes/startup.view @@ -1,70 +1,70 @@ - - - - -"Welcome to use CDT!" - - - - - - - - - -
      -
      -Please change my style. - - -
      - + + + + +"Welcome to use CDT!" + + + + + + + + + +
      +
      +Please change my style. + + +
      + \ No newline at end of file diff --git a/src/themes/time.view b/src/main/java/themes/time.view similarity index 100% rename from src/themes/time.view rename to src/main/java/themes/time.view diff --git a/src/themes/tinyeditor.view b/src/main/java/themes/tinyeditor.view similarity index 100% rename from src/themes/tinyeditor.view rename to src/main/java/themes/tinyeditor.view diff --git a/src/tinystruct/examples/error.java b/src/main/java/tinystruct/examples/error.java similarity index 100% rename from src/tinystruct/examples/error.java rename to src/main/java/tinystruct/examples/error.java diff --git a/src/tinystruct/examples/firstApplication.java b/src/main/java/tinystruct/examples/firstApplication.java similarity index 96% rename from src/tinystruct/examples/firstApplication.java rename to src/main/java/tinystruct/examples/firstApplication.java index 5cac45b..cdb3de5 100644 --- a/src/tinystruct/examples/firstApplication.java +++ b/src/main/java/tinystruct/examples/firstApplication.java @@ -1,143 +1,143 @@ -package tinystruct.examples; -import org.tinystruct.AbstractApplication; -import org.tinystruct.Application; -import org.tinystruct.ApplicationContext; -import org.tinystruct.ApplicationException; -import org.tinystruct.data.component.Builder; -import org.tinystruct.data.component.Table; -import org.tinystruct.data.tools.Generator; -import org.tinystruct.data.tools.MySQLGenerator; -import org.tinystruct.system.ApplicationManager; - -import custom.objects.User; - -public class firstApplication extends AbstractApplication { - - @Override - public void init() { - // TODO Auto-generated method stub - this.setAction("praise", "praise"); - this.setAction("say", "say"); - this.setAction("youhappy", "happy"); - - this.setAction("user", "findUser"); - this.setAction("users", "findUsers"); - - this.setAction("version", "version", "GET"); - this.setAction("version", "setVersion","POST"); - - this.setAction("read", "read"); - - this.setAction("generate", "generate_with_user_table"); - } - - public String praise(){ - return "Praise to the Lord!"; - } - - public boolean happy(){ - return true; - } - - public Object read(String json,String name){ - Builder builder = new Builder(); - try { - builder.parse(json); - } catch (ApplicationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return builder.get(name); - } - - public String say(String words){ - return words; - } - - @Override - public String version() { - // TODO Auto-generated method stub - return this.context.getAttribute("name") + this.context.getAttribute("number").toString(); - } - - public void setVersion(float number){ - this.context.setAttribute("name", "struct"); - this.context.setAttribute("number", number); - } - - public void generate_with_user_table(){ - try { - String[] list=new String[]{"User"}; - Generator generator=new MySQLGenerator(); - for(String className:list) - { - generator.setFileName("src/custom/objects/"); - generator.setPackageName("custom.objects"); - generator.importPackages("java.util.Date"); - generator.create(className,className); - System.out.println("class:"+className+" table:"+className); - System.out.println("Done!"); - } - } catch (ApplicationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public User findUser(Object userId) throws ApplicationException{ - - if(userId!=null){ - User user = new User(); - user.setId(userId); - user.findOneById(); - - return user; - } - - return null; - } - - public Table findUsers() throws ApplicationException{ - return new User().findAll(); - } - - /** - * The following example code only for you to reference. - * @param args - * @throws ApplicationException - */ - public static void main(String[]args) throws ApplicationException { - ApplicationManager.install(new firstApplication()); - - System.out.println(ApplicationManager.call("praise", null)); // Praise to the Lord! - System.out.println("I am "+ApplicationManager.call("youhappy", null)+"ly happy"); // I am truely happy - - ApplicationManager.call("say/Hello World", null); // Hello World - - Application app=ApplicationManager.get( firstApplication.class.getName()); - app.invoke("say", new Object[]{"

      Hello, World!

      "}); //

      Hello, World!

      - app.invoke("say", new Object[]{"

      Bye!

      "}); //

      Bye!

      - - ApplicationContext context=new ApplicationContext(); - context.setAttribute("name", "struct"); - context.setAttribute("number", 2.0); - - context.setAttribute("METHOD", "GET"); - System.out.println("Current version: "+ApplicationManager.call("version", context)); // Current version: struct2.0 - - context.setAttribute("METHOD", "POST"); - ApplicationManager.call("version/3", context); - - context.setAttribute("METHOD", "GET"); - System.out.println("Current version: "+ApplicationManager.call("version", context)); // Current version: struct3.0 - - Object name = app.invoke("read", new Object[]{"{\"name\":\"Mover\",\"age\":30}","name"}); - System.out.println(name); - - ApplicationManager.call("generate", null); - - System.out.println(ApplicationManager.call("user/1", null)); // http://localhost:8080/user/1 - System.out.println(ApplicationManager.call("users", null)); // http://localhost:8080/users - } +package tinystruct.examples; +import org.tinystruct.AbstractApplication; +import org.tinystruct.Application; +import org.tinystruct.ApplicationContext; +import org.tinystruct.ApplicationException; +import org.tinystruct.data.component.Builder; +import org.tinystruct.data.component.Table; +import org.tinystruct.data.tools.Generator; +import org.tinystruct.data.tools.MySQLGenerator; +import org.tinystruct.system.ApplicationManager; + +import custom.objects.User; + +public class firstApplication extends AbstractApplication { + + @Override + public void init() { + // TODO Auto-generated method stub + this.setAction("praise", "praise"); + this.setAction("say", "say"); + this.setAction("youhappy", "happy"); + + this.setAction("user", "findUser"); + this.setAction("users", "findUsers"); + + this.setAction("version", "version", "GET"); + this.setAction("version", "setVersion","POST"); + + this.setAction("read", "read"); + + this.setAction("generate", "generate_with_user_table"); + } + + public String praise(){ + return "Praise to the Lord!"; + } + + public boolean happy(){ + return true; + } + + public Object read(String json,String name){ + Builder builder = new Builder(); + try { + builder.parse(json); + } catch (ApplicationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return builder.get(name); + } + + public String say(String words){ + return words; + } + + @Override + public String version() { + // TODO Auto-generated method stub + return this.context.getAttribute("name") + this.context.getAttribute("number").toString(); + } + + public void setVersion(float number){ + this.context.setAttribute("name", "struct"); + this.context.setAttribute("number", number); + } + + public void generate_with_user_table(){ + try { + String[] list=new String[]{"User"}; + Generator generator=new MySQLGenerator(); + for(String className:list) + { + generator.setFileName("src/custom/objects/"); + generator.setPackageName("custom.objects"); + generator.importPackages("java.util.Date"); + generator.create(className,className); + System.out.println("class:"+className+" table:"+className); + System.out.println("Done!"); + } + } catch (ApplicationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public User findUser(Object userId) throws ApplicationException{ + + if(userId!=null){ + User user = new User(); + user.setId(userId); + user.findOneById(); + + return user; + } + + return null; + } + + public Table findUsers() throws ApplicationException{ + return new User().findAll(); + } + + /** + * The following example code only for you to reference. + * @param args + * @throws ApplicationException + */ + public static void main(String[]args) throws ApplicationException { + ApplicationManager.install(new firstApplication()); + + System.out.println(ApplicationManager.call("praise", null)); // Praise to the Lord! + System.out.println("I am "+ApplicationManager.call("youhappy", null)+"ly happy"); // I am truely happy + + ApplicationManager.call("say/Hello World", null); // Hello World + + Application app=ApplicationManager.get( firstApplication.class.getName()); + app.invoke("say", new Object[]{"

      Hello, World!

      "}); //

      Hello, World!

      + app.invoke("say", new Object[]{"

      Bye!

      "}); //

      Bye!

      + + ApplicationContext context=new ApplicationContext(); + context.setAttribute("name", "struct"); + context.setAttribute("number", 2.0); + + context.setAttribute("METHOD", "GET"); + System.out.println("Current version: "+ApplicationManager.call("version", context)); // Current version: struct2.0 + + context.setAttribute("METHOD", "POST"); + ApplicationManager.call("version/3", context); + + context.setAttribute("METHOD", "GET"); + System.out.println("Current version: "+ApplicationManager.call("version", context)); // Current version: struct3.0 + + Object name = app.invoke("read", new Object[]{"{\"name\":\"Mover\",\"age\":30}","name"}); + System.out.println(name); + + ApplicationManager.call("generate", null); + + System.out.println(ApplicationManager.call("user/1", null)); // http://localhost:8080/user/1 + System.out.println(ApplicationManager.call("users", null)); // http://localhost:8080/users + } } \ No newline at end of file diff --git a/src/tinystruct/examples/hello.java b/src/main/java/tinystruct/examples/hello.java similarity index 82% rename from src/tinystruct/examples/hello.java rename to src/main/java/tinystruct/examples/hello.java index 86cb1c5..3a4e0fd 100644 --- a/src/tinystruct/examples/hello.java +++ b/src/main/java/tinystruct/examples/hello.java @@ -75,26 +75,6 @@ public static void main(String[] args) throws ApplicationException, Instantiatio ApplicationManager.install((Application) clz.newInstance()); ApplicationManager.call("say/Merry Christmas!", null); } - - String path="i/say/hi/James/How are you?"; - int pos = -1; - String tpath = path; - StringBuffer buffer=new StringBuffer(); - buffer.delete(0, 1); - while ((pos = tpath.lastIndexOf('/'))!=-1) { - tpath = tpath.substring(0, pos); - System.out.println("route:"+tpath); -// action = actions.getAction(tpath, method); - - if(true) { - String arg = path.substring(pos+1); - String[] _args = arg.split("/"); - - for(String arg1 : _args) - System.out.println(arg1); - } - } - } } diff --git a/src/tinystruct/examples/image2.java b/src/main/java/tinystruct/examples/image2.java similarity index 100% rename from src/tinystruct/examples/image2.java rename to src/main/java/tinystruct/examples/image2.java diff --git a/src/tinystruct/examples/reading.java b/src/main/java/tinystruct/examples/reading.java similarity index 97% rename from src/tinystruct/examples/reading.java rename to src/main/java/tinystruct/examples/reading.java index 7f0f288..e0479b5 100644 --- a/src/tinystruct/examples/reading.java +++ b/src/main/java/tinystruct/examples/reading.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package tinystruct.examples; - +package tinystruct.examples; + import java.io.IOException; import java.net.URL; import java.text.SimpleDateFormat; @@ -43,533 +43,533 @@ import custom.objects.User; import custom.objects.article; import custom.objects.book; - - -public class reading extends AbstractApplication { - private String bookId; - private int chapterId; - private int sectionId; - - private int maxChapter = 0; - private int lastChapterId; - private int nextChapterId; - private HttpServletResponse response; - private book book; - private HttpServletRequest request; - private User usr; - - @Override - public void init() { - this.setAction("book", "read"); - this.setAction("book/api", "api"); - this.setAction("book/feed", "feed"); + + +public class reading extends AbstractApplication { + private String bookId; + private int chapterId; + private int sectionId; + + private int maxChapter = 0; + private int lastChapterId; + private int nextChapterId; + private HttpServletResponse response; + private book book; + private HttpServletRequest request; + private User usr; + + @Override + public void init() { + this.setAction("book", "read"); + this.setAction("book/api", "api"); + this.setAction("book/feed", "feed"); this.setText("holy.book.forward"); this.setText("holy.book.previous"); this.setText("holy.book.next"); - - this.book=new book(); - - this.setVariable("TEMPLATES_DIR", "/themes", false); + + this.book=new book(); + + this.setVariable("TEMPLATES_DIR", "/themes", false); this.setVariable("metas", ""); - - String username=""; - if(this.getVariable("username")!=null) { - username = String.valueOf(this.getVariable("username").getValue()); - } - - this.setText("page.welcome.hello", (username == null || username.trim() - .length() == 0) ? "" : username + ","); - } - - @Override - public String version() { - return null; - } - + + String username=""; + if(this.getVariable("username")!=null) { + username = String.valueOf(this.getVariable("username").getValue()); + } + + this.setText("page.welcome.hello", (username == null || username.trim() + .length() == 0) ? "" : username + ","); + } + + @Override + public String version() { + return null; + } + public Object read() throws ApplicationException { throw new ApplicationException("Invalid book Id"); - } - - public Object read(String bookId) throws ApplicationException { - return this.read(bookId, 1); - } - - public Object read(String bookId,int chapterId) throws ApplicationException { - return this.read(bookId, chapterId, 0); - } - - public Object read(String bookId, int chapterId, int sectionId) throws ApplicationException { + } + + public Object read(String bookId) throws ApplicationException { + return this.read(bookId, 1); + } + + public Object read(String bookId,int chapterId) throws ApplicationException { + return this.read(bookId, chapterId, 0); + } + + public Object read(String bookId, int chapterId, int sectionId) throws ApplicationException { if(bookId == null) throw new ApplicationException("Invalid book Id"); - - if(chapterId == 0) chapterId=1; - - this.request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - this.setVariable("action", this.config.get("default.base_url")+this.context.getAttribute("REQUEST_ACTION").toString()); - this.setVariable("base_url", String.valueOf(this.context.getAttribute("HTTP_HOST"))); - - HttpSession session = this.request.getSession(); - if(session.getAttribute("usr")!=null) { - this.usr = (User) session.getAttribute("usr"); - - this.setVariable("user.status",""); - this.setVariable("user.profile",""+this.usr.getEmail()+""); - this.setVariable("scripts","$.ajax({url:\""+this.getLink("services/getwords")+"\",dataType:\"xml\",type:'GET'}).success(function(data){data=wordsXML(data);ldialog.show(data);});"); - } - else { - this.setVariable("user.status",""+this.getProperty("page.login.caption")+""); - this.setVariable("user.profile",""); - this.setVariable("scripts",""); - } - - this.bookId = bookId; - this.chapterId = chapterId; - this.sectionId = sectionId; - - book = book==null?new book():this.book; - try { - String lang = this.getLocale().toString(); - if(lang.equalsIgnoreCase("en_GB")) { - lang = "en_US"; - } - - Table table = book.findWith("WHERE id=? and language=?", - new Object[] { this.bookId, lang }); - - if (table.size() > 0) { - Row row = table.get(0); - book.setData(row); - } - } catch (ApplicationException e) { - e.printStackTrace(); - } - + + if(chapterId == 0) chapterId=1; + + this.request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + this.setVariable("action", this.config.get("default.base_url")+this.context.getAttribute("REQUEST_ACTION").toString()); + this.setVariable("base_url", String.valueOf(this.context.getAttribute("HTTP_HOST"))); + + HttpSession session = this.request.getSession(); + if(session.getAttribute("usr")!=null) { + this.usr = (User) session.getAttribute("usr"); + + this.setVariable("user.status",""); + this.setVariable("user.profile",""+this.usr.getEmail()+""); + this.setVariable("scripts","$.ajax({url:\""+this.getLink("services/getwords")+"\",dataType:\"xml\",type:'GET'}).success(function(data){data=wordsXML(data);ldialog.show(data);});"); + } + else { + this.setVariable("user.status",""+this.getProperty("page.login.caption")+""); + this.setVariable("user.profile",""); + this.setVariable("scripts",""); + } + + this.bookId = bookId; + this.chapterId = chapterId; + this.sectionId = sectionId; + + book = book==null?new book():this.book; + try { + String lang = this.getLocale().toString(); + if(lang.equalsIgnoreCase("en_GB")) { + lang = "en_US"; + } + + Table table = book.findWith("WHERE id=? and language=?", + new Object[] { this.bookId, lang }); + + if (table.size() > 0) { + Row row = table.get(0); + book.setData(row); + } + } catch (ApplicationException e) { + e.printStackTrace(); + } + this.setVariable(new DataVariable("book",book), true); - this.setText("book.info", new Object[]{book.getAuthor(), book.getPublishDate(), book.getPublisher()}); - - String condition = "book_id=? and chapter_id=?"; - - String where = "WHERE " + condition + " order by section_id"; - - article article = new article(); - - Table vtable = article.findWith(where, new Object[] {this.bookId,this.chapterId}); - - this.maxChapter = article.setRequestFields("max(chapter_id) as max_chapter").findWith("WHERE book_id=?", - new Object[] { this.bookId }).get(0).get(0).get("max_chapter").intValue(); - this.lastChapterId = this.chapterId - 1 <= 0 ? 1 : this.chapterId - 1; - this.nextChapterId = this.chapterId + 1 > this.maxChapter ? this.maxChapter - : this.chapterId + 1; - - this.setVariable("chapterId", String.valueOf(this.chapterId)); - this.setVariable("sectionId", String.valueOf(this.sectionId)); - this.setVariable("maxchapter", String.valueOf(this.maxChapter)); - this.setVariable("lastchapter", String.valueOf(this.lastChapterId)); - this.setVariable("nextchapter", String.valueOf(this.nextChapterId)); - + this.setText("book.info", new Object[]{book.getAuthor(), book.getPublishDate(), book.getPublisher()}); + + String condition = "book_id=? and chapter_id=?"; + + String where = "WHERE " + condition + " order by section_id"; + + article article = new article(); + + Table vtable = article.findWith(where, new Object[] {this.bookId,this.chapterId}); + + this.maxChapter = article.setRequestFields("max(chapter_id) as max_chapter").findWith("WHERE book_id=?", + new Object[] { this.bookId }).get(0).get(0).get("max_chapter").intValue(); + this.lastChapterId = this.chapterId - 1 <= 0 ? 1 : this.chapterId - 1; + this.nextChapterId = this.chapterId + 1 > this.maxChapter ? this.maxChapter + : this.chapterId + 1; + + this.setVariable("chapterId", String.valueOf(this.chapterId)); + this.setVariable("sectionId", String.valueOf(this.sectionId)); + this.setVariable("maxchapter", String.valueOf(this.maxChapter)); + this.setVariable("lastchapter", String.valueOf(this.lastChapterId)); + this.setVariable("nextchapter", String.valueOf(this.nextChapterId)); + this.setText("holy.book.info", book.getName(),this.chapterId,this.maxChapter); - + this.setVariable(new DataVariable("book",book), true); - - int count = vtable.size(); - StringBuffer content = new StringBuffer(); - String line; - - if (count > 0) { - int i; - - content.append("
      "); - - for (i = 0; i < count; i++) { - Row item = vtable.get(i); - article.setData(item); - - line = article.getContent(); - - if(line!=null) { - if (i == 0 && line.trim().length()>0 && line.charAt(0)!='<') - line = "" + line.substring(0, 1) - + "" + line.substring(1, line.length()); + + int count = vtable.size(); + StringBuffer content = new StringBuffer(); + String line; + + if (count > 0) { + int i; + + content.append("
      "); + + for (i = 0; i < count; i++) { + Row item = vtable.get(i); + article.setData(item); + + line = article.getContent(); + + if(line!=null) { + if (i == 0 && line.trim().length()>0 && line.charAt(0)!='<') + line = "" + line.substring(0, 1) + + "" + line.substring(1, line.length()); if(line.contains("div")){ System.err.println(article.getId()); - } - line = line.replaceAll("
      ", "
      ").replaceAll("\n\n", "
      "); - content - .append("" + line + "

      "); - } - - } - - content.append("
      "); - } else { - content.append("暂时没有任何内容"); - } - - this.setVariable("content", content.toString()); - - return this; - } - - public String feed() throws ApplicationException { + } + line = line.replaceAll("
      ", "
      ").replaceAll("\n\n", "
      "); + content + .append("" + line + "

      "); + } + + } + + content.append("
      "); + } else { + content.append("暂时没有任何内容"); + } + + this.setVariable("content", content.toString()); + + return this; + } + + public String feed() throws ApplicationException { throw new ApplicationException("Invalid book Id"); - } - - public String feed(String bookId, int chapterId) throws ApplicationException { - Element element = new Element(); - - Element root = (Element) element.clone(); - root.setName("rss"); - root.setAttribute("version", "2.0"); - root.setAttribute("xmlns:content", - "http://purl.org/rss/1.0/modules/content/"); - root.setAttribute("xmlns:wfw", "http://wellformedweb.org/CommentAPI/"); - root.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); - root.setAttribute("xmlns:atom", "http://www.w3.org/2005/Atom"); - root.setAttribute("xmlns:sy", - "http://purl.org/rss/1.0/modules/syndication/"); - root.setAttribute("xmlns:slash", - "http://purl.org/rss/1.0/modules/slash/"); - - Element channel = (Element) element.clone(); - channel.setName("channel"); - - Element title = (Element) element.clone(); - title.setName("title"); - title.setData(this.getProperty("application.title")); - channel.addElement(title); - - Element atom_link = (Element) element.clone(); - atom_link.setName("atom:link"); - atom_link.setAttribute("href", this.getLink("bible").replaceAll("&", "&")); - atom_link.setAttribute("rel", "self"); - atom_link.setAttribute("type", "application/rss+xml"); - channel.addElement(atom_link); - - Element link = (Element) element.clone(); - link.setName("link"); - link.setData(this.getLink("bible").replaceAll("&", "&")); - channel.addElement(link); - - Element description = (Element) element.clone(); - description.setName("description"); - description.setData(""); - channel.addElement(description); - - Date date = new Date(); - SimpleDateFormat format = new SimpleDateFormat("MM/dd"),full_format = new SimpleDateFormat("yyyy-MM-dd"); - Element lastBuildDate = (Element) element.clone(); - lastBuildDate.setName("lastBuildDate"); - - lastBuildDate.setData(full_format.format(date)); - channel.addElement(lastBuildDate); - - Element generator = (Element) element.clone(); - generator.setName("generator"); - generator.setData("g"); - channel.addElement(generator); - - Element language = (Element) element.clone(); - language.setName("language"); - language.setData(this.getLocale().toString()); - channel.addElement(language); - - Element sy_updatePeriod = (Element) element.clone(); - sy_updatePeriod.setName("sy:updatePeriod"); - sy_updatePeriod.setData("daily"); - channel.addElement(sy_updatePeriod); - - Element sy_updateFrequency = (Element) element.clone(); - sy_updateFrequency.setName("sy:updateFrequency"); - sy_updateFrequency.setData("1"); - channel.addElement(sy_updateFrequency); - - Table vtable = this.load(bookId, chapterId, 0); - - Element item = new Element("item"); - Element item_title = new Element("title"); - item_title.setData(""); - item.addElement(item_title); - - Element item_link = new Element("link"); - item_link.setData(this.getLink("bible").replace("&", "&")+"/"+ format.format(new Date())); - item.addElement(item_link); - - Element item_comments = new Element("comments"); - item_comments.setData(""); - item.addElement(item_comments); - - Element item_pubDate = new Element("pubDate"); - item_pubDate.setData(full_format.format(date)); - item.addElement(item_pubDate); - - Element dc_creator = new Element("dc:creator"); - dc_creator.setData(""); - item.addElement(dc_creator); - - Element category = (Element) element.clone(); - category.setName("category"); - category.setData(format.format(date)); - item.addElement(category); - - Element guid = (Element) element.clone(); - guid.setName("guid"); - guid.setAttribute("isPermaLink", "true"); - guid.setData(this.getLink("feed").replace("&", "&")+"/" - + format.format(new Date())); - item.addElement(guid); - - // start - StringBuffer buffer=new StringBuffer(); - String finded; - buffer.append("
        "); - int count = vtable.size(); - if (count > 0) { - Field fields; - for (Enumeration table = vtable.elements(); table.hasMoreElements();) { - Row row = table.nextElement(); - Iterator iterator = row.iterator(); - - while (iterator.hasNext()) { - fields = iterator.next(); - finded = fields.get("content").value().toString(); - buffer.append("" + fields.get("section_id").intValue() - + "" + finded + ""); - } - } - buffer.append("
      "); - } else { - buffer.append("暂时没有任何内容"); - } - - Element item_description = (Element) element.clone(); - item_description.setName("description"); - item_description - .setData(""); - - item.addElement(item_description); - - Element content_encoded = (Element) element.clone(); - content_encoded.setName("content:encoded"); - content_encoded.setData(""); - item.addElement(content_encoded); - - Element wfw_commentRss = (Element) element.clone(); - wfw_commentRss.setName("wfw:commentRss"); - wfw_commentRss.setData(""); - item.addElement(wfw_commentRss); - - Element slash_comments = (Element) element.clone(); - slash_comments.setName("slash:comments"); - slash_comments.setData(""); - item.addElement(slash_comments); - - channel.addElement(item); - - root.addElement(channel); - // end - - this.response = (HttpServletResponse) this.context - .getAttribute("HTTP_RESPONSE"); - - this.response.setContentType("text/xml;charset=" - + this.config.get("charset")); - - StringBuffer xbuffer = new StringBuffer(); - xbuffer.append("\r\n"); - xbuffer.append(root); - - return xbuffer.toString(); - } - - public Object book() throws ApplicationException { + } + + public String feed(String bookId, int chapterId) throws ApplicationException { + Element element = new Element(); + + Element root = (Element) element.clone(); + root.setName("rss"); + root.setAttribute("version", "2.0"); + root.setAttribute("xmlns:content", + "http://purl.org/rss/1.0/modules/content/"); + root.setAttribute("xmlns:wfw", "http://wellformedweb.org/CommentAPI/"); + root.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); + root.setAttribute("xmlns:atom", "http://www.w3.org/2005/Atom"); + root.setAttribute("xmlns:sy", + "http://purl.org/rss/1.0/modules/syndication/"); + root.setAttribute("xmlns:slash", + "http://purl.org/rss/1.0/modules/slash/"); + + Element channel = (Element) element.clone(); + channel.setName("channel"); + + Element title = (Element) element.clone(); + title.setName("title"); + title.setData(this.getProperty("application.title")); + channel.addElement(title); + + Element atom_link = (Element) element.clone(); + atom_link.setName("atom:link"); + atom_link.setAttribute("href", this.getLink("bible").replaceAll("&", "&")); + atom_link.setAttribute("rel", "self"); + atom_link.setAttribute("type", "application/rss+xml"); + channel.addElement(atom_link); + + Element link = (Element) element.clone(); + link.setName("link"); + link.setData(this.getLink("bible").replaceAll("&", "&")); + channel.addElement(link); + + Element description = (Element) element.clone(); + description.setName("description"); + description.setData(""); + channel.addElement(description); + + Date date = new Date(); + SimpleDateFormat format = new SimpleDateFormat("MM/dd"),full_format = new SimpleDateFormat("yyyy-MM-dd"); + Element lastBuildDate = (Element) element.clone(); + lastBuildDate.setName("lastBuildDate"); + + lastBuildDate.setData(full_format.format(date)); + channel.addElement(lastBuildDate); + + Element generator = (Element) element.clone(); + generator.setName("generator"); + generator.setData("g"); + channel.addElement(generator); + + Element language = (Element) element.clone(); + language.setName("language"); + language.setData(this.getLocale().toString()); + channel.addElement(language); + + Element sy_updatePeriod = (Element) element.clone(); + sy_updatePeriod.setName("sy:updatePeriod"); + sy_updatePeriod.setData("daily"); + channel.addElement(sy_updatePeriod); + + Element sy_updateFrequency = (Element) element.clone(); + sy_updateFrequency.setName("sy:updateFrequency"); + sy_updateFrequency.setData("1"); + channel.addElement(sy_updateFrequency); + + Table vtable = this.load(bookId, chapterId, 0); + + Element item = new Element("item"); + Element item_title = new Element("title"); + item_title.setData(""); + item.addElement(item_title); + + Element item_link = new Element("link"); + item_link.setData(this.getLink("bible").replace("&", "&")+"/"+ format.format(new Date())); + item.addElement(item_link); + + Element item_comments = new Element("comments"); + item_comments.setData(""); + item.addElement(item_comments); + + Element item_pubDate = new Element("pubDate"); + item_pubDate.setData(full_format.format(date)); + item.addElement(item_pubDate); + + Element dc_creator = new Element("dc:creator"); + dc_creator.setData(""); + item.addElement(dc_creator); + + Element category = (Element) element.clone(); + category.setName("category"); + category.setData(format.format(date)); + item.addElement(category); + + Element guid = (Element) element.clone(); + guid.setName("guid"); + guid.setAttribute("isPermaLink", "true"); + guid.setData(this.getLink("feed").replace("&", "&")+"/" + + format.format(new Date())); + item.addElement(guid); + + // start + StringBuffer buffer=new StringBuffer(); + String finded; + buffer.append("
        "); + int count = vtable.size(); + if (count > 0) { + Field fields; + for (Enumeration table = vtable.elements(); table.hasMoreElements();) { + Row row = table.nextElement(); + Iterator iterator = row.iterator(); + + while (iterator.hasNext()) { + fields = iterator.next(); + finded = fields.get("content").value().toString(); + buffer.append("" + fields.get("section_id").intValue() + + "" + finded + ""); + } + } + buffer.append("
      "); + } else { + buffer.append("暂时没有任何内容"); + } + + Element item_description = (Element) element.clone(); + item_description.setName("description"); + item_description + .setData(""); + + item.addElement(item_description); + + Element content_encoded = (Element) element.clone(); + content_encoded.setName("content:encoded"); + content_encoded.setData(""); + item.addElement(content_encoded); + + Element wfw_commentRss = (Element) element.clone(); + wfw_commentRss.setName("wfw:commentRss"); + wfw_commentRss.setData(""); + item.addElement(wfw_commentRss); + + Element slash_comments = (Element) element.clone(); + slash_comments.setName("slash:comments"); + slash_comments.setData(""); + item.addElement(slash_comments); + + channel.addElement(item); + + root.addElement(channel); + // end + + this.response = (HttpServletResponse) this.context + .getAttribute("HTTP_RESPONSE"); + + this.response.setContentType("text/xml;charset=" + + this.config.get("charset")); + + StringBuffer xbuffer = new StringBuffer(); + xbuffer.append("\r\n"); + xbuffer.append(root); + + return xbuffer.toString(); + } + + public Object book() throws ApplicationException { throw new ApplicationException("Invalid book Id"); - } - - public Object book(String bookId) throws ApplicationException { - return this.book(bookId, 1); - } - - public Object book(String bookId,int chapterId) throws ApplicationException { - return this.book(bookId, chapterId, 0); - } - - public Object book(String bookId,int chapterId,int sectionId) throws ApplicationException { - StringBuffer xml = new StringBuffer(); - String finded = ""; - - Table vtable = this.load(bookId, chapterId, sectionId); - - xml.append(""); - xml.append("\r\n"); - Field fields; - for (Enumeration table = vtable.elements(); table - .hasMoreElements();) { - Row row = table.nextElement(); - Iterator iterator = row.iterator(); - - while (iterator.hasNext()) { - fields = iterator.next(); - finded = fields.get("content").value().toString(); - if (this.sectionId == Integer.parseInt(fields.get("section_id") - .value().toString())) { - xml.append("" + finded + ""); - } else { - xml.append("" + finded + ""); - } - } - } - xml.append(""); - - return xml.toString(); - } - - private Table load(String bookId,int chapterId,int sectionId) throws ApplicationException { - - this.bookId = bookId; - this.chapterId = chapterId; - this.sectionId = sectionId; - - book = new book(); - try { - String lang = this.getLocale().toString(); - if(this.getLocale().toString().equalsIgnoreCase("en_GB")) { - lang = "en_US"; - } - - Table table = book.findWith("WHERE id=? and language=?", - new Object[] { this.bookId, lang }); - - if (table.size() > 0) { - Row row = table.get(0); - book.setData(row); - } - } catch (ApplicationException e) { - e.printStackTrace(); - } - - String condition = ""; - - if (this.chapterId == 0) { - condition = "book_id=" + this.bookId; - } else { - condition = "book_id=" + this.bookId + " and chapter_id=" - + this.chapterId; - } - - String where = "WHERE " + condition + " order by section_id"; - - article article = new article(); - Table vtable = article.findWith(where, new Object[] {}); - - this.maxChapter = article.setRequestFields( - "max(chapter_id) as max_chapter").findWith("WHERE book_id=?", - new Object[] { this.bookId }).get(0).get(0).get("max_chapter") - .intValue(); - this.lastChapterId = this.chapterId - 1 <= 0 ? 1 : this.chapterId - 1; - this.nextChapterId = this.chapterId + 1 > this.maxChapter ? this.maxChapter - : this.chapterId + 1; - - this.setText("holy.book.info", book.getName(),this.chapterId,this.maxChapter); - - return vtable; - } - - public Object api() throws ApplicationException - { - boolean valid = false; - - HttpServletRequest request=(HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - - String s = "Basic realm=\"Login for Book API\""; - response.setHeader("WWW-Authenticate", s); - - // Get the Authorization header, if one was supplied - String authHeader = request.getHeader("Authorization"); - if (authHeader != null) { - StringTokenizer st = new StringTokenizer(authHeader); - if (st.hasMoreTokens()) { - String basic = st.nextToken(); - - // We only handle HTTP Basic authentication - - if (basic.equalsIgnoreCase("Basic")) { - String credentials = st.nextToken(); - - // This example uses sun.misc.* classes. - // You will need to provide your own - // if you are not comfortable with that. - - String userPass = new String(Base64.decode(credentials)); - // The decoded string is in the form - // "userID:password". - - int p = userPass.indexOf(":"); - if (p != -1) { - final String userID = userPass.substring(0, p); - final String password = userPass.substring(p + 1); - - // Validate user ID and password - // and set valid true true if valid. - // In this example, we simply check - // that neither field is blank - - if ((!userID.trim().equals("")) - && (!password.trim().equals(""))) { - Authentication context=new Authentication(){ - public boolean status() { - return userID.equals("Mover") && password.equals("ingod.asia"); - } - }; - valid = context.status(); - } - } - } - } - } - - // If the user was not validated, fail with a - // 401 status code (UNAUTHORIZED) and - // pass back a WWW-Authenticate header for - // this servlet. - // - // Note that this is the normal situation the - // first time you access the page. The client - // web browser will prompt for userID and password - // and cache them so that it doesn't have to - // prompt you again. - - if (!valid) { - response.setHeader("WWW-Authenticate", - "Basic realm=\"Login for Bible API\""); - response.setStatus(401); - - return "Forbidden! Authentication failed!"; - } - - return this.feed(); - } + } + + public Object book(String bookId) throws ApplicationException { + return this.book(bookId, 1); + } + + public Object book(String bookId,int chapterId) throws ApplicationException { + return this.book(bookId, chapterId, 0); + } + + public Object book(String bookId,int chapterId,int sectionId) throws ApplicationException { + StringBuffer xml = new StringBuffer(); + String finded = ""; + + Table vtable = this.load(bookId, chapterId, sectionId); + + xml.append(""); + xml.append("\r\n"); + Field fields; + for (Enumeration table = vtable.elements(); table + .hasMoreElements();) { + Row row = table.nextElement(); + Iterator iterator = row.iterator(); + + while (iterator.hasNext()) { + fields = iterator.next(); + finded = fields.get("content").value().toString(); + if (this.sectionId == Integer.parseInt(fields.get("section_id") + .value().toString())) { + xml.append("" + finded + ""); + } else { + xml.append("" + finded + ""); + } + } + } + xml.append(""); + + return xml.toString(); + } + + private Table load(String bookId,int chapterId,int sectionId) throws ApplicationException { + + this.bookId = bookId; + this.chapterId = chapterId; + this.sectionId = sectionId; + + book = new book(); + try { + String lang = this.getLocale().toString(); + if(this.getLocale().toString().equalsIgnoreCase("en_GB")) { + lang = "en_US"; + } + + Table table = book.findWith("WHERE id=? and language=?", + new Object[] { this.bookId, lang }); + + if (table.size() > 0) { + Row row = table.get(0); + book.setData(row); + } + } catch (ApplicationException e) { + e.printStackTrace(); + } + + String condition = ""; + + if (this.chapterId == 0) { + condition = "book_id=" + this.bookId; + } else { + condition = "book_id=" + this.bookId + " and chapter_id=" + + this.chapterId; + } + + String where = "WHERE " + condition + " order by section_id"; + + article article = new article(); + Table vtable = article.findWith(where, new Object[] {}); + + this.maxChapter = article.setRequestFields( + "max(chapter_id) as max_chapter").findWith("WHERE book_id=?", + new Object[] { this.bookId }).get(0).get(0).get("max_chapter") + .intValue(); + this.lastChapterId = this.chapterId - 1 <= 0 ? 1 : this.chapterId - 1; + this.nextChapterId = this.chapterId + 1 > this.maxChapter ? this.maxChapter + : this.chapterId + 1; + + this.setText("holy.book.info", book.getName(),this.chapterId,this.maxChapter); + + return vtable; + } + + public Object api() throws ApplicationException + { + boolean valid = false; + + HttpServletRequest request=(HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + + String s = "Basic realm=\"Login for Book API\""; + response.setHeader("WWW-Authenticate", s); + + // Get the Authorization header, if one was supplied + String authHeader = request.getHeader("Authorization"); + if (authHeader != null) { + StringTokenizer st = new StringTokenizer(authHeader); + if (st.hasMoreTokens()) { + String basic = st.nextToken(); + + // We only handle HTTP Basic authentication + + if (basic.equalsIgnoreCase("Basic")) { + String credentials = st.nextToken(); + + // This example uses sun.misc.* classes. + // You will need to provide your own + // if you are not comfortable with that. + + String userPass = new String(Base64.decode(credentials)); + // The decoded string is in the form + // "userID:password". + + int p = userPass.indexOf(":"); + if (p != -1) { + final String userID = userPass.substring(0, p); + final String password = userPass.substring(p + 1); + + // Validate user ID and password + // and set valid true true if valid. + // In this example, we simply check + // that neither field is blank + + if ((!userID.trim().equals("")) + && (!password.trim().equals(""))) { + Authentication context=new Authentication(){ + public boolean status() { + return userID.equals("Mover") && password.equals("ingod.asia"); + } + }; + valid = context.status(); + } + } + } + } + } + + // If the user was not validated, fail with a + // 401 status code (UNAUTHORIZED) and + // pass back a WWW-Authenticate header for + // this servlet. + // + // Note that this is the normal situation the + // first time you access the page. The client + // web browser will prompt for userID and password + // and cache them so that it doesn't have to + // prompt you again. + + if (!valid) { + response.setHeader("WWW-Authenticate", + "Basic realm=\"Login for Bible API\""); + response.setStatus(401); + + return "Forbidden! Authentication failed!"; + } + + return this.feed(); + } public static void main(String[]args) throws ApplicationException, IOException{ book book=new book(); @@ -612,5 +612,5 @@ public static void main(String[]args) throws ApplicationException, IOException{ } } - } + } } \ No newline at end of file diff --git a/src/tinystruct/examples/redirectChecker.java b/src/main/java/tinystruct/examples/redirectChecker.java similarity index 100% rename from src/tinystruct/examples/redirectChecker.java rename to src/main/java/tinystruct/examples/redirectChecker.java diff --git a/src/tinystruct/examples/smalltalk.java b/src/main/java/tinystruct/examples/smalltalk.java similarity index 97% rename from src/tinystruct/examples/smalltalk.java rename to src/main/java/tinystruct/examples/smalltalk.java index ccee340..87c6d05 100644 --- a/src/tinystruct/examples/smalltalk.java +++ b/src/main/java/tinystruct/examples/smalltalk.java @@ -1,340 +1,340 @@ -package tinystruct.examples; - -import java.awt.image.BufferedImage; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.text.SimpleDateFormat; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Queue; -import java.util.concurrent.ArrayBlockingQueue; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSessionEvent; -import javax.servlet.http.HttpSessionListener; - -import org.tinystruct.ApplicationException; -import org.tinystruct.data.component.Builder; -import org.tinystruct.data.component.Builders; -import org.tinystruct.datatype.Variable; -import org.tinystruct.handle.Reforward; -import org.tinystruct.system.util.Matrix; -import org.tinystruct.system.util.StringUtilities; -import org.tinystruct.transfer.http.upload.ContentDisposition; -import org.tinystruct.transfer.http.upload.MultipartFormData; - -public class smalltalk extends talk implements HttpSessionListener { - - public void init() { - super.init(); - - this.setAction("talk", "index"); - this.setAction("talk/join", "join"); - this.setAction("talk/start", "start"); - this.setAction("talk/upload", "upload"); - this.setAction("talk/command", "command"); - this.setAction("talk/topic", "topic"); - this.setAction("talk/matrix", "matrix"); - - this.setVariable("message", ""); - this.setVariable("topic", ""); - } - - public talk index() { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - Object meetingCode = request.getSession().getAttribute("meeting_code"); - - if ( meetingCode == null ) { - meetingCode = java.util.UUID.randomUUID().toString(); - request.getSession().setAttribute("meeting_code", meetingCode); - - System.out.println("New meeting generated:" + meetingCode); - } - - List session_ids; - final String sessionId = request.getSession().getId(); - if (this.meetings.get(meetingCode) == null) { - this.meetings.put(meetingCode.toString(), new ArrayBlockingQueue(DEFAULT_MESSAGE_POOL_SIZE)); - } - - // If the current user is not in the list of the sessions, we create a default session list for the meeting generated. - if((session_ids = this.sessions.get(meetingCode)) == null) - { - this.sessions.put(meetingCode.toString(), session_ids = new ArrayList()); - } - - if(!session_ids.contains(sessionId)) - session_ids.add(sessionId); - - if(!this.list.containsKey(sessionId)) - { - this.list.put(sessionId, new ArrayDeque()); - } - - this.setVariable("meeting_code", meetingCode.toString()); - this.setVariable("session_id", request.getSession().getId()); - - Variable topic; - if ((topic = this.getVariable(meetingCode.toString())) != null) { - this.setVariable("topic", topic.getValue().toString().replaceAll("[\r\n]", "
      "), true); - } - - return this; - } - - public String matrix() throws ApplicationException { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - - if (request.getParameter("meeting_code") != null) { - BufferedImage qrImage = Matrix.toQRImage(this.getLink("talk/join") + "/" + request.getParameter("meeting_code"), 100, 100); - return "data:image/png;base64," + Matrix.getBase64Image(qrImage); - } - - return ""; - } - - public String join(String meetingCode) throws ApplicationException { - if (meetings.containsKey(meetingCode)) { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - request.getSession().setAttribute("meeting_code", meetingCode); - - this.setVariable("meeting_code", meetingCode); - - Reforward reforward = new Reforward(request, response); - reforward.setDefault("/?q=talk"); - reforward.forward(); - } else { - return "Invalid meeting code."; - } - - return "Please start the conversation with your name: " + this.config.get("default.base_url") + "talk/start/YOUR NAME"; - } - - public String start(String name) throws ApplicationException { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - request.getSession().setAttribute("user", name); - - Object meetingCode = request.getSession().getAttribute("meeting_code"); - if (meetingCode == null) { - Reforward reforward = new Reforward(request, response); - reforward.setDefault("/?q=talk"); - reforward.forward(); - } else { - this.setVariable("meeting_code", meetingCode.toString()); - } - - return name; - } - - public String command() { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - response.setContentType("application/json"); - - final Object meetingCode = request.getSession().getAttribute("meeting_code"); - final String sessionId = request.getSession().getId(); - if ( meetingCode != null && sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) { - if (request.getSession().getAttribute("user") == null) { - return "{ \"error\": \"missing user\" }"; - } - - Builder builder = new Builder(); - builder.put("user", request.getSession().getAttribute("user")); - builder.put("cmd", request.getParameter("cmd")); - - return this.save(meetingCode, builder); - } - response.setStatus(403); - return "{ \"error\": \"expired\" }"; - } - - public String save() { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - response.setContentType("application/json"); - - final Object meetingCode = request.getSession().getAttribute("meeting_code"); - if (this.meetings.containsKey(meetingCode)) { - final String sessionId = request.getSession().getId(); - if ( meetingCode != null && sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) { - String message; - if ((message = request.getParameter("text")) != null && !message.isEmpty()) { - String[] agent = request.getHeader("User-Agent").split(" "); - this.setVariable("browser", agent[agent.length - 1]); - - final SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d h:m:s"); - final Builder builder = new Builder(); - builder.put("user", request.getSession().getAttribute("user")); - builder.put("time", format.format(new Date())); - builder.put("message", filter(message)); - builder.put("session_id", sessionId); - - return this.save(meetingCode, builder); - } - } - } - - response.setStatus(403); - return "{ \"error\": \"expired\" }"; - } - - public String update() throws ApplicationException, IOException { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - final Object meetingCode = request.getSession().getAttribute("meeting_code"); - final String sessionId = request.getSession().getId(); - if (meetingCode != null) { - return this.update(meetingCode.toString(), sessionId); - } - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - response.setContentType("application/json"); - response.setStatus(403); - return "{ \"error\": \"expired\" }"; - } - - public String update(String meetingCode, String sessionId) throws ApplicationException, IOException { - String error = "{ \"error\": \"expired\" }"; - if (this.meetings.containsKey(meetingCode)) { - List list; - if((list = sessions.get(meetingCode)) != null && list.contains(sessionId)) { - return this.update(sessionId); - } - error = "{ \"error\": \"session-timeout\" }"; - } - - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - response.setContentType("application/json"); - response.setStatus(403); - return error; - } - - public String upload() throws ApplicationException { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - response.setContentType("text/html;charset=UTF-8"); - - // Create path components to save the file - final String path = this.config.get("system.directory") != null ? this.config.get("system.directory").toString() + "/files" : "files"; - - final Builders builders = new Builders(); - try { - final MultipartFormData iter = new MultipartFormData(request); - ContentDisposition e = null; - int read = 0; - while ((e = iter.getNextPart()) != null) { - final String fileName = e.getFileName(); - final Builder builder = new Builder(); - builder.put("type", StringUtilities.implode(";", Arrays.asList(e.getContentType()))); - builder.put("file", new StringBuffer().append(this.context.getAttribute("HTTP_SCHEME")).append("://").append(this.context.getAttribute("HTTP_SERVER")).append(":"+ request.getServerPort()).append( "/files/").append(fileName)); - final File f = new File(path + File.separator + fileName); - if (!f.exists()) { - if (!f.getParentFile().exists()) { - f.getParentFile().mkdirs(); - } - } - - final OutputStream out = new FileOutputStream(f); - final BufferedOutputStream bout= new BufferedOutputStream(out); - final ByteArrayInputStream is = new ByteArrayInputStream(e.getData()); - final BufferedInputStream bs = new BufferedInputStream(is); - final byte[] bytes = new byte[8192]; - while ((read = bs.read(bytes)) != -1) { - bout.write(bytes, 0, read); - } - bout.close(); - bs.close(); - - builders.add(builder); - System.out.println(String.format("File %s being uploaded to %s", new Object[] { fileName, path })); - } - } catch (IOException e) { - throw new ApplicationException(e.getMessage(), e); - } catch (ServletException e) { - throw new ApplicationException(e.getMessage(), e); - } - - return builders.toString(); - } - - public boolean topic() { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - final Object meeting_code = request.getSession().getAttribute("meeting_code"); - - if ( meeting_code != null ) { - this.setVariable(meeting_code.toString(), filter(request.getParameter("topic"))); - return true; - } - - return false; - } - - protected talk exit() { - final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); - request.getSession().removeAttribute("meeting_code"); - return this; - } - - @Override - protected String filter(String text) { - text = text.replaceAll("(.*)<\\/script>", ""); - return text; - } - - @Override - public void sessionCreated(HttpSessionEvent arg0) { - Object meetingCode = arg0.getSession().getAttribute("meeting_code"); - if ( meetingCode == null ) { - meetingCode = java.util.UUID.randomUUID().toString(); - arg0.getSession().setAttribute("meeting_code", meetingCode); - - System.out.println("New meeting generated by HttpSessionListener:" + meetingCode); - } - - final String sessionId = arg0.getSession().getId(); - if(!this.list.containsKey(sessionId)) - { - this.list.put(sessionId, new ArrayDeque()); - } - } - - @Override - public void sessionDestroyed(HttpSessionEvent arg0) { - Object meetingCode = arg0.getSession().getAttribute("meeting_code"); - if ( meetingCode != null ) { - final SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d h:m:s"); - final Builder builder = new Builder(); - builder.put("user", null); - builder.put("time", format.format(new Date())); - builder.put("cmd", "expired"); - this.save(meetingCode, builder); - - Queue messages; - List session_ids; - if((session_ids = this.sessions.get(meetingCode)) != null) { - session_ids.remove(arg0.getSession().getId()); - } - - if ((messages = this.meetings.get(meetingCode)) != null) { - messages.remove(meetingCode); - } - - final String sessionId = arg0.getSession().getId(); - if(this.list.containsKey(sessionId)) - { - this.list.remove(sessionId); - wakeup(); - } - } - } -} +package tinystruct.examples; + +import java.awt.image.BufferedImage; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.text.SimpleDateFormat; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +import org.tinystruct.ApplicationException; +import org.tinystruct.data.component.Builder; +import org.tinystruct.data.component.Builders; +import org.tinystruct.datatype.Variable; +import org.tinystruct.handle.Reforward; +import org.tinystruct.system.util.Matrix; +import org.tinystruct.system.util.StringUtilities; +import org.tinystruct.transfer.http.upload.ContentDisposition; +import org.tinystruct.transfer.http.upload.MultipartFormData; + +public class smalltalk extends talk implements HttpSessionListener { + + public void init() { + super.init(); + + this.setAction("talk", "index"); + this.setAction("talk/join", "join"); + this.setAction("talk/start", "start"); + this.setAction("talk/upload", "upload"); + this.setAction("talk/command", "command"); + this.setAction("talk/topic", "topic"); + this.setAction("talk/matrix", "matrix"); + + this.setVariable("message", ""); + this.setVariable("topic", ""); + } + + public talk index() { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + Object meetingCode = request.getSession().getAttribute("meeting_code"); + + if ( meetingCode == null ) { + meetingCode = java.util.UUID.randomUUID().toString(); + request.getSession().setAttribute("meeting_code", meetingCode); + + System.out.println("New meeting generated:" + meetingCode); + } + + List session_ids; + final String sessionId = request.getSession().getId(); + if (this.meetings.get(meetingCode) == null) { + this.meetings.put(meetingCode.toString(), new ArrayBlockingQueue(DEFAULT_MESSAGE_POOL_SIZE)); + } + + // If the current user is not in the list of the sessions, we create a default session list for the meeting generated. + if((session_ids = this.sessions.get(meetingCode)) == null) + { + this.sessions.put(meetingCode.toString(), session_ids = new ArrayList()); + } + + if(!session_ids.contains(sessionId)) + session_ids.add(sessionId); + + if(!this.list.containsKey(sessionId)) + { + this.list.put(sessionId, new ArrayDeque()); + } + + this.setVariable("meeting_code", meetingCode.toString()); + this.setVariable("session_id", request.getSession().getId()); + + Variable topic; + if ((topic = this.getVariable(meetingCode.toString())) != null) { + this.setVariable("topic", topic.getValue().toString().replaceAll("[\r\n]", "
      "), true); + } + + return this; + } + + public String matrix() throws ApplicationException { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + + if (request.getParameter("meeting_code") != null) { + BufferedImage qrImage = Matrix.toQRImage(this.getLink("talk/join") + "/" + request.getParameter("meeting_code"), 100, 100); + return "data:image/png;base64," + Matrix.getBase64Image(qrImage); + } + + return ""; + } + + public String join(String meetingCode) throws ApplicationException { + if (meetings.containsKey(meetingCode)) { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + request.getSession().setAttribute("meeting_code", meetingCode); + + this.setVariable("meeting_code", meetingCode); + + Reforward reforward = new Reforward(request, response); + reforward.setDefault("/?q=talk"); + reforward.forward(); + } else { + return "Invalid meeting code."; + } + + return "Please start the conversation with your name: " + this.config.get("default.base_url") + "talk/start/YOUR NAME"; + } + + public String start(String name) throws ApplicationException { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + request.getSession().setAttribute("user", name); + + Object meetingCode = request.getSession().getAttribute("meeting_code"); + if (meetingCode == null) { + Reforward reforward = new Reforward(request, response); + reforward.setDefault("/?q=talk"); + reforward.forward(); + } else { + this.setVariable("meeting_code", meetingCode.toString()); + } + + return name; + } + + public String command() { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + response.setContentType("application/json"); + + final Object meetingCode = request.getSession().getAttribute("meeting_code"); + final String sessionId = request.getSession().getId(); + if ( meetingCode != null && sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) { + if (request.getSession().getAttribute("user") == null) { + return "{ \"error\": \"missing user\" }"; + } + + Builder builder = new Builder(); + builder.put("user", request.getSession().getAttribute("user")); + builder.put("cmd", request.getParameter("cmd")); + + return this.save(meetingCode, builder); + } + response.setStatus(403); + return "{ \"error\": \"expired\" }"; + } + + public String save() { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + response.setContentType("application/json"); + + final Object meetingCode = request.getSession().getAttribute("meeting_code"); + if (this.meetings.containsKey(meetingCode)) { + final String sessionId = request.getSession().getId(); + if ( meetingCode != null && sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) { + String message; + if ((message = request.getParameter("text")) != null && !message.isEmpty()) { + String[] agent = request.getHeader("User-Agent").split(" "); + this.setVariable("browser", agent[agent.length - 1]); + + final SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d h:m:s"); + final Builder builder = new Builder(); + builder.put("user", request.getSession().getAttribute("user")); + builder.put("time", format.format(new Date())); + builder.put("message", filter(message)); + builder.put("session_id", sessionId); + + return this.save(meetingCode, builder); + } + } + } + + response.setStatus(403); + return "{ \"error\": \"expired\" }"; + } + + public String update() throws ApplicationException, IOException { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + final Object meetingCode = request.getSession().getAttribute("meeting_code"); + final String sessionId = request.getSession().getId(); + if (meetingCode != null) { + return this.update(meetingCode.toString(), sessionId); + } + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + response.setContentType("application/json"); + response.setStatus(403); + return "{ \"error\": \"expired\" }"; + } + + public String update(String meetingCode, String sessionId) throws ApplicationException, IOException { + String error = "{ \"error\": \"expired\" }"; + if (this.meetings.containsKey(meetingCode)) { + List list; + if((list = sessions.get(meetingCode)) != null && list.contains(sessionId)) { + return this.update(sessionId); + } + error = "{ \"error\": \"session-timeout\" }"; + } + + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + response.setContentType("application/json"); + response.setStatus(403); + return error; + } + + public String upload() throws ApplicationException { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); + response.setContentType("text/html;charset=UTF-8"); + + // Create path components to save the file + final String path = this.config.get("system.directory") != null ? this.config.get("system.directory").toString() + "/files" : "files"; + + final Builders builders = new Builders(); + try { + final MultipartFormData iter = new MultipartFormData(request); + ContentDisposition e = null; + int read = 0; + while ((e = iter.getNextPart()) != null) { + final String fileName = e.getFileName(); + final Builder builder = new Builder(); + builder.put("type", StringUtilities.implode(";", Arrays.asList(e.getContentType()))); + builder.put("file", new StringBuffer().append(this.context.getAttribute("HTTP_SCHEME")).append("://").append(this.context.getAttribute("HTTP_SERVER")).append(":"+ request.getServerPort()).append( "/files/").append(fileName)); + final File f = new File(path + File.separator + fileName); + if (!f.exists()) { + if (!f.getParentFile().exists()) { + f.getParentFile().mkdirs(); + } + } + + final OutputStream out = new FileOutputStream(f); + final BufferedOutputStream bout= new BufferedOutputStream(out); + final ByteArrayInputStream is = new ByteArrayInputStream(e.getData()); + final BufferedInputStream bs = new BufferedInputStream(is); + final byte[] bytes = new byte[8192]; + while ((read = bs.read(bytes)) != -1) { + bout.write(bytes, 0, read); + } + bout.close(); + bs.close(); + + builders.add(builder); + System.out.println(String.format("File %s being uploaded to %s", new Object[] { fileName, path })); + } + } catch (IOException e) { + throw new ApplicationException(e.getMessage(), e); + } catch (ServletException e) { + throw new ApplicationException(e.getMessage(), e); + } + + return builders.toString(); + } + + public boolean topic() { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + final Object meeting_code = request.getSession().getAttribute("meeting_code"); + + if ( meeting_code != null ) { + this.setVariable(meeting_code.toString(), filter(request.getParameter("topic"))); + return true; + } + + return false; + } + + protected talk exit() { + final HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); + request.getSession().removeAttribute("meeting_code"); + return this; + } + + @Override + protected String filter(String text) { + text = text.replaceAll("(.*)<\\/script>", ""); + return text; + } + + @Override + public void sessionCreated(HttpSessionEvent arg0) { + Object meetingCode = arg0.getSession().getAttribute("meeting_code"); + if ( meetingCode == null ) { + meetingCode = java.util.UUID.randomUUID().toString(); + arg0.getSession().setAttribute("meeting_code", meetingCode); + + System.out.println("New meeting generated by HttpSessionListener:" + meetingCode); + } + + final String sessionId = arg0.getSession().getId(); + if(!this.list.containsKey(sessionId)) + { + this.list.put(sessionId, new ArrayDeque()); + } + } + + @Override + public void sessionDestroyed(HttpSessionEvent arg0) { + Object meetingCode = arg0.getSession().getAttribute("meeting_code"); + if ( meetingCode != null ) { + final SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d h:m:s"); + final Builder builder = new Builder(); + builder.put("user", null); + builder.put("time", format.format(new Date())); + builder.put("cmd", "expired"); + this.save(meetingCode, builder); + + Queue messages; + List session_ids; + if((session_ids = this.sessions.get(meetingCode)) != null) { + session_ids.remove(arg0.getSession().getId()); + } + + if ((messages = this.meetings.get(meetingCode)) != null) { + messages.remove(meetingCode); + } + + final String sessionId = arg0.getSession().getId(); + if(this.list.containsKey(sessionId)) + { + this.list.remove(sessionId); + wakeup(); + } + } + } +} diff --git a/src/tinystruct/examples/startup.java b/src/main/java/tinystruct/examples/startup.java similarity index 100% rename from src/tinystruct/examples/startup.java rename to src/main/java/tinystruct/examples/startup.java diff --git a/src/tinystruct/examples/talk.java b/src/main/java/tinystruct/examples/talk.java similarity index 100% rename from src/tinystruct/examples/talk.java rename to src/main/java/tinystruct/examples/talk.java diff --git a/src/tinystruct/examples/time.java b/src/main/java/tinystruct/examples/time.java similarity index 100% rename from src/tinystruct/examples/time.java rename to src/main/java/tinystruct/examples/time.java diff --git a/src/tinystruct/examples/tinyeditor.java b/src/main/java/tinystruct/examples/tinyeditor.java similarity index 100% rename from src/tinystruct/examples/tinyeditor.java rename to src/main/java/tinystruct/examples/tinyeditor.java diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..2bc67eb --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,47 @@ +#driver = org.sqlite.JDBC +#database.url = jdbc:sqlite:/Users/mover/applications/mobile1.0/data/tiny.sqlite +#database.user = +#database.password = +#database.connections.max = 1 + +[database] +#MySQL +driver=com.mysql.jdbc.Driver +database.url=jdbc:mysql://localhost:3306/database?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8 +database.user=root +database.password=****** +database.connections.max=10 + +[default] +default.file.encoding=UTF-8 +default.login.page=user/login +default.home.page=praise +default.reload.mode=true +default.date.format=yyyy-MM-dd HH:mm:ss +default.import.applications=tinystruct.examples.error;tinystruct.examples.firstApplication;tinystruct.examples.time;tinystruct.examples.tinyeditor;tinystruct.examples.hello;tinystruct.examples.smalltalk;tinystruct.examples.image2 +default.url_rewrite=disabled + +[error] +default.error.process=false +default.error.page=error + +[event] +log.status=off +log.file= +system.directory=/Users/mover/applications/tinystruct2.0 + +[mail] +mail.ssl.on = true +mail.smtp.host=smtp.126.com +mail.pop3.host=pop.gmail.com +#mail.smtp.host=localhost +mail.smtp.port=25 +mail.pop3.port=995 +mail.smtp.auth=true +mail.pop3.auth=true +mail.store.protocol = pop3 +#mail.smtp.auth=false +#smtp.auth.user=*******@ingod.asia +#smtp.auth.user=*******@gmail.com +smtp.auth.user=*******@gmail.com +smtp.auth.pwd=******* diff --git a/src/tinystruct/examples/test.java b/src/tinystruct/examples/test.java deleted file mode 100644 index 47e43a2..0000000 --- a/src/tinystruct/examples/test.java +++ /dev/null @@ -1,106 +0,0 @@ -package tinystruct.examples; - -import java.io.File; -import java.util.Collection; -import java.util.Iterator; - -import org.tinystruct.AbstractApplication; -import org.tinystruct.Application; -import org.tinystruct.ApplicationException; -import org.tinystruct.application.Action; -import org.tinystruct.application.Actions; -import org.tinystruct.data.component.Builder; -import org.tinystruct.system.ClassFileLoader; -import org.tinystruct.system.Configuration; -import org.tinystruct.system.Settings; -import org.tinystruct.system.util.StringUtilities; -import org.tinystruct.system.util.TextFileLoader; - -public class test { - - /** - * @param args - * @throws ApplicationException - */ - public static void main(String[] args) throws ApplicationException { - // TODO Auto-generated method stub - // Use ClassFileLoader to load Java class - ClassFileLoader loader = ClassFileLoader.getInstance(); - - Configuration config = new Settings("/application.properties"); - config.set("default.apps.path", "WEB-INF/classes"); - config.set("default.apps.package", "tinystruct.examples"); - - Builder builder = new Builder(); - File fi = new File(".lock"); - StringBuffer lock=new StringBuffer(); - if(fi.exists()) { - TextFileLoader f = new TextFileLoader(".lock"); - lock = f.getContent(); - } - - if(lock.length() == 0){ - builder.parse("{\"installed\":{},\"updated\":true }"); - } - else - builder.parse(lock.toString()); - - Builder build = (Builder) builder.get("installed"); - - String apps_package = config.get("default.apps.package").toString(); - String apps_package_dir = config.get("default.apps.path").toString()+"/"+apps_package.replaceAll("\\.", "/"); - - File files = new File(apps_package_dir); - File[] list = files.listFiles(); - - String path; - for(int i=0;i clz = loader.findClass(list[i].getName()); - - if(clz!=null && clz.getSuperclass().equals(AbstractApplication.class)) { - Class clzz = (Class) clz; - try { - Application app = clzz.newInstance(); - Actions actions = app.actions(); - - Collection a = actions.list(); - System.out.println(a.size()); - Iterator la = a.iterator(); - while(la.hasNext()) { - Action act = la.next(); - path = act.getPath(); - if(path.equalsIgnoreCase("say")){ - System.out.println(path+":"+build.get(path)); - } - - if(build.get(path)==null || !( build.get(path).toString().equals(act.getApplicationName()))) { - build.put(path,act.getApplicationName()); - builder.put("updated", false); - } - } - }catch (Exception ex) { - ex.printStackTrace(); - continue; - } - } - } - } - - Actions acts = Actions.getInstance(); - - int size = ((Builder) (builder.get("installed"))).size(); - System.out.println(size+":"+acts.list().size()); - builder.put("updated", acts.list().size() == size); - if(builder.get("updated").toString().equalsIgnoreCase("false")) { - File file=new File(".lock"); - - builder.put("updated", true); - builder.saveAsFile(file); - - System.out.println("Updated lock."); - } - - } - -}