Esempio n. 1
0
  public static String setGraphXml(String sourceNode, Map<String, String> map, String xml)
      throws IOException {
    Document doc = Dom4jUtil.loadXml(xml);
    Element root = doc.getRootElement();

    Element node = (Element) root.selectSingleNode("//bg:Gateway[@id='" + sourceNode + "']");
    Element portsEl = node.element("ports");
    List portList = portsEl.elements();

    for (int i = 0; i < portList.size(); i++) {
      Element portEl = (Element) portList.get(i);
      if ((portEl.attribute("x") != null) || (portEl.attribute("y") != null)) {
        String id = portEl.attributeValue("id");
        Element outNode =
            (Element) root.selectSingleNode("//bg:SequenceFlow[@startPort='" + id + "']");
        if (outNode != null) {
          String outPort = outNode.attributeValue("endPort");
          Element tmpNode = (Element) root.selectSingleNode("//ciied:Port[@id='" + outPort + "']");
          Element taskNode = tmpNode.getParent().getParent();
          String taskId = taskNode.attributeValue("id");

          Element conditionEl = outNode.element("condition");
          if (conditionEl != null) {
            outNode.remove(conditionEl);
          }
          if (map.containsKey(taskId)) {
            String condition = (String) map.get(taskId);
            Element elAdd = outNode.addElement("condition");
            elAdd.addText(condition);
          }
        }
      }
    }
    return doc.asXML();
  }
Esempio n. 2
0
 /** Method calcFeedBack. */
 private void calcFeedBack() {
   if (feedbacktesting) {
     List<?> el_ofts = el_assessment.selectNodes("outcomes_processing/outcomes_feedback_test");
     feedbackavailable = false;
     for (Iterator<?> it_oft = el_ofts.iterator(); it_oft.hasNext(); ) {
       Element el_oft = (Element) it_oft.next();
       // <!ELEMENT outcomes_feedback_test (test_variable , displayfeedback+)>
       Element el_testvar = (Element) el_oft.selectSingleNode("test_variable");
       // must exist: dtd
       // <!ELEMENT test_variable (variable_test | and_test | or_test |
       // not_test)>
       Element el_varandornot =
           (Element) el_testvar.selectSingleNode("variable_test|and_test|or_test|not_test");
       String elname = el_varandornot.getName();
       ScoreBooleanEvaluable sbe = QTIHelper.getSectionBooleanEvaluableInstance(elname);
       float totalscore = getScore();
       boolean fulfilled = sbe.eval(el_varandornot, totalscore);
       if (fulfilled) {
         // get feedback
         Element el_displayfeedback = (Element) el_oft.selectSingleNode("displayfeedback");
         String linkRefId = el_displayfeedback.attributeValue("linkrefid");
         // must exist (dtd)
         // ignore feedbacktype, since we section or assess feedback only
         // accepts material, no hints or solutions
         Element el_resolved =
             (Element)
                 el_assessment.selectSingleNode(".//assessfeedback[@ident='" + linkRefId + "']");
         getOutput().setEl_response(new AssessFeedback(el_resolved));
         // give the whole assessmentfeedback to render
         feedbackavailable = true;
       }
     }
   }
 }
  public void testWithoutItemsEnumParentWithExplicitLabelsAndValues() throws Exception {
    BeanWithEnum testBean = new BeanWithEnum();
    testBean.setTestEnum(TestEnum.VALUE_2);
    getPageContext().getRequest().setAttribute("testBean", testBean);

    this.selectTag.setPath("testBean.testEnum");
    this.tag.setItemLabel("enumLabel");
    this.tag.setItemValue("enumValue");

    this.selectTag.doStartTag();
    int result = this.tag.doStartTag();
    assertEquals(BodyTag.SKIP_BODY, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
    this.selectTag.doEndTag();

    String output = getWriter().toString();
    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();

    assertEquals(2, rootElement.elements().size());
    Node value1 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_1']");
    Node value2 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_2']");
    assertEquals("Label: VALUE_1", value1.getText());
    assertEquals("Label: VALUE_2", value2.getText());
    assertEquals(value2, rootElement.selectSingleNode("option[@selected]"));
  }
  public void testWithMultiList() throws Exception {
    List list = new ArrayList();
    list.add(Country.COUNTRY_UK);
    list.add(Country.COUNTRY_AT);
    this.bean.setSomeList(list);

    this.tag.setPath("someList");
    this.tag.setItems("${countries}");
    this.tag.setItemValue("isoCode");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);

    String output = getWriter().toString();
    output = "<doc>" + output + "</doc>";

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();
    assertEquals(2, rootElement.elements().size());

    Element selectElement = rootElement.element("select");
    assertEquals("select", selectElement.getName());
    assertEquals("someList", selectElement.attribute("name").getValue());

    List children = selectElement.elements();
    assertEquals("Incorrect number of children", 4, children.size());

    String hdivValue = this.confidentiality ? "3" : "UK";
    Element e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']");
    assertEquals("UK node not selected", "selected", e.attribute("selected").getValue());

    hdivValue = this.confidentiality ? "1" : "AT";
    e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']");
    assertEquals("AT node not selected", "selected", e.attribute("selected").getValue());
  }
  public void testWithMultiMap() throws Exception {
    Map someMap = new HashMap();
    someMap.put("M", "Male");
    someMap.put("F", "Female");
    this.bean.setSomeMap(someMap);

    this.tag.setPath("someMap");
    this.tag.setItems("${sexes}");

    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);

    String output = getWriter().toString();
    output = "<doc>" + output + "</doc>";

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();
    assertEquals(2, rootElement.elements().size());

    Element selectElement = rootElement.element("select");
    assertEquals("select", selectElement.getName());
    assertEquals("someMap", selectElement.attribute("name").getValue());

    List children = selectElement.elements();
    assertEquals("Incorrect number of children", 2, children.size());

    String hdivValue = this.confidentiality ? "1" : "M";
    Element e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']");
    assertEquals("M node not selected", "selected", e.attribute("selected").getValue());

    hdivValue = this.confidentiality ? "2" : "F";
    e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']");
    assertEquals("F node not selected", "selected", e.attribute("selected").getValue());
  }
  public void testWithIntegerArray() throws Exception {
    this.tag.setPath("someIntegerArray");
    Integer[] array = new Integer[50];
    for (int i = 0; i < array.length; i++) {
      array[i] = new Integer(i);
    }
    this.tag.setItems(array);
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);

    String output = getWriter().toString();
    output = "<doc>" + output + "</doc>";

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();
    assertEquals(2, rootElement.elements().size());

    Element selectElement = rootElement.element("select");
    assertEquals("select", selectElement.getName());
    assertEquals("someIntegerArray", selectElement.attribute("name").getValue());

    List children = selectElement.elements();
    assertEquals("Incorrect number of children", array.length, children.size());

    Element e = (Element) selectElement.selectSingleNode("option[text() = '12']");
    assertEquals("'12' node not selected", "selected", e.attribute("selected").getValue());

    e = (Element) selectElement.selectSingleNode("option[text() = '34']");
    assertEquals("'34' node not selected", "selected", e.attribute("selected").getValue());
  }
