Пример #1
0
 /**
  * Gets the viewable node by WCMComposer (depends on site mode)
  *
  * @param repository the repository's name
  * @param workspace the workspace's name
  * @param nodeIdentifier the node's path or node's UUID
  * @param version the base version (e.g. <code>WCMComposer.BASE_VERSION</code> )
  * @param cacheVisibility the visibility of cache
  * @return the viewable node. Return <code>null</code> if <code>nodeIdentifier</code> is invalid
  * @see #getViewableNodeByComposer(String repository, String workspace, String nodeIdentifier)
  *     getViewableNodeByComposer()
  * @see WCMComposer
  */
 public static Node getViewableNodeByComposer(
     String repository,
     String workspace,
     String nodeIdentifier,
     String version,
     String cacheVisibility) {
   try {
     HashMap<String, String> filters = new HashMap<String, String>();
     StringBuffer filterLang =
         new StringBuffer(Util.getPortalRequestContext().getLocale().getLanguage());
     String country = Util.getPortalRequestContext().getLocale().getCountry();
     if (country != null && country.length() > 0) {
       filterLang.append("_").append(country);
     }
     filters.put(WCMComposer.FILTER_LANGUAGE, filterLang.toString());
     filters.put(WCMComposer.FILTER_MODE, Utils.getCurrentMode());
     PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance();
     PortletMode portletMode = portletRequestContext.getApplicationMode();
     filters.put(WCMComposer.PORTLET_MODE, portletMode.toString());
     if (version != null) filters.put(WCMComposer.FILTER_VERSION, version);
     filters.put(WCMComposer.FILTER_VISIBILITY, cacheVisibility);
     return WCMCoreUtils.getService(WCMComposer.class)
         .getContent(
             workspace,
             Text.escapeIllegalJcrChars(nodeIdentifier),
             filters,
             WCMCoreUtils.getUserSessionProvider());
   } catch (Exception e) {
     return null;
   }
 }
 /**
  * Escapes special characters of node name in a path.
  *
  * @param path the path
  * @return the escaped node name
  */
 private String escapeIllegalJcrCharsOnNodeName(String path) {
   int lastIndex = path.lastIndexOf("/");
   if (lastIndex != -1) {
     String nodeName = path.substring(lastIndex + 1);
     path =
         new StringBuffer(path)
             .delete(path.length() - nodeName.length(), path.length())
             .append(Text.escapeIllegalJcrChars(nodeName))
             .toString();
   }
   return path;
 }