Exemplo n.º 1
0
  private Content parseContent(Element e) {
    String value = null;
    String type = getAttributeValue(e, "type");
    type = (type != null) ? type : "text/plain";
    String mode = getAttributeValue(e, "mode");
    if (mode == null) {
      mode = Content.XML; // default to xml content
    }
    if (mode.equals(Content.ESCAPED)) {
      // do nothing XML Parser took care of this
      value = e.getText();
    } else if (mode.equals(Content.BASE64)) {
      value = Base64.decode(e.getText());
    } else if (mode.equals(Content.XML)) {
      XMLOutputter outputter = new XMLOutputter();
      List<org.jdom2.Content> eContent = e.getContent();
      Iterator<org.jdom2.Content> i = eContent.iterator();
      while (i.hasNext()) {
        org.jdom2.Content c = i.next();
        if (c instanceof Element) {
          Element eC = (Element) c;
          if (eC.getNamespace().equals(getAtomNamespace())) {
            ((Element) c).setNamespace(Namespace.NO_NAMESPACE);
          }
        }
      }
      value = outputter.outputString(eContent);
    }

    Content content = new Content();
    content.setType(type);
    content.setMode(mode);
    content.setValue(value);
    return content;
  }
Exemplo n.º 2
0
  // convert to shared dimensions
  private void setSharedDimensions(
      Variable v, List<Element> values, List<Dimension> unknownDims, String location) {
    if (values.size() == 0) return;

    // remove the "scalar" dumbension
    Iterator<Element> iter = values.iterator();
    while (iter.hasNext()) {
      Element value = iter.next();
      String dimName = value.getText().trim();
      if (dimName.equalsIgnoreCase("scalar")) iter.remove();
    }

    // gotta have same number of dimensions
    List<Dimension> oldDims = v.getDimensions();
    if (oldDims.size() != values.size()) {
      log.error("Different number of dimensions for {} {}", v, location);
      return;
    }

    List<Dimension> newDims = new ArrayList<>();
    Group group = v.getParentGroup();

    for (int i = 0; i < values.size(); i++) {
      Element value = values.get(i);
      String dimName = value.getText().trim();
      dimName = NetcdfFile.makeValidCdmObjectName(dimName);

      Dimension dim = group.findDimension(dimName);
      Dimension oldDim = oldDims.get(i);
      if (dim == null) dim = checkUnknownDims(dimName, unknownDims, oldDim, location);

      if (dim == null) {
        log.error(
            "Unknown Dimension= {} for variable = {} {} ", dimName, v.getFullName(), location);
        return;
      }
      if (dim.getLength() != oldDim.getLength()) {
        log.error(
            "Shared dimension ("
                + dim.getShortName()
                + ") has different length than data dimension ("
                + oldDim.getShortName()
                + ") shared="
                + dim.getLength()
                + " org="
                + oldDim.getLength()
                + " for "
                + v
                + " "
                + location);
        return;
      }
      newDims.add(dim);
    }
    v.setDimensions(newDims);
    if (showWork) System.out.printf(" set shared dimensions for %s %n", v.getNameAndDimensions());
  }
