public static String getRealNodePath(Node node) throws Exception { if (node.isNodeType("nt:frozenNode")) { Node realNode = getRealNode(node); return Text.escape(realNode.getPath(), '%', true) + "?version=" + node.getParent().getName(); } return Text.escape(node.getPath(), '%', true); }
public static String getWebdavURL(Node node, boolean withTimeParam, boolean isGetRealNodePath) throws Exception { NodeLocation location = NodeLocation.getNodeLocationByNode(getRealNode(node)); String repository = location.getRepository(); String workspace = location.getWorkspace(); String currentProtal = PortalContainer.getCurrentRestContextName(); String portalName = PortalContainer.getCurrentPortalContainerName(); String originalNodePath = isGetRealNodePath ? getRealNodePath(node) : Text.escape(node.getPath(), '%', true); StringBuffer imagePath = new StringBuffer(); imagePath .append("/") .append(portalName) .append("/") .append(currentProtal) .append("/jcr/") .append(repository) .append("/") .append(workspace) .append(originalNodePath); if (withTimeParam) { if (imagePath.indexOf("?") > 0) { imagePath.append("&time="); } else { imagePath.append("?time="); } imagePath.append(System.currentTimeMillis()); } return imagePath.toString(); }
/** * 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; }