diff --git a/org.eclipse.examples.slideshow.text/.classpath b/org.eclipse.examples.slideshow.text/.classpath new file mode 100755 index 0000000..64c5e31 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.examples.slideshow.text/.project b/org.eclipse.examples.slideshow.text/.project new file mode 100755 index 0000000..0a49cda --- /dev/null +++ b/org.eclipse.examples.slideshow.text/.project @@ -0,0 +1,28 @@ + + + org.eclipse.examples.slideshow.text + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.examples.slideshow.text/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.examples.slideshow.text/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 0000000..5ba90e4 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Wed Oct 01 22:00:36 EDT 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/org.eclipse.examples.slideshow.text/META-INF/MANIFEST.MF b/org.eclipse.examples.slideshow.text/META-INF/MANIFEST.MF new file mode 100755 index 0000000..742fbf2 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Slideshow Text Plug-in +Bundle-SymbolicName: org.eclipse.examples.slideshow.text +Bundle-Version: 0.2.0.qualifier +Bundle-Vendor: The Eclipse Foundation +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.eclipse.examples.slideshow.core;bundle-version="0.1.0" +Import-Package: org.eclipse.core.runtime;version="[3.4.0,4.0.0)", + org.eclipse.mylyn.wikitext.core.parser, + org.eclipse.mylyn.wikitext.core.parser.markup, + org.eclipse.mylyn.wikitext.mediawiki.core +Export-Package: org.eclipse.examples.slideshow.text diff --git a/org.eclipse.examples.slideshow.text/about.html b/org.eclipse.examples.slideshow.text/about.html new file mode 100755 index 0000000..56d49c3 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