Exemplo n.º 3
0
  public void addVariables(Element inRoot) throws org.jdom2.DataConversionException {
    Element vs = inRoot.getChild("decoder").getChild("variables");

    Element segment = new Element("segment");
    segment.setAttribute("space", "253");
    root.addContent(segment);

    Iterator it = vs.getDescendants();
    while (it.hasNext()) {
      Object o = it.next();
      if (o instanceof Element) {
        Element e = (Element) o;
        if (e.getName().equals("variable")) {
          // get common attributes
          String comment = e.getAttributeValue("comment");
          for (Object oc : e.getChildren("comment")) {
            Element ec = (Element) oc;
            if (ec.getAttributeValue("lang", "xml").equals("")) comment = ec.getText();
          }
          String name = e.getAttributeValue("label");
          if (name.equals("")) name = e.getAttributeValue("item");
          for (Object on : e.getChildren("label")) {
            Element en = (Element) on;
            if (en.getAttributeValue("lang", "xml").equals("")) name = en.getText();
          }

          long cv = e.getAttribute("CV").getIntValue();

          // find subtype and process
          Element type;
          type = e.getChild("decVal");
          if (type != null) {
            segment.addContent(handleDecVal(type, cv, name, comment, e.getAttributeValue("mask")));
            continue;
          }
          type = e.getChild("enumVal");
          if (type != null) {
            segment.addContent(handleEnumVal(type, cv, name, comment, e.getAttributeValue("mask")));
            continue;
          }
          type = e.getChild("shortAddressVal");
          if (type != null) {
            segment.addContent(handleShortAddressVal(type, cv, name, comment));
            continue;
          }
          type = e.getChild("longAddressVal");
          if (type != null) {
            segment.addContent(handleLongAddressVal(type, cv, name, comment));
            continue;
          }
        }
      }
    }
  }
Exemplo n.º 4
0
  private JoinArray readJoinArray(NetcdfDataset ds, Element joinElement) {
    JoinArray.Type type = JoinArray.Type.valueOf(joinElement.getAttributeValue("type"));
    Element paramElem = joinElement.getChild("param");
    String paramS = paramElem.getText();
    Integer param = Integer.parseInt(paramS);

    Element varElem = joinElement.getChild("variable");
    String varName = varElem.getText();
    VariableDS v = (VariableDS) ds.findVariable(varName);
    return new JoinArray(v, type, param);
  }
  /*
   * (non-Javadoc)
   *
   * @see com.mydomain.maizsoft.cargaarchivos.ArchivoXML#read()
   */
  @Override
  public void read() {

    @SuppressWarnings("deprecation")
    SAXBuilder leer = new SAXBuilder(false);
    try {
      Document document = leer.build(getPath() + getNombre());

      Element raiz = document.getRootElement();
      raiz.getAttributeValue(ConstantesArchivosXML.SUPERPADRE);

      Element padre = raiz.getChild(ConstantesArchivosXML.PADRE);

      List usuarios = raiz.getChildren(ConstantesArchivosXML.PADRE);

      Iterator padres = usuarios.iterator();

      while (padres.hasNext()) {
        Element elePadre = (Element) padres.next();
        Element idPadre = elePadre.getChild(ConstantesArchivosXML.PADREID);
        List cursos = elePadre.getChildren(ConstantesArchivosXML.HIJO);
        Iterator hijos = cursos.iterator();
        long var2 = Long.parseLong(idPadre.getText());
        HistorialNotas nueva = new HistorialNotas();
        nueva.setUserAccount(entityManager.find(Usuario.class, var2));

        while (hijos.hasNext()) {
          Element eleHijo = (Element) hijos.next();
          Element idHijo = eleHijo.getChild(ConstantesArchivosXML.HIJOID);
          Element semestre = eleHijo.getChild(ConstantesArchivosXML.HIJOSEMESTRE);
          Element nota = eleHijo.getChild(ConstantesArchivosXML.HIJONOTA);
          long var = Long.parseLong(idHijo.getText());
          nueva.setGrupoCurso(entityManager.find(GrupoCurso.class, var));
          double notad = Double.parseDouble(nota.getText());
          nueva.setSemestre(semestre.getText());
          nueva.setNota(notad);
          entityManager.persist(nueva);
        }
      }

    } catch (Exception e) {
      FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
      mensaje.add("Se produjo un error técnico :(");
    }

    FacesMessages mensaje = (FacesMessages) Component.getInstance(FacesMessages.class);
    mensaje.add("Proceso exitoso :-)");
  }
 public static String strip(String s) {
   Element e = stringToElement(s);
   if (e != null) {
     s = e.getText();
   }
   return s;
 }
  static void filterMarkerInElement(List<Element> eltList, Map<String, Object> parameterMap) {
    final Pattern patternMarker = Pattern.compile("\\$\\{([^}]+)\\}"); // matching pattern is ${..}

    for (Element elt : eltList) {
      String elementValue = elt.getText();

      if (elementValue == null) {
        continue;
      }

      Matcher matcher = patternMarker.matcher(elementValue);
      while (matcher.find()) {
        String marker = matcher.group(0); // full pattern matched ${..}
        String markerName = matcher.group(1); // get only text between curly braces
        String parameterValue = ServletUtil.getFirstParameter(parameterMap.get(markerName));

        if (parameterValue != null) {
          elementValue = elementValue.replace(marker, parameterValue);
          elt.setText(elementValue);

        } else {
          logger.warn(
              "Found marker \""
                  + marker
                  + "\" with NO matching parameter in Element <"
                  + elt.getName()
                  + ">");
        }
      }
    }
  }
