Source Code Cross Referenced for EntryBean.java in  » Portal » Open-Portal » com » sun » portal » app » blog » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.app.blog.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved. 
003:         *
004:         * Sun Microsystems, Inc. has intellectual property rights relating to
005:         * technology embodied in the product that is described in this document. 
006:         * In particular, and without limitation, these intellectual property 
007:         * rights may include one or more of the U.S. patents listed at 
008:         * http://www.sun.com/patents and one or more additional patents or
009:         * pending patent applications in the U.S. and in other countries.
010:         * 
011:         * U.S. Government Rights - Commercial software. Government users are subject
012:         * to the Sun Microsystems, Inc. standard license agreement and applicable 
013:         * provisions of the FAR and its supplements. Use is subject to license terms. 
014:         * This distribution may include materials developed by third parties.
015:         * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered 
016:         * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 
017:         */
018:        package com.sun.portal.app.blog.model;
019:
020:        import com.sun.portal.app.blog.HTMLCleaner;
021:        import com.sun.portal.app.blog.Resources;
022:        import com.sun.syndication.feed.atom.Content;
023:        import com.sun.syndication.feed.atom.Entry;
024:        import com.sun.syndication.feed.atom.Person;
025:        import com.sun.syndication.feed.atom.Link;
026:        import java.util.ArrayList;
027:        import java.util.Collections;
028:        import java.util.Comparator;
029:        import java.util.Date;
030:        import java.util.Iterator;
031:        import java.util.List;
032:        import java.util.regex.Pattern;
033:
034:        public class EntryBean {
035:            private static interface Patterns {
036:                public static final Pattern SCRIPTS = Pattern.compile(
037:                        "<(no)?script[^>]*>.*</(no)?script>", Pattern.DOTALL);
038:                public static final Pattern TAGS = Pattern.compile("<[^>]+>");
039:                public static final Pattern ENTITY_REFS = Pattern
040:                        .compile("&[^;]+;");
041:                public static final Pattern WHITESPACE = Pattern
042:                        .compile("\\s+");
043:            }
044:
045:            public abstract static class ColumnComparator implements  Comparator {
046:                protected boolean ascending;
047:
048:                public ColumnComparator(boolean ascending) {
049:                    this .ascending = ascending;
050:                }
051:
052:                public abstract int compare(Object o1, Object o2);
053:            }
054:
055:            public static class TitleComparator extends ColumnComparator {
056:                public TitleComparator(boolean ascending) {
057:                    super (ascending);
058:                }
059:
060:                public int compare(Object o1, Object o2) {
061:                    EntryBean eb1 = (EntryBean) o1;
062:                    EntryBean eb2 = (EntryBean) o2;
063:
064:                    if (ascending) {
065:                        return eb1.getTitle().compareTo(eb2.getTitle());
066:                    } else {
067:                        return eb2.getTitle().compareTo(eb1.getTitle());
068:                    }
069:                }
070:            }
071:
072:            public static class AuthorComparator extends ColumnComparator {
073:                public AuthorComparator(boolean ascending) {
074:                    super (ascending);
075:                }
076:
077:                public int compare(Object o1, Object o2) {
078:                    EntryBean eb1 = (EntryBean) o1;
079:                    EntryBean eb2 = (EntryBean) o2;
080:
081:                    if (ascending) {
082:                        return eb1.getAuthor().compareTo(eb2.getAuthor());
083:                    } else {
084:                        return eb2.getAuthor().compareTo(eb1.getAuthor());
085:                    }
086:                }
087:            }
088:
089:            public static class UpdatedComparator extends ColumnComparator {
090:                public UpdatedComparator(boolean ascending) {
091:                    super (ascending);
092:                }
093:
094:                public int compare(Object o1, Object o2) {
095:                    EntryBean eb1 = (EntryBean) o1;
096:                    EntryBean eb2 = (EntryBean) o2;
097:
098:                    if (ascending) {
099:                        return eb1.getUpdated().compareTo(eb2.getUpdated());
100:                    } else {
101:                        return eb2.getUpdated().compareTo(eb1.getUpdated());
102:                    }
103:                }
104:            }
105:
106:            private static final int MAX_DISPLAY_TITLE_LENGTH = 128;
107:            private static final HTMLCleaner CLEANER = new HTMLCleaner();
108:            private static final Resources RESOURCES = new Resources(
109:                    "com.sun.portal.app.blog.model.EntryBean");
110:
111:            private String title;
112:            private String content;
113:            private String filteredContent;
114:            private Date updated;
115:            private String link;
116:            private String editLink;
117:            private String id;
118:            private String author;
119:            private String authorEmail;
120:            private boolean writable;
121:            private String displayTitle;
122:
123:            public EntryBean() {
124:                //nothing
125:            }
126:
127:            public String getTitle() {
128:                return title;
129:            }
130:
131:            public Date getUpdated() {
132:                return updated;
133:            }
134:
135:            public String getLink() {
136:                return link;
137:            }
138:
139:            public void setTitle(String title) {
140:                this .title = title;
141:            }
142:
143:            public String getContent() {
144:                return content;
145:            }
146:
147:            public String getFilteredContent() {
148:                return filteredContent;
149:            }
150:
151:            private void setFilteredContent() {
152:                String content = getContent();
153:                if (content == null) {
154:                    filteredContent = null;
155:                    return;
156:                }
157:                filteredContent = filterContent(content);
158:                //presentation layer will truncate the size
159:            }
160:
161:            public void setContent(String content) {
162:                this .content = content;
163:                setFilteredContent();
164:            }
165:
166:            public void setUpdated(Date updated) {
167:                this .updated = updated;
168:            }
169:
170:            public void setLink(String link) {
171:                this .link = link;
172:            }
173:
174:            public void clear() {
175:                setTitle(null);
176:                setContent(null);
177:                setLink(null);
178:                setEditLink(null);
179:                setUpdated(null);
180:                setId(null);
181:            }
182:
183:            public void populate(EntryBean other) {
184:                if (other == null) {
185:                    throw new NullPointerException("other cannot be null");
186:                }
187:                setTitle(other.getTitle());
188:                setContent(other.getContent());
189:                setLink(other.getLink());
190:                setEditLink(other.getEditLink());
191:                setUpdated(other.getUpdated());
192:                setId(other.getId());
193:                setAuthor(other.getAuthor());
194:                setWritable(other.isWritable());
195:            }
196:
197:            public static EntryBean getEntryBean(Entry entry, String userName) {
198:                EntryBean entryBean = new EntryBean();
199:                entryBean.setId(entry.getId());
200:                entryBean.setTitle(entry.getTitle());
201:                entryBean.setDisplayTitle(entry.getTitle());
202:                List contents = entry.getContents();
203:                if (contents != null && contents.size() > 0) {
204:                    String content = ((Content) contents.get(0)).getValue();
205:                    entryBean.setContent(content);
206:                }
207:                entryBean.setUpdated(entry.getUpdated());
208:                List altLinks = entry.getAlternateLinks();
209:                entryBean.setLink(getHref(altLinks, "alternate"));
210:                List otherLinks = entry.getOtherLinks();
211:                entryBean.setEditLink(getHref(otherLinks, "edit"));
212:                List authors = entry.getAuthors();
213:                if (authors != null && authors.size() > 0) {
214:                    // pick 1st person as display author
215:                    // is this valid?
216:                    Person p = (Person) authors.get(0);
217:                    entryBean.setAuthor(p.getName());
218:                    entryBean.setAuthorEmail(p.getEmail());
219:                }
220:                entryBean.setWritable(userName.equals(entryBean.getAuthor()));
221:
222:                return entryBean;
223:            }
224:
225:            private static String getHref(List links, String rel) {
226:                String href = null;
227:                if (links != null) {
228:                    for (Iterator i = links.iterator(); i.hasNext();) {
229:                        Link l = (Link) i.next();
230:                        if (l.getRel().equals(rel)) {
231:                            href = l.getHref();
232:                            break;
233:                        }
234:                    }
235:                }
236:                return href;
237:            }
238:
239:            public static List getEntryBeans(List entries, String userName) {
240:                if (entries == null) {
241:                    return null;
242:                }
243:                List entryBeans = new ArrayList();
244:                for (Iterator i = entries.iterator(); i.hasNext();) {
245:                    Entry entry = (Entry) i.next();
246:                    EntryBean entryBean = EntryBean.getEntryBean(entry,
247:                            userName);
248:                    entryBeans.add(entryBean);
249:                }
250:
251:                return entryBeans;
252:            }
253:
254:            public Entry toEntry() {
255:                Entry entry = new Entry();
256:                entry.setTitle(getTitle());
257:                Content content = new Content();
258:                content.setValue(getContent());
259:                content.setMode(Content.XML);
260:                entry.setContents(Collections.singletonList(content));
261:                if (getId() != null) {
262:                    entry.setId(getId());
263:                }
264:                String author = getAuthor();
265:                if (author != null) {
266:                    Person p = new Person();
267:                    p.setName(author);
268:                    entry.setAuthors(Collections.singletonList(p));
269:                }
270:                return entry;
271:            }
272:
273:            public String getId() {
274:                return id;
275:            }
276:
277:            public void setId(String id) {
278:                this .id = id;
279:            }
280:
281:            public String getEditLink() {
282:                return editLink;
283:            }
284:
285:            public void setEditLink(String editLink) {
286:                this .editLink = editLink;
287:            }
288:
289:            private static String filterContent(String s) {
290:                s = CLEANER.clean(s);
291:
292:                return s;
293:            }
294:
295:            public String getAuthor() {
296:                return (author == null || author.length() == 0) ? RESOURCES
297:                        .get("getAuthor.noAuthor") : author;
298:            }
299:
300:            public void setAuthor(String author) {
301:                this .author = author;
302:            }
303:
304:            public String getAuthorEmail() {
305:                return authorEmail;
306:            }
307:
308:            public boolean isAuthorEmailExists() {
309:                return authorEmail != null && authorEmail.length() > 0;
310:            }
311:
312:            public String getAuthorEmailLink() {
313:                if (authorEmail == null) {
314:                    return null;
315:                }
316:                return "mailto:" + authorEmail;
317:            }
318:
319:            public void setAuthorEmail(String authorEmail) {
320:                this .authorEmail = authorEmail;
321:            }
322:
323:            public boolean isWritable() {
324:                return writable;
325:            }
326:
327:            public void setWritable(boolean writable) {
328:                this .writable = writable;
329:            }
330:
331:            public String getDisplayTitle() {
332:                return displayTitle;
333:            }
334:
335:            public void setDisplayTitle(String displayTitle) {
336:                if (displayTitle != null
337:                        && displayTitle.length() > MAX_DISPLAY_TITLE_LENGTH) {
338:                    displayTitle = displayTitle.substring(0,
339:                            MAX_DISPLAY_TITLE_LENGTH - 1);
340:                    displayTitle += RESOURCES.get("more");
341:                }
342:                this.displayTitle = displayTitle;
343:            }
344:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.