private void processCloud(Element element, IFeed feed) {
    ICloud cloud = Owl.getModelFactory().createCloud(feed);

    /* Interpret Attributes */
    List<?> cloudAttributes = element.getAttributes();
    for (Iterator<?> iter = cloudAttributes.iterator(); iter.hasNext(); ) {
      Attribute attribute = (Attribute) iter.next();
      String name = attribute.getName().toLowerCase();

      /* Check wether this Attribute is to be processed by a Contribution */
      if (processAttributeExtern(attribute, cloud)) continue;

      /* Domain */
      else if ("domain".equals(name)) // $NON-NLS-1$
      cloud.setDomain(attribute.getValue());

      /* Path */
      else if ("path".equals(name)) // $NON-NLS-1$
      cloud.setPath(attribute.getValue());

      /* Port */
      else if ("port".equals(name)) { // $NON-NLS-1$
        int port = StringUtils.stringToInt(attribute.getValue());
        if (port >= 0) cloud.setPort(port);
      }

      /* Procedure Call */
      else if ("registerprocedure".equals(name)) // $NON-NLS-1$
      cloud.setRegisterProcedure(attribute.getValue());

      /* Path */
      else if ("protocol".equals(name)) // $NON-NLS-1$
      cloud.setProtocol(attribute.getValue());
    }
  }
  private void processEnclosure(Element element, INews news) {
    IAttachment attachment = Owl.getModelFactory().createAttachment(null, news);

    /* Interpret Attributes */
    List<?> attachmentAttributes = element.getAttributes();
    for (Iterator<?> iter = attachmentAttributes.iterator(); iter.hasNext(); ) {
      Attribute attribute = (Attribute) iter.next();
      String name = attribute.getName().toLowerCase();

      /* Check wether this Attribute is to be processed by a Contribution */
      if (processAttributeExtern(attribute, attachment)) continue;

      /* URL */
      else if ("url".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(attribute.getValue());
        if (uri != null) {
          attachment.setLink(uri);
        }
      }

      /* Type */
      else if ("type".equals(name)) // $NON-NLS-1$
      {
        attachment.setType(attribute.getValue());

        /*Generate the mp3 player HTML Object */
        if (!Owl.getPreferenceService().getGlobalScope().getBoolean(DefaultPreferences.HIDE_MP3)) {
          if (Mp3Util.isMp3(attribute.getValue())) {
            String HTMLtoAppend = ""; // $NON-NLS-1$
            if (!(news.isNewsWithMp3())) {
              news.setNewsWithMp3();
              HTMLtoAppend += Mp3Util.getHeader();
            }
            HTMLtoAppend += Mp3Util.getPlayerCode(attachment.getLink().toString());
            news.setDescription(news.getDescription() + HTMLtoAppend);
          }
        }
      }

      /* Length */
      else if ("length".equals(name)) { // $NON-NLS-1$
        int length = StringUtils.stringToInt(attribute.getValue());
        if (length >= 0) attachment.setLength(length);
      }
    }
  }
  private void processImage(Element element, IFeed feed) {
    IImage image = Owl.getModelFactory().createImage(feed);

    /* Check wether the Attributes are to be processed by a Contribution */
    processNamespaceAttributes(element, image);

    /* Interpret Children */
    List<?> imageChilds = element.getChildren();
    for (Iterator<?> iter = imageChilds.iterator(); iter.hasNext(); ) {
      Element child = (Element) iter.next();
      String name = child.getName().toLowerCase();

      /* Check wether this Element is to be processed by a Contribution */
      if (processElementExtern(child, image)) continue;

      /* URL */
      else if ("url".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(child.getText());
        if (uri != null) image.setLink(uri);
        processNamespaceAttributes(child, image);
      }

      /* Title */
      else if ("title".equals(name)) { // $NON-NLS-1$
        image.setTitle(child.getText());
        processNamespaceAttributes(child, image);
      }

      /* Link */
      else if ("link".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(child.getText());
        if (uri != null) image.setHomepage(uri);
        processNamespaceAttributes(child, image);
      }

      /* Description */
      else if ("description".equals(name)) { // $NON-NLS-1$
        image.setDescription(child.getText());
        processNamespaceAttributes(child, image);
      }

      /* Width */
      else if ("width".equals(name)) { // $NON-NLS-1$
        int width = StringUtils.stringToInt(child.getTextNormalize());
        if (width >= 0) image.setWidth(width);
        processNamespaceAttributes(child, image);
      }

      /* Height */
      else if ("height".equals(name)) { // $NON-NLS-1$
        int height = StringUtils.stringToInt(child.getTextNormalize());
        if (height >= 0) image.setHeight(height);
        processNamespaceAttributes(child, image);
      }
    }
  }