Exemplo n.º 8
0
  TimeStringParsing() throws IOException {

    String filename =
        "file:C:\\Documents and Settings\\caron\\.unidata\\cachePersist\\fileD-godas-singleAgg.ncml";
    Element aggElem = ucar.nc2.util.xml.Parse.readRootElement(filename);

    List<Element> ncList = aggElem.getChildren("netcdf", NcMLReader.ncNS);
    for (Element netcdfElemNested : ncList) {
      String location = netcdfElemNested.getAttributeValue("location");

      List<Element> cacheElemList = netcdfElemNested.getChildren("cache", NcMLReader.ncNS);
      for (Element cacheElemNested : cacheElemList) {
        String varName = cacheElemNested.getAttributeValue("varName");
        String sdata = cacheElemNested.getText();
        System.out.println("text size = " + sdata.length());

        long start = System.nanoTime();
        String[] vals = sdata.split(" ");
        double took = .001 * .001 * .001 * (System.nanoTime() - start);
        System.out.println(" split took = " + took + " sec; ");

        start = System.nanoTime();
        Array data = Array.makeArray(DataType.DOUBLE, vals);
        took = .001 * .001 * .001 * (System.nanoTime() - start);
        System.out.println(" makeArray took = " + took + " sec; ");
      }
    }
  }
Exemplo n.º 9
0
  static void parseXml(Element p_element, MessageDigest p_md, ArrayList<String> p_ignoreList) {
    p_md.update(p_element.getName().getBytes());

    String content = p_element.getText();

    if (content != null) {
      p_md.update(content.getBytes());
    }

    for (Attribute attribute : p_element.getAttributes()) {
      String name = attribute.getName();

      if (p_ignoreList.contains(name)) {
        continue;
      }

      String value = attribute.getValue();

      if (value != null) {
        p_md.update(value.getBytes());
      }
    }

    for (Element child : p_element.getChildren()) {
      parseXml(child, p_md, p_ignoreList);
    }
  }
Exemplo n.º 10
0
 private Person parsePerson(Element ePerson) {
   Person person = new Person();
   Element e = ePerson.getChild("name", getAtomNamespace());
   if (e != null) {
     person.setName(e.getText());
   }
   e = ePerson.getChild("url", getAtomNamespace());
   if (e != null) {
     person.setUrl(e.getText());
   }
   e = ePerson.getChild("email", getAtomNamespace());
   if (e != null) {
     person.setEmail(e.getText());
   }
   return person;
 }
