protected void set(final String nodename, final Content nodeContent) {
   final Element el = ElementUtils.contains(getRoot(), nodename);
   if (el == null) {
     add(nodename, nodeContent);
   } else {
     el.setContent(nodeContent);
   }
 }
  /** {@inheritDoc} */
  public Content encodeXML(final String name, Namespace ns) {
    Element element = new Element(name, ns);
    // Element element = new Element(name,
    // Namespace.getNamespace("llrp",LLRPConstants.LLRPNAMESPACE));
    element.setContent(new Text(toString()));

    return element;
  }
 protected void transformXML(File[] files) {
   int number = 0;
   try {
     SAXBuilder builder = new SAXBuilder();
     for (int f = 0; f < files.length; f++) {
       int fn = f + 1;
       // split by treatment
       Document doc = builder.build(files[f]);
       Element root = doc.getRootElement();
       List<Element> treatments =
           XPath.selectNodes(root, "/tax:taxonx/tax:taxonxBody/tax:treatment");
       // detach all but one treatments from doc
       ArrayList<Element> saved = new ArrayList<Element>();
       for (int t = 1; t < treatments.size(); t++) {
         Element e = treatments.get(t);
         doc.removeContent(e);
         e.detach();
         saved.add(e);
       }
       // now doc is a template to create other treatment files
       // root.detach();
       formatDescription(
           (Element) XPath.selectSingleNode(root, "/tax:taxonx/tax:taxonxBody/tax:treatment"),
           ".//tax:div[@type='description']",
           ".//tax:p",
           fn,
           0);
       root.detach();
       writeTreatment2Transformed(root, fn, 0);
       listener.info((number++) + "", fn + "_0.xml"); // list the file on GUI here
       getDescriptionFrom(root, fn, 0);
       // replace treatement in doc with a new treatment in saved
       Iterator<Element> it = saved.iterator();
       int count = 1;
       while (it.hasNext()) {
         Element e = it.next();
         Element body = root.getChild("taxonxBody", root.getNamespace());
         Element treatment =
             (Element) XPath.selectSingleNode(root, "/tax:taxonx/tax:taxonxBody/tax:treatment");
         // in treatment/div[@type="description"], replace <tax:p> tag with <description
         // pid="1.txtp436_1.txt">
         int index = body.indexOf(treatment);
         e = formatDescription(e, ".//tax:div[@type='description']", ".//tax:p", fn, count);
         body.setContent(index, e);
         // write each treatment as a file in the target/transfromed folder
         // write description text in the target/description folder
         root.detach();
         writeTreatment2Transformed(root, fn, count);
         listener.info((number++) + "", fn + "_" + count + ".xml"); // list the file on GUI here
         getDescriptionFrom(root, fn, count);
         count++;
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     LOGGER.error("Type4Transformer : error.", e);
   }
 }
Beispiel #4
0
  /**
   * Used for editing : swaps 2 elements.
   *
   * @param el1
   * @param el2
   * @throws Exception
   */
  protected void swapElements(Element el1, Element el2) throws Exception {

    Element parent = el1.getParentElement();
    if (parent == null) {
      throw new IllegalArgumentException("No parent element for swapping");
    }

    int index1 = parent.indexOf(el1);
    if (index1 == -1) {
      throw new IllegalArgumentException("Element 1 not found for swapping");
    }
    int index2 = parent.indexOf(el2);
    if (index2 == -1) {
      throw new IllegalArgumentException("Element 2 not found for swapping");
    }

    Element el1Spare = (Element) el1.clone();

    parent.setContent(index1, (Element) el2.clone());
    parent.setContent(index2, el1Spare);
  }
  private Element createXmlElement(final String version) {
    final List<Element> contentList = new ArrayList<Element>(16);
    contentList.add(createElement(DimapProductConstants.TAG_BAND_INDEX, "1"));
    contentList.add(createElement(DimapProductConstants.TAG_BAND_NAME, "filtered_coffee"));
    contentList.add(createElement(DimapProductConstants.TAG_BAND_DESCRIPTION, "with milk & sugar"));
    final String typeString = ProductData.getTypeString(_source.getGeophysicalDataType());
    contentList.add(createElement(DimapProductConstants.TAG_DATA_TYPE, typeString));
    contentList.add(createElement(DimapProductConstants.TAG_PHYSICAL_UNIT, "l"));
    contentList.add(createElement(DimapProductConstants.TAG_SOLAR_FLUX, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_BAND_WAVELEN, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_BANDWIDTH, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_SCALING_FACTOR, "1.0"));
    contentList.add(createElement(DimapProductConstants.TAG_SCALING_OFFSET, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_SCALING_LOG_10, "false"));
    contentList.add(createElement(DimapProductConstants.TAG_NO_DATA_VALUE_USED, "true"));
    contentList.add(
        createElement(
            DimapProductConstants.TAG_NO_DATA_VALUE,
            String.valueOf(_source.getGeophysicalNoDataValue())));
    final List<Element> filterBandInfoList = new ArrayList<Element>(5);
    filterBandInfoList.add(createElement(DimapProductConstants.TAG_FILTER_SOURCE, "anyBand"));
    filterBandInfoList.add(
        createElement(
            DimapProductConstants.TAG_FILTER_OPERATOR_CLASS_NAME,
            "org.esa.beam.framework.datamodel.GeneralFilterBand$Mean"));
    final Element filterBandInfo = new Element(DimapProductConstants.TAG_FILTER_BAND_INFO);
    filterBandInfo.setAttribute(
        GeneralFilterBandPersistable.ATTRIBUTE_BAND_TYPE,
        GeneralFilterBandPersistable.GENERAL_FILTER_BAND_TYPE);
    if (GeneralFilterBandPersistable.VERSION_1_1.equals(version)) {
      filterBandInfoList.add(createElement(DimapProductConstants.TAG_FILTER_SUB_WINDOW_SIZE, "5"));
      filterBandInfo.setAttribute(
          GeneralFilterBandPersistable.ATTRIBUTE_VERSION, GeneralFilterBandPersistable.VERSION_1_1);
    } else {
      // Version 1.0
      filterBandInfoList.add(createElement(DimapProductConstants.TAG_FILTER_SUB_WINDOW_WIDTH, "5"));
      filterBandInfoList.add(
          createElement(DimapProductConstants.TAG_FILTER_SUB_WINDOW_HEIGHT, "2"));
    }
    filterBandInfo.addContent(filterBandInfoList);
    contentList.add(filterBandInfo);

    final Element root = new Element(DimapProductConstants.TAG_SPECTRAL_BAND_INFO);
    root.setContent(contentList);
    return root;
  }
  public void setLastRun(String alertName) {
    List alerts = this.xmlDocument.getRootElement().getChildren("alert");

    for (int i = 0; i < alerts.size(); i++) {
      Element alertElement = (Element) alerts.get(i);
      String name = alertElement.getChildText("name");
      if (name.equalsIgnoreCase(alertName)) {
        Element lastRunEl = alertElement.getChild("last-run");
        if (lastRunEl != null) {
          CDATA cdata = new CDATA(Dates.today("yyyy/MM/dd", ""));
          List cdataL = new ArrayList();
          cdataL.add(cdata);
          lastRunEl.setContent(cdataL);
          this.output();
        }
      }
    }
  }
Beispiel #7
0
 @Override
 public void populateXml(Element e2) {
   super.populateXml(e2);
   e2.setContent(new org.jdom.Text(script));
 }
  @Override
  public void generate(final File reportsDir, final VersionManagerSession session)
      throws VManException {
    final Map<VersionlessProjectKey, Set<Dependency>> missingDependencies =
        session.getMissingDependencies();
    if (missingDependencies.isEmpty()) {
      return;
    }

    final Element deps = new Element("dependencies");

    for (final Map.Entry<VersionlessProjectKey, Set<Dependency>> depsEntry :
        missingDependencies.entrySet()) {
      if (deps.getContentSize() > 0) {
        deps.addContent("\n\n");
      }

      deps.addContent(new Comment("START: " + depsEntry.getKey()));

      for (final Dependency dep : depsEntry.getValue()) {
        final Element d = new Element("dependency");
        deps.addContent(d);

        d.addContent(new Element("groupId").setText(dep.getGroupId()));
        d.addContent(new Element("artifactId").setText(dep.getArtifactId()));
        d.addContent(new Element("version").setText(dep.getVersion()));

        if (isNotEmpty(dep.getType()) && !"jar".equals(dep.getType())) {
          d.addContent(new Element("type").setText(dep.getType()));
        }

        if (isNotEmpty(dep.getClassifier())) {
          d.addContent(new Element("classifier").setText(dep.getClassifier()));
        }

        // if ( dep.isOptional() )
        // {
        // d.addContent( new Element( "optional" ).setText( Boolean.toString( true ) ) );
        // }
        //
        // if ( dep.getExclusions() != null && !dep.getExclusions().isEmpty() )
        // {
        // Element ex = new Element( "exclusions" );
        // d.addContent( ex );
        //
        // for ( Exclusion exclusion : dep.getExclusions() )
        // {
        // ex.addContent( new Element( "groupId" ).setText( exclusion.getGroupId() ) );
        // ex.addContent( new Element( "artifactId" ).setText( exclusion.getArtifactId() ) );
        // }
        // }
      }

      deps.addContent(new Comment("END: " + depsEntry.getKey()));
    }

    final Element dm = new Element("dependencyManagement");
    dm.setContent(deps);

    final Document doc = new Document(dm);

    final Format fmt = Format.getPrettyFormat();
    fmt.setIndent("  ");
    fmt.setTextMode(TextMode.PRESERVE);

    final XMLOutputter output = new XMLOutputter(fmt);

    final File report = new File(reportsDir, ID);
    FileWriter writer = null;
    try {
      reportsDir.mkdirs();

      writer = new FileWriter(report);
      output.output(doc, writer);
    } catch (final IOException e) {
      throw new VManException("Failed to generate %s report! Error: %s", e, ID, e.getMessage());
    } finally {
      closeQuietly(writer);
    }
  }
 protected void add(final String nodename, final Content nodetext) {
   final Element el = new Element(nodename);
   el.setContent(nodetext);
   this.addContent(el);
 }