Esempio n. 7
0
 @Override
 protected TreeNode createFromXmlElement(TreeNode parent, Element element) {
   Find find = new Find();
   Element methodElement = (Element) element.selectSingleNode("method");
   find.setMethod(getMethod(methodElement.getText()));
   Element valueElement = (Element) element.selectSingleNode("value");
   find.setValue(valueElement.getText());
   return find;
 }
 public static boolean accepts(Element element) {
   return ActionDefinition.accepts(element)
       && hasComponentName(element, COMPONENT_NAME)
       && ((element.selectSingleNode(
                   ActionSequenceDocument.COMPONENT_DEF_NAME + "/" + QUERY_ELEMENT)
               != null) //$NON-NLS-1$
           || (element.selectSingleNode(
                   ActionSequenceDocument.ACTION_INPUTS_NAME + "/" + QUERY_ELEMENT)
               != null)); //$NON-NLS-1$
 }
Esempio n. 9
0
  public ColumnDefinition(final Element p) {

    this();

    setName(p.selectSingleNode("Name").getText());

    if (p.getName().equals("CalculatedColumn")) {
      setType(TYPE.CALCULATED_COLUMN);
      setFormula(p.selectSingleNode("Formula").getText());
    } else {
      setType(TYPE.COLUMN);
      setIndex(Integer.parseInt(p.attributeValue("idx")));
    }
  }
  public void testWithCollection() throws Exception {
    getPageContext()
        .setAttribute(
            SelectTag.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.country", false));

    this.tag.setItems("${countries}");
    this.tag.setItemValue("isoCode");
    this.tag.setItemLabel("name");
    this.tag.setId("myOption");
    this.tag.setCssClass("myClass");
    this.tag.setOnclick("CLICK");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();
    output = "<doc>" + output + "</doc>";

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();

    List children = rootElement.elements();
    assertEquals("Incorrect number of children", 4, children.size());

    Element element = (Element) rootElement.selectSingleNode("option[@value = 'UK']");
    assertEquals("UK node not selected", "selected", element.attribute("selected").getValue());
    assertEquals("myOption3", element.attribute("id").getValue());
    assertEquals("myClass", element.attribute("class").getValue());
    assertEquals("CLICK", element.attribute("onclick").getValue());
  }
Esempio n. 11
0
  @Override
  public ResultDTO executeCommand(
      String screenName,
      String querynodeXpath,
      JSONObject jsonRecord,
      InputDTO inputDTO,
      ResultDTO resultDTO) {
    ResultDTO resDTO = new ResultDTO();
    try {
      Element rootXml = ScreenMapRepo.findMapXMLRoot(screenName);
      Element processorElm =
          (Element) rootXml.selectSingleNode("/root/screen/bl/" + querynodeXpath + " ");
      String methodName = processorElm.attributeValue("method");

      if ("testMethod1".equals(methodName)) {
        testMethod1();
        System.out.println(ServletActionContext.getContext().getSession());
        System.out.println(
            "Session var retreived:"
                + ServletActionContext.getContext().getSession().get("mysessionkey"));
      } else {
        System.out.println("ProgramSetup BL methodname is not defined");
      }

      List<String> errors = new ArrayList<String>();
      errors.add("business.logic.unimplemented");
      resDTO.setMessages(errors);
    } catch (FrontendException e) {
      resDTO.addError("error.accessxml");
    }
    return resDTO;
  }
Esempio n. 12
0
 @Override
 protected TreeNode createFromXmlElement(TreeNode parent, Element element) {
   Class classs = new Class();
   Element pathElement = (Element) element.selectSingleNode("filePath");
   classs.setClassFilePath(pathElement.getText());
   return classs;
 }
  /**
   * Returns the Clearspace username of the user by id.
   *
   * @param id ID to retrieve Username of.
   * @return The username of the user in Clearspace.
   * @throws org.jivesoftware.openfire.user.UserNotFoundException If the user was not found.
   */
  protected String getUsernameByID(Long id) throws UserNotFoundException {
    // Checks if it is in the cache
    if (usernameCache.containsKey(id)) {
      return usernameCache.get(id);
    }

    // Gets the user's ID from Clearspace
    try {
      String path = ClearspaceUserProvider.USER_URL_PREFIX + "usersByID/" + id;
      Element element =
          executeRequest(org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET, path);

      String username =
          WSUtils.getElementText(
              element.selectSingleNode("return"), "username"); // TODO: is this right?

      // Escape the username so that it can be used as a JID.
      username = JID.escapeNode(username);

      usernameCache.put(id, username);

      return username;
    } catch (UserNotFoundException unfe) {
      // It is a supported exception, throw it again
      throw unfe;
    } catch (Exception e) {
      // It is not a supported exception, wrap it into a UserNotFoundException
      throw new UserNotFoundException("Unexpected error", e);
    }
  }
Esempio n. 14
0
  /**
   * 设置配置项属性值
   *
   * @param id 字段ID
   * @param value 字段值
   * @param operName 操作人
   */
  protected void setAttribute(String id, String value, String operName) {

    Element el = (Element) this.xmlDoc.getRootElement().selectSingleNode("./fields");
    if (el == null) {
      el = this.xmlDoc.getRootElement().addElement("fields");
    }
    String oldVal = null;
    String newVal = (value == null) ? "" : value;
    Element el2 = (Element) el.selectSingleNode("./field[@id='" + id + "']");
    if (el2 == null) {
      el2 = el.addElement("field");
      el2.addAttribute("id", id);
    } else {
      oldVal = el2.getText();
    }
    if (newVal.equals(oldVal)) return;
    el2.setText(newVal);
    this.attr.put(id, newVal);
    FieldInfo field = FieldManager.getFieldById("ITSM", id);
    if (field != null) {
      if (oldVal != null) {
        if (!field.isEncrypt()) oldVal = field.getHtmlCode(oldVal);
      }
      if (!field.isEncrypt()) newVal = field.getHtmlCode(newVal);
    }
    addHistory(id, oldVal, newVal, operName);
  }
Esempio n. 15
0
  /**
   * @param componentDefinition
   * @param props
   */
  private static void updateComponent(final Element componentDefinition, final HashMap props) {
    Iterator iter = props.keySet().iterator();

    while (iter.hasNext()) {
      Object key = iter.next();
      Node node = componentDefinition.selectSingleNode(key.toString());
      if (node == null) {
        node = componentDefinition.addElement(key.toString());
      }
      if (PivotViewComponent.OPTIONS.equals(node.getName())) {
        List optionsList = (List) props.get(key);
        Iterator optsIter = optionsList.iterator();
        while (optsIter.hasNext()) {
          String anOption = optsIter.next().toString();
          Node anOptionNode = node.selectSingleNode(anOption);
          if (anOptionNode == null) {
            ((Element) node).addElement(anOption);
          }
        }
      } else {
        Object value = props.get(key);
        if (value != null) {
          // remove existing text
          node.setText(""); // $NON-NLS-1$
          ((Element) node).addCDATA(value.toString());
        }
      }
    }
    // the property "mdx" is no longer being put in the hashmap. So,
    // query will be passed properly now.
  }
Esempio n. 16
0
  private void initSections(Element assessment, Switches sw) {
    sectionContexts = new ArrayList<SectionContext>(2);

    // <!ELEMENT sectionref (#PCDATA)>
    // <!ATTLIST sectionref %I_LinkRefId; >
    List<?> sections = assessment.selectNodes("section|sectionref");

    for (Iterator<?> iter = sections.iterator(); iter.hasNext(); ) {
      Element el_section = (Element) iter.next();

      // resolve sectionref into the correct sections
      if (el_section.getName().equals("sectionref")) {
        String linkRefId = el_section.attributeValue("linkrefid");
        el_section = (Element) el_section.selectSingleNode("//section[@ident='" + linkRefId + "']");
        if (el_section == null) {
          throw new RuntimeException(
              "sectionref with ref '" + linkRefId + "' could not be resolved");
        }
      }

      SectionContext sc = new SectionContext();
      sc.setUp(assessInstance, el_section, sw);
      sectionContexts.add(sc);
    }
  }
 /**
  * @方法功能描述 : 查询没有子节点的节点,使用xpath方式 @方法名:getSingleNode
  *
  * @param parent
  * @param nodeNodeName
  * @return @参数描述 : 父节点,子节点名称 @返回类型:Node
  */
 public static Node getSingleNode(Element parent, String nodeNodeName) {
   nodeNodeName = nodeNodeName.trim();
   String xpath = "//";
   if (parent == null) return null;
   if (nodeNodeName == null || nodeNodeName.equals("")) return null;
   xpath += nodeNodeName;
   Node kid = parent.selectSingleNode(xpath);
   return kid;
 }
 private static Object getBeanById(Element e) throws Exception {
   Object object = null;
   Node node = e.selectSingleNode("//id");
   log.debug("没有找到属性" + e.getName() + "的id");
   if (node != null) {
     Integer id = Integer.parseInt(node.getText());
     // object =  shiftService.getObjectById(Class.forName(domain_package_dot+e.getName()),id);
   }
   return object;
 }
Esempio n. 19
0
 /**
  * 设置配置项的值并保存
  *
  * @param fileName 文件名
  * @param path 路径
  * @param value 值
  * @throws Exception 异常
  */
 public static void setStringValue(String fileName, String path, String value) throws Exception {
   Element root = getRoot(fileName);
   if (root == null) {
     return;
   }
   Element node = (Element) root.selectSingleNode(path);
   if (node == null) {
     return;
   }
   node.setText(value);
   writeBack(fileName);
 }
Esempio n. 20
0
 /**
  * 读取字符配置值
  *
  * @param fileName 文件名
  * @param path 路径
  * @param defaultValue 默认值
  * @return 结果
  */
 public static String getStringValue(String fileName, String path, String defaultValue) {
   Element root = getRoot(fileName);
   if (root == null) {
     return defaultValue;
   }
   Element node = (Element) root.selectSingleNode(path);
   if (node == null) {
     return defaultValue;
   }
   String result = node.getText();
   return result;
 }
Esempio n. 21
0
 /**
  * 读取整形配置值
  *
  * @param fileName 文件名
  * @param path 路径
  * @param defaultValue 默认值
  * @return 结果
  */
 public static int getIntValue(String fileName, String path, int defaultValue) {
   Element root = getRoot(fileName);
   if (root == null) {
     return defaultValue;
   }
   Element node = (Element) root.selectSingleNode(path);
   if (node == null) {
     return defaultValue;
   }
   String result = node.getText();
   return Integer.parseInt(result);
 }
Esempio n. 22
0
 /**
  * 读取浮点配置值
  *
  * @param fileName 文件名
  * @param path 路径
  * @param defaultValue 默认值
  * @return 结果
  */
 public static double getDoubleValue(String fileName, String path, double defaultValue) {
   Element root = getRoot(fileName);
   if (root == null) {
     return defaultValue;
   }
   Element node = (Element) root.selectSingleNode(path);
   if (node == null) {
     return defaultValue;
   }
   String result = node.getText();
   return Double.parseDouble(result);
 }
Esempio n. 23
0
 public static String selectTextValue(Element elem, String xpath, String def, boolean trim) {
   Node node = elem.selectSingleNode(xpath);
   if (node == null) {
     return def;
   } else {
     String val = node.getText();
     if (trim) {
       val = val.trim();
     }
     return val;
   }
 }
Esempio n. 24
0
  public String selectList(
      String screenName,
      String panelname,
      String querynode,
      JSONObject jsonObject,
      InputDTO jsonInput,
      ResultDTO prevResultDTO) {
    String parsedquery = "";
    try {
      String xmlconfigfile = ScreenMapRepo.findMapXMLPath(screenName);
      org.dom4j.Document document1 = new SAXReader().read(xmlconfigfile);
      org.dom4j.Element root = document1.getRootElement();
      Node crudnode = root.selectSingleNode("//crud");
      Node node = crudnode.selectSingleNode(querynode);
      if (node == null) throw new Exception("<" + querynode + "> node not defined");

      String outstack = ((Element) node).attributeValue("outstack");
      panelname = outstack;

      String updatequery = "";
      updatequery += node.getText();

      List<Element> nodeList = crudnode.selectNodes("../fields/field/*");
      logger.debug("fields size:" + nodeList.size());
      HashMap<String, DataType> hmfielddbtype = new HashMap<String, PrepstmtDTO.DataType>();
      QueryParser.populateFieldDBType(nodeList, hmfielddbtype);

      /*Pattern pattern  = Pattern.compile(":(\\w*)",Pattern.DOTALL|Pattern.MULTILINE);
      Matcher m = pattern.matcher(updatequery);
      while(m.find()){
      	String val = "";
      	logger.debug(m.group(0)+ " "+ m.group(1));
      	if(jsonObject.has(m.group(1))){
      		val = jsonObject.getString(m.group(1));
      		updatequery = updatequery.replaceAll(":"+m.group(1), val);
      	}
      }*/
      // SET
      List<Element> primarykeys = crudnode.selectNodes("../fields/field/*[@primarykey]");

      PrepstmtDTOArray arparam = new PrepstmtDTOArray();
      parsedquery =
          QueryParser.parseQuery(
              updatequery, panelname, jsonObject, arparam, hmfielddbtype, jsonInput, prevResultDTO);

      logger.debug(
          "UPDATE query:" + parsedquery + "\n Expanded prep:" + arparam.toString(parsedquery));
    } catch (Exception e) {
      logger.debug("Exception caught in InsertData", e);
    }
    return parsedquery;
  }
  public void testWithCollectionAndCustomEditor() throws Exception {
    PropertyEditor propertyEditor = new SimpleFloatEditor();

    TestBean target = new TestBean();
    target.setMyFloat(new Float("12.34"));

    BeanPropertyBindingResult errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
    errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor);
    exposeBindingResult(errors);

    getPageContext()
        .setAttribute(
            SelectTag.LIST_VALUE_PAGE_ATTRIBUTE,
            new BindStatus(getRequestContext(), "testBean.myFloat", false));

    this.tag.setItems("${floats}");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
    String output = getOutput();
    output = "<doc>" + output + "</doc>";

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();

    List children = rootElement.elements();
    assertEquals("Incorrect number of children", 6, children.size());

    Element element = (Element) rootElement.selectSingleNode("option[text() = '12.34f']");
    assertNotNull("Option node should not be null", element);
    assertEquals("12.34 node not selected", "selected", element.attribute("selected").getValue());
    assertNull("No id rendered", element.attribute("id"));

    element = (Element) rootElement.selectSingleNode("option[text() = '12.35f']");
    assertNotNull("Option node should not be null", element);
    assertNull("12.35 node incorrectly selected", element.attribute("selected"));
    assertNull("No id rendered", element.attribute("id"));
  }
