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.HashMap;
7 import java.util.List;
8 import java.util.Set;
9 import java.util.TreeSet;
10
11 import com.iqser.core.model.Attribute;
12 import com.iqser.core.model.Content;
13 import com.liferay.portal.kernel.log.Log;
14 import com.liferay.portal.kernel.log.LogFactoryUtil;
15
16 import de.iqser.factory.PreviewRenderingFactory;
17 import de.iqser.factory.RenderingFactoryIF;
18 import de.iqser.service.PortletIQserService;
19
20 public class DefaultFactory implements RenderingFactoryIF {
21
22 private static Log _ilog = LogFactoryUtil.getLog(DefaultFactory.class);
23 private Content myContent= null;
24
25 public void init(String iqserWebserviceUrl, int contentId) {
26 myContent= PortletIQserService.getContent(iqserWebserviceUrl, contentId);
27 }
28
29 public String getJSP() {
30 return "defaultView.jsp";
31 }
32
33 public String getDisplayTitle() {
34 if( myContent == null) {
35 return "initialize factory!";
36 }
37 Collection<Attribute> attributes = myContent.getAttributes();
38
39 String title= null;
40 for (Attribute attr : attributes) {
41
42
43 if( attr.getName().equalsIgnoreCase("title")) {
44 title= attr.getValue();
45 }
46 else if( attr.getName().equalsIgnoreCase("NAME")) {
47 title= attr.getValue();
48 break;
49 }
50 }
51 return title;
52 }
53
54 public String getType() {
55 if( myContent == null) {
56 return "initialize factory!";
57 }
58 String type= myContent.getType();
59 return type;
60 }
61
62 public String getModificationDate() {
63 if( myContent == null) {
64 return "initialize factory!";
65 }
66 SimpleDateFormat formatter= new SimpleDateFormat("dd.MM.yyyy");
67 long timeMillis= myContent.getModificationDate();
68 String formattedDate= formatter.format(timeMillis);
69 return formattedDate;
70 }
71
72 public float getScore() {
73 if( myContent == null) {
74 return 0;
75 }
76 float score= myContent.getModificationDate();
77 return score;
78 }
79
80 public String getURL() {
81 if( myContent == null) {
82 return "initialize factory!";
83 }
84 Collection<Attribute> attributes = myContent.getAttributes();
85 String url= null;
86 for (Attribute attr : attributes) {
87 if( attr.getName().equalsIgnoreCase("PREVIEW_URL")) {
88 url= attr.getValue();
89 break;
90 }
91 }
92 if( url == null) {
93 url= myContent.getContentUrl();
94 }
95 if( _ilog.isInfoEnabled() ) {
96 _ilog.info("Using url : " + url);
97 }
98 return url;
99 }
100
101 public List<String[]> getAttributes() {
102 List<String[]> foundAttributes= new ArrayList<String[]>();
103 Collection<Attribute> attributes = myContent.getAttributes();
104 for (Attribute attr : attributes) {
105 String name= attr.getName();
106
107 Set<String> excludedAttrs= new TreeSet<String>();
108 excludedAttrs.add("CONTENT");
109 excludedAttrs.add("DEFAULT");
110 excludedAttrs.add("TYPE");
111 excludedAttrs.add("URL");
112 excludedAttrs.add("PROVIDER");
113 excludedAttrs.add("CONTENTID");
114 excludedAttrs.add("MODIFICATIONDATE");
115 if(excludedAttrs.contains(name)) {
116 if( _ilog.isInfoEnabled()) {
117 _ilog.info("Skipping technical attribute :" + name);
118 }
119 continue;
120 }
121
122 String value= attr.getValue();
123 if( value.length() > 200) {
124 value= value.substring(0,200);
125 }
126 String[]arr= new String[2];
127 arr[0]= name;
128 arr[1]= value;
129 foundAttributes.add(arr);
130 }
131 return foundAttributes;
132 }
133
134 public String getText() {
135 if( myContent == null) {
136 return "initialize factory!";
137 }
138 String fullText= myContent.getFulltext();
139 return fullText;
140 }
141
142 public String getText(int maxLength) {
143 if( myContent == null) {
144 return "initialize factory!";
145 }
146 String fullText= myContent.getFulltext();
147
148 String startText= null;
149 if( fullText.length() > maxLength) {
150 startText= fullText.substring(0, maxLength);
151 }
152 else {
153 startText= fullText;
154 }
155 return startText;
156 }
157
158 }