Author: tchemit Date: 2011-08-19 18:26:27 +0200 (Fri, 19 Aug 2011) New Revision: 646 Url: http://nuiton.org/repositories/revision/maven-nuiton-skin/646 Log: Anomalie #1694: No scmwebeditor link if site file is prefixed by vm Modified: trunk/src/main/java/org/nuiton/maven/skin/NuitonSiteRenderer.java trunk/src/main/java/org/nuiton/maven/skin/ScmwebeditorUtils.java Modified: trunk/src/main/java/org/nuiton/maven/skin/NuitonSiteRenderer.java =================================================================== --- trunk/src/main/java/org/nuiton/maven/skin/NuitonSiteRenderer.java 2011-08-19 15:27:02 UTC (rev 645) +++ trunk/src/main/java/org/nuiton/maven/skin/NuitonSiteRenderer.java 2011-08-19 16:26:27 UTC (rev 646) @@ -181,16 +181,16 @@ // add our tool to velocity context - ScmwebeditorUtils tools = - new ScmwebeditorUtils(context, getLogger()); + ScmwebeditorUtils tool = new ScmwebeditorUtils(context, getLogger()); - tools.setLocale(locale); - tools.setLocales(locales); - tools.setMavenProject(mavenProject); - tools.setScmwebeditorURL(scmwebeditorPrefixURL); - tools.setSiteSourcesType(siteSourcesType); - tools.setSiteXmlScmwebeditorURL(siteXmlScmwebeditorURL); - context.put("ScmwebeditorUtils", tools); + tool.setLocale(locale); + tool.setLocales(locales); + tool.setMavenProject(mavenProject); + tool.setScmwebeditorPrefixURL(scmwebeditorPrefixURL); + tool.setSiteSourcesType(siteSourcesType); + tool.setSiteXmlScmwebeditorURL(siteXmlScmwebeditorURL); + tool.buildStates(); + context.put("ScmwebeditorUtils", tool); } return context; Modified: trunk/src/main/java/org/nuiton/maven/skin/ScmwebeditorUtils.java =================================================================== --- trunk/src/main/java/org/nuiton/maven/skin/ScmwebeditorUtils.java 2011-08-19 15:27:02 UTC (rev 645) +++ trunk/src/main/java/org/nuiton/maven/skin/ScmwebeditorUtils.java 2011-08-19 16:26:27 UTC (rev 646) @@ -48,7 +48,7 @@ private Locale locale; - private String scmwebeditorURL; + private String scmwebeditorPrefixURL; private String siteXmlScmwebeditorURL; @@ -56,11 +56,55 @@ private MavenProject mavenProject; + private String currentFileName; + + private File file; + + private String scmwebeditorFileURL; + public ScmwebeditorUtils(VelocityContext context, Logger logger) { this.context = context; this.logger = logger; + + currentFileName = (String) context.get("currentFileName"); } + public void buildStates() { + + File file = getFile(currentFileName); + boolean exist = file.exists(); + boolean withVm = false; + if (!exist) { + + // perharps the file have .vm extension + file = new File(file.getAbsolutePath() + ".vm"); + if (file.exists()) { + + // this is velocity file! + exist = true; + withVm = true; + } + } + + if (exist) { + + // file exists (so can be edited) + getLogger().debug("[" + currentFileName + "] on filesystem = " + file); + this.file = file; + + // compute here the scmwebeditor link + String relativePath = getRelativePath(currentFileName, '/'); + if (withVm) { + + // on a velocity file + relativePath += ".vm"; + } + + scmwebeditorFileURL = scmwebeditorPrefixURL + relativePath; + getLogger().debug("[" + currentFileName + "] scmwebeditor url = " + scmwebeditorFileURL); + } + } + public void setContext(VelocityContext context) { this.context = context; } @@ -73,8 +117,8 @@ this.locale = locale; } - public void setScmwebeditorURL(String scmwebeditorURL) { - this.scmwebeditorURL = scmwebeditorURL; + public void setScmwebeditorPrefixURL(String scmwebeditorPrefixURL) { + this.scmwebeditorPrefixURL = scmwebeditorPrefixURL; } public void setSiteSourcesType(String siteSourcesType) { @@ -94,20 +138,12 @@ } public boolean isCurrentFileEditable() { - String editFile = getCurrentFileName(); - File file = getFile(editFile); - getLogger().debug("[" + editFile + "] on filesystem = " + file); - boolean exist = file.exists(); + boolean exist = file != null; return exist; } public String getCurrentFileScmwebeditorURL() { - String editFile = getCurrentFileName(); - String relativePath = getRelativePath(editFile, '/'); - - String result = scmwebeditorURL + relativePath; - getLogger().debug("[" + editFile + "] scmwebeditor url = " + result); - return result; + return scmwebeditorFileURL; } protected VelocityContext getContext() { @@ -122,25 +158,18 @@ return mavenProject; } - protected String getAlignedFileName() { - return (String) context.get("alignedFileName"); - } - protected String getCurrentFileName() { - return (String) context.get("currentFileName"); + return currentFileName; } - protected boolean isFirstLocale() { return locale.equals(locales.get(0)); } - protected String getRelativePath(String editFile, char separator) { - String alignedFileName = getAlignedFileName(); - int lastIndex = alignedFileName.lastIndexOf(".") + 1; + int lastIndex = editFile.lastIndexOf(".") + 1; if (lastIndex > 0) { editFile = editFile.substring(0, lastIndex); }
participants (1)
-
tchemit@users.nuiton.org