Package org.jdom

Examples of org.jdom.Attribute


    // RSS 1.0 Administration Module support

    // 0..1 generator element
    Element elGenerator = channel.getChild("generatorAgent", adminNS);
    if (elGenerator != null) {
      Attribute generator = elGenerator.getAttribute("resource", ParserUtils
          .getNamespace(elGenerator, "rdf"));
      if (generator != null) {
        chnl.setGenerator(generator.getValue());
      }
    }

    // RSS 1.0 Syndication Module support

    // 0..1 update period element
    Element updatePeriod = channel.getChild("updatePeriod", syNS);
    if (updatePeriod != null) {
      try {
        ChannelUpdatePeriod channelUpdatePeriod = ChannelUpdatePeriod
            .valueFromText(updatePeriod.getTextTrim());
        chnl.setUpdatePeriod(channelUpdatePeriod);
      } catch (IllegalArgumentException ex) {
        logger.warn(updatePeriod.getTextTrim(), ex);
      }
    }

    // 0..1 update frequency element
    Element updateFrequency = channel.getChild("updateFrequency", syNS);
    if (updateFrequency != null) {
      chnl.setUpdateFrequency((new Integer(updateFrequency.getTextTrim()))
          .intValue());
    }

    // 0..1 update base element
    Element updateBase = channel.getChild("updateBase", syNS);
    if (updateBase != null) {
      chnl.setUpdateBase(ParserUtils.getDate(updateBase.getTextTrim()));
    }

    if ((updatePeriod != null) && updateFrequency != null) {
      int ttl = getTTL(chnl.getUpdatePeriod(), chnl.getUpdateFrequency());
      chnl.setTtl(ttl);
    }

    // item elements
    List items = root.getChildren("item", defNS);
    Iterator i = items.iterator();
    while (i.hasNext()) {
      Element item = (Element) i.next();

      ParserUtils.matchCaseOfChildren(item, new String[] { "title", "link",
          "encoded", "description", "creator", "subject", "date", "sourceURL",
          "source", "timestamp", "reference" });

      // get title element
      Element elTitle = item.getChild("title", defNS);
      String strTitle = "<No Title>";
      if (elTitle != null) {
        strTitle = elTitle.getTextTrim();
      }
      if (logger.isDebugEnabled()) {
        logger.debug("Item element found (" + strTitle + ").");
      }

      // get link element
      Element elLink = item.getChild("link", defNS);
      String strLink = "";
      if (elLink != null) {
        strLink = elLink.getTextTrim();
      }

      // get description element
      Element elDesc = item.getChild("encoded", contentNS);
      if (elDesc == null) {
        elDesc = item.getChild("description", defNS);
      }
      if (elDesc == null) {
        elDesc = item.getChild("description", dcNS);
      }
      String strDesc = "";
      if (elDesc != null) {
        strDesc = elDesc.getTextTrim();
      }

      // generate new RSS item (link to article)
      ItemIF rssItem = cBuilder.createItem(item, chnl, strTitle, strDesc,
          ParserUtils.getURL(strLink));
      rssItem.setFound(dateParsed);

      // get creator element
      Element elCreator = item.getChild("creator", dcNS);
      if (elCreator != null) {
        rssItem.setCreator(elCreator.getTextTrim());
      }

      // get subject element
      Element elSubject = item.getChild("subject", dcNS);
      if (elSubject != null) {
        // TODO: Mulitple subject elements not handled currently
        rssItem.setSubject(elSubject.getTextTrim());
      }

      // get date element
      Element elDate = item.getChild("date", dcNS);
      if (elDate != null) {
        rssItem.setDate(ParserUtils.getDate(elDate.getTextTrim()));
      }

      // get source element - default to Aggregation module, then try Dublin Core
      String sourceName = null;
      String sourceLocation = null;
      Date sourceTimestamp = null;

      Element elSourceURL = item.getChild("sourceURL", agNS);
      if (elSourceURL == null) { //  No Aggregation module - try Dublin Core
        elSourceURL = item.getChild("source", dcNS);
        if (elSourceURL != null) {
          sourceLocation = elSourceURL.getTextTrim();
          sourceName = "Source";
        }
      } else { // Aggregation module
        sourceLocation = elSourceURL.getTextTrim();
        Element elSourceName = item.getChild("source", agNS);
        if (elSourceName != null) {
          sourceName = elSourceName.getTextTrim();
        }
        Element elSourceTimestamp = item.getChild("timestamp", agNS);
        if (elSourceTimestamp != null) {
          sourceTimestamp = ParserUtils
              .getDate(elSourceTimestamp.getTextTrim());
        }
      }

      if (sourceLocation != null) {
        ItemSourceIF itemSource = cBuilder.createItemSource(rssItem,
            sourceName, sourceLocation, sourceTimestamp);
        rssItem.setSource(itemSource);
      }

      // comments element - use Annotation module
      Element elReference = item.getChild("reference", annotateNS);
      if (elReference != null) {
        Attribute resource = elReference.getAttribute("resource", ParserUtils
            .getNamespace(elReference, "rdf"));
        if (resource != null) {
          URL resourceURL = ParserUtils.getURL(resource.getValue());
          if (resourceURL != null) {
            rssItem.setComments(resourceURL);
          }
        }
      }
View Full Code Here


      Element elGuid = item.getChild("guid", defNS);
      if (elGuid != null) {
        String guidUrl = elGuid.getTextTrim();
        if (guidUrl != null) {
          boolean permaLink = true;
          Attribute permaLinkAttribute = elGuid.getAttribute("isPermaLink",
              defNS);
          if (permaLinkAttribute != null) {
            String permaLinkStr = permaLinkAttribute.getValue();
            if (permaLinkStr != null) {
              permaLink = Boolean.valueOf(permaLinkStr).booleanValue();
            }
          }
          ItemGuidIF itemGuid = cBuilder.createItemGuid(rssItem, guidUrl,
              permaLink);
          rssItem.setGuid(itemGuid);
        }
      }

      // get source element
      Element elSource = item.getChild("source", defNS);
      if (elSource != null) {
        String sourceName = elSource.getTextTrim();
        Attribute sourceAttribute = elSource.getAttribute("url", defNS);
        if (sourceAttribute != null) {
          String sourceLocation = sourceAttribute.getValue().trim();
          ItemSourceIF itemSource = cBuilder.createItemSource(rssItem,
              sourceName, sourceLocation, null);
          rssItem.setSource(itemSource);
        }
      }

      // get enclosure element
      Element elEnclosure = item.getChild("enclosure", defNS);
      if (elEnclosure != null) {
        URL location = null;
        String type = null;
        int length = -1;
        Attribute urlAttribute = elEnclosure.getAttribute("url", defNS);
        if (urlAttribute != null) {
          location = ParserUtils.getURL(urlAttribute.getValue().trim());
        }
        Attribute typeAttribute = elEnclosure.getAttribute("type", defNS);
        if (typeAttribute != null) {
          type = typeAttribute.getValue().trim();
        }
        Attribute lengthAttribute = elEnclosure.getAttribute("length", defNS);
        if (lengthAttribute != null) {
          try {
            length = Integer.parseInt(lengthAttribute.getValue().trim());
          } catch (NumberFormatException e) {
            logger.warn(e);
          }
        }
        ItemEnclosureIF itemEnclosure = cBuilder.createItemEnclosure(rssItem,
View Full Code Here

      // get source element (an RSS 0.92 element)
      Element source = item.getChild("source");
      if (source != null) {
        String sourceName = source.getTextTrim();
        Attribute sourceAttribute = source.getAttribute("url");
        if (sourceAttribute != null) {
          String location = sourceAttribute.getValue().trim();
          ItemSourceIF itemSource =
            cBuilder.createItemSource(rssItem, sourceName, location, null);
          rssItem.setSource(itemSource);
        }
      }

      // get enclosure element (an RSS 0.92 element)
      Element enclosure = item.getChild("enclosure");
      if (enclosure != null) {
        URL location = null;
        String type = null;
        int length = -1;
        Attribute urlAttribute = enclosure.getAttribute("url");
        if (urlAttribute != null) {
          location = ParserUtils.getURL(urlAttribute.getValue().trim());
        }
        Attribute typeAttribute = enclosure.getAttribute("type");
        if (typeAttribute != null) {
          type = typeAttribute.getValue().trim();
        }
        Attribute lengthAttribute = enclosure.getAttribute("length");
        if (lengthAttribute != null) {
          try {
            length = Integer.parseInt(lengthAttribute.getValue().trim());
          } catch (NumberFormatException e) {
            logger.warn(e);
          }
        }
        ItemEnclosureIF itemEnclosure =
View Full Code Here

        try {
            if (node instanceof Element) {
                OUTPUT.output((Element)node, sw);
            }
            else if (node instanceof Attribute) {
                Attribute attribute = (Attribute)node;
                sw.write(" ");
                sw.write(attribute.getQualifiedName());
                sw.write("=\"");
                sw.write(OUTPUT.escapeAttributeEntities(attribute.getValue()));
                sw.write("\"");
            }
            else if (node instanceof Text) {
                OUTPUT.output((Text)node, sw);
            }
View Full Code Here

            Element e = (Element)node;
            if(localName == null) {
                result.addAll(e.getAttributes());
            }
            else {
                Attribute attr = e.getAttribute(localName, Namespace.getNamespace("", namespaceUri));
                if(attr != null) {
                    result.add(attr);
                }
            }
        } else if (node instanceof ProcessingInstruction) {
            ProcessingInstruction pi = (ProcessingInstruction)node;
            if ("target".equals(localName)) {
                result.add(new Attribute("target", pi.getTarget()));
            }
            else if ("data".equals(localName)) {
                result.add(new Attribute("data", pi.getData()));
            }
            else {
                result.add(new Attribute(localName, pi.getValue(localName)));
            }
        } else if (node instanceof DocType) {
            DocType doctype = (DocType)node;
            if ("publicId".equals(localName)) {
                result.add(new Attribute("publicId", doctype.getPublicID()));
            }
            else if ("systemId".equals(localName)) {
                result.add(new Attribute("systemId", doctype.getSystemID()));
            }
            else if ("elementName".equals(localName)) {
                result.add(new Attribute("elementName", doctype.getElementName()));
            }
        }
    }
View Full Code Here

        String description = element.getText();
        String dependencies = element.getAttributeValue("depends");
        Collection<String> dependencyNames = Util.isNullOrTrimmedBlank(dependencies) ? null : Arrays.asList(dependencies.split(","));
        String category = element.getAttributeValue("category");
        boolean mandatoryUpdate = Boolean.valueOf(element.getAttributeValue("mandatoryUpdate"));
        Attribute orderAttr = element.getAttribute("order");
       
        String changes = "";
       
        if(element.getChild("changes")!=null) {
          changes = element.getChildText("changes");
        }
       
        String platform = element.getAttributeValue("platform","");
        String arch = element.getAttributeValue("arch", "");

        if(orderAttr == null) {
            log.warn("In extension store descriptor for " + id + ", <" + element.getName() + "> requires an 'order' attribute. Assuming '99999'");
       
        int type = element.getName().equalsIgnoreCase("install") ? ExtensionBundle.TYPE_INSTALLABLE : ExtensionBundle.TYPE_CONFIGUREABLE;
        try {
            return new ExtensionBundle(new VersionInfo.Version(version), type, id, name, description, license, productURL, instructionsURL, requiredHostVersion, dependencyNames, category, mandatoryUpdate, orderAttr == null ? 99999 : orderAttr.getIntValue(), changes, platform, arch);
        }
        catch(DataConversionException dce) {
            throw new IOException("Invalid order attribute. " + dce.getMessage());
        }
    }
View Full Code Here

      }
      version = new VersionInfo.Version(ver);

      if (doc.getRootElement().getName().equals("bundle")) {

        Attribute a = doc.getRootElement().getAttribute("id");
        id = a == null ? null : a.getValue();

        if (id == null) {
          throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR,
                  "<bundle> element requires attribute 'id'");
        }
        if (log.isDebugEnabled())
          log.debug("Application bundle id is " + id);

        name = doc.getRootElement().getAttribute("name").getValue();
        if (log.isDebugEnabled())
          log.debug("Application bundle name is " + name);

        Attribute orderAttr = doc.getRootElement().getAttribute("order");
        if (orderAttr == null) {
          log.warn("<bundle> element in " + getFile().getPath() + " now requires attribute 'order'. Assuming 99999");
          order = 99999;
        } else {
          try {
            order = orderAttr.getIntValue();
          } catch (DataConversionException dce) {
            throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR,
                    "'order' attribute is invalid. " + dce.getMessage());
          }
        }
View Full Code Here

    String erg = "";
   
    List l = node.getAttributes();
    Iterator i = l.iterator();
    while (i.hasNext()) {
     Attribute attr = (Attribute)i.next();
     erg += attr.getName() + "=" + attr.getValue() + " " ;
     element.attributes.put(attr.getName(), attr.getValue());
    }
    return erg;
   }
