/** * Updates an existing shadow blip. * * @param shadowBlip the blip that is shadowing. * @param blipToShadow the blip being shadowed. */ private void updateShadowBlip(Blip shadowBlip, Blip blipToShadow) { Preconditions.checkNotNull(shadowBlip, "Shadow blip can't be null"); Preconditions.checkNotNull(blipToShadow, "Blip to shadow can't be null"); shadowBlip.all().replace(blipToShadow.getContent()); for (Annotation annotation : blipToShadow.getAnnotations()) { if (annotation.getName().equals(ECHOEY_ANNOTATION)) { continue; } shadowBlip.range(annotation.getRange().getStart(), annotation.getRange().getEnd()).annotate( annotation.getName(), annotation.getValue()); } shadowBlip.all().annotate(ECHOEY_ANNOTATION, blipToShadow.getBlipId()); shadowBlipMap.put(blipToShadow.getBlipId(), shadowBlip.getBlipId()); }
/** * Creates a new shadow blip. * * Note that this method will not know the id of the new blip since the * server will generate it. * * @param blip the blip to create a new shadow blip for. */ private void createShadowBlip(Blip blip) { Blip newBlip = blip.continueThread(); newBlip.all().replace(blip.getContent()); newBlip.all().annotate(ECHOEY_ANNOTATION, blip.getBlipId()); }
@Override public void renderLogin(String userRecordKey, Wavelet wavelet) { // Clear login form. wavelet.getRootBlip().all().delete(); PersistenceManager pm = SingletonPersistenceManagerFactory.get().getPersistenceManager(); OAuthUser userProfile = null; try { userProfile = pm.getObjectById(OAuthUser.class, userRecordKey); } catch (JDOObjectNotFoundException objectNotFound) { LOG.severe("Error fetching object from datastore with key: " + userRecordKey); } finally { pm.close(); } String url = userProfile.getAuthUrl(); // Add authentication prompt and insert link to service provider log-in page // to wavelet. wavelet.getRootBlip().all().delete(); StringBuilder b = new StringBuilder(); b.append("\n"); int startIndex = b.length(); b.append(LOGIN_LINK_TEXT + "\n\n"); wavelet.getRootBlip().append(b.toString()); // Add button to click when authentication is complete. wavelet.getRootBlip().append(new FormElement(ElementType.BUTTON, LOGIN_BUTTON_ID, LOGIN_BUTTON_CAPTION)); // Linkify the authorization link. wavelet.getRootBlip().range(startIndex, startIndex + LOGIN_LINK_TEXT.length()).annotate( LINK_ANNOTATION_KEY, url); }
public void testDocumentModifyParametersForAnnotate() { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().replace("foo foo foo"); blip.all("foo").annotate("key", "value1", "value2", "value3"); List<OperationRequest> ops = blip.getOperationQueue().getPendingOperations(); DocumentModifyAction action = (DocumentModifyAction) ops.get(ops.size() - 1).getParameter( ParamsProperty.MODIFY_ACTION); assertEquals("key", action.getAnnotationKey()); assertEquals(Arrays.asList("value1", "value2", "value3"), action.getValues()); }
public void testDocumentModifyParametersForAnnotate() { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().replace("foo foo foo"); blip.all("foo").annotate("key", "value1", "value2", "value3"); List<OperationRequest> ops = blip.getOperationQueue().getPendingOperations(); DocumentModifyAction action = (DocumentModifyAction) ops.get(ops.size() - 1).getParameter( ParamsProperty.MODIFY_ACTION); assertEquals("key", action.getAnnotationKey()); assertEquals(Arrays.asList("value1", "value2", "value3"), action.getValues()); }
/** * Copies the content of the source blip into the target blip. * * @param fromBlip the source blip. * @param toBlip the target blip. */ public static void copyBlipContents(Blip fromBlip, Blip toBlip) { for (BlipContent blipContent: fromBlip.all().values()) { toBlip.append(blipContent); } for (Annotation annotation : fromBlip.getAnnotations()) { Range range = annotation.getRange(); toBlip.range(range.getStart() + 1, range.getEnd() + 1).annotate(annotation.getName(), annotation.getValue()); } }
blip.range(5, 8).annotate(key, "bold"); assertEquals(1, blip.getAnnotations().size()); assertEquals(new Annotation(key, "bold", 3, 8), blip.getAnnotations().get(key).get(0)); blip.range(4, 12).annotate(key, "italic"); assertEquals(1, blip.getAnnotations().size()); assertEquals(2, blip.getAnnotations().get(key).size()); blip.range(3, 5).annotate("foo", "bar"); assertEquals(2, blip.getAnnotations().namesSet().size()); assertEquals(3, blip.getAnnotations().get(key).size());
blip.range(5, 8).annotate(key, "bold"); assertEquals(1, blip.getAnnotations().size()); assertEquals(new Annotation(key, "bold", 3, 8), blip.getAnnotations().get(key).get(0)); blip.range(4, 12).annotate(key, "italic"); assertEquals(1, blip.getAnnotations().size()); assertEquals(2, blip.getAnnotations().get(key).size()); blip.range(3, 5).annotate("foo", "bar"); assertEquals(2, blip.getAnnotations().namesSet().size()); assertEquals(3, blip.getAnnotations().get(key).size());