From 93e1222278cc5be53f0f8c00eb477e372e737417 Mon Sep 17 00:00:00 2001 From: bbrodt Date: Thu, 10 Mar 2011 16:02:49 -0700 Subject: [PATCH 1/2] Add content describer for BPMN2 file types --- org.jboss.bpmn2.editor.ui/META-INF/MANIFEST.MF | 2 + org.jboss.bpmn2.editor.ui/plugin.xml | 17 +++- .../bpmn2/editor/ui/BPMN2ContentDescriber.java | 90 ++++++++++++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/BPMN2ContentDescriber.java diff --git a/org.jboss.bpmn2.editor.ui/META-INF/MANIFEST.MF b/org.jboss.bpmn2.editor.ui/META-INF/MANIFEST.MF index 2188cb4..1bd5a9d 100644 --- a/org.jboss.bpmn2.editor.ui/META-INF/MANIFEST.MF +++ b/org.jboss.bpmn2.editor.ui/META-INF/MANIFEST.MF @@ -38,3 +38,5 @@ Export-Package: org.jboss.bpmn2.editor.ui, org.jboss.bpmn2.editor.ui.util, org.jboss.bpmn2.editor.ui.views, org.jboss.bpmn2.editor.ui.wizards +Import-Package: org.apache.xerces.parsers, + org.apache.xerces.xni diff --git a/org.jboss.bpmn2.editor.ui/plugin.xml b/org.jboss.bpmn2.editor.ui/plugin.xml index d270528..e3231b8 100644 --- a/org.jboss.bpmn2.editor.ui/plugin.xml +++ b/org.jboss.bpmn2.editor.ui/plugin.xml @@ -28,15 +28,24 @@ icon="icons/bpmn2_editor_16.png" id="org.jboss.bpmn2.editor.ui.bpmn2editor" name="BPMN2 Visual Editor"> + + - - + + + + Date: Thu, 10 Mar 2011 16:14:40 -0700 Subject: [PATCH 2/2] Change line endings to unix-style --- .../bpmn2/editor/ui/BPMN2ContentDescriber.java | 180 ++++++++++---------- 1 files changed, 90 insertions(+), 90 deletions(-) diff --git a/org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/BPMN2ContentDescriber.java b/org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/BPMN2ContentDescriber.java index a836969..fd3d031 100644 --- a/org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/BPMN2ContentDescriber.java +++ b/org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/BPMN2ContentDescriber.java @@ -1,90 +1,90 @@ -package org.jboss.bpmn2.editor.ui; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; - -import org.apache.xerces.parsers.SAXParser; -import org.apache.xerces.xni.Augmentations; -import org.apache.xerces.xni.QName; -import org.apache.xerces.xni.XMLAttributes; -import org.apache.xerces.xni.XNIException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.ITextContentDescriber; -import org.xml.sax.InputSource; - - -public class BPMN2ContentDescriber implements ITextContentDescriber { - - private static final String BPMN2_NAMESPACE = "http://www.omg.org/spec/BPMN/20100524/MODEL"; //$NON-NLS-1$ - private static final String ROOT_ELEMENT = "definitions"; //$NON-NLS-1$ - - private RootElementParser parser; - - public BPMN2ContentDescriber() { - } - - public int describe(Reader contents, IContentDescription description) throws IOException { - return doDescribe(contents) == null ? INVALID : VALID; - } - - public int describe(InputStream contents, IContentDescription description) throws IOException { - return describe(new InputStreamReader(contents), description); - } - - private synchronized String doDescribe(Reader contents) throws IOException { - try { - InputSource source = new InputSource(contents); - parser = new RootElementParser(); - parser.parse(source); - } catch (AcceptedException e) { - return e.acceptedRootElement; - } catch (RejectedException e) { - return null; - } catch (Exception e) { - return null; - } - finally { - parser = null; - } - - return null; - } - - public QualifiedName[] getSupportedOptions() { - return null; - } - - private class RootElementParser extends SAXParser { - public void startElement(QName qName, XMLAttributes attributes, Augmentations augmentations) throws XNIException { - - super.startElement(qName, attributes, augmentations); - - if (ROOT_ELEMENT.equals(qName.localpart)) { - String namespace = fNamespaceContext.getURI(qName.prefix); - if (BPMN2_NAMESPACE.equals(namespace)) - throw new AcceptedException(qName.localpart); - else - throw new RejectedException(); - } else - throw new RejectedException(); - } - } - - private class AcceptedException extends RuntimeException { - public String acceptedRootElement; - - public AcceptedException(String acceptedRootElement) { - this.acceptedRootElement = acceptedRootElement; - } - - private static final long serialVersionUID = 1L; - } - - private class RejectedException extends RuntimeException { - private static final long serialVersionUID = 1L; - } - -} +package org.jboss.bpmn2.editor.ui; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +import org.apache.xerces.parsers.SAXParser; +import org.apache.xerces.xni.Augmentations; +import org.apache.xerces.xni.QName; +import org.apache.xerces.xni.XMLAttributes; +import org.apache.xerces.xni.XNIException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.ITextContentDescriber; +import org.xml.sax.InputSource; + + +public class BPMN2ContentDescriber implements ITextContentDescriber { + + private static final String BPMN2_NAMESPACE = "http://www.omg.org/spec/BPMN/20100524/MODEL"; //$NON-NLS-1$ + private static final String ROOT_ELEMENT = "definitions"; //$NON-NLS-1$ + + private RootElementParser parser; + + public BPMN2ContentDescriber() { + } + + public int describe(Reader contents, IContentDescription description) throws IOException { + return doDescribe(contents) == null ? INVALID : VALID; + } + + public int describe(InputStream contents, IContentDescription description) throws IOException { + return describe(new InputStreamReader(contents), description); + } + + private synchronized String doDescribe(Reader contents) throws IOException { + try { + InputSource source = new InputSource(contents); + parser = new RootElementParser(); + parser.parse(source); + } catch (AcceptedException e) { + return e.acceptedRootElement; + } catch (RejectedException e) { + return null; + } catch (Exception e) { + return null; + } + finally { + parser = null; + } + + return null; + } + + public QualifiedName[] getSupportedOptions() { + return null; + } + + private class RootElementParser extends SAXParser { + public void startElement(QName qName, XMLAttributes attributes, Augmentations augmentations) throws XNIException { + + super.startElement(qName, attributes, augmentations); + + if (ROOT_ELEMENT.equals(qName.localpart)) { + String namespace = fNamespaceContext.getURI(qName.prefix); + if (BPMN2_NAMESPACE.equals(namespace)) + throw new AcceptedException(qName.localpart); + else + throw new RejectedException(); + } else + throw new RejectedException(); + } + } + + private class AcceptedException extends RuntimeException { + public String acceptedRootElement; + + public AcceptedException(String acceptedRootElement) { + this.acceptedRootElement = acceptedRootElement; + } + + private static final long serialVersionUID = 1L; + } + + private class RejectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +} -- 1.7.4.msysgit.0