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);
      }
    }
  }
  /**
   * "Draws" the Elements on the Pane. Currently supported types are:
   * <li>
   *
   *     <ul>
   *       Normal data Elements
   * </ul>
   *
   * <ul>
   *   Outbound data Elements (are only shown not clickable
   * </ul>
   *
   * <ul>
   *   Inbound Data is shown
   * </ul>
   *
   * <ul>
   *   Pictures are shown
   * </ul>
   *
   * @param coll the collectible that should be drawn
   */
  public void drawElements(Collectible coll) {

    // clear prior content
    try {
      this.remove(0, this.getLength());
    } catch (BadLocationException ex) {
      // shoudl always work
    }

    // get dataElements
    Element data = coll.getContent();

    // foreach : get name, type, content
    List<Element> fields = data.getChildren("field");
    for (Element element : fields) {
      String name = element.getAttribute("name").getValue();

      // might be a picture
      Attribute typeAttribute = element.getAttribute("type");

      // might be a Inbound
      List<Element> childElements = element.getChildren("li");

      // is it a picture? If so draw it.
      if (typeAttribute != null) {
        drawPicture(element);
      }

      // is it a multifield, then draw it
      else if (childElements != null && childElements.size() > 0) {
        drawString(name + ":\n", this.getStyle("bold"));
        for (Element childElement : childElements) {
          drawChildElement(childElement);
        }
      }

      // is it a single field. Draw it.
      else {
        String content = element.getTextNormalize();
        drawString(name + ":\n", this.getStyle("bold"));
        drawString(content + "\n", this.getStyle("regular"));
      }
    }

    // informListeners
    fireChangedUpdate(
        new DefaultDocumentEvent(0, this.getLength(), DocumentEvent.EventType.CHANGE));
  }
示例#3
0
 public void readXML(final Element elem) throws XMLSyntaxError {
   XMLHelper.checkName(elem, DATABASE_CONNECTION_ELEMENT_NAME);
   if (XMLHelper.contains(elem, EMBEDDED_SOURCE_ELEMENT_NAME)) {
     final Element embedElem = elem.getChild(EMBEDDED_SOURCE_ELEMENT_NAME);
     setEmbeddedSQLLocation(
         XMLHelper.getAttribute(embedElem, EMBEDDED_URL_ATTRIBUTE_NAME).getValue());
     setUrl("jdbc:hsqldb:.");
     setDriverClass("org.hsqldb.jdbcDriver");
     setUserName("sa");
     setPassword("");
   } else {
     final Element urlElement = XMLHelper.getMandatoryChild(elem, URL_SOURCE_ELEMENT_NAME);
     sourceURL = urlElement.getTextNormalize();
     driverClass = XMLHelper.getAttribute(urlElement, DRIVER_CLASS_ATTRIBUTE_NAME).getValue();
     userName = XMLHelper.getAttribute(urlElement, USERNAME_ATTRIBUTE_NAME).getValue();
     password = XMLHelper.getAttribute(urlElement, PASSWORD_ATTRIBUTE_NAME).getValue();
   }
   this.table = new Table(XMLHelper.getMandatoryChild(elem, TABLE_ELEMENT_NAME));
   this.objectKey =
       new Column(XMLHelper.getMandatoryChild(elem, OBJECT_KEY_ELEMENT_NAME), this.table);
 }
  /**
   * This method is used to recursively create a java object based on the provided element.
   * Available elements : list, item, map, string and data. To create simple object see the
   * convertSimpleObject method.
   *
   * @param element the element to convert.
   * @return the created POJO, null if the element does not fit.
   */
  private void appendObject(Map<String, Object> container, Element element) {

    final String name = element.getQualifiedName();
    final List<Attribute> attributes = element.getAttributes();
    final List<Element> childElements = element.getChildren();

    /*
     * The simplest tag containing only a text value !
     */
    if ((childElements.size() == 0) && (attributes.size() == 0)) {
      container.put(name, element.getTextNormalize());
      return;
    }

    /*
     * Element is composed of attributes and child elements that we put in a map
     */
    final Map<String, Object> objectMap = new HashMap<String, Object>();

    // add attributes, using the predefined prefix to avoid collisions with
    // elements names
    for (final Attribute attr : attributes) {
      objectMap.put(this.mAttrPrefix + attr.getQualifiedName(), attr.getValue());
    }

    // add child elements under their names (recursive call)
    for (final Element elt : childElements) {
      appendObject(objectMap, elt);
    }

    // add all the text content concatenated in one
    final String textContent = element.getTextNormalize();

    if (textContent.length() > 0) {
      objectMap.put(this.mTextAttrName, textContent);
    }

    /*
     * now its time to add our object in the parent container but.. are we
     * the only one with the given name ?
     */
    if (container.containsKey(name)) {
      // we are not alone !
      final Object existingMappedElement = container.get(name);
      List<Object> fraternity;

      if (existingMappedElement instanceof List) {
        // the fraternity is allready organized
        fraternity = (List) existingMappedElement;
        fraternity.add(objectMap);

      } else {
        // we have one self-ignoring brother
        // > create the fraternity
        fraternity = new ArrayList<Object>();
        fraternity.add(existingMappedElement);
        fraternity.add(objectMap);
      }
      container.put(name, fraternity);

    } else {
      // we are truly unique.. (until now)
      container.put(name, objectMap);
    }
  }
  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);
    }
  }
 /** draw the ChildElements of an Inbound Element# */
 private void drawChildElement(Element element) {
   String content = element.getTextNormalize();
   drawString(content + "\n", this.getStyle("regular"));
 }