Author: bbrodt
Date: 2010-05-20 12:31:36 -0400 (Thu, 20 May 2010)
New Revision: 22217
Added:
trunk/bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/BPELContentDescriber.java
Log:
https://jira.jboss.org/browse/JBIDE-6006
https://jira.jboss.org/browse/JBIDE-6093
Had to roll my own BPEL Content Describer class - XMLRootElementContentDescriber2 has
some...strange behavior
Added:
trunk/bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/BPELContentDescriber.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/BPELContentDescriber.java
(rev 0)
+++
trunk/bpel/plugins/org.eclipse.bpel.ui/src/org/eclipse/bpel/ui/BPELContentDescriber.java 2010-05-20
16:31:36 UTC (rev 22217)
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.bpel.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;
+
+/**
+ * @author Bob Brodt
+ *
+ * added for
https://jira.jboss.org/browse/JBIDE-6006
+ */
+public class BPELContentDescriber implements ITextContentDescriber {
+
+ private static final String WSBPEL_2_NAMESPACE =
"http://docs.oasis-open.org/wsbpel/2.0/process/executable"; //$NON-NLS-1$
+ private static final String ROOT_ELEMENT = "process"; //$NON-NLS-1$
+
+ private RootElementParser parser;
+
+ public BPELContentDescriber() {
+ }
+
+ 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 (WSBPEL_2_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;
+ }
+}