Exemplo n.º 11
0
 private String parseTextConstructToString(final Element e) {
   String value = null;
   String type = getAttributeValue(e, "type");
   if (type == null) {
     type = Content.TEXT;
   }
   if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) {
     // XHTML content needs special handling
     final XMLOutputter outputter = new XMLOutputter();
     final List<org.jdom2.Content> eContent = e.getContent();
     final Iterator<org.jdom2.Content> i = eContent.iterator();
     while (i.hasNext()) {
       final org.jdom2.Content c = i.next();
       if (c instanceof Element) {
         final Element eC = (Element) c;
         if (eC.getNamespace().equals(getAtomNamespace())) {
           ((Element) c).setNamespace(Namespace.NO_NAMESPACE);
         }
       }
     }
     value = outputter.outputString(eContent);
   } else {
     // Everything else comes in verbatim
     value = e.getText();
   }
   return value;
 }
  @Test
  public void WriteXml_LaunchedApplicationOperation_OK() throws JDOMException, IOException {
    LaunchedApplicationOperation ann =
        new LaunchedApplicationOperation("lMode", "lName", "application-a", "product-p", true);

    SAXBuilder saxBuilder = new SAXBuilder();
    StringReader sr =
        new StringReader(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<Recording>"
                + "   <AnotherExistingOperation></AnotherExistingOperation>"
                + "</Recording>");

    Document document = saxBuilder.build(sr);
    Element xRecording = document.getRootElement();
    Element xAnnotation = xRecording.getChild("LaunchedApplicationOperation");
    Assert.assertEquals(false, xAnnotation != null);

    ann.writeXML(xRecording);
    xAnnotation = xRecording.getChild("LaunchedApplicationOperation");
    Assert.assertEquals(true, xAnnotation != null);

    Attribute xDateTime = xAnnotation.getAttribute("dateTime");
    Assert.assertEquals(true, xDateTime != null);

    Attribute xMode = xAnnotation.getAttribute("mode");
    Assert.assertEquals(true, xMode != null);
    Assert.assertEquals("lMode", xMode.getValue());

    Element xName = xAnnotation.getChild("Name");
    Assert.assertEquals(true, xName != null);
    Assert.assertEquals("lName", xName.getText());

    Element xApplication = xAnnotation.getChild("Application");
    Assert.assertEquals(true, xApplication != null);
    Assert.assertEquals("application-a", xApplication.getText());

    Element xProduct = xAnnotation.getChild("Product");
    Assert.assertEquals(true, xProduct != null);
    Assert.assertEquals("product-p", xProduct.getText());

    Attribute t = xProduct.getAttribute("use");
    Assert.assertEquals(true, t != null);
    Assert.assertEquals(true, t.getBooleanValue());
  }
Exemplo n.º 13
0
 private void setSupportedProtocols() {
   protocols = new ArrayList<LocoAddress.Protocol>();
   if (_element.getChild("protocols") != null) {
     List<Element> protocolList = _element.getChild("protocols").getChildren("protocol");
     for (Element e : protocolList) {
       protocols.add(LocoAddress.Protocol.getByShortName(e.getText()));
     }
   }
 }
Exemplo n.º 14
0
  public static InstanceNotFoundException fromInstanceNotFoundExceptionXml(InputStream ex)
      throws ParsingException {
    try {

      SAXBuilder builder = new SAXBuilder();
      Document document = builder.build(ex);
      Element rootElement = document.getRootElement();

      Element instanceId = rootElement.getChild("instanceId", XML_NS);
      Element instanceType = rootElement.getChild("instanceType", XML_NS);

      return new InstanceNotFoundException(instanceId.getText(), instanceType.getText());
    } catch (JDOMException | IOException e) {
      throw new ParsingException(e);
    } catch (Exception e) {
      throw new ParsingException(e);
    }
  }
  private void parseRoles(Element e, Namespace nsYawl) {

    // ... and roles
    for (Element eRole : e.getChildren("role", nsYawl)) {
      String role = eRole.getText();
      if (role.indexOf(',') > -1) addRoles(role);
      else addRole(role);
    }
  }
  private void parseParticipants(Element e, Namespace nsYawl) {

    // from the specified initial set, add all participants
    for (Element eParticipant : e.getChildren("participant", nsYawl)) {
      String participant = eParticipant.getText();
      if (participant.indexOf(',') > -1) addParticipantsByID(participant);
      else addParticipant(participant);
    }
  }