Esempio n. 26
0
 private void createBundleForExternalMission() {
   // TODO: This method should probably go into a specific subclass of
   // Mission which encapsulates the specifics of ExternalMissions.
   Element parametersElement = (Element) xmlMissionNode.selectSingleNode("parameters");
   if (parametersElement != null) {
     Map<String, String> arguments = XMLUtilities.extractParameters(parametersElement);
     if (bundleForExternalMission == null) bundleForExternalMission = new Bundle();
     Set<String> keys = arguments.keySet();
     for (Iterator<String> iterator = keys.iterator(); iterator.hasNext(); ) {
       String currentKey = iterator.next();
       bundleForExternalMission.putString(currentKey, arguments.get(currentKey));
     }
   }
 }
Esempio n. 27
0
  public void testWithFloatCustom() throws Exception {
    PropertyEditor propertyEditor = new SimpleFloatEditor();
    BeanPropertyBindingResult errors = new BeanPropertyBindingResult(getTestBean(), COMMAND_NAME);
    errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor);
    exposeBindingResult(errors);

    this.tag.setPath("myFloat");

    Float[] array =
        new Float[] {
          new Float("12.30"), new Float("12.32"), new Float("12.34"), new Float("12.36"),
          new Float("12.38"), new Float("12.40"), new Float("12.42"), new Float("12.44"),
          new Float("12.46"), new Float("12.48")
        };

    this.tag.setItems(array);
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);

    String output = getWriter().toString();
    assertTrue(output.startsWith("<select "));
    assertTrue(output.endsWith("</select>"));

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();
    assertEquals("select", rootElement.getName());
    assertEquals("myFloat", rootElement.attribute("name").getValue());
    List children = rootElement.elements();
    assertEquals("Incorrect number of children", array.length, children.size());

    Element e = (Element) rootElement.selectSingleNode("option[text() = '12.34f']");
    assertEquals("'12.34' node not selected", "selected", e.attribute("selected").getValue());

    e = (Element) rootElement.selectSingleNode("option[text() = '12.32f']");
    assertNull("'12.32' node incorrectly selected", e.attribute("selected"));
  }
