This repository was archived by the owner on Dec 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathrss.jsp
More file actions
189 lines (169 loc) · 6.13 KB
/
rss.jsp
File metadata and controls
189 lines (169 loc) · 6.13 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<%
/*
* Copyright 2012 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
%><%@page contentType="text/html;charset=utf-8" %>
<%@page import="com.netflix.hystrix.HystrixCommand"%>
<%@page import="com.netflix.recipes.rss.hystrix.AddRSSCommand"%>
<%@page import="com.netflix.recipes.rss.hystrix.DeleteRSSCommand"%>
<%@ page import="com.netflix.recipes.rss.hystrix.GetRSSCommand" %>
<%@ page import="org.json.JSONArray" %>
<%@ page import="org.json.JSONObject" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.concurrent.Future" %>
<%
// TODO: Fix the bootstrap css and js accessibility issue
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh">
<title>Netflix OSS RSS Reader</title>
<!-- TODO: Should host locally -->
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">Netflix OSS RSS Reader</a>
<div class="nav-collapse collapse">
<form class="navbar-form pull-right" method="POST" action="/jsp/rss.jsp">
<input class="span8" type="text" placeholder="Enter the feed Url" name="url">
<button type="submit" class="btn">Add</button>
</form>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>
<%
// Delete a RSS feed
String delFeedUrl = request.getParameter("delFeedUrl");
if (delFeedUrl != null) {
HystrixCommand<String> deleteCommand = new DeleteRSSCommand(delFeedUrl);
Future<String> future = deleteCommand.queue();
String responseString = future.get();
response.sendRedirect("/jsp/rss.jsp");
}
// Add a RSS feed
String url = request.getParameter("url");
if (url != null) {
url = URLEncoder.encode(url, "UTF-8");
HystrixCommand<String> addCommand = new AddRSSCommand(url);
Future<String> future = addCommand.queue();
String responseString = future.get();
response.sendRedirect("/jsp/rss.jsp");
}
// Get RSS feeds
HystrixCommand<String> getCommand = new GetRSSCommand();
Future<String> future = getCommand.queue();
String responseString = future.get();
// When a user has only 1 subcription, middle tier returns a jsonobject instead of an array
final JSONObject jo = new JSONObject(responseString);
JSONArray subscriptions = new JSONArray();
if (jo.has("subscriptions")) {
if (jo.get("subscriptions") instanceof JSONObject) {
subscriptions.put(jo.get("subscriptions"));
} else {
subscriptions = jo.getJSONArray("subscriptions");
}
}
// Compute the number of rows
int numFeeds = subscriptions.length();
int totalRows = (numFeeds % 3 == 0)? (numFeeds/3) : (numFeeds/3) + 1;
%>
<!-- To hide/show the delete button -->
<style type="text/css">
h4 .icon-remove {
visibility:hidden;
}
h4:hover .icon-remove {
visibility:visible;
}
</style>
<div class="container">
<%
int index = 0;
int itemIndex = 0;
for (int rowIndex = 0; rowIndex < totalRows; rowIndex++) {
%>
<div class="row">
<%
for (int colIndex = 0; colIndex < 3; colIndex++) {
if (index >= numFeeds) break;
JSONObject rss = (JSONObject) subscriptions.get(index);
%>
<div class="span4">
<h4><%=rss.get("title")%> <a href="?delFeedUrl=<%=URLEncoder.encode((String) rss.get("url"), "UTF-8")%>"><i class="icon-remove"></i> </a></h4>
<%
JSONArray items = (JSONArray) rss.get("items");
for (int i = 0; i < items.length(); i++) {
// Only 3 feeds per row
if (i > 4) break;
JSONObject item = (JSONObject) items.get(i);
%>
<p id="item<%=itemIndex%>" data-container="body" data-content="<%=((String)item.get("description")).replace('"','\'')%>" data-trigger="hover" data-placement="right" data-html="true"><a href="<%=item.get("link")%>"><%=item.get("title")%></a></p>
<%
itemIndex++;
}
%>
</div>
<%
index++;
}
%>
</div>
<%
}
%>
</div>
<hr>
<footer align="center">
<p>Netflix Inc. 2013</p>
</footer>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<script>
$(function ()
{
<%
for (int i = 0; i < itemIndex; i++) {
%>
$("#item<%=i%>").popover();
<%
}
%>
});
</script>
</body>
</html>