Esempio n. 4
0
  /**
   * @param searchMarks The Set of <code>ISearchMark</code> to update the results in.
   * @param fromUserEvent Indicates whether to update the saved searches due to a user initiated
   *     event or an automatic one.
   */
  public void updateSavedSearches(Collection<ISearchMark> searchMarks, boolean fromUserEvent) {
    boolean firstUpdate = !fUpdatedOnce.get();

    fUpdatedOnce.set(true);
    IModelSearch modelSearch = Owl.getPersistenceService().getModelSearch();
    Set<SearchMarkEvent> events = new HashSet<SearchMarkEvent>(searchMarks.size());

    /* For each Search Mark */
    for (ISearchMark searchMark : searchMarks) {

      /* Return early if shutting down */
      if (Controller.getDefault().isShuttingDown()) return;

      /* Execute the search */
      List<SearchHit<NewsReference>> results =
          modelSearch.searchNews(searchMark.getSearchConditions(), searchMark.matchAllConditions());

      /* Fill Result into Map Buckets */
      Map<INews.State, List<NewsReference>> resultsMap =
          new EnumMap<INews.State, List<NewsReference>>(INews.State.class);

      Set<State> visibleStates = INews.State.getVisible();
      for (SearchHit<NewsReference> searchHit : results) {

        /* Return early if shutting down */
        if (Controller.getDefault().isShuttingDown()) return;

        INews.State state = (State) searchHit.getData(INews.STATE);
        if (visibleStates.contains(state)) {
          List<NewsReference> newsRefs = resultsMap.get(state);
          if (newsRefs == null) {
            newsRefs = new ArrayList<NewsReference>(results.size() / 3);
            resultsMap.put(state, newsRefs);
          }
          newsRefs.add(searchHit.getResult());
        }
      }

      /* Set Result */
      Pair<Boolean, Boolean> result = searchMark.setNewsRefs(resultsMap);
      boolean changed = result.getFirst();
      boolean newNewsAdded = result.getSecond();

      /* Create Event to indicate changed results if any */
      if (changed)
        events.add(
            new SearchMarkEvent(
                searchMark, null, true, !firstUpdate && !fromUserEvent && newNewsAdded));
    }

    /* Notify Listeners */
    if (!events.isEmpty() && !Controller.getDefault().isShuttingDown())
      DynamicDAO.getDAO(ISearchMarkDAO.class).fireNewsChanged(events);
  }
  private void onRestoreDefaults() {
    IPreferenceScope defaultScope = Owl.getPreferenceService().getDefaultScope();
    int[] defaultItemsState = defaultScope.getIntegers(DefaultPreferences.TOOLBAR_ITEMS);
    int defaultMode = defaultScope.getInteger(DefaultPreferences.TOOLBAR_MODE);

    fPreferences.putIntegers(DefaultPreferences.TOOLBAR_ITEMS, defaultItemsState);
    fPreferences.putInteger(DefaultPreferences.TOOLBAR_MODE, defaultMode);
    fItemViewer.refresh();
    fModeViewer.setSelection(new StructuredSelection(CoolBarMode.values()[defaultMode]));
    updateButtonEnablement();
  }
  /** @param parentShell */
  public CustomizeToolbarDialog(Shell parentShell) {
    super(parentShell);
    fResources = new LocalResourceManager(JFaceResources.getResources());
    fFirstTimeOpen =
        (Activator.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS_KEY) == null);
    fPreferences = Owl.getPreferenceService().getGlobalScope();

    /* Colors */
    fSeparatorBorderFg = OwlUI.getColor(fResources, new RGB(210, 210, 210));
    fSeparatorBg = OwlUI.getColor(fResources, new RGB(240, 240, 240));
  }
  private void internalSetAuthCredentials(
      ICredentials credentials, URI link, String realm, boolean persist)
      throws CredentialsException {

    /* Store Credentials in In-Memory Store */
    if (!persist) {
      fInMemoryStore.put(toCacheKey(link, realm), credentials);
    }

    /* Store Credentials in secure Storage */
    else {
      ISecurePreferences securePreferences = getSecurePreferences();

      /* Check if Bundle is Stopped */
      if (securePreferences == null) return;

      /* Store in Equinox Security Storage */
      ISecurePreferences allFeedsPreferences = securePreferences.node(SECURE_FEED_NODE);
      ISecurePreferences feedPreferences =
          allFeedsPreferences.node(EncodingUtils.encodeSlashes(link.toString()));
      ISecurePreferences realmPreference =
          feedPreferences.node(EncodingUtils.encodeSlashes(realm != null ? realm : REALM));

      IPreferenceScope globalScope = Owl.getPreferenceService().getGlobalScope();

      /* OS Password is only supported on Windows and Mac */
      boolean useOSPassword = globalScope.getBoolean(DefaultPreferences.USE_OS_PASSWORD);
      if (!Platform.OS_WIN32.equals(Platform.getOS())
          && !Platform.OS_MACOSX.equals(Platform.getOS())) useOSPassword = false;

      boolean encryptPW =
          useOSPassword || globalScope.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD);
      try {
        if (credentials.getUsername() != null)
          realmPreference.put(USERNAME, credentials.getUsername(), encryptPW);

        if (credentials.getPassword() != null)
          realmPreference.put(PASSWORD, credentials.getPassword(), encryptPW);

        if (credentials.getDomain() != null)
          realmPreference.put(DOMAIN, credentials.getDomain(), encryptPW);

        realmPreference.flush(); // Flush to disk early
      } catch (StorageException e) {
        throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
      } catch (IOException e) {
        throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
      }
    }

    /* Uncache */
    removeUnprotected(link, realm);
  }
  private List<ISearchCondition> getDefaultConditions() {
    List<ISearchCondition> conditions = new ArrayList<ISearchCondition>(1);
    IModelFactory factory = Owl.getModelFactory();

    ISearchField field = factory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
    ISearchCondition condition =
        factory.createSearchCondition(field, SearchSpecifier.CONTAINS_ALL, ""); // $NON-NLS-1$

    conditions.add(condition);

    return conditions;
  }
  private ISecurePreferences getSecurePreferences() {
    if (!InternalOwl.IS_ECLIPSE) {
      IPreferenceScope prefs = Owl.getPreferenceService().getGlobalScope();
      boolean useOSPasswordProvider = prefs.getBoolean(DefaultPreferences.USE_OS_PASSWORD);

      /* Disable OS Password if Master Password shall be used */
      if (prefs.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD)) useOSPasswordProvider = false;

      /* Try storing credentials in profile folder */
      try {
        Activator activator = Activator.getDefault();

        /* Check if Bundle is Stopped */
        if (activator == null) return null;

        IPath stateLocation = activator.getStateLocation();
        stateLocation = stateLocation.append(SECURE_STORAGE_FILE);
        URL location = stateLocation.toFile().toURL();
        Map<String, String> options = null;

        /* Use OS dependent password provider if available */
        if (useOSPasswordProvider) {
          if (Platform.OS_WIN32.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, WIN_PW_PROVIDER_ID);
          } else if (Platform.OS_MACOSX.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, MACOS_PW_PROVIDER_ID);
          }
        }

        /* Use RSSOwl password provider */
        else {
          options = new HashMap<String, String>();
          options.put(IProviderHints.REQUIRED_MODULE_ID, RSSOWL_PW_PROVIDER_ID);
        }

        return SecurePreferencesFactory.open(location, options);
      } catch (MalformedURLException e) {
        Activator.safeLogError(e.getMessage(), e);
      } catch (IllegalStateException e1) {
        Activator.safeLogError(e1.getMessage(), e1);
      } catch (IOException e2) {
        Activator.safeLogError(e2.getMessage(), e2);
      }
    }

    /* Fallback to default location */
    return SecurePreferencesFactory.getDefault();
  }
  private void processCategory(Element element, IEntity type) {
    ICategory category = Owl.getModelFactory().createCategory(null, type);
    category.setName(element.getText());

    /* Interpret Attributes */
    List<?> categoryAttributes = element.getAttributes();
    for (Iterator<?> iter = categoryAttributes.iterator(); iter.hasNext(); ) {
      Attribute attribute = (Attribute) iter.next();
      String name = attribute.getName().toLowerCase();

      /* Check wether this Attribute is to be processed by a Contribution */
      if (processAttributeExtern(attribute, category)) continue;

      /* Domain */
      else if ("domain".equals(name)) // $NON-NLS-1$
      category.setDomain(attribute.getValue());
    }
  }
  private void processTextInput(Element element, IFeed feed) {
    ITextInput input = Owl.getModelFactory().createTextInput(feed);

    /* Check wether the Attributes are to be processed by a Contribution */
    processNamespaceAttributes(element, input);

    /* Interpret Attributes */
    List<?> inputChilds = element.getChildren();
    for (Iterator<?> iter = inputChilds.iterator(); iter.hasNext(); ) {
      Element child = (Element) iter.next();
      String name = child.getName().toLowerCase();

      /* Check wether this Element is to be processed by a Contribution */
      if (processElementExtern(child, input)) continue;

      /* Title */
      else if ("title".equals(name)) { // $NON-NLS-1$
        input.setTitle(child.getText());
        processNamespaceAttributes(child, input);
      }

      /* Description */
      else if ("description".equals(name)) { // $NON-NLS-1$
        input.setDescription(child.getText());
        processNamespaceAttributes(child, input);
      }

      /* Name */
      else if ("name".equals(name)) { // $NON-NLS-1$
        input.setName(child.getText());
        processNamespaceAttributes(child, input);
      }

      /* Link */
      else if ("link".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(child.getText());
        if (uri != null) input.setLink(uri);
        processNamespaceAttributes(child, input);
      }
    }
  }
  /*
   * @see org.eclipse.ui.IEditorInput#getPersistable()
   */
  public IPersistableElement getPersistable() {
    IPreferenceScope preferences = Owl.getPreferenceService().getGlobalScope();

    boolean useExternalBrowser =
        preferences.getBoolean(DefaultPreferences.USE_CUSTOM_EXTERNAL_BROWSER)
            || preferences.getBoolean(DefaultPreferences.USE_DEFAULT_EXTERNAL_BROWSER);
    if (useExternalBrowser) return null;

    boolean restore = preferences.getBoolean(DefaultPreferences.REOPEN_BROWSER_TABS);
    if (!restore) return null;

    return new IPersistableElement() {
      public String getFactoryId() {
        return FACTORY_ID;
      }

      public void saveState(IMemento memento) {
        memento.putString(URL, fCurrentUrl != null ? fCurrentUrl : fUrl);
      }
    };
  }
  private void processSource(Element element, INews news) {
    ISource source = Owl.getModelFactory().createSource(news);
    source.setName(element.getText());

    /* Check wether the Attributes are to be processed by a Contribution */
    processNamespaceAttributes(element, source);

    /* Interpret Attributes */
    List<?> attributes = element.getAttributes();
    for (Iterator<?> iter = attributes.iterator(); iter.hasNext(); ) {
      Attribute attribute = (Attribute) iter.next();
      String name = attribute.getName().toLowerCase();

      /* Check wether this Attribute is to be processed by a Contribution */
      if (processAttributeExtern(attribute, source)) continue;

      /* URL */
      else if ("url".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(attribute.getValue());
        if (uri != null) source.setLink(uri);
      }
    }
  }
  private void processGuid(Element element, INews news) {

    // TODO We don't pass guid to contributions because it cannot be modified
    // See bug #587 for a discussion about a soluton
    /* Check whether the Attributes are to be processed by a Contribution */
    //    processNamespaceAttributes(element, guid);

    Boolean permaLink = null;
    /* Interpret Attributes */
    List<?> attributes = element.getAttributes();
    for (Iterator<?> iter = attributes.iterator(); iter.hasNext(); ) {
      Attribute attribute = (Attribute) iter.next();
      String name = attribute.getName().toLowerCase();

      //      /* Check whether this Attribute is to be processed by a Contribution */
      //      if (processAttributeExtern(attribute, guid))
      //        continue;

      /* Is Permalink */
      if ("ispermalink".equals(name)) // $NON-NLS-1$
      permaLink = Boolean.parseBoolean(attribute.getValue());
    }
    Owl.getModelFactory().createGuid(news, element.getText(), permaLink);
  }