View Full Code Here

    }


    public void checkScript() {
        if (_script != null && _type == Editor.DOC_MONITOR) {
            Attribute language = _script.getAttribute("language");
            Attribute javaClass = _script.getAttribute("java_class");
            Attribute comClass = _script.getAttribute("com_class");
            Attribute resource = _script.getAttribute("resource");
            List includes = _script.getChildren("include");

            if (language == null && javaClass == null && comClass == null && resource == null && includes.size() == 0) {
                _parent.removeChild("monitor", _dom.getNamespace());
                // _dom.setChanged(true);
View Full Code Here

            case Editor.CONFIG:
              new ConfigForm(c, SWT.NONE, _dom, _gui);
              break;
            case Editor.PARAMETER:
              int type = getType(objTreeItemUserdata.getElement());
              Attribute a = Utils.getJobElement(objTreeItemUserdata.getElement()).getAttribute("name");
              if (a == null) {
                new sos.scheduler.editor.conf.forms.ParameterForm(c, SWT.NONE, _dom, objTreeItemUserdata.getElement(), _gui, type);
              }else {
                String jobname = a.getValue();
                new sos.scheduler.editor.conf.forms.ParameterForm(c, SWT.NONE, _dom, objTreeItemUserdata.getElement(), _gui, type,jobname);
              }
              break;
            case Editor.SECURITY:
              new SecurityForm(c, SWT.NONE, _dom, objTreeItemUserdata.getElement());
View Full Code Here

TOP

Related Classes of org.jdom.Attribute

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.