Skip to content

Commit c29d32f

Browse files
author
jiuling-wang
committed
final
0 parents  commit c29d32f

File tree

72 files changed

+996
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+996
-0
lines changed

.project

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>UTReaderWeb</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.google.appengine.eclipse.core.gaeProjectChangeNotifier</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
<buildCommand>
29+
<name>com.google.appengine.eclipse.core.projectValidator</name>
30+
<arguments>
31+
</arguments>
32+
</buildCommand>
33+
<buildCommand>
34+
<name>com.google.appengine.eclipse.core.enhancerbuilder</name>
35+
<arguments>
36+
</arguments>
37+
</buildCommand>
38+
</buildSpec>
39+
<natures>
40+
<nature>org.eclipse.jdt.core.javanature</nature>
41+
<nature>com.google.appengine.eclipse.core.gaeNature</nature>
42+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
43+
</natures>
44+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
filesCopiedToWebInfLib=appengine-api-1.0-sdk-1.8.4.jar|appengine-api-labs.jar|appengine-endpoints.jar|appengine-jsr107cache-1.8.4.jar|asm-4.0.jar|datanucleus-api-jdo-3.1.3.jar|datanucleus-api-jpa-3.1.3.jar|datanucleus-appengine-2.1.2.jar|datanucleus-core-3.1.3.jar|geronimo-jpa_2.0_spec-1.0.jar|jdo-api-3.0.1.jar|jsr107cache-1.1.jar|jta-1.1.jar
3+
gaeDatanucleusVersion=v2
4+
gaeDeployDialogSettings=
5+
gaeHrdEnabled=true
6+
googleCloudSqlEnabled=false
7+
localDevMySqlEnabled=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
eclipse.preferences.version=1
2+
warSrcDir=war
3+
warSrcDirIsOutput=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding//src/com/web/utreader/utility/ParseUtil.java=UTF-8

.settings/org.eclipse.jdt.core.prefs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4+
org.eclipse.jdt.core.compiler.compliance=1.6
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.source=1.6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<installed facet="java" version="1.6"/>
4+
</faceted-project>

UTReaderWeb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 46e6b6818f74eb142e31e18490a73a5741603012

src/META-INF/jdoconfig.xml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
5+
6+
<persistence-manager-factory name="transactions-optional">
7+
<property name="javax.jdo.PersistenceManagerFactoryClass"
8+
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
9+
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
10+
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
11+
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
12+
<property name="javax.jdo.option.RetainValues" value="true"/>
13+
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
14+
<property name="datanucleus.appengine.singletonPMFForName" value="true"/>
15+
</persistence-manager-factory>
16+
</jdoconfig>