Esempio n. 15
0
 /**
  * @param parentShell
  * @param folderName
  */
 public AggregateNewsDialog(Shell parentShell, String folderName) {
   super(parentShell);
   fFolderName = folderName;
   fResources = new LocalResourceManager(JFaceResources.getResources());
   fPreferences = Owl.getPreferenceService().getGlobalScope();
 }
  private void processChannel(Element element, IFeed feed) {

    /* Interpret Attributes */
    List<?> attributes = element.getAttributes();
    for (Iterator<?> iter = attributes.iterator(); iter.hasNext(); ) {
      Attribute attribute = (Attribute) iter.next();

      /* Check wether this Attribute is to be processed by a Contribution */
      processAttributeExtern(attribute, feed);
    }

    /* Interpret Children */
    List<?> channelChildren = element.getChildren();
    for (Iterator<?> iter = channelChildren.iterator(); iter.hasNext(); ) {
      Element child = (Element) iter.next();
      String name = child.getName().toLowerCase();

      /* Check wether this Element is to be processed by a Contribution */
      if (processElementExtern(child, feed)) continue;

      /* Item */
      else if ("item".equals(name)) // $NON-NLS-1$
      processItems(child, feed);

      /* Title */
      else if ("title".equals(name)) { // $NON-NLS-1$
        feed.setTitle(child.getText());
        processNamespaceAttributes(child, feed);
      }

      /* Link */
      else if ("link".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(child.getText());

        /*
         * Do not use the URI if it is empty. This is a workaround for
         * FeedBurner feeds that use a Atom 1.0 Link Element in place of an RSS
         * feed which RSSOwl 2 is not yet able to handle on this scope.
         */
        if (uri != null && StringUtils.isSet(uri.toString())) feed.setHomepage(uri);
        processNamespaceAttributes(child, feed);
      }

      /* Description */
      else if ("description".equals(name)) { // $NON-NLS-1$
        feed.setDescription(child.getText());
        processNamespaceAttributes(child, feed);
      }

      /* Publish Date */
      else if ("pubdate".equals(name)) { // $NON-NLS-1$
        feed.setPublishDate(DateUtils.parseDate(child.getText()));
        processNamespaceAttributes(child, feed);
      }

      /* Image */
      else if ("image".equals(name)) // $NON-NLS-1$
      processImage(child, feed);

      /* Language */
      else if ("language".equals(name)) { // $NON-NLS-1$
        feed.setLanguage(child.getText());
        processNamespaceAttributes(child, feed);
      }

      /* Copyright */
      else if ("copyright".equals(name)) { // $NON-NLS-1$
        feed.setCopyright(child.getText());
        processNamespaceAttributes(child, feed);
      }

      /* Webmaster */
      else if ("webmaster".equals(name)) { // $NON-NLS-1$
        feed.setWebmaster(child.getText());
        processNamespaceAttributes(child, feed);
      }

      /* Managing Editor */
      else if ("managingeditor".equals(name)) { // $NON-NLS-1$
        IPerson person = Owl.getModelFactory().createPerson(null, feed);
        person.setName(child.getText());

        processNamespaceAttributes(child, person);
      }

      /* Last Build Date */
      else if ("lastbuilddate".equals(name)) { // $NON-NLS-1$
        feed.setLastBuildDate(DateUtils.parseDate(child.getText()));
        processNamespaceAttributes(child, feed);
      }

      /* Category */
      else if ("category".equals(name)) // $NON-NLS-1$
      processCategory(child, feed);

      /* Generator */
      else if ("generator".equals(name)) { // $NON-NLS-1$
        feed.setGenerator(child.getText());
        processNamespaceAttributes(child, feed);
      }

      /* Docs */
      else if ("docs".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(child.getText());
        if (uri != null) feed.setDocs(uri);
        processNamespaceAttributes(child, feed);
      }

      /* Rating */
      else if ("rating".equals(name)) { // $NON-NLS-1$
        feed.setRating(child.getText());
        processNamespaceAttributes(child, feed);
      }

      /* TTL */
      else if ("ttl".equals(name)) { // $NON-NLS-1$
        int ttl = StringUtils.stringToInt(child.getTextNormalize());
        if (ttl >= 0) feed.setTTL(ttl);
        processNamespaceAttributes(child, feed);
      }

      /* Skip Hours */
      else if ("skiphours".equals(name)) { // $NON-NLS-1$
        processNamespaceAttributes(child, feed);
        List<?> skipHoursChildren = child.getChildren("hour"); // $NON-NLS-1$

        /* For each <hour> Element */
        for (Iterator<?> iterator = skipHoursChildren.iterator(); iterator.hasNext(); ) {
          Element skipHour = (Element) iterator.next();
          processNamespaceAttributes(skipHour, feed);

          int hour = StringUtils.stringToInt(skipHour.getTextNormalize());
          if (0 <= hour && hour < 24) feed.addHourToSkip(hour);
        }
      }

      /* Skip Days */
      else if ("skipdays".equals(name)) { // $NON-NLS-1$
        processNamespaceAttributes(child, feed);
        List<?> skipDaysChildren = child.getChildren("day"); // $NON-NLS-1$

        /* For each <day> Element */
        for (Iterator<?> iterator = skipDaysChildren.iterator(); iterator.hasNext(); ) {
          Element skipDay = (Element) iterator.next();
          processNamespaceAttributes(skipDay, feed);

          String day = skipDay.getText().toLowerCase();
          int index = IFeed.DAYS.indexOf(day);
          if (index >= 0) feed.addDayToSkip(index);
        }
      }

      /* TextInput */
      else if ("textinput".equals(name)) // $NON-NLS-1$
      processTextInput(child, feed);

      /* Cloud */
      else if ("cloud".equals(name)) // $NON-NLS-1$
      processCloud(child, feed);
    }
  }
  private void processItems(Element element, IFeed feed) {
    INews news =
        Owl.getModelFactory()
            .createNews(null, feed, new Date(System.currentTimeMillis() - (fNewsCounter++ * 1)));
    news.setBase(feed.getBase());

    /* Check wether the Attributes are to be processed by a Contribution */
    processNamespaceAttributes(element, news);

    /* Interpret Children */
    List<?> newsChilds = element.getChildren();
    for (Iterator<?> iter = newsChilds.iterator(); iter.hasNext(); ) {
      Element child = (Element) iter.next();
      String name = child.getName().toLowerCase();

      /* Check wether this Element is to be processed by a Contribution */
      if (processElementExtern(child, news)) continue;

      /* Title */
      else if ("title".equals(name)) { // $NON-NLS-1$
        news.setTitle(child.getText());
        processNamespaceAttributes(child, news);
      }

      /* Link */
      else if ("link".equals(name)) { // $NON-NLS-1$
        URI uri = URIUtils.createURI(child.getText());
        if (uri != null) {
          news.setLink(uri);
          itemUrl = child.getText();
        }
        processNamespaceAttributes(child, news);
      }

      /* Description */
      else if ("description".equals(name)) { // $NON-NLS-1$
        if (!Owl.getPreferenceService().getGlobalScope().getBoolean(DefaultPreferences.HIDE_LIKE)) {
          news.setDescription(child.getText() + FacebookLikeUtil.getButtonCode(itemUrl));
          processNamespaceAttributes(child, news);
        } else {
          news.setDescription(child.getText());
          processNamespaceAttributes(child, news);
        }
      }

      /* Publish Date */
      else if ("pubdate".equals(name)) { // $NON-NLS-1$
        news.setPublishDate(DateUtils.parseDate(child.getText()));
        processNamespaceAttributes(child, news);
      }

      /* Author */
      else if ("author".equals(name)) { // $NON-NLS-1$
        IPerson person = Owl.getModelFactory().createPerson(null, news);
        person.setName(child.getText());

        processNamespaceAttributes(child, person);
      }

      /* Comments */
      else if ("comments".equals(name)) { // $NON-NLS-1$
        news.setComments(child.getText());
        processNamespaceAttributes(child, news);
      }

      /* Attachment */
      else if ("enclosure".equals(name)) // $NON-NLS-1$
      processEnclosure(child, news);

      /* Category */
      else if ("category".equals(name)) // $NON-NLS-1$
      processCategory(child, news);

      /* GUID */
      else if ("guid".equals(name)) // $NON-NLS-1$
      processGuid(child, news);

      /* Source */
      else if ("source".equals(name)) // $NON-NLS-1$
      processSource(child, news);
    }
  }