Exemplo n.º 17
0
  public Element getXml() {
    Element me = new Element("SoundEvent");
    me.setAttribute("name", name);
    me.setAttribute("label", me.getText());
    for (Trigger t : trigger_list.values()) {
      me.addContent(t.getXml());
    }

    return (me);
  }
Exemplo n.º 18
0
 private Person parsePerson(final String baseURI, final Element ePerson, final Locale locale) {
   final Person person = new Person();
   Element e = ePerson.getChild("name", getAtomNamespace());
   if (e != null) {
     person.setName(e.getText());
   }
   e = ePerson.getChild("uri", getAtomNamespace());
   if (e != null) {
     person.setUri(e.getText());
     if (isRelativeURI(e.getText())) {
       person.setUriResolved(resolveURI(baseURI, ePerson, e.getText()));
     }
   }
   e = ePerson.getChild("email", getAtomNamespace());
   if (e != null) {
     person.setEmail(e.getText());
   }
   person.setModules(parsePersonModules(ePerson, locale));
   return person;
 }
Exemplo n.º 19
0
 private Date parseDate(XPathExpression<Element> expression, Element element)
     throws ParseException {
   Element result = expression.evaluateFirst(element);
   if (result != null) {
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
     return dateFormat.parse(result.getText());
   } else {
     throw new IllegalArgumentException(
         "Could not evaluate [" + expression + "] on [" + element + "]");
   }
 }
Exemplo n.º 20
0
  /**
   * Lee el documento con la ruta xpath indicada
   *
   * @param doc Documento xml
   * @param ruta Ruta xpath
   */
  public static void xpath(Document doc, String ruta) {

    XPathExpression<Element> xpath = XPathFactory.instance().compile(ruta, Filters.element());
    List<Element> elemento = xpath.evaluate(doc);
    Iterator it = elemento.iterator();

    while (it.hasNext()) {
      Element at = (Element) it.next();
      System.out.println(at.getName() + ": " + at.getText());
    }
  }
  public Module parse(Element syndRoot) {
    boolean foundSomething = false;
    SyModule sm = new SyModuleImpl();

    Element e = syndRoot.getChild("updatePeriod", getDCNamespace());
    if (e != null) {
      foundSomething = true;
      sm.setUpdatePeriod(e.getText());
    }
    e = syndRoot.getChild("updateFrequency", getDCNamespace());
    if (e != null) {
      foundSomething = true;
      sm.setUpdateFrequency(Integer.parseInt(e.getText().trim()));
    }
    e = syndRoot.getChild("updateBase", getDCNamespace());
    if (e != null) {
      foundSomething = true;
      sm.setUpdateBase(DateParser.parseDate(e.getText()));
    }
    return (foundSomething) ? sm : null;
  }
Exemplo n.º 22
0
 private void addAttributeIfExists(Element elem, String name, Variable v, boolean isDoubleArray) {
   Element child = elem.getChild(name);
   if (child == null) return;
   if (isDoubleArray) {
     List<Element> vElems = child.getChildren();
     List<Double> values = new ArrayList<>();
     for (Element ve : vElems) {
       String valueS = ve.getText().trim();
       try {
         values.add(Double.parseDouble(valueS));
       } catch (NumberFormatException e) {
       }
     }
     Attribute att = new Attribute(name, values);
     v.addAttribute(att);
   } else {
     String value = child.getText().trim();
     Attribute att = new Attribute(name, value);
     v.addAttribute(att);
   }
 }
