Package org.apache.rave.model

Examples of org.apache.rave.model.Widget


        return null;
    }
   
    @SuppressWarnings("deprecation")
    public Widget publishWidgetUrlToWookie(String widgetStrUrl){
        Widget widget = null;
        File tempWgtFile = null;
        try {
            if(adminUsername.equals(null) || adminUsername.equals("") || adminPassword.equals(null) || adminPassword.equals("")){
                throw new WookieConnectorException("Either the wookie username or password is not defined in portal.properties", null);
            }
            connectorService = getWookieConnectorService(wookieServerUrl, wookieApiKey, "");
            // TODO - replace code with line below when bundled with wookie 0.13.0
            // wookie-0.13.0 can accept postWidget with a url parameter as well as file parameter
            //org.apache.wookie.connector.framework.Widget wookieWidget = connectorService.postWidget(widgetUrl, adminUsername, adminPassword);
           
            URL widgetUrl = new URL(widgetStrUrl);
            String tempUploadFolder = System.getProperty("java.io.tmpdir");
            String filename = normalizeFileName(widgetUrl);
            tempWgtFile = new File(tempUploadFolder, filename);
            FileUtils.copyURLToFile(widgetUrl, tempWgtFile, 10000, 10000);
            org.apache.wookie.connector.framework.Widget wookieWidget = connectorService.postWidget(tempWgtFile,  adminUsername, adminPassword);
            widget = new W3CWidget();
            widget.setUrl(wookieWidget.getIdentifier());
            widget.setDescription(wookieWidget.getDescription());
            widget.setTitle(wookieWidget.getTitle());
            widget.setType("W3C");
            widget.setThumbnailUrl(wookieWidget.getIcon().toString());
        } catch (WookieConnectorException e){
            logger.warn(e.getMessage());
            return returnURLFromConfig(tempWgtFile);
        } catch (MalformedURLException e) {
            logger.error("Malformed url error. " + e.getMessage());
View Full Code Here


    // the original file.wgt.  This method tries to find the .wgt id in the config file of the downloaded zip file
    // so we can determine if it has already been added to rave without having to reimport to wookie.
    // This routine does not generate identifiers, as wookie would on empty <id> elements found in the config.xml.
    // NOTE: this has been fixed in wookie 0.13.0 onwards
    private Widget returnURLFromConfig(File wgtFile){
        Widget widget = null;
        try {
            final ZipFile zipFile = new ZipFile(wgtFile);
            ZipEntry entry = zipFile.getEntry("config.xml");
            InputStream input = zipFile.getInputStream(entry);
            BufferedReader br = new BufferedReader(new InputStreamReader(input, "UTF-8"));
            try {
                String line = null;
                while (( line = br.readLine()) != null){
                    if(line.contains("id=")){
                        String val = line.substring(line.indexOf("id=")+4, line.indexOf("\"", line.indexOf("id=")+5));
                        widget = new W3CWidget();
                        widget.setUrl(val);
                        return widget;
                    }
                }
            }
            finally {
View Full Code Here

        replay(wookieWidgetMetadataRepository);
       
        expect(widgetService.getWidget(VALID_IDENTIFIER)).andReturn(TEST_WIDGET);
        replay(widgetService);
       
        Widget w = widgetMetadataResolver.getMetadata(VALID_IDENTIFIER);
        assertNotNull(w);
        assertEquals("freeder", w.getTitle());
        assertEquals("http://wookie.apache.org/widgets/freeder", w.getUrl());
        assertEquals("An RSS reader widget optimised for small screens or desktop widgets.", w.getDescription());
        assertEquals("http://localhost:8080/wookie/wservices/wookie.apache.org/widgets/freeder/images/icon.png", w.getThumbnailUrl());
        assertEquals(TYPE, w.getType());
    }
View Full Code Here

        expect(wookieWidgetMetadataRepository.getWidgetMetadata(VALID_IDENTIFIER)).andReturn(null);
        replay(wookieWidgetMetadataRepository);
       
        expect(widgetService.getWidget(VALID_IDENTIFIER)).andReturn(null);
        replay(widgetService);
        Widget w = widgetMetadataResolver.getMetadata(VALID_IDENTIFIER);
        assertNull(w);
    }
View Full Code Here

     *
     * @param url url for the widget
     * @return
     */
    public Widget getMetadata(String url) {
        Widget widget = new WidgetImpl();
        JSONObject jsonGadget = null;
        try {
            jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
            if (jsonGadget != null) {
                String query = jsonGadget.getString("modulePrefs");
                if (query != null) {
                    JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
                    if (jsonModulePrefsObject != null) {
                        widget.setTitle(parseProperty(jsonModulePrefsObject, "title"));
                        widget.setTitleUrl(parseProperty(jsonModulePrefsObject, "titleUrl"));
                        widget.setDescription(parseProperty(jsonModulePrefsObject, "description"));
                        widget.setAuthor(parseProperty(jsonModulePrefsObject, "author"));
                        widget.setAuthorEmail(parseProperty(jsonModulePrefsObject, "authorEmail"));
                        widget.setThumbnailUrl(parseProperty(jsonModulePrefsObject, "thumbnail"));
                        widget.setScreenshotUrl(parseProperty(jsonModulePrefsObject, "screenshot"));
                        widget.setUrl(url);
                        widget.setType(getSupportedContext());
                    }
                }
            }
        } catch (JSONException e) {
            try {
View Full Code Here

    @Test
    public void getMetadata() {
        expect(gadgetMetadataRepository.getGadgetMetadata(VALID_GADGET_URL)).andReturn(VALID_METADATA);
        replay(gadgetMetadataRepository);
        Widget w = widgetMetadataResolver.getMetadata(VALID_GADGET_URL);
        assertNotNull(w);
    }
View Full Code Here

    @Test(expected = IllegalArgumentException.class)
    public void getMetadata_invalid() {
        expect(gadgetMetadataRepository.getGadgetMetadata(VALID_GADGET_URL)).andReturn(INVALID_METADATA);
        replay(gadgetMetadataRepository);
        Widget w = widgetMetadataResolver.getMetadata(VALID_GADGET_URL);
        assertNotNull(w);
    }
View Full Code Here

        return gadgetMetadataRepository.getGadgetMetadata(gadgetUrl);
    }

    @Override
    public String getEncryptedSecurityToken(String pageId, String url) {
        Widget widget = widgetService.getWidgetByUrl(url);
        Page page = pageService.getPage(pageId);
        validate(widget);
        // Use a dummy RegionWidget to generate the security token
        RegionWidget regionWidget = new RegionWidgetImpl(String.valueOf(System.currentTimeMillis()),"-1",
                new RegionImpl("-1", page, -1));
View Full Code Here

        assertThat(result, is(sameInstance(VALID_METADATA)));
    }

    @Test
    public void getEncryptedSecurityToken_valid() {
        Widget widget = new WidgetImpl("25", VALID_GADGET_URL);
        Page page = new PageImpl(VALID_PAGE_ID, VALID_OWNER_ID);
        widget.setWidgetStatus(WidgetStatus.PUBLISHED);
        expect(widgetService.getWidgetByUrl(VALID_GADGET_URL)).andReturn(widget);
        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
        expect(tokenService.getEncryptedSecurityToken(isA(RegionWidget.class), eq(widget))).andReturn(VALID_TOKEN);
        replay(widgetService, pageService, tokenService);
View Full Code Here

        assertThat(openSocialService.getEncryptedSecurityToken(VALID_PAGE_ID, VALID_GADGET_URL), is(equalTo(VALID_TOKEN)));
    }

    @Test(expected = IllegalStateException.class)
    public void getEncryptedSecurityToken_NotPublished() {
        Widget widget = new WidgetImpl("25", VALID_GADGET_URL);
        widget.setWidgetStatus(WidgetStatus.PREVIEW);
        expect(widgetService.getWidgetByUrl(VALID_GADGET_URL)).andReturn(widget);
        replay(widgetService, pageService, tokenService);

        assertThat(openSocialService.getEncryptedSecurityToken(VALID_PAGE_ID, VALID_GADGET_URL), is(equalTo(VALID_TOKEN)));
    }
View Full Code Here

TOP

Related Classes of org.apache.rave.model.Widget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.