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 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);
      }
    }
  }
예제 #3
0
  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 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 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);
      }
    }
  }
  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);
  }
  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);
    }
  }