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 9fc589c..a2305b7 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 @@ -14,6 +14,7 @@ import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import net.sourceforge.phpeclipse.wiki.preferences.Util; import net.sourceforge.phpeclipse.wiki.renderer.IContentRenderer; import net.sourceforge.phpeclipse.wiki.renderer.RendererFactory; +import net.sourceforge.phpeclipse.wiki.renderer.StringUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -87,18 +88,63 @@ public class CreatePageAction implements IObjectActionDelegate { public void selectionChanged(IAction action, ISelection selection) { } + public static boolean createFragmentPage(IFile file, StringBuffer htmlBuffer) { + BufferedInputStream stream = null; + boolean noContent = true; + 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")); + noContent = StringUtil.checkNoContent(content); + 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) { + } + } + return noContent; + } + public static void createPage(IFile file) { + 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); - createPage(file, binBasePath, srcBasePath); + createPage(templateFileName, file, binBasePath, srcBasePath); } - public static void createPage(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(file, binBasepath, srcBasePath, renderer); + convertWikiFile(templateFileName, file, binBasePath, srcBasePath, renderer); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -111,6 +157,9 @@ public class CreatePageAction implements IObjectActionDelegate { } catch (CoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); } } else { String fname = file.getName().toLowerCase(); @@ -124,7 +173,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) { @@ -159,10 +208,10 @@ public class CreatePageAction implements IObjectActionDelegate { } } - public static void convertWikiFile(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(htmlBuffer, file, renderer, true); + convertWikiBuffer(templateFileName, htmlBuffer, file, renderer, true); String htmlName = Util.getHTMLFileName(file, binBasePath, srcBasePath); if (htmlName != null) { writeHTMLFile(htmlBuffer, htmlName); @@ -188,17 +237,17 @@ public class CreatePageAction implements IObjectActionDelegate { return; } - public static void convertWikiBuffer(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(htmlBuffer, filePath, content, renderer, completeHTML); + createWikiBuffer(templateFileName, htmlBuffer, filePath, content, renderer, completeHTML); } catch (IOException e) { e.printStackTrace(); } finally { @@ -217,8 +266,8 @@ public class CreatePageAction implements IObjectActionDelegate { * @param content * @param renderer */ - public static void createWikiBuffer(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; @@ -229,7 +278,7 @@ public class CreatePageAction implements IObjectActionDelegate { index++; } } - renderer.render(content, htmlBuffer, level, completeHTML); + renderer.render(templateFileName, content, htmlBuffer, level, completeHTML); } public static void writeHTMLFile(StringBuffer buffer, String filename) {