@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 testBlipOperations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); assertEquals(1, wavelet.getBlips().size()); Blip other = blip.reply(); other.append("hello world"); assertEquals("\nhello world", other.getContent()); assertEquals(2, wavelet.getBlips().size()); Blip inline = blip.insertInlineBlip(3); assertEquals("\n", inline.getContent()); assertEquals(3, wavelet.getBlips().size()); }
/** * 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 testBlipOperations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); assertEquals(1, wavelet.getBlips().size()); Blip other = blip.reply(); other.append("hello world"); assertEquals("\nhello world", other.getContent()); assertEquals(2, wavelet.getBlips().size()); Blip inline = blip.insertInlineBlip(3); assertEquals("\n", inline.getContent()); assertEquals(3, wavelet.getBlips().size()); }
public void testUpdateElement() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); // Update the image by appending a query param to the URL. blip.first(ElementType.IMAGE).updateElement(new MapFunction() { @Override public Map<String, String> call(BlipContent source) { Image matchedImage = (Image) source; Map<String, String> properties = new HashMap<String, String>(); properties.put("url", matchedImage.getUrl() + "?version=newversion"); return properties; } }); Image image = (Image) blip.first(ElementType.IMAGE).value(); assertEquals(url + "?version=newversion", image.getUrl()); }
public void testUpdateElement() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); // Update the image by appending a query param to the URL. blip.first(ElementType.IMAGE).updateElement(new MapFunction() { @Override public Map<String, String> call(BlipContent source) { Image matchedImage = (Image) source; Map<String, String> properties = new HashMap<String, String>(); properties.put("url", matchedImage.getUrl() + "?version=newversion"); return properties; } }); Image image = (Image) blip.first(ElementType.IMAGE).value(); assertEquals(url + "?version=newversion", image.getUrl()); }
String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl()); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl());
String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl()); blip.append(new Image(url, 100, 100, "Cool pix.")); blip.append(" some piece of text."); assertEquals("\n some piece of text.", blip.getContent()); assertEquals(url, ((Image) blip.first(ElementType.IMAGE).value()).getUrl());