'/' in wiki names are not converted back to ':' anymore (but ':' are converted to '/', if there's no corresonding *.xml file)
// int pos = selection.getOffset();
ArrayList startPositionList = new ArrayList();
char[] text = doc.get().toCharArray();
- try {
+ try {
char ch = ' ';
int i = 0;
int startPos = -1;
}
HashSet wikiNames = new HashSet();
ArrayList filesList = new ArrayList();
- String str;
+ ArrayList wikiList = new ArrayList();
+ String wikiTitle;
Integer posInteger;
IFile currentFile = ((IFileEditorInput) editor.getEditorInput()).getFile();
for (int i = 0; i < startPositionList.size(); i++) {
posInteger = (Integer) startPositionList.get(i);
- str = getWikiString(editor, doc, posInteger.intValue());
+ wikiTitle = getWikiTitle(editor, doc, posInteger.intValue());
- if (str != null && !str.equals("")) {
- if (!wikiNames.contains(str)) {
- IFile file = getWikiFile(currentFile, str);
+ if (wikiTitle != null && !wikiTitle.equals("")) {
+ if (!wikiNames.contains(wikiTitle)) {
+ IFile file = getWikiFile(currentFile, wikiTitle);
filesList.add(file);
- wikiNames.add(str);
+ wikiList.add(wikiTitle);
+ wikiNames.add(wikiTitle);
}
}
}
if (filesList.size() > 0) {
IFile[] files = new IFile[filesList.size()];
+ String[] wikiTitles = new String[filesList.size()];
filesList.toArray(files);
-
- Job job = new CreateFilesJob(files);
+ wikiList.toArray(wikiTitles);
+ Job job = new CreateFilesJob(files, wikiTitles);
// job.setRule(createRule(files));
job.setRule(null);
job.setUser(true);
import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
import net.sourceforge.phpeclipse.wiki.preferences.Util;
+import net.sourceforge.phpeclipse.wiki.xml.Page;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
public class CreateFilesJob extends WorkspaceJob {
IFile[] files;
+ String[] wikiTitles;
- public CreateFilesJob(IFile[] files) {
+ public CreateFilesJob(IFile[] files, String[] wikiTitles) {
super("Create Wiki Files Job");
this.files = files;
+ this.wikiTitles = wikiTitles;
}
public IStatus runInWorkspace(IProgressMonitor monitor) {
try {
monitor.beginTask("Create Wiki Files", 100);
IFile file;
+ String wikiTitle;
int partOfWork = 100 / files.length;
int work = 0;
String newText = WikiEditorPlugin.AUTOMATICALLY_CREATED;
ProblemConsole console = new ProblemConsole();
for (int i = 0; i < files.length; i++) {
file = files[i];
+ wikiTitle = wikiTitles[i];
IContainer parent = file.getParent();
if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
if (!file.exists()) {
monitor.subTask("Create File: "+file.getLocation().toString());
file.create(source, true, monitor);
+ Page page = new Page("", wikiTitle, "");
+ page.createXMLFile(file, false);
} else {
String message = "File: " + file.getLocation().toString() + "\n==>file already exists!";
monitor.subTask(message);
import net.sourceforge.phpeclipse.wiki.editor.WikiEditor;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
import net.sourceforge.phpeclipse.wiki.preferences.Util;
+import net.sourceforge.phpeclipse.wiki.xml.Page;
+import net.sourceforge.phpeclipse.wiki.xml.XStreamManager;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
}
}
- public static String getWikiString(AbstractTextEditor editor, IDocument document, int initialPos) {
+ public static String getWikiTitle(AbstractTextEditor editor, IDocument document, int initialPos) {
try {
int pos = initialPos;
int line = document.getLineOfOffset(pos);
wikiLinkStart = i + 1;
break;
}
- if (word.charAt(i) == '|') { // links wih different description
+ if (word.charAt(i) == '|') { // links with different description
wikiLinkEnd = i;
}
if (word.charAt(i) == '#') { // for links with anchors
IDocument doc = getDocument();
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
int pos = selection.getOffset();
-
- String textRegion = getWikiString(editor, doc, pos);
+
+ String wikiTitle = getWikiTitle(editor, doc, pos);
IFileEditorInput ei = (IFileEditorInput) editor.getEditorInput();
- openWikiFile(ei.getFile(), textRegion, true);
+ openWikiFile(ei.getFile(), wikiTitle, true);
}
- public void openWikiUrl(IProject project, String word) {
- if (word != null && !word.equals("")) {
- IFile cfile = project.getFile("dummy.wp");
- IFile file = getWikiFile(cfile, word);
+ // public void openWikiUrl(IProject project, String wikiTitle) {
+ // if (wikiTitle != null && !wikiTitle.equals("")) {
+ // IFile cfile = project.getFile("dummy.wp");
+ // IFile file = getWikiFile(cfile, wikiTitle);
+ // try {
+ // createNewFileIfNeeded(file, wikiTitle);
+ //
+ // IDE.openEditor(WikiEditorPlugin.getDefault().getActivePage(), file, true);
+ // } catch (Exception e) {
+ // //
+ // WikiEditorPlugin.getDefault().logAndReport(WikiEditorPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TITLE),
+ // // WikiPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TEXT), e);
+ // }
+ // }
+ // }
+
+ protected void openWikiFile(IFile cfile, String wikiTitle, boolean openEditor) {
+ if (wikiTitle != null && !wikiTitle.equals("")) {
+ IFile file = getWikiFile(cfile, wikiTitle);
try {
- createNewFileIfNeeded(file, word);
- // if (WikiEditorPlugin.getDefault().getPreferenceStore().getBoolean(WikiConstants.REUSE_EDITOR)) {
- // saveIfNeeded();
- // getActivePage().reuseEditor(reusableEditor, new FileEditorInput(file));
- // } else {
+ createNewFileIfNeeded(file, wikiTitle);
+
+ Page page = new Page("", wikiTitle, "");
+ page.createXMLFile(file, false);
+// createXMLFile(wikiTitle, file, false);
+
IDE.openEditor(WikiEditorPlugin.getDefault().getActivePage(), file, true);
- // redrawText();
- // }
} catch (Exception e) {
// WikiEditorPlugin.getDefault().logAndReport(WikiEditorPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TITLE),
// WikiPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TEXT), e);
}
- }
- }
-
- protected void openWikiFile(IFile cfile, String word, boolean openEditor) {
- if (word != null && !word.equals("")) {
- IFile file = getWikiFile(cfile, word);
- try {
- createNewFileIfNeeded(file, word);
- // if (WikiEditorPlugin.getDefault().getPreferenceStore().getBoolean(WikiConstants.REUSE_EDITOR)) {
- // saveIfNeeded();
- // getActivePage().reuseEditor(reusableEditor, new FileEditorInput(file));
- // } else {
- IDE.openEditor(WikiEditorPlugin.getDefault().getActivePage(), file, true);
- // redrawText();
- // }
- } catch (Exception e) {
- // WikiEditorPlugin.getDefault().logAndReport(WikiEditorPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TITLE),
- // WikiPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TEXT), e);
+ }
+ }
+
+ /**
+ * @param wikiTitle
+ * @param file
+ * @throws CoreException
+ */
+ private void createXMLFile(String wikiTitle, IFile file, boolean modify) throws CoreException {
+ String srcBasePath = Util.getWikiTextsPath(file);
+ String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
+
+ String filename = Util.getXMLFileName(file, binBasePath, srcBasePath);
+ IPath path = new Path(filename);
+ IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
+ IContainer parent = xmlFile.getParent();
+ if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
+ Util.createFolder((IFolder) parent, null);
+ }
+ Page page = new Page("", wikiTitle, "");
+ byte[] buffer = XStreamManager.toXML(page).getBytes();
+ ByteArrayInputStream source = new ByteArrayInputStream(buffer);
+ if (!xmlFile.exists()) {
+ // only if file doesn't exists
+ xmlFile.create(source, true, null);
+ } else {
+ if (modify) {
+ xmlFile.setContents(source, true, true, null);
}
- }
+ }
}
protected void createNewFileIfNeeded(IFile file, String word) throws CoreException {
HashMap map = new HashMap();
String wikiTitle;
for (int i = 0; i < files.length; i++) {
- wikiTitle = Util.getReadableWikiName(files[i]);
+ wikiTitle = null;
+ file = files[i];
+ String srcBasePath = Util.getWikiTextsPath(file);
+ String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
+
+ String fileXMLName = Util.getXMLFileName(file, binBasePath, srcBasePath);
+ IPath path = new Path(fileXMLName);
+ IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
+ if (xmlFile.exists()) {
+ try {
+ Page page = XStreamManager.fromXML(xmlFile.getContents());
+ if (page != null) {
+ wikiTitle = page.getTitle();
+ }
+ // timestamp = XMLReader.getDateTimestamp(xmlFile.getContents());
+ } catch (Exception e2) {
+ }
+ }
+ if (wikiTitle==null) {
+ // if no XML file exists we create the name from the filename
+ wikiTitle = Util.getReadableWikiName(files[i]);
+ }
buffer.append(wikiTitle);
- map.put(wikiTitle, files[i]);
+ map.put(wikiTitle, file);
if (i != files.length - 1) {
buffer.append("\n");
}
}
/**
- * Extract the wiki name from the current filename, replaces '/' with ':' characters, but doesn't replace '_' characters
+ * Extract the wiki name from the current filename, but doesn't replace '_' characters
*
* @param currentFile
* @return
}
/**
- * Extract the wiki name from the current filename, replaces '/' with ':' characters, and '_' with ' ' characters if
+ * Extract the wiki name from the current filename, replaces '_' with ' ' characters if
* <code>replaceUnderscore==true</code>
*
* @param currentFile
for (int i = basePath.length() + 1; i < lastIndex; i++) {
ch = filePath.charAt(i);
switch (ch) {
- case '/':
- result.append(':');
- break;
+// case '/':
+// result.append(':');
+// break;
default:
if (ch == '_' && replaceUnderscore) {
result.append(' ');
package net.sourceforge.phpeclipse.wiki.xml;
+import java.io.ByteArrayInputStream;
import java.util.ArrayList;
+import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.preferences.Util;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
//
public class Page {
public Revision get(int index) {
return (Revision) listOfRevisions.get(index);
}
+
+ public void createXMLFile(IFile file, boolean modify) throws CoreException {
+ String srcBasePath = Util.getWikiTextsPath(file);
+ String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
+
+ String filename = Util.getXMLFileName(file, binBasePath, srcBasePath);
+ IPath path = new Path(filename);
+ IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
+ IContainer parent = xmlFile.getParent();
+ if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
+ Util.createFolder((IFolder) parent, null);
+ }
+// Page page = new Page("", wikiTitle, "");
+ byte[] buffer = XStreamManager.toXML(this).getBytes();
+ ByteArrayInputStream source = new ByteArrayInputStream(buffer);
+ if (!xmlFile.exists()) {
+ // only if file doesn't exists
+ xmlFile.create(source, true, null);
+ } else {
+ if (modify) {
+ xmlFile.setContents(source, true, true, null);
+ }
+ }
+ }
}
\ No newline at end of file