Esempio n. 28
0
 public String extractTimeLimitFromDocument() {
   if (isNullDocument()) {
     return "";
   }
   String timeLimit = "-";
   final Element el_assess = (Element) document.selectSingleNode("questestinterop/assessment");
   final Element el_duration = (Element) el_assess.selectSingleNode("duration");
   if (el_duration != null) {
     final long dur = QTIHelper.parseISODuration(el_duration.getTextTrim());
     final long min = dur / 1024 / 60;
     final long sec = (dur - (min * 60 * 1024)) / 1024;
     timeLimit = "" + min + "' " + sec + "''";
   }
   return timeLimit;
 }
Esempio n. 29
0
 public String extractObjectivesFromDocument() {
   if (isNullDocument()) {
     return "";
   }
   String objectives = "-";
   final Element el_objectives =
       (Element) document.selectSingleNode("//questestinterop/assessment/objectives");
   if (el_objectives != null) {
     final Element el_mat = (Element) el_objectives.selectSingleNode("material/mattext");
     if (el_mat != null) {
       objectives = el_mat.getTextTrim();
     }
   }
   return objectives;
 }
Esempio n. 30
0
    protected ConfigSaveState updatePartial(String xmlPartial, final String md5) throws Exception {
      LOGGER.debug("[Config Save] Updating partial");
      org.dom4j.Document document = documentRoot();
      Element root = document.getRootElement();

      Element configElement = ((Element) root.selectSingleNode(getXpath()));
      List nodes = configElement.getParent().content();
      int index = nodes.indexOf(configElement);

      LOGGER.debug("[Config Save] Converting to object");
      Element newConfigElement = reader.read(new StringReader(xmlPartial)).getRootElement();
      nodes.set(index, newConfigElement);

      return saveConfig(document.asXML(), md5);
    }