From: <jbo...@li...> - 2005-08-26 14:21:08
|
Author: ral...@jb... Date: 2005-08-26 10:20:57 -0400 (Fri, 26 Aug 2005) New Revision: 972 Modified: trunk/forge/portal-extensions/forge-prj-freezone/src/java/org/jboss/forge/projects/freezone/Freezone.java Log: freezone handles folders Modified: trunk/forge/portal-extensions/forge-prj-freezone/src/java/org/jboss/forge/projects/freezone/Freezone.java =================================================================== --- trunk/forge/portal-extensions/forge-prj-freezone/src/java/org/jboss/forge/projects/freezone/Freezone.java 2005-08-26 13:37:25 UTC (rev 971) +++ trunk/forge/portal-extensions/forge-prj-freezone/src/java/org/jboss/forge/projects/freezone/Freezone.java 2005-08-26 14:20:57 UTC (rev 972) @@ -56,17 +56,7 @@ h = content.indexOf(" href="); //search for one of the link types if (h == -1) { -// ch = content.indexOf("HREF=");//search for the capitalized version as well -// if(ch == -1) - return null; -// else -// { -// start = ch; //found the capitalized version -// content= content.substring(0, ch) + -// content.substring(ch, ch+4).toLowerCase() + -// content.substring(ch+4); //need to make it lower case for -// //later parsing -// } + return null; } else start = h; int begin = content.substring(start).indexOf('"'); @@ -101,7 +91,59 @@ || link.startsWith("https:") || link.startsWith("mailto:") || link.startsWith("news:") || link.startsWith("file:"); } + +// modifies path to page/resource so folder structure can be supported + private String modifyPath(String path, String element) { + System.out.println("element is: "+ element); + System.out.println("path is: "+ path); + int start, end; + String mainPath = ""; + + int pre = path.lastIndexOf('/'); + if(pre== -1)//we are in root dir + { + return element; + } + else { + mainPath = path.substring(0, pre); + System.out.println("main path is: " + mainPath); + }//main path to page + + + if (element.startsWith("/")) + return element.substring(1); //base path, start with WEB-root + if (element.startsWith("./")) + element = element.substring(1);//ignore ./ only clutters the code + if (element.indexOf('/') != -1) { + if (element.indexOf("../") != -1)//need to go up a few levels + { + while (element.indexOf("../") != -1) //do we need to go more + { + if (mainPath.equals("")) + return DEFAULT_PAGE; //trying to go too far up + else { + start = element.lastIndexOf("../");//go one level up + end = mainPath.lastIndexOf("/");//find last level + element = element.substring(0, start) + //+ mainPath + // .substring(end, mainPath.length()) + + element + .substring(start + 3, element.length()); + // System.out.println("element is: " + element); + mainPath = mainPath.substring(0, end); + // System.out.println("mainPath is: " + mainPath); + }//else + + }//while + + }//if ../ + + } + + return mainPath + '/' + element; + } + public void doView(JBossRenderRequest request, JBossRenderResponse response) throws IOException { response.setContentType("text/html"); @@ -134,6 +176,7 @@ throw new Exception(); String nextRef; + String nextRef2; while(pageContent.indexOf("HREF=")!= -1) { pageContent = forgeHelper.replace(pageContent,"HREF=", "href="); @@ -142,11 +185,14 @@ // Replacing links while ((nextRef = findNextReference(pageContent, "link")) != null) { if(!isExternalLink(nextRef)) + { //it would be relative not outside link + nextRef2 = modifyPath(pagePath, nextRef); pageContent = forgeHelper.replace(pageContent, "href=" + '"' + nextRef + '"', projectsHelper.createFreezonePageLink(portalName, - projectId, nextRef) + '"'); + projectId, nextRef2) + '"'); + } else { pageContent = forgeHelper.replace(pageContent, "href=" + '"' + nextRef, "$"+nextRef+'"'); |