X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java index 02546eb..1e4a8db 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java @@ -87,6 +87,47 @@ public class CreatePageAction implements IObjectActionDelegate { public void selectionChanged(IAction action, ISelection selection) { } + public static void createFragmentPage(IFile file, StringBuffer htmlBuffer) { + BufferedInputStream stream = null; + try { +// String templateFileName = Util.getLocalTemplate(file); + // String cssUrl = Util.getLocalCssUrl(file); + String srcBasePath = Util.getWikiTextsPath(file); + String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); + IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject()); + stream = new BufferedInputStream(file.getContents()); + + String fileName = Util.getHTMLFileName(file, binBasePath, srcBasePath); + String content = new String(getInputStreamAsCharArray(stream, -1, "utf-8")); + String filePath = file.getLocation().toString(); // file.getProjectRelativePath().toString() + if (filePath.startsWith(srcBasePath)) { + filePath = filePath.substring(srcBasePath.length() + 1); + } + // calculate the depth of the file (i.e. ../../../ as much as needed) + int index = 0; + int level = 0; + while (index >= 0) { + index = fileName.indexOf('/', index); + if (index >= 0) { + level++; + index++; + } + } + renderer.render(null, content, htmlBuffer, level, false); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (stream != null) { + stream.close(); + } + } catch (IOException e) { + } + } + + } + public static void createPage(IFile file) { String templateFileName = Util.getLocalTemplate(file); String cssUrl = Util.getLocalCssUrl(file); @@ -95,12 +136,12 @@ public class CreatePageAction implements IObjectActionDelegate { createPage(templateFileName, file, binBasePath, srcBasePath); } - public static void createPage(String templateFileName, IFile file, String binBasepath, String srcBasePath) { + public static void createPage(String templateFileName, IFile file, String binBasePath, String srcBasePath) { // only interested in files with the "wp" extension if ("wp".equalsIgnoreCase(file.getFileExtension())) { try { IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject()); - convertWikiFile(templateFileName, file, binBasepath, srcBasePath, renderer); + convertWikiFile(templateFileName, file, binBasePath, srcBasePath, renderer); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -114,7 +155,7 @@ public class CreatePageAction implements IObjectActionDelegate { // TODO Auto-generated catch block e1.printStackTrace(); } catch (Exception e) { - // TODO Auto-generated catch block + // TODO Auto-generated catch block e.printStackTrace(); } } else { @@ -129,7 +170,7 @@ public class CreatePageAction implements IObjectActionDelegate { InputStream contentStream = null; try { - String filename = Util.getHTMLFileName(file, binBasepath, srcBasePath); + String filename = Util.getHTMLFileName(file, binBasePath, srcBasePath); if (filename != null) { int index = filename.lastIndexOf('/'); if (index >= 0) { @@ -164,8 +205,8 @@ public class CreatePageAction implements IObjectActionDelegate { } } - public static void convertWikiFile(String templateFileName, IFile file, String binBasePath, String srcBasePath, IContentRenderer renderer) - throws CoreException { + public static void convertWikiFile(String templateFileName, IFile file, String binBasePath, String srcBasePath, + IContentRenderer renderer) throws CoreException { StringBuffer htmlBuffer = new StringBuffer(); convertWikiBuffer(templateFileName, htmlBuffer, file, renderer, true); String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath); @@ -193,15 +234,15 @@ public class CreatePageAction implements IObjectActionDelegate { return; } - public static void convertWikiBuffer(String templateFileName, StringBuffer htmlBuffer, IFile file, IContentRenderer renderer, boolean completeHTML) - throws CoreException { + public static void convertWikiBuffer(String templateFileName, StringBuffer htmlBuffer, IFile file, IContentRenderer renderer, + boolean completeHTML) throws CoreException { BufferedInputStream stream = new BufferedInputStream(file.getContents()); try { String content = new String(getInputStreamAsCharArray(stream, -1, null)); String srcPath = Util.getWikiTextsPath(file); String filePath = file.getLocation().toString(); // file.getProjectRelativePath().toString() if (filePath.startsWith(srcPath)) { - filePath = filePath.substring(srcPath.length()+1); + filePath = filePath.substring(srcPath.length() + 1); } createWikiBuffer(templateFileName, htmlBuffer, filePath, content, renderer, completeHTML); } catch (IOException e) { @@ -222,8 +263,8 @@ public class CreatePageAction implements IObjectActionDelegate { * @param content * @param renderer */ - public static void createWikiBuffer(String templateFileName, StringBuffer htmlBuffer, String fileName, String content, IContentRenderer renderer, - boolean completeHTML) { + public static void createWikiBuffer(String templateFileName, StringBuffer htmlBuffer, String fileName, String content, + IContentRenderer renderer, boolean completeHTML) { // calculate the depth of the file (i.e. ../../../ as much as needed) int index = 0; int level = 0;