-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexAccess.java
More file actions
52 lines (44 loc) · 1.25 KB
/
Copy pathIndexAccess.java
File metadata and controls
52 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package server;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class IndexAccess implements Accessable {
@Override
public void serve(Connection connection) {
String isout = connection.getValue("isout");
try {
connection.responseHTML(200, loadOldIndex(isout));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private HtmlPage loadOldIndex(String isout){
ShoppingListModel slLoder = new ShoppingListModel();
slLoder.loadFromFile();
List<ShoppingList> sls = slLoder.getAllShoppingLists();
IndexHtmlPage indexP;
if(isout.isEmpty()){
indexP = new IndexHtmlPage();
}else{
indexP = new ProIndexHtmlPage();
}
for(int i=0; i<sls.size(); i++)
{
ShoppingList sl = sls.get(i);
String placeName = sl.getPlace().getName();
List<Item> items = sl.getAllItems();
ArrayList<ArrayList<String>> itemArr = new ArrayList<ArrayList<String>>();
for(int j=0; j<items.size(); j++)
{
ArrayList<String> arr = new ArrayList<String>();
arr.add(items.get(j).getName());
arr.add(items.get(j).getQuantity());
arr.add(items.get(j).getOptional());
itemArr.add(arr);
}
indexP.addItemsToPlace(itemArr, placeName);
}
return indexP;
}
}