/** * Returns the first reference to this blip's content that matches * {@code target}. * * @param target the text to search for. * @return an instance of {@link BlipContentRefs}. */ public BlipContentRefs first(String target) { return all(target, 1); }
/** * Returns the first reference to this blip's content that matches * {@code target} and {@code restrictions}. * * @param target the type of element to search for. * @param restrictions the list of restrictions to filter the search. * @return an instance of {@link BlipContentRefs}. */ public BlipContentRefs first(ElementType target, Restriction... restrictions) { return all(target, 1, restrictions); }
/** * 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(); // TODO (elizabethford): Eventually have buildUrl from within gadget with gadget fetching // request key from datastore. // Add the gadget. String gadgetString = ""; try { String gadgetUrl = "http://" + remoteHost + GADGET_PATH; gadgetString = gadgetUrl + "?" + URLEncoder.encode("key", CHARACTER_ENCODING) + "=" + URLEncoder.encode(userRecordKey, CHARACTER_ENCODING); } catch (UnsupportedEncodingException e) { LOG.warning(e.toString()); } Gadget gadget = new Gadget(gadgetString); LOG.info(gadgetString); wavelet.getRootBlip().append(gadget); } }
/** * 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()); }
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()); }
public void testSearchWithNoMatchShouldNotGenerateOperation() { Blip blip = newBlip("\nFoo bar.", Collections.<Annotation>emptyList()); blip.all(":(").replace(":)"); assertEquals(0, wavelet.getOperationQueue().getPendingOperations().size()); }
public void testSearchWithNoMatchShouldNotGenerateOperation() { Blip blip = newBlip("\nFoo bar.", Collections.<Annotation>emptyList()); blip.all(":(").replace(":)"); assertEquals(0, wavelet.getOperationQueue().getPendingOperations().size()); }
public void testDocumentModifyParametersForClearAnnotation() { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().clearAnnotation("key"); List<OperationRequest> ops = blip.getOperationQueue().getPendingOperations(); DocumentModifyAction action = (DocumentModifyAction) ops.get(ops.size() - 1).getParameter( ParamsProperty.MODIFY_ACTION); assertEquals("key", action.getAnnotationKey()); }
public void testDocumentModifyParametersForClearAnnotation() { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().clearAnnotation("key"); List<OperationRequest> ops = blip.getOperationQueue().getPendingOperations(); DocumentModifyAction action = (DocumentModifyAction) ops.get(ops.size() - 1).getParameter( ParamsProperty.MODIFY_ACTION); assertEquals("key", action.getAnnotationKey()); }
public void testDocumentModify() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().replace("a text with text and then some text"); assertEquals("\na text with text and then some text", blip.getContent()); blip.at(8).insert("text "); blip.all("text").replace("foo", "bar"); assertEquals("\na foo bar with foo and then some bar", blip.getContent()); }
public void testDocumentModify() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().replace("a text with text and then some text"); assertEquals("\na text with text and then some text", blip.getContent()); blip.at(8).insert("text "); blip.all("text").replace("foo", "bar"); assertEquals("\na foo bar with foo and then some bar", blip.getContent()); }
public void testIteration() throws Exception { Blip blip = newBlip("\naaa 012 aaa 345 aaa 322", Collections.<Annotation>emptyList()); Range[] expectedRanges = {new Range(1, 4), new Range(9, 12), new Range(17, 20)}; BlipContentRefs blipRefs = blip.all("aaa"); int index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Now let's make sure that we can iterate again. index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Assert iteration with blip refs that has no match. assertFalse(blip.all("invalid").iterator().hasNext()); }
public void testIteration() throws Exception { Blip blip = newBlip("\naaa 012 aaa 345 aaa 322", Collections.<Annotation>emptyList()); Range[] expectedRanges = {new Range(1, 4), new Range(9, 12), new Range(17, 20)}; BlipContentRefs blipRefs = blip.all("aaa"); int index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Now let's make sure that we can iterate again. index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Assert iteration with blip refs that has no match. assertFalse(blip.all("invalid").iterator().hasNext()); }
public void testBundledAnnotations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().insert(BundledAnnotation.listOf("style", "bold"), "\nhello"); assertEquals(2, blip.getAnnotations().size()); assertEquals(new Annotation("style", "bold", 0, 6), blip.getAnnotations().get("style").get(0)); }
/** * 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()); } }
public void testBundledAnnotations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.all().insert(BundledAnnotation.listOf("style", "bold"), "\nhello"); assertEquals(2, blip.getAnnotations().size()); assertEquals(new Annotation("style", "bold", 0, 6), blip.getAnnotations().get("style").get(0)); }
public void testDeleteAll() { Blip blip = newBlip("\nNew title\nNew content", Arrays.asList( new Annotation("style/fontWeight", "bold", new Range(10,11)), new Annotation("conv/title", "", new Range(0,10)))); blip.all().delete(); assertEquals("\n", blip.getContent()); }
public void testDeleteAll() { Blip blip = newBlip("\nNew title\nNew content", Arrays.asList( new Annotation("style/fontWeight", "bold", new Range(10,11)), new Annotation("conv/title", "", new Range(0,10)))); blip.all().delete(); assertEquals("\n", blip.getContent()); }