@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); } }
@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 testDeleteRangeThatSpansAcrossAnnotationEndPoint() throws Exception { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 3))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 2), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testDeleteRangeInsideAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 5))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 3), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testDeleteRangeThatSpansAcrossAnnotationEndPoint() throws Exception { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 3))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 2), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
public void testDeleteRangeInsideAnnotation() { Blip blip = newBlip("\nFoo bar.", Arrays.asList(new Annotation(ANNOTATION_KEY, "bold", 1, 5))); // Delete "oo" blip.range(2, 4).delete(); assertEquals("\nF bar.", blip.getContent()); assertEquals(new Range(1, 3), blip.getAnnotations().get(ANNOTATION_KEY).get(0).getRange()); }
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()); }
public void testDocumentOperations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); List<BlipContent> newLines = blip.all("\n").values(); assertEquals(2, newLines.size()); assertEquals(Arrays.asList(Plaintext.of("\n"), Plaintext.of("\n")), newLines); blip.first("world").replace("jupiter"); String[] bits = blip.getContent().split("\n"); assertEquals(3, bits.length); assertEquals("hello jupiter!", bits[1]); blip.range(2, 5).delete(); assertTrue(blip.getContent().startsWith("\nho jupiter!")); blip.first("ho").insertAfter("la"); assertTrue(blip.getContent().startsWith("\nhola jupiter!")); blip.at(3).insert(" "); assertTrue(blip.getContent().startsWith("\nho la jupiter!")); blip.all().delete(); blip.at(1).insert("world!"); blip.first("world").insert(new BlipContentFunction() { @Override public BlipContent call(BlipContent source) { return Plaintext.of("Hello " + source.getText().length() + " "); } }); assertEquals("\nHello 5 world!", blip.getContent()); }
public void testDocumentOperations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); List<BlipContent> newLines = blip.all("\n").values(); assertEquals(2, newLines.size()); assertEquals(Arrays.asList(Plaintext.of("\n"), Plaintext.of("\n")), newLines); blip.first("world").replace("jupiter"); String[] bits = blip.getContent().split("\n"); assertEquals(3, bits.length); assertEquals("hello jupiter!", bits[1]); blip.range(2, 5).delete(); assertTrue(blip.getContent().startsWith("\nho jupiter!")); blip.first("ho").insertAfter("la"); assertTrue(blip.getContent().startsWith("\nhola jupiter!")); blip.at(3).insert(" "); assertTrue(blip.getContent().startsWith("\nho la jupiter!")); blip.all().delete(); blip.at(1).insert("world!"); blip.first("world").insert(new BlipContentFunction() { @Override public BlipContent call(BlipContent source) { return Plaintext.of("Hello " + source.getText().length() + " "); } }); assertEquals("\nHello 5 world!", blip.getContent()); }
assertTrue(element instanceof Image); blip.first("twelve ").delete(); assertTrue(blip.getContent().startsWith("\nchars")); element = blip.at(originalLength + 12 - "twelve ".length()).value().asElement(); assertEquals("Yet another cool pix.", ((Image) element).getCaption()); blip.all().delete(); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n " + url + " some piece of text.", blip.getContent()); blip.all().delete(); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text.");
assertTrue(element instanceof Image); blip.first("twelve ").delete(); assertTrue(blip.getContent().startsWith("\nchars")); element = blip.at(originalLength + 12 - "twelve ".length()).value().asElement(); assertEquals("Yet another cool pix.", ((Image) element).getCaption()); blip.all().delete(); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n " + url + " some piece of text.", blip.getContent()); blip.all().delete(); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text.");