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;
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 <i>depth</i> 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);
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();
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e) {
- // TODO Auto-generated catch block
+ // TODO Auto-generated catch block
e.printStackTrace();
}
} else {
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) {
}
}
- 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);
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) {
* @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 <i>depth</i> of the file (i.e. ../../../ as much as needed)
int index = 0;
int level = 0;