1 31 32 package org.opencms.workplace.galleries; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.file.CmsPropertyDefinition; 36 import org.opencms.file.CmsResource; 37 import org.opencms.file.types.CmsResourceTypePointer; 38 import org.opencms.jsp.CmsJspActionElement; 39 import org.opencms.main.CmsException; 40 import org.opencms.main.CmsLog; 41 import org.opencms.main.OpenCms; 42 import org.opencms.util.CmsStringUtil; 43 import org.opencms.workplace.explorer.CmsNewResource; 44 import org.opencms.workplace.explorer.CmsNewResourceUpload; 45 46 import java.util.ArrayList ; 47 import java.util.Iterator ; 48 import java.util.List ; 49 50 import javax.servlet.http.HttpServletRequest ; 51 import javax.servlet.http.HttpServletResponse ; 52 import javax.servlet.jsp.PageContext ; 53 54 import org.apache.commons.logging.Log; 55 56 71 public class CmsLinkGallery extends A_CmsGallery { 72 73 74 public static final String URI_GALLERY = PATH_GALLERIES + "link_fs.jsp"; 75 76 77 private static final Log LOG = CmsLog.getLog(CmsLinkGallery.class); 78 79 80 private static final Integer ORDER_GALLERY = new Integer (30); 81 82 85 public CmsLinkGallery() { 86 87 } 89 90 95 public CmsLinkGallery(CmsJspActionElement jsp) { 96 97 super(jsp); 98 } 99 100 107 public CmsLinkGallery(PageContext context, HttpServletRequest req, HttpServletResponse res) { 108 109 this(new CmsJspActionElement(context, req, res)); 110 } 111 112 115 public String applyButton() { 116 117 if (MODE_VIEW.equals(getParamDialogMode())) { 118 return button(null, null, "apply_in.png", Messages.GUI_BUTTON_PASTE_0, 0); 120 } else { 121 String uri = getParamResourcePath(); 122 if (MODE_WIDGET.equals(getParamDialogMode())) { 123 try { 125 CmsResource res = getCms().readResource(getParamResourcePath()); 126 uri = new String (CmsFile.upgrade(res, getCms()).getContents()); 127 } catch (CmsException e) { 128 LOG.error(e); 130 } 131 } else { 132 uri = getJsp().link(uri); 134 } 135 136 return button( 137 "javascript:link('" + uri + "',document.form.title.value, document.form.title.value);", 138 null, 139 "apply.png", 140 Messages.GUI_BUTTON_PASTE_0, 141 0); 142 } 143 } 144 145 150 public String buildGalleryItemPreview() { 151 152 StringBuffer html = new StringBuffer (32); 153 try { 154 if (CmsStringUtil.isNotEmpty(getParamResourcePath())) { 155 CmsResource res = getCms().readResource(getParamResourcePath()); 156 if (res != null) { 157 String pointer = new String (CmsFile.upgrade(res, getCms()).getContents()); 159 if (CmsStringUtil.isEmptyOrWhitespaceOnly(pointer)) { 160 pointer = getJsp().link(getCms().getSitePath(res)); 161 } 162 String title = getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE); 163 String description = getJsp().property( 164 CmsPropertyDefinition.PROPERTY_DESCRIPTION, 165 getParamResourcePath()); 166 String keywords = getJsp().property(CmsPropertyDefinition.PROPERTY_KEYWORDS, getParamResourcePath()); 167 String lastmodified = getMessages().getDateTime(res.getDateLastModified()); 168 html.append("<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" style=\"align: middle; width:100%; background-color: ThreeDFace; margin: 0;\">"); 169 html.append("<tr align=\"left\">"); 170 html.append("<td width=\"35%\"><b>"); 171 html.append(key(Messages.GUI_INPUT_LINKTO_0)); 172 html.append("</b></td>"); 173 html.append("<td width=\"65%\"><a HREF=\"#\" onclick=\""); 174 html.append("javascript:window.open('"); 175 html.append(getJsp().link(getCms().getSitePath(res))); 176 html.append("','_preview','')"); 177 html.append("\">"); 178 html.append(pointer); 179 html.append("</a></td>"); 180 html.append(previewRow(key(Messages.GUI_LABEL_NAME_0), res.getName())); 182 html.append(previewRow(key(Messages.GUI_INPUT_TITLE_0), title)); 184 html.append(previewRow(key(Messages.GUI_INPUT_DATELASTMODIFIED_0), lastmodified)); 186 if (CmsStringUtil.isNotEmpty(description)) { 188 html.append(previewRow(key(Messages.GUI_INPUT_DESCRIPTION_0), description)); 189 } 190 if (CmsStringUtil.isNotEmpty(keywords)) { 192 html.append(previewRow(key(Messages.GUI_INPUT_KEYWORDS_0), keywords)); 193 } 194 html.append("</table>"); 195 } 196 } 197 } catch (CmsException e) { 198 LOG.error(e); 200 } 201 return html.toString(); 202 } 203 204 207 public int getGalleryItemsTypeId() { 208 209 return CmsResourceTypePointer.getStaticTypeId(); 210 } 211 212 215 public String getHeadFrameSetHeight() { 216 217 return "450"; 218 } 219 220 225 public Integer getOrder() { 226 227 return ORDER_GALLERY; 228 } 229 230 235 public String getWizardUrl() { 236 237 StringBuffer wizardUrl = new StringBuffer (8); 238 wizardUrl.append(getJsp().link( 239 PATH_DIALOGS 240 + OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypePointer.getStaticTypeName()).getNewResourceUri())); 241 wizardUrl.append("?action=newform&"); 242 wizardUrl.append(CmsNewResourceUpload.PARAM_REDIRECTURL); 243 wizardUrl.append("="); 244 wizardUrl.append(PATH_GALLERIES); 245 wizardUrl.append("gallery_list.jsp&"); 246 wizardUrl.append(CmsNewResourceUpload.PARAM_TARGETFRAME); 247 wizardUrl.append("=gallery_list&"); 248 wizardUrl.append(CmsNewResource.PARAM_CURRENTFOLDER); 249 wizardUrl.append("="); 250 251 return wizardUrl.toString(); 252 } 253 254 257 public String wizardButton() { 258 259 return button("javascript:wizard();", null, "upload.png", Messages.GUI_TITLE_NEW_0, 0); 260 } 261 262 265 protected String buildGalleryItemListCustomEndCols(CmsResource res, String tdClass) { 266 267 StringBuffer result = new StringBuffer (64); 268 result.append("\t<td class=\""); 269 result.append(tdClass); 270 result.append("\">"); 271 String linkTarget; 272 try { 273 CmsFile file = CmsFile.upgrade(res, getCms()); 274 linkTarget = new String (file.getContents()); 275 } catch (CmsException e) { 276 linkTarget = ""; 277 } 278 result.append(linkTarget); 279 result.append("</td>\n"); 280 return result.toString(); 281 } 282 283 286 protected String buildGalleryItemListHeadline() { 287 288 StringBuffer headline = new StringBuffer (16); 289 headline.append("<tr>"); 290 headline.append("<td class=\"headline\"> </td>"); 291 headline.append("<td class=\"headline\" width=\"25%\">"); 292 headline.append(key(Messages.GUI_LABEL_NAME_0)); 293 headline.append("</td>"); 294 headline.append("<td class=\"headline\" width=\"45%\">"); 295 headline.append(key(Messages.GUI_LABEL_TITLE_0)); 296 headline.append("</td>"); 297 headline.append("<td class=\"headline\" width=\"30%\">"); 298 headline.append(key(Messages.GUI_INPUT_LINKTO_0)); 299 headline.append("</td>"); 300 headline.append("</tr>"); 301 302 return headline.toString(); 303 } 304 305 313 protected List getSearchHits(List items) { 314 315 String searchword = getParamSearchWord().toLowerCase(); 316 List hitlist = new ArrayList (); 317 if (items != null) { 318 Iterator i = items.iterator(); 319 while (i.hasNext()) { 320 try { 321 CmsResource res = (CmsResource)i.next(); 322 String resname = res.getName().toLowerCase(); 323 String restitle = getJsp().property( 324 CmsPropertyDefinition.PROPERTY_TITLE, 325 getCms().getSitePath(res), 326 resname).toLowerCase(); 327 CmsFile file = CmsFile.upgrade(res, getCms()); 329 String link = new String (file.getContents()).toLowerCase(); 330 331 if (restitle.indexOf(searchword) != -1 332 || resname.indexOf(searchword) != -1 333 || link.indexOf(searchword) != -1) { 334 hitlist.add(res); 336 } 337 } catch (CmsException e) { 338 } 340 } 341 } 342 343 return hitlist; 344 } 345 } | Popular Tags |