src/META-INF/persistence.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
5+
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
6+
7+
<persistence-unit name="transactions-optional">
8+
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
9+
<properties>
10+
<property name="datanucleus.NontransactionalRead" value="true"/>
11+
<property name="datanucleus.NontransactionalWrite" value="true"/>
12+
<property name="datanucleus.ConnectionURL" value="appengine"/>
13+
</properties>
14+
</persistence-unit>
15+
</persistence>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.web.utreader;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
import java.util.logging.Logger;
6+
7+
import javax.servlet.http.HttpServlet;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
11+
import com.web.utreader.utility.CategoryInfo;
12+
import com.web.utreader.utility.OfyService;
13+
import com.web.utreader.utility.ParseUtil;
14+
15+
public class CheckUpdatesServlet extends HttpServlet{
16+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
17+
throws IOException{
18+
final Logger log = Logger.getLogger(CheckUpdatesServlet.class.getName());
19+
List<CategoryInfo> list = OfyService.ofy().load().type(CategoryInfo.class).list();
20+
21+
if (list.isEmpty()){
22+
log.warning("check for updates info null" );
23+
list.add(new CategoryInfo((long) 1));
24+
}
25+
for (int i = 0; i < 7; i++){
26+
ParseUtil.getNewsByCategory(i,list.get(0));
27+
}
28+
OfyService.ofy().save().entities(list).now();
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.web.utreader;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
import javax.servlet.http.HttpServlet;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
11+
import com.google.appengine.labs.repackaged.org.json.Cookie;
12+
import com.google.gson.Gson;
13+
import com.web.utreader.model.Comment;
14+
import com.web.utreader.utility.OfyService;
15+
16+
public class GetCommentsServlet extends HttpServlet{
17+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
18+
throws IOException {
19+
int cid = Integer.parseInt(req.getParameter("cid"));
20+
int id = Integer.parseInt(req.getParameter("id"));
21+
List<Comment> list = OfyService.ofy().load().type(Comment.class).list();
22+
ArrayList<Comment> res = new ArrayList<Comment>();
23+
for (Comment comment : list){
24+
if (comment.id == id && comment.cid == cid){
25+
res.add(comment);
26+
}
27+
28+
}
29+
Gson gson = new Gson();
30+
String json = gson.toJson(res);
31+
32+
resp.setContentType("application/json");
33+
resp.getWriter().print(json);
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.web.utreader;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.Comparator;
7+
import java.util.List;
8+
import java.util.logging.Logger;
9+
10+
import javax.servlet.http.HttpServlet;
11+
import javax.servlet.http.HttpServletRequest;
12+
import javax.servlet.http.HttpServletResponse;
13+
14+
import com.google.gson.Gson;
15+
import com.web.utreader.model.NewsDetails;
16+
import com.web.utreader.model.NewsSummary;
17+
import com.web.utreader.utility.CategoryInfo;
18+
import com.web.utreader.utility.OfyService;
19+
import com.web.utreader.utility.ParseUtil;
20+
21+
public class GetNewsDetailsServlet extends HttpServlet{
22+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
23+
throws IOException {
24+
final Logger log = Logger.getLogger(GetNewsDetailsServlet.class.getName());
25+
int cid = Integer.parseInt(req.getParameter("cid"));
26+
int sid = Integer.parseInt(req.getParameter("sid"));
27+
List<CategoryInfo> infolist = OfyService.ofy().load().type(CategoryInfo.class).list();
28+
29+
if (infolist.isEmpty()){
30+
infolist.add(new CategoryInfo((long) 1));
31+
}
32+
if (infolist.get(0).getID(cid) == 0){
33+
ParseUtil.getNewsByCategory(cid,infolist.get(0));
34+
}
35+
36+
int endId = infolist.get(0).getID(cid) - sid;
37+
String string = "currentIndx = ";
38+
for (int i = 0; i < infolist.get(0).currectIndex.length; i++) string+=(""+infolist.get(0).currectIndex[i]+",");
39+
log.warning(string);
40+
log.warning("sid = " + sid + " endid = " + endId);
41+
42+
43+
List<NewsDetails> list = OfyService.ofy().load().type(NewsDetails.class).filter("cid", cid).list();
44+
ArrayList<NewsDetails> newsDetailsList = new ArrayList<NewsDetails>();
45+
// for (NewsDetails s:list){
46+
//
47+
// if (s.id < endId && s.id >= startId){
48+
// newsDetailsList.add(s);
49+
// if (newsDetailsList.size() == 6){
50+
// break;
51+
// }
52+
// }
53+
// }
54+
for (NewsDetails s:list){
55+
if (s.id < sid || sid == 0){
56+
newsDetailsList.add(s);
57+
}
58+
}
59+
Collections.sort(newsDetailsList,new Comparator<NewsDetails>(){
60+
public int compare(NewsDetails a, NewsDetails b){
61+
if (a.id < b.id){
62+
return 1;
63+
}else{
64+
return -1;
65+
}
66+
}
67+
});
68+
ArrayList<NewsDetails> result = new ArrayList<NewsDetails>();
69+
if (newsDetailsList.size() <= 6){
70+
result = newsDetailsList;
71+
}else{
72+
for (int i = 0; i < 6; i++){
73+
result.add(newsDetailsList.get(i));
74+
}
75+
}
76+
OfyService.ofy().save().entities(infolist).now();
77+
Gson gson = new Gson();
78+
String json = gson.toJson(result);
79+
80+
resp.setContentType("application/json");
81+
resp.getWriter().print(json);
82+
83+
}
84+
85+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.web.utreader;
2+
3+
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.logging.Logger;
7+
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
import com.google.gson.Gson;
13+
import com.web.utreader.model.Comment;
14+
import com.web.utreader.model.UserInfo;
15+
import com.web.utreader.utility.OfyService;
16+
17+
public class GetTopicsServlet extends HttpServlet{
18+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
19+
throws IOException {
20+
final Logger log = Logger.getLogger(GetTopicsServlet.class.getName());
21+
String username = req.getParameter("username");
22+
List<UserInfo> list = OfyService.ofy().load().type(UserInfo.class).list();
23+
String res = "";
24+
for (UserInfo info : list){
25+
log.warning("username = " + info.username );
26+
log.warning("topics = " + info.topics );
27+
if (info.username.equals(username)){
28+
res = info.topics;
29+
break;
30+
}
31+
32+
}
33+
resp.getWriter().println(res);
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.web.utreader;
2+
3+
4+
5+
import java.io.IOException;
6+
import java.util.logging.Logger;
7+
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
import org.mortbay.log.Log;
13+
import org.omg.CORBA.PRIVATE_MEMBER;
14+
15+
import com.web.utreader.model.Comment;
16+
import com.web.utreader.utility.OfyService;
17+
18+
19+
public class PostCommentsServlet extends HttpServlet{
20+
public void doPost(HttpServletRequest req, HttpServletResponse resp)
21+
throws IOException {
22+
final Logger log = Logger.getLogger(PostCommentsServlet.class.getName());
23+
int cid = Integer.parseInt(req.getParameter("cid"));
24+
int id = Integer.parseInt(req.getParameter("id"));
25+
String content = req.getParameter("content");
26+
String name = req.getParameter("name");
27+
Comment comment = new Comment(cid,id,name,content);
28+
log.warning(comment.toString());
29+
OfyService.ofy().save().entity(comment).now();
30+
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.web.utreader;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import javax.servlet.http.HttpServlet;
7+
import javax.servlet.http.HttpServletRequest;
8+
import javax.servlet.http.HttpServletResponse;
9+
10+
import com.googlecode.objectify.Key;
11+
import com.googlecode.objectify.Result;
12+
import com.web.utreader.model.UserInfo;
13+
import com.web.utreader.utility.OfyService;
14+
15+
public class PostTopicsServlet extends HttpServlet{
16+
public void doPost(HttpServletRequest req, HttpServletResponse resp)
17+
throws IOException{
18+
String username = req.getParameter("username");
19+
String topics = req.getParameter("topics");
20+
List<UserInfo> list= OfyService.ofy().load().type(UserInfo.class).filter("username", username).list();
21+
if (list.isEmpty()){
22+
UserInfo userInfo = new UserInfo(username,topics);
23+
OfyService.ofy().save().entity(userInfo).now();
24+
}else{
25+
for (UserInfo info:list){
26+
if (info.username.equals(username)){
27+
info.topics = topics;
28+
OfyService.ofy().save().entity(info).now();
29+
}
30+
}
31+
}
32+
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.web.utreader;
2+
3+
import java.io.IOException;
4+
import javax.servlet.http.*;
5+
6+
@SuppressWarnings("serial")
7+
public class UTReaderWebServlet extends HttpServlet {
8+
public void doGet(HttpServletRequest req, HttpServletResponse resp)
9+
throws IOException {
10+
resp.setContentType("text/plain");
11+
resp.getWriter().println("Hello, world");
12+
}
13+
}

0 commit comments

Comments
 (0)