Esempio n. 18
0
  private void registerListeners() {

    /* Index Listener */
    fIndexListener =
        new IndexListener() {
          public void indexUpdated(int entitiesCount) {
            updateSavedSearchesFromEvent(entitiesCount);
          }
        };

    Owl.getPersistenceService().getModelSearch().addIndexListener(fIndexListener);

    /* Bookmark Listener: Update on Reparent */
    fBookmarkListener =
        new BookMarkAdapter() {
          @Override
          public void entitiesUpdated(Set<BookMarkEvent> events) {
            for (BookMarkEvent event : events) {
              if (event.isRoot()) {
                IFolder oldParent = event.getOldParent();
                IFolder parent = event.getEntity().getParent();

                if (oldParent != null && !oldParent.equals(parent)) {
                  updateSavedSearchesFromEvent(1);
                  break;
                }
              }
            }
          }
        };

    DynamicDAO.addEntityListener(IBookMark.class, fBookmarkListener);

    /* News Bin Listener: Update on Reparent */
    fNewsBinListener =
        new NewsBinAdapter() {
          @Override
          public void entitiesUpdated(Set<NewsBinEvent> events) {
            for (NewsBinEvent event : events) {
              if (event.isRoot()) {
                IFolder oldParent = event.getOldParent();
                IFolder parent = event.getEntity().getParent();

                if (oldParent != null && !oldParent.equals(parent)) {
                  updateSavedSearchesFromEvent(1);
                  break;
                }
              }
            }
          }
        };

    DynamicDAO.addEntityListener(INewsBin.class, fNewsBinListener);

    /* Folder Listener: Update on Reparent */
    fFolderListener =
        new FolderAdapter() {
          @Override
          public void entitiesUpdated(Set<FolderEvent> events) {
            for (FolderEvent event : events) {
              if (event.isRoot()) {
                IFolder oldParent = event.getOldParent();
                IFolder parent = event.getEntity().getParent();

                if (oldParent != null && !oldParent.equals(parent)) {
                  updateSavedSearchesFromEvent(1);
                  break;
                }
              }
            }
          }
        };

    DynamicDAO.addEntityListener(IFolder.class, fFolderListener);
  }
