Search in sources :

Example 26 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class DocShare method handleStartMessage.

/**
 * This method called by the {@link #handleMessage(ID, byte[])} method if
 * the type of the message received is a start message (sent by remote party
 * via {@link #startShare(ID, String, ID, String, ITextEditor)}.
 *
 * @param message
 *            the UpdateMessage received.
 * @throws IDCreateException
 */
protected void handleStartMessage(final StartMessage message) throws IDCreateException {
    final ID senderID = message.getSenderID();
    Assert.isNotNull(senderID);
    final String senderUsername = message.getSenderUsername();
    Assert.isNotNull(senderUsername);
    final ID our = message.getReceiverID();
    Assert.isNotNull(our);
    final String filename = message.getFilename();
    Assert.isNotNull(filename);
    final String documentContent = message.getDocumentContent();
    Assert.isNotNull(documentContent);
    // SYNC API. Create an instance of the synchronization strategy on the receiver
    syncStrategy = createSynchronizationStrategy(false);
    Assert.isNotNull(syncStrategy);
    // First synchronize on any state changes by getting stateLock
    synchronized (stateLock) {
        // If we are already sharing, or have non-null start content
        if (isSharing() || startContent != null) {
            sendStopMessage(senderID);
            // And we're done
            return;
        }
        // Otherwise set start content to the message-provided
        // documentContent
        startContent = documentContent;
    }
    // Then open UI and show text editor if appropriate
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            try {
                // First, ask user if they want to receive the doc
                if (openReceiverDialog(senderID, senderUsername, filename)) {
                    // If so, then we create a new DocShareEditorInput
                    final DocShareEditorInput dsei = new DocShareEditorInput(getTempFileStore(senderUsername, filename, startContent), senderUsername, filename);
                    // Then open up text editor
                    final ITextEditor ep;
                    IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(dsei, getEditorIdForFileName(filename));
                    // if it's not a text editor, offer it a chance to give us one
                    if (editorPart != null && !(editorPart instanceof ITextEditor))
                        ep = (ITextEditor) editorPart.getAdapter(ITextEditor.class);
                    else
                        ep = (ITextEditor) editorPart;
                    // Then change our local state
                    localStartShare(getLocalRosterManager(), our, senderID, our, ep);
                } else {
                    // Send stop message to initiator
                    sendStopMessage();
                    // Then we stop the local share
                    localStopShare();
                }
            } catch (final Exception e) {
                logError(Messages.DocShare_EXCEPTION_RECEIVING_MESSAGE_TITLE, e);
                showErrorToUser(Messages.DocShare_EXCEPTION_RECEIVING_MESSAGE_TITLE, NLS.bind(Messages.DocShare_EXCEPTION_RECEIVING_MESSAGE_MESSAGE, e.getLocalizedMessage()));
            }
        }
    });
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ID(org.eclipse.ecf.core.identity.ID) ECFException(org.eclipse.ecf.core.util.ECFException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException)

Example 27 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class VBParser method parseMessage2.

private ThreadMessage parseMessage2(final ID id, final CharSequence seq) {
    ThreadMessage msg = null;
    ThreadMessageFactory tmf = new ThreadMessageFactory();
    msg = (ThreadMessage) tmf.createBBObject(id, null, null);
    Matcher m;
    String uname;
    Long l = parseTimestamp(seq);
    if (l != null) {
        msg.timePosted = new Date(l);
    }
    m = Pattern.compile("<div id=\"postmenu_" + ((ThreadMessageID) id).getLongValue() + "\">(.*?)</div>", Pattern.DOTALL).matcher(seq);
    if (m.find()) {
        String userInfoStr = m.group(1);
        m = PAT_MSG_USER.matcher(userInfoStr);
        if (m.find()) {
            MemberFactory mf = new MemberFactory();
            uname = new String(StringUtil.simpleStripHTML(m.group(3)));
            ID uid = null;
            try {
                uid = mf.createBBObjectId(namespace, baseURL, m.group(2));
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IDCreateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            msg.author = (IMember) mf.createBBObject(uid, uname, null);
        } else {
            // Didn't find a registered author, so the userinfo should
            // contain only the username.
            msg.author = new Member(new String(userInfoStr.trim()));
        }
    }
    m = Pattern.compile("#<a href=\"showpost.php\\?p=" + ((ThreadMessageID) id).getLongValue() + "(?:.*?)><strong>([0-9]+)</strong></a>").matcher(seq);
    m.find();
    msg.number = Integer.parseInt(m.group(1));
    m = PAT_MSG_TITLE.matcher(seq);
    m.find();
    msg.setNameInternal(new String(StringUtil.stripHTMLTrim(m.group(1))));
    m = PAT_MSG_MESSAGE.matcher(seq);
    m.find();
    String message = StringUtil.stripHTMLFullTrim(m.group(1));
    msg.message = message;
    return msg;
}
Also used : ThreadMessageFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory) Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) MemberFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.MemberFactory) ThreadMessageID(org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadMessageID) ID(org.eclipse.ecf.core.identity.ID) IMember(org.eclipse.ecf.bulletinboard.IMember) Date(java.util.Date)