Exemplo n.º 23
0
  private static boolean comparerObjet(Element triplet1, Element triplet2) {
    Element uri1 = triplet1.getChild("uri");
    Element uri2 = triplet2.getChild("uri");
    Element literal1 = triplet1.getChild("literal");
    Element literal2 = triplet1.getChild("literal");
    if ((uri1 == null && uri2 != null) || (uri2 == null && uri1 != null)) {
      return false;
    } else if (uri1 != null && uri2 != null) {
      String uri1text = uri1.getText();
      String uri2text = uri2.getText();
      if (!(uri1text.equals(uri2text))) {
        return false;
      }
    } else if (literal1 != null && literal2 != null) {
      String lang1 = literal1.getAttributeValue("lang", Namespace.XML_NAMESPACE);
      String lang2 = literal2.getAttributeValue("lang", Namespace.XML_NAMESPACE);
      String datatype1 = literal1.getAttributeValue("datatype");
      String datatype2 = literal2.getAttributeValue("datatype");
      String literal1Text = literal1.getText();
      String literal2Text = literal2.getText();

      if (lang1 != null && lang2 != null) {

        if (!lang1.equals(lang2)) {
          return false;
        } else if (!literal1Text.equals(literal2Text)) {

          return false;
        }
      } else if (datatype1 != null && datatype2 != null) {
        if (!datatype1.equals(datatype2)) {
          return false;
        } else if (!literal1Text.equals(literal2Text)) {
          return false;
        }
      }
    }
    return true;
  }
Exemplo n.º 24
0
 private void operatorsToIdentifiers(final Element ancestor, final Set<String> identifiers) {
   assert ancestor != null && identifiers != null;
   final List<Element> toReplace = new ArrayList<Element>();
   for (Element element : ancestor.getDescendants(new ElementFilter(OPERATOR, MATHMLNS))) {
     if (identifiers.contains(element.getTextTrim())) {
       toReplace.add(element);
     }
   }
   for (Element element : toReplace) {
     LOGGER.log(Level.FINE, "Creating an identifier from {0}", element.getText());
     replaceElement(element, IDENTIFIER);
   }
 }
Exemplo n.º 25
0
 public RTerrain(Element e, String... path) {
   super(e.getAttributeValue("id"), path);
   color = e.getAttributeValue("color");
   text = e.getAttributeValue("char");
   description = e.getText();
   String mov = e.getAttributeValue("mod");
   if (mov != null) {
     modifier = Modifier.valueOf(mov.toUpperCase());
   }
   String mod = e.getAttributeValue("sub");
   if (mod != null) {
     type = Subtype.valueOf(mod.toUpperCase());
   }
 }
Exemplo n.º 26
0
 private void replaceIdentifiers(final Element ancestor, final Set<String> operators) {
   assert ancestor != null && operators != null;
   final List<Element> toReplace = new ArrayList<Element>();
   for (Element element : ancestor.getDescendants(new ElementFilter(IDENTIFIER, MATHMLNS))) {
     // TODO: control whole ranges of symbols rather than listed ones
     if (operators.contains(element.getTextTrim())) {
       toReplace.add(element);
     }
   }
   for (Element element : toReplace) {
     LOGGER.log(Level.FINE, "Creating an operator from {0}", element.getText());
     replaceElement(element, OPERATOR);
   }
 }
