Created
January 25, 2011 09:38
-
-
Save josephg/794716 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.waveprotocol.wave.model.export; | |
| import org.waveprotocol.wave.model.conversation.Conversation; | |
| import org.waveprotocol.wave.model.conversation.ConversationBlip; | |
| import org.waveprotocol.wave.model.conversation.ConversationView; | |
| import org.waveprotocol.wave.model.conversation.TitleHelper; | |
| import org.waveprotocol.wave.model.conversation.WaveBasedConversationView; | |
| import org.waveprotocol.wave.model.conversation.WaveletBasedConversation; | |
| import org.waveprotocol.wave.model.document.util.LineContainers; | |
| import org.waveprotocol.wave.model.document.util.XmlStringBuilder; | |
| import org.waveprotocol.wave.model.id.IdGenerator; | |
| import org.waveprotocol.wave.model.id.IdGeneratorImpl; | |
| import org.waveprotocol.wave.model.id.WaveId; | |
| import org.waveprotocol.wave.model.id.WaveletId; | |
| import org.waveprotocol.wave.model.operation.SilentOperationSink; | |
| import org.waveprotocol.wave.model.operation.wave.BasicWaveletOperationContextFactory; | |
| import org.waveprotocol.wave.model.operation.wave.WaveletOperation; | |
| import org.waveprotocol.wave.model.schema.SchemaCollection; | |
| import org.waveprotocol.wave.model.version.HashedVersion; | |
| import org.waveprotocol.wave.model.wave.ParticipantId; | |
| import org.waveprotocol.wave.model.wave.ParticipationHelper; | |
| import org.waveprotocol.wave.model.wave.ReadOnlyWaveView; | |
| import org.waveprotocol.wave.model.wave.data.ObservableWaveletData; | |
| import org.waveprotocol.wave.model.wave.data.WaveletData; | |
| import org.waveprotocol.wave.model.wave.data.impl.ObservablePluggableMutableDocument; | |
| import org.waveprotocol.wave.model.wave.data.impl.WaveletDataImpl; | |
| import org.waveprotocol.wave.model.wave.opbased.OpBasedWavelet; | |
| import java.util.ArrayList; | |
| import java.util.Random; | |
| public class ClientOpFactory { | |
| public static WaveletOperation[] blah() { | |
| long time = System.currentTimeMillis(); | |
| ParticipantId author = ParticipantId.ofUnsafe("[email protected]"); | |
| IdGenerator idGenerator = new IdGeneratorImpl(author.getDomain(), new IdGeneratorImpl.Seed() { | |
| Random r = new Random(); | |
| @Override | |
| public String get() { | |
| return Long.toString(Math.abs(r.nextLong()), 36); | |
| } | |
| }); | |
| WaveId waveId = idGenerator.newWaveId(); | |
| WaveletId waveletId = idGenerator.newConversationRootWaveletId(); | |
| // System.out.println(waveId + " " + waveletId); | |
| ObservableWaveletData data = | |
| new WaveletDataImpl(waveletId, | |
| author, time, 0, HashedVersion.unsigned(0), time, | |
| waveId, | |
| ObservablePluggableMutableDocument.createFactory(SchemaCollection.empty())); | |
| // SilentOperationSink | |
| final ArrayList<WaveletOperation> ops = new ArrayList<WaveletOperation>(); | |
| OpBasedWavelet wavelet = | |
| new OpBasedWavelet(waveId, data, new BasicWaveletOperationContextFactory(author), | |
| ParticipationHelper.IGNORANT, | |
| SilentOperationSink.Executor.<WaveletOperation, WaveletData>build(data), | |
| new SilentOperationSink<WaveletOperation>(){ | |
| @Override | |
| public void consume(WaveletOperation op) { | |
| ops.add(op); | |
| }}); | |
| ReadOnlyWaveView waveView = new ReadOnlyWaveView(waveId); | |
| waveView.addWavelet(wavelet); | |
| ConversationView conversationView = | |
| WaveBasedConversationView.create(waveView, idGenerator); | |
| WaveletBasedConversation.makeWaveletConversational(wavelet); | |
| Conversation conversation = conversationView.getRoot(); | |
| conversation.addParticipant(author); | |
| // WaveViewData waveViewData = WaveViewDataImpl.create(waveId, ImmutableList.of(data)); | |
| ConversationBlip blip = conversation.getRootThread().appendBlip(); | |
| LineContainers.appendToLastLine(blip.getContent(), XmlStringBuilder.createText("hello")); | |
| TitleHelper.maybeFindAndSetImplicitTitle(blip.getContent()); | |
| return ops.toArray(new WaveletOperation[0]); | |
| } | |
| public static void main(String... args) { | |
| WaveletOperation[] x = blah(); | |
| for (WaveletOperation op : x) { | |
| System.out.println(op); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment