View Javadoc

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 DMSFactory implements RenderingFactoryIF {
18  	
19  	private static Log _ilog = LogFactoryUtil.getLog(DMSFactory.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 "dmsView.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  			// allowed attributes for the title are in this order: NAME, Title, that means NAME can overwrite Title
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;		// no need to check other attributes
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  		String contentUrl= myContent.getContentUrl();
82  		
83  		if( _ilog.isInfoEnabled() ) {
84  			_ilog.info("Using dmsUrl : " + contentUrl);
85  		}
86  		return contentUrl;
87  	}
88  	
89  	public String getURL_LF523() {
90  		if( myContent == null) {
91  			return "initialize factory!";
92  		}
93  		String contentUrl= myContent.getContentUrl();
94  		// get parentFolderId
95  		Collection<Attribute> attributes = myContent.getAttributes();
96  		long parentFolderId= -1;
97  		for (Attribute attr : attributes) {
98  			if( attr.getName().equalsIgnoreCase("parentFolderId")) {
99  				String parentFolderIdStr= attr.getValue();
100 				try {
101 					parentFolderId= (new Long(parentFolderIdStr)).longValue();
102 				} catch (NumberFormatException e) {
103 					_ilog.error("NumberformatException for id :" + parentFolderIdStr);
104 				}
105 				break; // stop search
106 			}
107 		}
108 		String lfFileName= "";
109 		for (Attribute attr : attributes) {
110 			if( attr.getName().equalsIgnoreCase("lfFileName")) {
111 				lfFileName= attr.getValue();
112 				break; // stop search
113 			}
114 		}
115 		if( _ilog.isInfoEnabled()) {
116 			_ilog.info("DMSFactory gets parentFolderId :" + parentFolderId + ", DMS file :" + lfFileName);
117 		}
118 		// we need an url like http://localhost:8080/c/document_library/get_file?p_l_id=10178&folderId=23604&name=DLFE-2201.txt
119 		StringBuffer buf= new StringBuffer();
120 		// TODO get server from portlet pref
121 		String serverAdress= "http://portal1.techmatrix.net";		// 5.3 server
122 		if( serverAdress.startsWith("http://") ) {
123 				buf.append(serverAdress);
124 		}
125 		else {
126 			buf.append("http://" + serverAdress);
127 		}
128 		// TODO we need an attribute for a plid
129 		long layoutId=  10485;	// from Hetzner 5.3.3 DEMO PDF
130 		
131 		buf.append("/c/document_library/get_file?p_l_id=");
132 		buf.append(layoutId);
133 		buf.append("&folderId=");
134 		buf.append(parentFolderId);
135 		buf.append("&name=");
136 		buf.append(lfFileName);
137 		String dmsUrl= buf.toString();
138 		
139 		if( _ilog.isInfoEnabled() ) {
140 			_ilog.info("Using dmsUrl : " + dmsUrl);
141 		}
142 		return dmsUrl;
143 	}
144 
145 	public List<String[]> getAttributes() {
146 		List<String[]> foundAttributes= new ArrayList<String[]>();
147 		Collection<Attribute> attributes = myContent.getAttributes();
148 		for (Attribute attr : attributes) {
149 			String name= attr.getName();
150 			String value= attr.getValue();
151 			if( value.length() > 200) {
152 				value= value.substring(0,200);
153 			}
154 			String[]arr= new String[2];
155 			arr[0]= name;
156 			arr[1]= value;
157 			foundAttributes.add(arr);
158 		}
159 		return foundAttributes;
160 	}
161 
162 	public String getText() {
163 		if( myContent == null) {
164 			return "initialize factory!";
165 		}
166 		String fullText= myContent.getFulltext();
167 		return fullText;
168 	}
169 
170 	public String getText(int maxLength) {
171 		// because we want the complete HTML, the maxLenght parameter is ignored here
172 		if( myContent == null) {
173 			return "initialize factory!";
174 		}
175 		String fullText= myContent.getFulltext();
176 
177 		return fullText;
178 	}
179 
180 }