Esempio n. 19
0
 private void unregisterListeners() {
   Owl.getPersistenceService().getModelSearch().removeIndexListener(fIndexListener);
   DynamicDAO.removeEntityListener(IBookMark.class, fBookmarkListener);
   DynamicDAO.removeEntityListener(INewsBin.class, fNewsBinListener);
   DynamicDAO.removeEntityListener(IFolder.class, fFolderListener);
 }
public class GoogleCredentialDialog extends TitleAreaDialog {

  /* Keep the visible instance saved */
  private static GoogleCredentialDialog fVisibleInstance;

  public static GoogleCredentialDialog getVisibleInstance() {
    return fVisibleInstance;
  }
  /* Fields */
  private LocalResourceManager fResources;
  private Text usernameField;
  private Text passwordField;
  private final URI gLink = URI.create(SyncUtils.GMAIL_LOGIN);

  private ICredentialsProvider gCredProvider =
      Owl.getConnectionService().getCredentialsProvider(gLink);

  public GoogleCredentialDialog(Shell parentShell) {
    super(parentShell);
    fResources = new LocalResourceManager(JFaceResources.getResources());
  }

  @Override
  protected void buttonPressed(int buttonId) {
    /* User pressed SAVE Button */
    if (buttonId == IDialogConstants.OK_ID) {
      final String username = usernameField.getText();
      final String password = passwordField.getText();
      if (!username.equals("") && !password.equals("")) { // $NON-NLS-1$//$NON-NLS-2$
        GmailCredentials credentials = new GmailCredentials(username, password);
        try {
          if (gCredProvider != null) {
            gCredProvider.setAuthCredentials(credentials, gLink, null);
          }
        } catch (CredentialsException e) {
          Activator.getDefault().getLog().log(e.getStatus());
        }
        GmailAuthenticationAction gAuthAction = new GmailAuthenticationAction();
        gAuthAction.addGmailFolder();
      } else {
        MessageDialog.openError(
            this.getParentShell(),
            "You must enter valid credentials",
            "Empty strings are not allowed"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    }

    super.buttonPressed(buttonId);
  }

  @Override
  public boolean close() {
    fVisibleInstance = null;
    fResources.dispose();
    return super.close();
  }

  @Override
  protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.setText(Messages.GoogleCredentialDialog_WINDOW_TITLE);
  }

  // Create the Dialog structure

  /*
   * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.OK_ID, "Save", true); // $NON-NLS-1$
    createButton(parent, IDialogConstants.CANCEL_ID, "Cancel", false); // $NON-NLS-1$
  }

  @Override
  protected Control createDialogArea(Composite parent) {

    /* Title */
    setTitle(Messages.GoogleCredentialDialog_TITLE);

    /* Title Image */
    setTitleImage(OwlUI.getImage(fResources, "icons/wizban/login_wiz.png")); // $NON-NLS-1$

    /* Title Message */
    setMessage(Messages.GoogleCredentialDialog_MESSAGE);

    /* Separator */
    new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    /* Composite to hold all components */
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(LayoutUtils.createGridLayout(3, 5, 10));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    /* Label for username */
    Label userLabel = new Label(composite, SWT.WRAP);
    userLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    userLabel.setText(Messages.GoogleCredentialDialog_USERNAME);

    /* Field for username */
    Composite textIndent = new Composite(composite, SWT.NONE);
    textIndent.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    textIndent.setLayout(new GridLayout(1, false));

    /* Label for username */
    Label userSuggestLabel = new Label(composite, SWT.WRAP);
    userSuggestLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    userSuggestLabel.setText("@gmail.com"); // $NON-NLS-1$

    usernameField = new Text(textIndent, SWT.BORDER);
    usernameField.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    usernameField.setFocus();

    /* Label for password */
    Label passwordLabel = new Label(composite, SWT.WRAP);
    passwordLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    passwordLabel.setText(Messages.GoogleCredentialDialog_PASSWORD);

    /* Field for password */
    Composite textIndent2 = new Composite(composite, SWT.NONE);
    textIndent2.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    textIndent2.setLayout(new GridLayout(1, false));

    passwordField = new Text(textIndent2, SWT.BORDER | SWT.PASSWORD);
    passwordField.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    /* Separator */
    new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    /* Try loading Credentials from Platform if available */
    preload();
    applyDialogFont(composite);
    return composite;
  }

  /*
   * @see org.eclipse.jface.window.Window#getShellStyle()
   */
  @Override
  protected int getShellStyle() {
    int style = SWT.TITLE | SWT.BORDER | SWT.CLOSE | getDefaultOrientation();
    return style;
  }

  @Override
  public int open() {
    fVisibleInstance = this;
    return super.open();
  }

  private void preload() {
    ICredentials authCredentials = null;
    try {
      if (gCredProvider != null) authCredentials = gCredProvider.getAuthCredentials(gLink, null);
    } catch (CredentialsException e) {
      Activator.getDefault().getLog().log(e.getStatus());
    }

    if (authCredentials != null) {
      String username = authCredentials.getUsername();
      String password = authCredentials.getPassword();

      if (StringUtils.isSet(username)) {
        usernameField.setText(username);
        usernameField.selectAll();
      }

      if (StringUtils.isSet(password)) passwordField.setText(password);
    }
  }
}