Exemplo n.º 27
0
    public HashSaltAnswer fromXml(
        final Element element, final boolean caseInsensitive, final String challengeText) {
      final String answerValue = element.getText();

      if (answerValue == null || answerValue.length() < 1) {
        throw new IllegalArgumentException("missing answer value");
      }

      final String hashString;
      final VERSION version;
      if (answerValue.contains(VERSION_SEPARATOR)) {
        final String[] s = answerValue.split(VERSION_SEPARATOR);
        try {
          version = VERSION.valueOf(s[0]);
        } catch (IllegalArgumentException e) {
          throw new IllegalArgumentException("unsupported version type " + s[0]);
        }
        hashString = s[1];
      } else {
        version = VERSION.A;
        hashString = answerValue;
      }

      final String salt =
          element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT) == null
              ? ""
              : element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT).getValue();
      final String hashCount =
          element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT) == null
              ? "1"
              : element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT).getValue();
      int saltCount = 1;
      try {
        saltCount = Integer.parseInt(hashCount);
      } catch (NumberFormatException e) {
        /* noop */
      }
      final String formatStr =
          element.getAttributeValue(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT) == null
              ? ""
              : element.getAttributeValue(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT);
      final FormatType formatType;
      try {
        formatType = FormatType.valueOf(formatStr);
      } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
            "unknown content format specified in xml format value: '" + formatStr + "'");
      }
      return new HashSaltAnswer(hashString, salt, saltCount, caseInsensitive, formatType, version);
    }
  @Test
  public void WriteXml_UpdatedFileOperation_OK() throws JDOMException, IOException {
    UpdatedFileOperation ann = new UpdatedFileOperation();

    SAXBuilder saxBuilder = new SAXBuilder();
    StringReader sr =
        new StringReader(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<Recording>"
                + "   <AnotherExistingOperation></AnotherExistingOperation>"
                + "</Recording>");

    Document document = saxBuilder.build(sr);
    Element xRecording = document.getRootElement();
    Element xAnnotation = xRecording.getChild("UpdatedFileOperation");
    Assert.assertEquals(false, xAnnotation != null);

    ann.writeXML(xRecording);
    xAnnotation = xRecording.getChild("UpdatedFileOperation");
    Assert.assertEquals(true, xAnnotation != null);

    Attribute xDateTime = xAnnotation.getAttribute("dateTime");
    Assert.assertEquals(true, xDateTime != null);

    Element xPath = xAnnotation.getChild("Path");
    Assert.assertEquals(true, xPath != null);
    Assert.assertEquals("", xPath.getText());

    Element xRevision = xAnnotation.getChild("Revision");
    Assert.assertEquals(true, xRevision != null);
    Assert.assertEquals("", xRevision.getText());

    Element xCommittedRevision = xAnnotation.getChild("CommittedRevision");
    Assert.assertEquals(true, xCommittedRevision != null);
    Assert.assertEquals("", xCommittedRevision.getText());
  }
Exemplo n.º 29
0
 private Element assignRecordsToBatchProcessPart(
     Element batchProcessElement, int quantityRecordsToAssign, List<String> recordsBatchPart) {
   List<Element> recordsElements = getRecordsElements(batchProcessElement);
   int toIndex =
       recordsElements.size() >= quantityRecordsToAssign
           ? quantityRecordsToAssign
           : recordsElements.size();
   recordsElements = recordsElements.subList(0, toIndex);
   Element recordsBatchPartElement = new Element(RECORDS);
   for (Element recordElement : recordsElements) {
     recordElement.detach();
     recordsBatchPartElement.addContent(recordElement.detach());
     recordsBatchPart.add(recordElement.getText());
   }
   return recordsBatchPartElement;
 }
Exemplo n.º 30
0
  /**
   * Load, starting with the memoryComboIcon element, then all the value-icon pairs
   *
   * @param element Top level Element to unpack.
   * @param o an Editor as an Object
   */
  public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;

    Element elem = element.getChild("itemList");
    List<Element> list = elem.getChildren("item");
    String[] items = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
      Element e = list.get(i);
      String item = e.getText();
      //            int idx = 0;
      //            try {
      //                idx = e.getAttribute("index").getIntValue();
      //            } catch ( org.jdom2.DataConversionException ex) {
      //                log.error("failed to convert ComboBoxIcon index attribute");
      //                idx = i;
      //            }
      items[i] = item;
    }

    MemoryComboIcon l = new MemoryComboIcon(p, items);

    loadTextInfo(l, element);
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
      log.error("incorrect information for a memory location; must use memory name");
      p.loadFailed();
      return;
    } else {
      name = attr.getValue();
    }

    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);

    if (m != null) {
      l.setMemory(name);
    } else {
      log.error("Memory named '" + attr.getValue() + "' not found.");
      p.loadFailed();
      return;
    }

    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
  }