January 19, 2009

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/org/documents/epl-v10.php. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.examples.slideshow.text/build.properties b/org.eclipse.examples.slideshow.text/build.properties new file mode 100755 index 0000000..34d2e4d --- /dev/null +++ b/org.eclipse.examples.slideshow.text/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/CopyrightToken.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/CopyrightToken.java new file mode 100755 index 0000000..e9e485b --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/CopyrightToken.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +import org.eclipse.mylyn.wikitext.core.parser.ImageAttributes; +import org.eclipse.mylyn.wikitext.core.parser.ImageAttributes.Align; +import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement; +import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor; + +public class CopyrightToken extends PatternBasedElement { + @Override + protected String getPattern(int groupOffset) { + return "(?:\\{Copyright:([^\\}]*)\\})"; + } + + @Override + protected int getPatternGroupCount() { + return 1; + } + + @Override + protected PatternBasedElementProcessor newProcessor() { + return new PatternBasedElementProcessor() { + @Override + public void emit() { + String message = group(1); + if (builder instanceof SlideDeckDocumentBuilder) { + ((SlideDeckDocumentBuilder)builder).copyright(message); + } + } + }; + } + + private static class ImageReplacementTokenProcessor extends PatternBasedElementProcessor { + @Override + public void emit() { + String imageUrl = group(1); + String optionsString = group(2); + + ImageAttributes attributes = new ImageAttributes(); + if (optionsString != null) { + String[] options = optionsString.split("\\s*\\|\\s*"); + for (String option : options) { + if ("center".equals(option)) { + attributes.setAlign(Align.Middle); + } else if ("left".equals(option)) { + attributes.setAlign(Align.Left); + } else if ("right".equals(option)) { + attributes.setAlign(Align.Right); + } else if ("none".equals(option)) { + attributes.setAlign(null); + } else if ("thumb".equals(option) || "thumbnail".equals(option)) { + // ignore + } else if (option.matches("\\d+px")) { + try { + int size = Integer.parseInt(option.substring(0, option.length() - 2)); + attributes.setWidth(size); + attributes.setHeight(size); + } catch (NumberFormatException e) { + // ignore + } + } else if ("frameless".equals(option)) { + attributes.setBorder(0); + } else if ("frame".equals(option)) { + attributes.setBorder(1); + } else { + attributes.setTitle(option); + } + } + } + builder.image(attributes, imageUrl); + } + } +} diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/ISlideDeckDocumentListener.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/ISlideDeckDocumentListener.java new file mode 100755 index 0000000..5fd72e0 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/ISlideDeckDocumentListener.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +public interface ISlideDeckDocumentListener { + + void slideAdded(SlideAddedEvent event); + +} diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/ISlideParserListener.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/ISlideParserListener.java new file mode 100755 index 0000000..d58c48e --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/ISlideParserListener.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +public interface ISlideParserListener { + + void slideAdded(SlideAddedEvent event); + +} diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/InsertCodeToken.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/InsertCodeToken.java new file mode 100644 index 0000000..60246bb --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/InsertCodeToken.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement; +import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor; + +public class InsertCodeToken extends PatternBasedElement { + + // TODO Add ability to turn on/off line numbers + // TODO Add flag to include Javadoc + // TODO Add flag to suppress all comments + // TODO Add flag to reformat + // TODO Add flag to preserve whitespace + @Override + protected String getPattern(int groupOffset) { + return "(?:\\{Code:([^\\}]*)\\})"; + } + + @Override + protected int getPatternGroupCount() { + return 1; + } + + @Override + protected PatternBasedElementProcessor newProcessor() { + return new PatternBasedElementProcessor() { + @Override + public void emit() { + String url = group(1); + if (builder instanceof SlideDeckDocumentBuilder) { + ((SlideDeckDocumentBuilder)builder).codeBlock(url); + } + } + }; + } + +} diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideAddedEvent.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideAddedEvent.java new file mode 100755 index 0000000..8146d07 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideAddedEvent.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +import org.eclipse.examples.slideshow.core.Slide; + +public class SlideAddedEvent { + + public final Slide slide; + public final int lineNumber; + + public SlideAddedEvent(Slide slide, int lineNumber) { + this.slide = slide; + this.lineNumber = lineNumber; + } + +} diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideDeckDocumentBuilder.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideDeckDocumentBuilder.java new file mode 100755 index 0000000..f5d4ae1 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideDeckDocumentBuilder.java @@ -0,0 +1,408 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.examples.slideshow.core.BlockChunk; +import org.eclipse.examples.slideshow.core.Chunk; +import org.eclipse.examples.slideshow.core.CodeBlockChunk; +import org.eclipse.examples.slideshow.core.IContent; +import org.eclipse.examples.slideshow.core.ImageChunk; +import org.eclipse.examples.slideshow.core.ListContent; +import org.eclipse.examples.slideshow.core.ListItemContent; +import org.eclipse.examples.slideshow.core.Slide; +import org.eclipse.examples.slideshow.core.SlideDeck; +import org.eclipse.examples.slideshow.core.SpanChunk; +import org.eclipse.examples.slideshow.core.TextChunk; +import org.eclipse.examples.slideshow.core.TextContent; +import org.eclipse.examples.slideshow.core.ListContent.ListType; +import org.eclipse.mylyn.wikitext.core.parser.Attributes; +import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder; +import org.eclipse.mylyn.wikitext.core.parser.ImageAttributes; + +public class SlideDeckDocumentBuilder extends DocumentBuilder { + + SlideDeck slideDeck; + Stack stack = new Stack(); + ListenerList listeners = new ListenerList(); + private final URL baseUrl; + + public SlideDeckDocumentBuilder(URL baseUrl) { + this.baseUrl = baseUrl; + } + + @Override + public void acronym(String text, String definition) { + // TODO Auto-generated method stub + + } + + @Override + public void beginBlock(BlockType type, Attributes attributes) { + if (type == BlockType.BULLETED_LIST) stack.push(new ListBuilder(getCurrentPartBuilder(), ListContent.ListType.BULLETED, attributes)); + else if (type == BlockType.NUMERIC_LIST) stack.push(new ListBuilder(getCurrentPartBuilder(), ListContent.ListType.NUMERIC, attributes)); + else if (type == BlockType.LIST_ITEM) stack.push(new ListItemBuilder(getCurrentPartBuilder())); + else if (type == BlockType.PARAGRAPH) stack.push(new ParagraphBuilder(getCurrentPartBuilder())); + else stack.push(new NoopBuilder(getCurrentPartBuilder())); + } + + private PartBuilder getCurrentPartBuilder() { + if (stack.isEmpty()) return null; + return stack.peek(); + } + + @Override + public void endBlock() { + getCurrentPartBuilder().end(); + stack.pop(); + } + + @Override + public void beginDocument() { + slideDeck = new SlideDeck(baseUrl); + } + + @Override + public void endDocument() { + clearBuilderStack(); + } + + @Override + public void beginHeading(int level, Attributes attributes) { + clearBuilderStack(); + stack.push(new SlideBuilder(level)); + } + + private void clearBuilderStack() { + while (!stack.isEmpty()) stack.pop().end(); + } + + @Override + public void endHeading() { + + } + + @Override + public void beginSpan(SpanType type, Attributes attributes) { + stack.push(new SpanBuilder(getCurrentPartBuilder(), type, attributes)); + } + + @Override + public void characters(String text) { + getCurrentPartBuilder().characters(text); + } + + @Override + public void charactersUnescaped(String literal) { + // TODO Auto-generated method stub + + } + + @Override + public void endSpan() { + stack.pop().end(); + } + + @Override + public void entityReference(String entity) { + // TODO Auto-generated method stub + + } + + @Override + public void image(Attributes attributes, String url) { + getCurrentPartBuilder().image(url, (ImageAttributes)attributes); + } + + @Override + public void imageLink(Attributes linkAttributes, + Attributes imageAttributes, String href, String imageUrl) { + // TODO Auto-generated method stub + } + + @Override + public void lineBreak() { + // TODO Auto-generated method stub + + } + + @Override + public void link(Attributes attributes, String hrefOrHashName, String text) { + beginSpan(SpanType.MONOSPACE, new Attributes()); + characters(text); + endSpan(); + } + + public void copyright(String message) { + getCurrentPartBuilder().setCopyright(message); + } + + public void codeBlock(String url) { + getCurrentPartBuilder().codeBlock(url); + } + + public SlideDeck getSlideDeck() { + return slideDeck; + } + + class PartBuilder { + + final PartBuilder parent; + + public PartBuilder(PartBuilder parent) { + this.parent = parent; + } + + public void codeBlock(String url) {} + + public void end() {} + + public void image(String url, ImageAttributes attributes) {} + + public void setCopyright(String message) { + getSlideDeck().setCopyright(message); + } + + public void characters(String text) { + PartBuilder parent = getParent(); + if (parent == null) return; + parent.characters(text); + } + + PartBuilder getParent() { + return parent; + } + + SlideBuilder getSlideBuilder() { + if (parent == null) return null; + if (parent instanceof SlideBuilder) return (SlideBuilder) parent; + return parent.getSlideBuilder(); + } + + Slide getSlide() { + if (getSlideBuilder() == null) return null; + return getSlideBuilder().getSlide(); + } + + ListBuilder getListBuilder() { + if (parent instanceof ListBuilder) return (ListBuilder) parent; + return parent.getListBuilder(); + } + + /** + * This method adds the provided instance of {@link IContent} to the + * receiver. In the default case, we assume that our object doesn't know + * how to hold content, so we pass the request onto the parent. If no + * parent exists, we bail out (thereby ignoring the content). + * + * @param content + */ + void addContent(IContent content) { + if (parent == null) return; + parent.addContent(content); + } + } + + class NoopBuilder extends PartBuilder { + + public NoopBuilder(PartBuilder parent) { + super(parent); + } + + } + + class SlideBuilder extends PartBuilder { + + Slide slide; + List contents = new ArrayList(); + + public SlideBuilder(int level) { + super(null); + slide = new Slide(); + slide.setLevel(level); + fireSlideAddedEvent(slide); + } + + public Slide getSlide() { + return slide; + } + + @Override + public void characters(String text) { + slide.setTitle(text); + } + + @Override + void addContent(IContent item) { + contents.add(item); + } + + @Override + public void setCopyright(String copyright) { + slide.setCopyright(copyright); + } + + @Override + public void end() { + slide.setContents((IContent[]) contents.toArray(new IContent[contents.size()])); + slideDeck.add(slide); + } + } + + class ListBuilder extends PartBuilder { + List items = new ArrayList(); + ListType type; + Attributes attributes; + + public ListBuilder(PartBuilder parent, ListType type, Attributes attributes) { + super(parent); + this.type = type; + this.attributes = attributes; + } + + public void addListItem(ListItemContent bulletContent) { + items.add(bulletContent); + } + + @Override + public void end() { + parent.addContent(new ListContent((IContent[]) items.toArray(new IContent[items.size()]), type)); + } + + @Override + void addContent(IContent item) { + items.add(item); + } + } + + /** + * The TextBuilder class is a generic sort of text handler that gathers + * {@link Chunk}s of text, images, etc. This type is abstract; subclasses are + * expected to do something with the gathere chunks. + */ + abstract class TextBuilder extends PartBuilder { + List chunks = new ArrayList(); + + public TextBuilder(PartBuilder parent) { + super(parent); + } + + @Override + public void characters(String characters) { + chunks.add(new TextChunk(getSlide(), characters)); + } + + Chunk[] getChunks() { + return (Chunk[]) chunks.toArray(new Chunk[chunks.size()]); + } + + @Override + public abstract void end(); + + @Override + public void image(String url, ImageAttributes attributes) { + int align = BlockChunk.ALIGN_NONE; + if (attributes.getAlign() == ImageAttributes.Align.Left) align = BlockChunk.ALIGN_LEFT; + else if (attributes.getAlign() == ImageAttributes.Align.Right) align = BlockChunk.ALIGN_RIGHT; + + BlockChunk chunk = new ImageChunk(getSlide(), url, align, attributes.getWidth(), attributes.getHeight()); + chunks.add(chunk); + } + + @Override + public void codeBlock(String url) { + CodeBlockChunk chunk = new CodeBlockChunk(getSlide(), url, BlockChunk.ALIGN_NONE); + chunks.add(chunk); + } + } + + class SpanBuilder extends TextBuilder { + + private final SpanType type; + + public SpanBuilder(PartBuilder parent, SpanType type, Attributes attributes) { + super(parent); + this.type = type; + } + + @Override + public void end() { + int style = SpanChunk.STYLE_NONE; + if (type == SpanType.ITALIC) style = SpanChunk.STYLE_ITALICS; + else if (type == SpanType.BOLD) style = SpanChunk.STYLE_BOLD; + + ((TextBuilder)getParent()).chunks.add(new SpanChunk(getSlide(), getChunks(), style)); + } + + } + + /** + * The ParagraphBuilder class adds an instance of {@link TextContent} to the + * current slide. The instance assumes that a {@link SlideBuilder} has been + * created lower on the stack. + */ + class ParagraphBuilder extends TextBuilder { + public ParagraphBuilder(PartBuilder parent) { + super(parent); + } + + @Override + public void end() { + SlideBuilder slideBuilder = getSlideBuilder(); + if (slideBuilder == null) return; + slideBuilder.addContent(new TextContent(getChunks())); + } + } + + /** + * The ListItemBuilder class adds a list item (bullet or numbered entry) to + * the parent list. The instance assumes that a type of {@link ListBuilder} + * has been created lower on the stack. + */ + class ListItemBuilder extends TextBuilder { + List nested = new ArrayList(); + + public ListItemBuilder(PartBuilder parent) { + super(parent); + } + + @Override + public void end() { + ListItemContent item = new ListItemContent(getChunks(), (IContent[]) nested.toArray(new IContent[nested.size()])); + parent.addContent(item); + } + + @Override + void addContent(IContent content) { + nested.add(content); + } + } + + public void addSlideDeckDocumentListener(ISlideDeckDocumentListener slideDeckDocumentListener) { + listeners.add(slideDeckDocumentListener); + } + + void fireSlideAddedEvent(Slide slide) { + if (listeners == null) return; + if (listeners.isEmpty()) return; + + SlideAddedEvent event = new SlideAddedEvent(slide, getLocator().getLineNumber()-1); + + for(Object listener : listeners.getListeners()) { + ((ISlideDeckDocumentListener)listener).slideAdded(event); + } + } +} \ No newline at end of file diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideMarkupLanguage.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideMarkupLanguage.java new file mode 100755 index 0000000..38e640d --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/SlideMarkupLanguage.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +import org.eclipse.mylyn.wikitext.mediawiki.core.MediaWikiLanguage; + +public class SlideMarkupLanguage extends MediaWikiLanguage { + + @Override + protected void addTokenExtensions(PatternBasedSyntax syntax) { + super.addTokenExtensions(syntax); + syntax.add(new CopyrightToken()); + syntax.add(new InsertCodeToken()); + } +} diff --git a/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/WikiTextParser.java b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/WikiTextParser.java new file mode 100755 index 0000000..d42aa12 --- /dev/null +++ b/org.eclipse.examples.slideshow.text/src/org/eclipse/examples/slideshow/text/WikiTextParser.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2009 The Eclipse Foundation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Eclipse Foundation - initial API and implementation + *******************************************************************************/ +package org.eclipse.examples.slideshow.text; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.net.URL; + +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.examples.slideshow.core.SlideDeck; +import org.eclipse.mylyn.wikitext.core.parser.MarkupParser; + +public class WikiTextParser { + + ListenerList listeners = new ListenerList(); + + public SlideDeck parse(String string) { + return parse(string, null); + } + + public SlideDeck parse(String string, URL baseUrl) { + try { + return parse(new StringReader(string), baseUrl); + } catch (IOException e) { + return null; // Should never get an IOException off a StringReader, right? + } + } + + public SlideDeck parse(Reader reader) throws IOException { + return parse(reader, null); + } + + public SlideDeck parse(Reader reader, URL baseUrl) throws IOException { + MarkupParser parser = new MarkupParser(new SlideMarkupLanguage()); + SlideDeckDocumentBuilder builder = new SlideDeckDocumentBuilder(baseUrl); + builder.addSlideDeckDocumentListener(new ISlideDeckDocumentListener() { + public void slideAdded(SlideAddedEvent event) { + fireSlideAddedEvent(event); + } + }); + parser.setBuilder(builder); + parser.parse(reader); + return builder.getSlideDeck(); + } + + public void addSlideParserListener(ISlideParserListener listener) { + listeners.add(listener); + } + + void fireSlideAddedEvent(SlideAddedEvent event) { + if (listeners == null) return; + if (listeners.isEmpty()) return; + + for (Object listener : listeners.getListeners()) { + ((ISlideParserListener)listener).slideAdded(event); + } + } + +}