1 package de.iqser.factory.classes;
2
3 import java.text.SimpleDateFormat;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.List;
7
8 import com.iqser.core.model.Attribute;
9 import com.iqser.core.model.Content;
10 import com.liferay.portal.kernel.log.Log;
11 import com.liferay.portal.kernel.log.LogFactoryUtil;
12
13 import de.iqser.factory.RenderingFactoryIF;
14 import de.iqser.portlets.PreviewPortlet;
15 import de.iqser.service.PortletIQserService;
16
17 public class HTMLFactory implements RenderingFactoryIF {
18
19 private static Log _ilog = LogFactoryUtil.getLog(HTMLFactory.class);
20
21 private Content myContent= null;
22 public void init(String iqserWebserviceUrl, int contentId) {
23 myContent= PortletIQserService.getContent(iqserWebserviceUrl, contentId);
24 }
25
26 public String getJSP() {
27 return "htmlView.jsp";
28 }
29
30 public String getDisplayTitle() {
31 if( myContent == null) {
32 return "initialize factory!";
33 }
34 Collection<Attribute> attributes = myContent.getAttributes();
35
36 String title= null;
37 for (Attribute attr : attributes) {
38
39
40 if( attr.getName().equalsIgnoreCase("title")) {
41 title= attr.getValue();
42 }
43 else if( attr.getName().equalsIgnoreCase("NAME")) {
44 title= attr.getValue();
45 break;
46 }
47 }
48 return title;
49 }
50
51 public String getType() {
52 if( myContent == null) {
53 return "initialize factory!";
54 }
55 String type= myContent.getType();
56 return type;
57 }
58
59 public String getModificationDate() {
60 if( myContent == null) {
61 return "initialize factory!";
62 }
63 SimpleDateFormat formatter= new SimpleDateFormat("dd.MM.yyyy");
64 long timeMillis= myContent.getModificationDate();
65 String formattedDate= formatter.format(timeMillis);
66 return formattedDate;
67 }
68
69 public float getScore() {
70 if( myContent == null) {
71 return 0;
72 }
73 float score= myContent.getModificationDate();
74 return score;
75 }
76
77 public String getURL() {
78 if( myContent == null) {
79 return "initialize factory!";
80 }
81 Collection<Attribute> attributes = myContent.getAttributes();
82 String url= null;
83 for (Attribute attr : attributes) {
84 if( attr.getName().equalsIgnoreCase("PREVIEW_URL")) {
85 url= attr.getValue();
86 break;
87 }
88 }
89 if( url == null) {
90 url= myContent.getContentUrl();
91 }
92 if( _ilog.isInfoEnabled() ) {
93 _ilog.info("Using url : " + url);
94 }
95 return url;
96 }
97
98 public List<String[]> getAttributes() {
99 List<String[]> foundAttributes= new ArrayList<String[]>();
100 Collection<Attribute> attributes = myContent.getAttributes();
101 for (Attribute attr : attributes) {
102 String name= attr.getName();
103 String value= attr.getValue();
104 if( value.length() > 200) {
105 value= value.substring(0,200);
106 }
107 String[]arr= new String[2];
108 arr[0]= name;
109 arr[1]= value;
110 foundAttributes.add(arr);
111 }
112 return foundAttributes;
113 }
114
115 public String getText() {
116 if( myContent == null) {
117 return "initialize factory!";
118 }
119 String fullText= myContent.getFulltext();
120 return fullText;
121 }
122
123 public String getText(int maxLength) {
124
125 if( myContent == null) {
126 return "initialize factory!";
127 }
128 String fullText= myContent.getFulltext();
129
130 return fullText;
131 }
132
133 }