public static final String join(String parent, String child) { if(parent == null || parent.length() == 0){ return child; } return CharUtils.chartrim(parent, '/') + "/" + child; }
/** * @param path ex. /folderA/fileName.ext * @return ex. /folderA */ public static final String getParentPath(String path) { if (path == null) { return null; } path = CharUtils.chartrim(path, '/'); int index = path.lastIndexOf("/"); if (index < 1) { return null; } return path.substring(0, index); }
/** * * @param path ex. /folderA/fileName.suf * @return ex. fileName.suf */ public static String getResourceName(String path) { if(path == null){ return null; } path = CharUtils.chartrim(path, '/'); int index = path.lastIndexOf('/'); if (index == -1) { return path; } else { return path.substring(index + 1); } }
public static boolean isWebDavTop(HttpServletRequest request) { String servletPath = request.getServletPath(); if (servletPath == null) { return false; // servletPath が NULL であれば WebDAV ではない } servletPath = CharUtils.chartrim(servletPath, '/'); boolean isWebDav = servletPath.equals(Constants.WEBDAV_URL_PREFIX); if (!isWebDav) { return false; } String pathInfo = request.getPathInfo(); if (pathInfo == null) { return true; // } pathInfo = pathInfo.replaceAll("/", ""); if (pathInfo.equals("")) { return true; } else { return false; } }
/** * クラスパスの配下の path の URL を取得する。 path 自体は存在しても存在しなくても構わない */ public static URL getResource(String path) { URL url = ResourceUtil.getResource(BASE); String fileName = url.toExternalForm(); String root = fileName.substring(0, fileName.length() - BASE.length()); String spec = CharUtils.chartrim(root, '/') + "/" + path; return URLUtil.create(spec); }
public static final boolean isAttachment(Resource res) { String pagePath = res.getPath(); pagePath = CharUtils.chartrim(pagePath, '/'); return res.isFolder() && pagePath.endsWith(CmsConstants.ATTACHEMENT_SUFFIX); }
private static final void addFile(JarOutputStream jOutput, File file, String prefix, String ignorePath) { prefix = CharUtils.chartrim(prefix, '/'); String path = ("".equals(prefix)) ? file.getName() : prefix + "/" + file.getName();
public String getMainPageParentPath() { if (getMainPagePath() == null) { return null; } int idx = CharUtils.chartrim(getMainPagePath(), '/').lastIndexOf('/'); if (idx > 0) { return getMainPagePath().substring(0, idx); } else { return ""; } }
protected void printLink(HtmlBuffer buf, CmsRequest request, String path, Resource resource) throws TgwSecurityException { WikiContext context = getConfiguration().getWikiContext(); String url = context.getURLByName(path, request).toString(); Map labelMap = (Map) labelInfo.get(); String labelName = (String) labelMap.get(resource.getPath()); if (labelName == null) { // second try labelName = (String) labelMap.get(CharUtils.chartrim(resource .getPath(), '/')); if (labelName == null) { labelName = resource.getPageName(); } } buf.appendAnchor(url, labelName); }
protected void printChildren(HtmlBuffer buf, CmsRequest request, String parent) throws PluginException { List folderList = null; WikiContext context = getConfiguration().getWikiContext(); try { parent = CharUtils.chartrim(parent, '/'); folderList = context.getResourceList(request, parent); Collections.sort(folderList, CmsUtils.COMPARATOR_FILEFOLDER); } catch (Exception e) { throw new PluginException(e); } if (folderList != null && folderList.size() > 0) { buf.appendStartTag("ul"); printFolderList(buf, folderList, request); buf.endTag(); } }
public String doHTMLView(CmsRequest request, CmsResponse response, PluginRequest prequest) throws PluginException { WikiContext context = getConfiguration().getWikiContext(); String path = request.getPage().getResource().getParentPath(); String[] args = prequest.getArgs(); if (args != null && args.length > 0) { path = args[0]; path = CharUtils.chartrim(path, '/'); } List list; try { list = context.getResourceList(request, path); } catch (Exception e) { throw new PluginException(e); } String name = prequest.getName(); HtmlBuffer buf = new HtmlBuffer(); if ("list".equals(name)) { renderList(list, buf, request, context); } else if ("navi".equals(name)) { renderNavi(list, buf, request, context); } return buf.toString(); }