Example 28 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class Thread method postReply.

public ID postReply(IThreadMessage message) throws IllegalWriteException, BBException {
    if ((mode & READ_ONLY) == READ_ONLY) {
        throw new IllegalWriteException(E_READ_ONLY);
    }
    ThreadMessage msg = (ThreadMessage) message;
    // FIXME assert msg.bb == bb;
    assert msg.getThread() == this;
    PostRequest request = new PostRequest(bb.getHttpClient(), bb.getURL(), "newreply.php");
    NameValuePair[] params = new NameValuePair[] { new NameValuePair("emailupdate", "9999"), new NameValuePair("rating", "0") };
    request.addParameters(params);
    params = new NameValuePair[] { new NameValuePair("title", message.getName()), new NameValuePair("message", msg.getMessage()), new NameValuePair("iconid", "0"), new NameValuePair("s", ""), new NameValuePair("do", "postreply"), new NameValuePair("t", String.valueOf(id.getLongValue())) };
    request.addParameters(params);
    if (message.getReplyTo() != null) {
        params = new NameValuePair[] { new NameValuePair("p", String.valueOf(((ThreadMessageID) message.getReplyTo().getID()).getLongValue())) };
        request.addParameters(params);
    }
    params = new NameValuePair[] { new NameValuePair("posthash", ""), new NameValuePair("poststarttime", ""), new NameValuePair("sbutton", "Submit Reply"), new NameValuePair("parseurl", "1") // checkbox : disabled new NameValuePair("disablesmilies", "1"),
    };
    request.addParameters(params);
    try {
        request.execute();
        // TODO: do we have to do this?
        String resp = request.getResponseBodyAsString();
        Header newLocation = request.getMethod().getResponseHeader("Location");
        if (newLocation == null) {
            throw ((VBParser) bb.getParser()).createVBException("The message was not posted.", resp);
        }
        Matcher m = Pattern.compile("showthread.php\\?p=([0-9]+)").matcher(newLocation.getValue());
        if (m.find()) {
            synchronized (this) {
                lastReadMessageId = (ThreadMessageID) new ThreadMessageFactory().createBBObjectId(bb.getNamespace(), bb.getURL(), m.group(1));
                return lastReadMessageId;
            }
        } else {
            throw ((VBParser) bb.getParser()).createVBException("The message was not posted.", resp);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IDCreateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ThreadMessageFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory) Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IOException(java.io.IOException) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) Header(org.apache.commons.httpclient.Header) IllegalWriteException(org.eclipse.ecf.bulletinboard.IllegalWriteException) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage)

Example 29 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class ServiceIDTest method testServiceIDFactoryNullScope.

/*
	 * org.eclipse.ecf.discovery.identity.IServiceIDFactory.createServiceID(Namespace, String[], String[], String[], String, String)
	 */
public void testServiceIDFactoryNullScope() {
    try {
        Namespace namespaceByName = IDFactory.getDefault().getNamespaceByName(namespace);
        ServiceIDFactory.getDefault().createServiceTypeID(namespaceByName, services, null, protocols, namingAuthority);
    } catch (IDCreateException e) {
        return;
    }
    fail("Invalid services may cause InvalidIDException");
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 30 with IDCreateException

use of org.eclipse.ecf.core.identity.IDCreateException in project ecf by eclipse.

the class ServiceIDTest method testServiceIDFactoryNullNA.

/*
	 * org.eclipse.ecf.discovery.identity.IServiceIDFactory.createServiceID(Namespace, String[], String[], String[], String, String)
	 */
public void testServiceIDFactoryNullNA() {
    try {
        Namespace namespaceByName = IDFactory.getDefault().getNamespaceByName(namespace);
        ServiceIDFactory.getDefault().createServiceTypeID(namespaceByName, services, scopes, protocols, null);
    } catch (IDCreateException e) {
        return;
    }
    fail("Invalid services may cause InvalidIDException");
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) Namespace(org.eclipse.ecf.core.identity.Namespace)

Aggregations

IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)34 ID (org.eclipse.ecf.core.identity.ID)16 Matcher (java.util.regex.Matcher)11 Namespace (org.eclipse.ecf.core.identity.Namespace)8 ThreadMessageID (org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)4 UnknownHostException (java.net.UnknownHostException)3 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)3 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)3 ThreadMessageFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory)3 URI (java.net.URI)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 NameValuePair (org.apache.commons.httpclient.NameValuePair)2 Job (org.eclipse.core.runtime.jobs.Job)2 IBBObject (org.eclipse.ecf.bulletinboard.IBBObject)2 IThreadMessage (org.eclipse.ecf.bulletinboard.IThreadMessage)2