private void loadTerminologyFromXML(String filename) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    InputStream input = this.getClass().getResourceAsStream(filename);
    try {
      Document doc = builder.build(input);
      Element root = doc.getRootElement();
      List codesets = root.getChildren("codeset");
      codeSetList.clear();
      groupList.clear();

      for (Iterator it = codesets.iterator(); it.hasNext(); ) {
        Element element = (Element) it.next();
        codeSetList.add(loadCodeSet(element));
      }

      List groups = root.getChildren("group");
      for (Iterator it = groups.iterator(); it.hasNext(); ) {
        Element element = (Element) it.next();
        groupList.add(loadGroup(element));
      }
    } finally {
      if (input != null) {
        input.close();
      }
    }
  }
  public void loadState(final Element element) {
    List groups = element.getChildren(GROUP_TAG);

    for (Object group : groups) {
      Element groupElement = (Element) group;
      String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR);

      final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupName);

      List projectsList = groupElement.getChildren(PROJECT_TAG);
      for (Object project : projectsList) {
        Element projectElement = (Element) project;
        String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
        String frameworks = projectElement.getAttributeValue(VALUES_ATTR);
        if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
          Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
          for (String key : StringUtil.split(frameworks, TOKENIZER)) {
            final UsageDescriptor descriptor = getUsageDescriptor(key);
            if (descriptor != null) frameworkDescriptors.add(descriptor);
          }
          getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors);
        }
      }
    }
  }
  @Override
  public void loadState(Element state) {
    final List<Element> abbreviations = state.getChildren("abbreviations");
    if (abbreviations != null && abbreviations.size() == 1) {
      final List<Element> actions = abbreviations.get(0).getChildren("action");
      if (actions != null && actions.size() > 0) {
        for (Element action : actions) {
          final String actionId = action.getAttributeValue("id");
          LinkedHashSet<String> values = myActionId2Abbreviations.get(actionId);
          if (values == null) {
            values = new LinkedHashSet<String>(1);
            myActionId2Abbreviations.put(actionId, values);
          }

          final List<Element> abbreviation = action.getChildren("abbreviation");
          if (abbreviation != null) {
            for (Element abbr : abbreviation) {
              final String abbrValue = abbr.getAttributeValue("name");
              if (abbrValue != null) {
                values.add(abbrValue);
              }
            }
          }
        }
      }
    }
  }
  /**
   * Fills a list with Privileges that reflect the input 'privileges' element. The 'privileges'
   * element has this format:
   *
   * <p><privileges> <group id="..."> <operation name="..."> ... </group> ... </privileges>
   *
   * <p>Operation names are: view, download, edit, etc... User defined operations are taken into
   * account.
   */
  private void addPrivileges(Element privil) throws BadInputEx {
    alPrivileges.clear();

    if (privil == null) return;

    for (Object o : privil.getChildren("group")) {
      Element group = (Element) o;
      String groupID = group.getAttributeValue("id");

      if (groupID == null) {
        throw new MissingParameterEx("attribute:id", group);
      }

      Privileges p = new Privileges(groupID);

      for (Object o1 : group.getChildren("operation")) {
        Element oper = (Element) o1;
        int op = getOperationId(oper);

        p.add(op);
      }

      alPrivileges.add(p);
    }
  }
  public ArrayList<RenderAbstracto> parseEntidad(ArrayList<String[]> campos) {
    ArrayList<RenderAbstracto> listaRenders = new ArrayList<RenderAbstracto>();

    try {
      Element raiz = doc.getRootElement();
      List clases = raiz.getChildren("class");

      if (!clases.isEmpty()) {
        Iterator it = clases.iterator();
        while (it.hasNext()) {
          Element e = (Element) it.next();

          // PARSE PROPERTIES ========================================
          List properties = e.getChildren("property");
          if (!properties.isEmpty()) {
            Iterator itpr = properties.iterator();
            while (itpr.hasNext()) {
              Element ep = (Element) itpr.next();
              listaRenders.add(createBasicRender(ep.getAttributeValue("type"), ep, campos));
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println("[ERROR]" + e.getMessage());
    }
    return listaRenders;
  }
Example #6
0
 private static void elementToSecurityConstraints(Element element, RetsConfig config) {
   if (element == null) {
     config.setSecurityConstraints(new ArrayList());
     return;
   }
   List securityConstraints = new ArrayList();
   List children = element.getChildren(GROUP_RULES);
   for (int i = 0; i < children.size(); i++) {
     Element child = (Element) children.get(i);
     String groupName = child.getAttributeValue(GROUP);
     GroupRules groupRules = new GroupRules(groupName);
     List grandChildren = child.getChildren();
     for (int j = 0; j < grandChildren.size(); j++) {
       Element grandChild = (Element) grandChildren.get(j);
       RuleDescription ruleDescription = new RuleDescription();
       if (grandChild.getName().equals(INCLUDE_RULE)) {
         ruleDescription.setType(RuleDescription.INCLUDE);
       } else if (grandChild.getName().equals(EXCLUDE_RULE)) {
         ruleDescription.setType(RuleDescription.EXCLUDE);
       } else {
         LOG.warn("Unknown rule" + grandChild.toString());
         continue;
       }
       ruleDescription.setResource(grandChild.getAttributeValue(RESOURCE));
       ruleDescription.setRetsClass(grandChild.getAttributeValue(CLASS));
       String systemNamesText = grandChild.getChildTextNormalize(SYSTEM_NAMES);
       String[] systemNamesArray = StringUtils.split(systemNamesText, " ");
       ruleDescription.setSystemNames(Arrays.asList(systemNamesArray));
       groupRules.addRule(ruleDescription);
     }
     securityConstraints.add(groupRules);
   }
   config.setSecurityConstraints(securityConstraints);
 }
 public void readExternalUtil(
     final Element element, final OptionsAndConfirmations optionsAndConfirmations)
     throws InvalidDataException {
   final Map<String, VcsShowOptionsSettingImpl> options = optionsAndConfirmations.getOptions();
   for (Element subElement : element.getChildren(OPTIONS_SETTING)) {
     final String id = subElement.getAttributeValue(ID_ATTRIBUTE);
     final String value = subElement.getAttributeValue(VALUE_ATTTIBUTE);
     if (id != null && value != null) {
       try {
         getOrCreateOption(options, id).setValue(Boolean.parseBoolean(value));
       } catch (Exception ignored) {
       }
     }
   }
   myReadValue.clear();
   for (Element subElement : element.getChildren(CONFIRMATIONS_SETTING)) {
     final String id = subElement.getAttributeValue(ID_ATTRIBUTE);
     final String value = subElement.getAttributeValue(VALUE_ATTTIBUTE);
     if (id != null && value != null) {
       try {
         myReadValue.put(id, VcsShowConfirmationOption.Value.fromString(value));
       } catch (Exception ignored) {
       }
     }
   }
 }
Example #8
0
  private String loadList(Element list) throws DataConversionException {
    pcgen.core.doomsdaybook.DDList dataList =
        new pcgen.core.doomsdaybook.DDList(
            allVars, list.getAttributeValue("title"), list.getAttributeValue("id"));
    java.util.List<?> elements = list.getChildren();

    for (final Object element : elements) {
      Element child = (Element) element;
      String elementName = child.getName();

      if (elementName.equals("VALUE")) {
        WeightedDataValue dv =
            new WeightedDataValue(child.getText(), child.getAttribute("weight").getIntValue());
        List<?> subElements = child.getChildren("SUBVALUE");

        for (final Object subElement1 : subElements) {
          Element subElement = (Element) subElement1;
          dv.addSubValue(subElement.getAttributeValue("type"), subElement.getText());
        }

        dataList.add(dv);
      }
    }

    allVars.addDataElement(dataList);

    return dataList.getId();
  }
Example #9
0
 /**
  * Include referred datasets into XML.
  *
  * @param resolvedXml : Job XML element.
  * @param conf : Job configuration
  * @throws CoordinatorJobException thrown if failed to include referred datasets into XML
  */
 @SuppressWarnings("unchecked")
 protected void includeDataSets(Element resolvedXml, Configuration conf)
     throws CoordinatorJobException {
   Element datasets = resolvedXml.getChild("datasets", resolvedXml.getNamespace());
   Element allDataSets = new Element("all_datasets", resolvedXml.getNamespace());
   List<String> dsList = new ArrayList<String>();
   if (datasets != null) {
     for (Element includeElem :
         (List<Element>) datasets.getChildren("include", datasets.getNamespace())) {
       String incDSFile = includeElem.getTextTrim();
       includeOneDSFile(incDSFile, dsList, allDataSets, datasets.getNamespace());
     }
     for (Element e : (List<Element>) datasets.getChildren("dataset", datasets.getNamespace())) {
       String dsName = e.getAttributeValue("name");
       if (dsList.contains(dsName)) { // Override with this DS
         // Remove old DS
         removeDataSet(allDataSets, dsName);
       } else {
         dsList.add(dsName);
       }
       allDataSets.addContent((Element) e.clone());
     }
   }
   insertDataSet(resolvedXml, allDataSets);
   resolvedXml.removeChild("datasets", resolvedXml.getNamespace());
 }
  @Override
  @SuppressWarnings({"HardCodedStringLiteral"})
  public void loadState(Element element) {
    Element entryPointsElement = element.getChild("entry_points");
    if (entryPointsElement != null) {
      final String version = entryPointsElement.getAttributeValue(VERSION_ATTR);
      if (!Comparing.strEqual(version, VERSION)) {
        convert(entryPointsElement, myPersistentEntryPoints);
      } else {
        List content = entryPointsElement.getChildren();
        for (final Object aContent : content) {
          Element entryElement = (Element) aContent;
          if (ENTRY_POINT_ATTR.equals(entryElement.getName())) {
            SmartRefElementPointerImpl entryPoint = new SmartRefElementPointerImpl(entryElement);
            myPersistentEntryPoints.put(entryPoint.getFQName(), entryPoint);
          }
        }
      }
    }
    try {
      ADDITIONAL_ANNOTATIONS.readExternal(element);
    } catch (Throwable ignored) {
    }

    getPatterns().clear();
    for (Element pattern : element.getChildren("pattern")) {
      final ClassPattern classPattern = new ClassPattern();
      XmlSerializer.deserializeInto(classPattern, pattern);
      getPatterns().add(classPattern);
    }
  }
  @NotNull
  public static TreeMap<String, Element> load(
      @NotNull Element rootElement,
      @Nullable PathMacroSubstitutor pathMacroSubstitutor,
      boolean intern) {
    if (pathMacroSubstitutor != null) {
      pathMacroSubstitutor.expandPaths(rootElement);
    }

    StringInterner interner = intern ? new StringInterner() : null;
    List<Element> children = rootElement.getChildren(COMPONENT);
    TreeMap<String, Element> map = new TreeMap<String, Element>();
    for (Element element : children) {
      String name = getComponentNameIfValid(element);
      if (name == null
          || !(element.getAttributes().size() > 1 || !element.getChildren().isEmpty())) {
        continue;
      }

      if (interner != null) {
        JDOMUtil.internElement(element, interner);
      }

      map.put(name, element);

      if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
        ((TrackingPathMacroSubstitutor) pathMacroSubstitutor)
            .addUnknownMacros(name, PathMacrosCollector.getMacroNames(element));
      }

      // remove only after "getMacroNames" - some PathMacroFilter requires element name attribute
      element.removeAttribute(NAME);
    }
    return map;
  }
  /**
   * @param args
   * @throws IOException
   * @throws FileNotFoundException
   * @throws JDOMException
   */
  public static void main(String[] args) throws FileNotFoundException, IOException, JDOMException {
    String xmlpath = "c:/catalog.xml";
    // 使用JDOM首先要指定使用什么解析器
    SAXBuilder builder = new SAXBuilder(false); // 这表示使用的是默认的解析器
    // 得到Document,以后要进行的所有操作都是对这个Document操作的
    Document doc = builder.build(xmlpath);
    // 得到根元素
    Element root = doc.getRootElement();
    // 得到元素(节点)的集合
    List bookslist = root.getChildren("books");
    // 轮循List集合
    for (Iterator iter = bookslist.iterator(); iter.hasNext(); ) {
      Element books = (Element) iter.next();
      List bookList = books.getChildren("book");
      for (Iterator it = bookList.iterator(); it.hasNext(); ) {
        Element book = (Element) it.next();
        // 取得元素的属性
        String level = book.getAttributeValue("level");
        System.out.println(level);
        // 取得元素的子元素(为最低层元素)的值 注意的是,必须确定book元素的名为“name”的子元素只有一个。
        String author = book.getChildTextTrim("author");
        System.out.println(author);
        // 改变元素(为最低层元素)的值;对Document的修改,并没有在实际的XML文档中进行修改
        book.getChild("author").setText("author_test");
      }
    }
    // 保存Document的修改到XML文件中
    // XMLOutputter outputter=new XMLOutputter();
    // outputter.output(doc,new FileOutputStream(xmlpath));

  }
Example #13
0
 public void readExternal(Element element) throws InvalidDataException {
   Element passwords = element.getChild(PASSWORDS);
   if (passwords != null) {
     for (Iterator eachPasswordElement = passwords.getChildren(PASSWORD).iterator();
         eachPasswordElement.hasNext(); ) {
       Element passElement = (Element) eachPasswordElement.next();
       String cvsRoot = passElement.getAttributeValue(CVSROOT_ATTR);
       String password = passElement.getAttributeValue(PASSWORD_ATTR);
       if ((cvsRoot != null) && (password != null))
         myCvsRootToStoringPasswordMap.put(
             cvsRoot, PServerPasswordScrambler.getInstance().unscramble(password));
     }
   }
   passwords = element.getChild(PPKPASSWORDS);
   if (passwords != null) {
     for (Iterator eachPasswordElement = passwords.getChildren(PASSWORD).iterator();
         eachPasswordElement.hasNext(); ) {
       Element passElement = (Element) eachPasswordElement.next();
       String cvsRoot = passElement.getAttributeValue(CVSROOT_ATTR);
       String password = passElement.getAttributeValue(PASSWORD_ATTR);
       if ((cvsRoot != null) && (password != null))
         myCvsRootToStoringPPKPasswordMap.put(
             cvsRoot, PServerPasswordScrambler.getInstance().unscramble(password));
     }
   }
 }
 public static GenerationDependencies fromXml(Element root) {
   String version = GenerationRootDependencies.getValue(root, ATTR_VERSION);
   if (version == null || !version.equals(Integer.toString(DEPENDENCIES_VERSION))) {
     /* regenerate all */
     return null;
   }
   Map<String, String> externalHashes = new HashMap<String, String>();
   for (Element e : ((List<Element>) root.getChildren(NODE_MODEL))) {
     String modelReference = GenerationRootDependencies.getValue(e, ATTR_MODEL_ID);
     String rootHash = GenerationRootDependencies.getValue(e, ATTR_HASH);
     if (modelReference != null) {
       externalHashes.put(modelReference, rootHash);
     }
   }
   List<GenerationRootDependencies> data = new ArrayList<GenerationRootDependencies>();
   for (Element e : ((List<Element>) root.getChildren(NODE_COMMON))) {
     data.add(GenerationRootDependencies.fromXml(e, true));
   }
   for (Element e : ((List<Element>) root.getChildren(NODE_ROOT))) {
     data.add(GenerationRootDependencies.fromXml(e, false));
   }
   String modelHash = GenerationRootDependencies.getValue(root, ATTR_MODEL_HASH);
   String paramsHash = GenerationRootDependencies.getValue(root, ATTR_PARAMS_HASH);
   if (externalHashes.isEmpty() && data.isEmpty()) {
     return new GenerationDependencies(modelHash, paramsHash);
   }
   return new GenerationDependencies(
       data,
       modelHash,
       paramsHash,
       externalHashes,
       Collections.<GenerationRootDependencies>emptyList(),
       0,
       0);
 }
Example #15
0
  @SuppressWarnings("unchecked")
  private Role parseRole(Element element) throws RESTLightClientException {
    Role role = new Role();

    role.setResourceURI(element.getChildText(RESOURCE_URI_ELEMENT));
    role.setId(element.getChildText(ROLE_ID_ELEMENT));
    role.setName(element.getChildText(ROLE_NAME_ELEMENT));
    role.setDescription(element.getChildText(ROLE_DESCRIPTION_ELEMENT));
    role.setSessionTimeout(Integer.parseInt(element.getChildText(ROLE_SESSION_TIMEOUT_ELEMENT)));

    Element subRoles = element.getChild(ROLE_ROLES_ELEMENT);

    if (subRoles != null) {
      for (Element subRole : (List<Element>) subRoles.getChildren(ROLE_ROLE_ELEMENT)) {
        role.getRoles().add(subRole.getValue());
      }
    }

    Element privileges = element.getChild(ROLE_PRIVILEGES_ELEMENT);

    if (privileges != null) {
      for (Element privilege : (List<Element>) privileges.getChildren(ROLE_PRIVILEGE_ELEMENT)) {
        role.getPrivileges().add(privilege.getValue());
      }
    }

    role.setUserManaged(
        element.getChildText(ROLE_USER_MANAGED_ELEMENT).equals("true") ? true : false);

    return role;
  }
  /** {@inheritDoc} */
  public void decodeXML(Element element) throws InvalidLLRPMessageException {
    List<Element> tempList = null;
    boolean atLeastOnce = false;
    Custom custom;

    Element temp = null;

    // child element are always in default LLRP namespace
    Namespace ns = Namespace.getNamespace(LLRPConstants.LLRPNAMESPACE);

    temp = element.getChild("I", ns);

    if (temp != null) {
      i = new C1G2TagInventoryStateAwareI(temp);
    }

    element.removeChild("I", ns);
    temp = element.getChild("S", ns);

    if (temp != null) {
      s = new C1G2TagInventoryStateAwareS(temp);
    }

    element.removeChild("S", ns);

    if (element.getChildren().size() > 0) {
      String message =
          "C1G2TagInventoryStateAwareSingulationAction has unknown element "
              + ((Element) element.getChildren().get(0)).getName();
      throw new InvalidLLRPMessageException(message);
    }
  }
 @SuppressWarnings("unchecked")
 protected final List<Element> getChildren(Element parent, String childName, Namespace namespace) {
   if (namespace == null) {
     return parent.getChildren(childName);
   } else {
     return parent.getChildren(childName, namespace);
   }
 }
Example #18
0
  /**
   * merge element into parent Simulates the Varien_Simplexml_Element::extendChild method
   *
   * @param element
   * @param parent
   * @param overwrite if true it will delete the original "element" from parent and use the new one
   *     (only if the original has no children)
   * @return
   */
  public static Element mergeXmlElement(Element element, Element parent, boolean overwrite) {

    if (element == null || parent == null) {
      return parent;
    }

    // detach parent
    // element = (Element)element.clone();
    element.detach();

    String sourceName = element.getName();
    // List<Element> sourceChildren = element.getChildren();
    // we need to create a new static list for avoiding a ConcurrentModificationException in the for
    // loop below
    List<Element> sourceChildren = new ArrayList(element.getChildren()); // static list

    //        Iterator itr = (currentElement.getChildren()).iterator();
    //        while(itr.hasNext()) {
    //            Element oneLevelDeep = (Element)itr.next();
    //            List twoLevelsDeep = oneLevelDeep.getChildren();
    //            // Do something with these children
    //        }

    Element original = parent.getChild(sourceName);
    // if element has no children
    if (sourceChildren.size() == 0) {

      if (original != null) {
        // if target already has children return without regard
        if (original.getChildren().size() > 0) {
          return parent;
        }
        // new element has no children, original exists without children too, and we are asking for
        // an overwrite
        if (overwrite) {
          // remove it only here (the new one is added later)
          parent.removeChild(sourceName);
        } else {
          return parent;
        }
      }

      parent.addContent(element);

    } else {
      if (original == null) {
        parent.addContent(element);
      } else {
        // we need to merge children
        for (Element child : sourceChildren) {
          Element newParent = original;
          mergeXmlElement(child, newParent, overwrite);
        }
      }
    }

    return parent;
  }
Example #19
0
  @Test
  public void testCreateFromUserWithBasicFieldValue_WithoutGivenRoot() {
    final Element returnedRootEl = creator.createUserInfoElement(userWithBasicFieldValue);

    assertEquals("block", returnedRootEl.getName());
    assertEquals(1, returnedRootEl.getChildren().size());
    assertEquals("prefix", ((Element) returnedRootEl.getChildren().get(0)).getName());
    assertEquals("user_prefix_value", ((Element) returnedRootEl.getChildren().get(0)).getValue());
  }
  private QueryResult gatherResultInfoForSelectQuery(
      String queryString, int queryNr, boolean sorted, Document doc, String[] rows) {
    Element root = doc.getRootElement();

    // Get head information
    Element child =
        root.getChild("head", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));

    // Get result rows (<head>)
    List headChildren =
        child.getChildren(
            "variable", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));

    Iterator it = headChildren.iterator();
    ArrayList<String> headList = new ArrayList<String>();
    while (it.hasNext()) {
      headList.add(((Element) it.next()).getAttributeValue("name"));
    }

    List resultChildren =
        root.getChild("results", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"))
            .getChildren(
                "result", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));
    int nrResults = resultChildren.size();

    QueryResult queryResult = new QueryResult(queryNr, queryString, nrResults, sorted, headList);

    it = resultChildren.iterator();
    while (it.hasNext()) {
      Element resultElement = (Element) it.next();
      String result = "";

      // get the row values and paste it together to one String
      for (int i = 0; i < rows.length; i++) {
        List bindings =
            resultElement.getChildren(
                "binding", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));
        String rowName = rows[i];
        for (int j = 0; j < bindings.size(); j++) {
          Element binding = (Element) bindings.get(j);
          if (binding.getAttributeValue("name").equals(rowName))
            if (result.equals(""))
              result +=
                  rowName + ": " + ((Element) binding.getChildren().get(0)).getTextNormalize();
            else
              result +=
                  "\n"
                      + rowName
                      + ": "
                      + ((Element) binding.getChildren().get(0)).getTextNormalize();
        }
      }

      queryResult.addResult(result);
    }
    return queryResult;
  }
Example #21
0
  @Test
  public void testDryRunPushDependencies() {
    try {
      CoordinatorJobBean job =
          addRecordToCoordJobTableForWaiting(
              "coord-job-for-action-input-check.xml", CoordinatorJob.Status.RUNNING, false, true);
      Path appPath = new Path(getFsTestCaseDir(), "coord");
      // actionXml only to check whether coord conf got resolved or not
      String actionXml = getCoordActionXml(appPath, "coord-action-for-action-input-check.xml");
      CoordinatorActionBean actionBean = createCoordinatorActionBean(job);

      String db = "default";
      String table = "tablename";
      String hcatDependency = getPushMissingDependencies(db, table);
      actionBean.setPushMissingDependencies(hcatDependency);

      Element eAction = createActionElement(actionXml);
      String newactionXml = CoordCommandUtils.dryRunCoord(eAction, actionBean);
      eAction = XmlUtils.parseXml(newactionXml);

      Element configElem =
          eAction
              .getChild("action", eAction.getNamespace())
              .getChild("workflow", eAction.getNamespace())
              .getChild("configuration", eAction.getNamespace());
      List<?> elementList = configElem.getChildren("property", configElem.getNamespace());
      Element e1 = (Element) elementList.get(0);
      Element e2 = (Element) elementList.get(1);
      // Make sure conf is not resolved as dependencies are not met
      assertEquals("${coord:dataIn('A')}", e1.getChild("value", e1.getNamespace()).getValue());
      assertEquals(
          "${coord:dataOut('LOCAL_A')}", e2.getChild("value", e2.getNamespace()).getValue());

      // Make the dependencies available
      populateTable(db, table);
      newactionXml = CoordCommandUtils.dryRunCoord(eAction, actionBean);

      eAction = XmlUtils.parseXml(newactionXml);
      configElem =
          eAction
              .getChild("action", eAction.getNamespace())
              .getChild("workflow", eAction.getNamespace())
              .getChild("configuration", eAction.getNamespace());
      elementList = configElem.getChildren("property", configElem.getNamespace());
      e1 = (Element) elementList.get(0);
      e2 = (Element) elementList.get(1);
      // Check for resolved conf
      assertEquals(
          "file://,testDir/2009/29,file://,testDir/2009/22,file://,testDir/2009/15,file://,testDir/2009/08",
          e1.getChild("value", e1.getNamespace()).getValue());
      assertEquals("file://,testDir/2009/29", e2.getChild("value", e1.getNamespace()).getValue());

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
 @Override
 public void visit(Element element) throws Exception {
   Element typeElement = element.getChild(REALM, namespace);
   if (typeElement != null) {
     if (element.getChildren(CONSTRAINT, namespace).size() == 0
         && element.getChildren(AUTH_CONSTRAINT, namespace).size() == 0) {
       element.removeChild(REALM, namespace);
     }
   }
 }
Example #23
0
 public void ifCmd(Element elem) throws TestCaseException {
   String isRun = replaceParam(elem.getAttributeValue("condition"));
   if (isRun != null && !isRun.equals("") && Boolean.valueOf(isRun)) {
     List<Element> children = UtilGenerics.cast(elem.getChildren());
     this.runCommands(children);
   } else {
     Element child = elem.getChild("else");
     List<Element> children = UtilGenerics.cast(child.getChildren());
     this.runCommands(children);
   }
 }
 public String encode() throws ParseException {
   Namespace ns = JabberCode.XMLNS_IQ_DISCO_ITEMS;
   Element query = getDOM().getChild("query", ns);
   if (node == null) query.removeAttribute("node");
   else query.setAttribute("node", node);
   if (!query.getChildren().isEmpty()) query.getChildren().clear();
   if (!items.isEmpty()) {
     int size = items.size();
     for (int i = 0; i < size; i++) query.addContent(((ServiceItem) items.get(i)).encode());
   }
   return super.encode();
 }
Example #25
0
  /** {@inheritDoc} */
  public void decodeXML(Element element) throws InvalidLLRPMessageException {
    List<Element> tempList = null;
    boolean atLeastOnce = false;
    Custom custom;

    Element temp = null;

    // child element are always in default LLRP namespace
    Namespace ns = Namespace.getNamespace(LLRPConstants.LLRPNAMESPACE);

    temp = element.getChild("OpSpecID", ns);

    if (temp != null) {
      opSpecID = new UnsignedShort(temp);
    }

    element.removeChild("OpSpecID", ns);
    temp = element.getChild("AccessPassword", ns);

    if (temp != null) {
      accessPassword = new UnsignedInteger(temp);
    }

    element.removeChild("AccessPassword", ns);
    temp = element.getChild("MB", ns);

    if (temp != null) {
      mB = new TwoBitField(temp);
    }

    element.removeChild("MB", ns);
    temp = element.getChild("WordPointer", ns);

    if (temp != null) {
      wordPointer = new UnsignedShort(temp);
    }

    element.removeChild("WordPointer", ns);
    temp = element.getChild("WordCount", ns);

    if (temp != null) {
      wordCount = new UnsignedShort(temp);
    }

    element.removeChild("WordCount", ns);

    if (element.getChildren().size() > 0) {
      String message =
          "C1G2BlockErase has unknown element "
              + ((Element) element.getChildren().get(0)).getName();
      throw new InvalidLLRPMessageException(message);
    }
  }
  private void addAttachArtifactDependency(
      @NotNull Element buildHelperCfg,
      @NotNull DependencyScope scope,
      @NotNull MavenProject mavenProject,
      @NotNull MavenArtifact artifact) {
    Library.ModifiableModel libraryModel = null;

    for (Element artifactsElement : (List<Element>) buildHelperCfg.getChildren("artifacts")) {
      for (Element artifactElement : (List<Element>) artifactsElement.getChildren("artifact")) {
        String typeString = artifactElement.getChildTextTrim("type");
        if (typeString != null && !typeString.equals("jar")) continue;

        OrderRootType rootType = OrderRootType.CLASSES;

        String classifier = artifactElement.getChildTextTrim("classifier");
        if ("sources".equals(classifier)) {
          rootType = OrderRootType.SOURCES;
        } else if ("javadoc".equals(classifier)) {
          rootType = JavadocOrderRootType.getInstance();
        }

        String filePath = artifactElement.getChildTextTrim("file");
        if (StringUtil.isEmpty(filePath)) continue;

        VirtualFile file = VfsUtil.findRelativeFile(filePath, mavenProject.getDirectoryFile());
        if (file == null) continue;

        file = JarFileSystem.getInstance().getJarRootForLocalFile(file);
        if (file == null) continue;

        if (libraryModel == null) {
          String libraryName = artifact.getLibraryName();
          assert libraryName.startsWith(MavenArtifact.MAVEN_LIB_PREFIX);
          libraryName =
              MavenArtifact.MAVEN_LIB_PREFIX
                  + "ATTACHED-JAR: "
                  + libraryName.substring(MavenArtifact.MAVEN_LIB_PREFIX.length());

          Library library = myModifiableModelsProvider.getLibraryByName(libraryName);
          if (library == null) {
            library = myModifiableModelsProvider.createLibrary(libraryName);
          }
          libraryModel = myModifiableModelsProvider.getLibraryModel(library);

          LibraryOrderEntry entry = myRootModelAdapter.getRootModel().addLibraryEntry(library);
          entry.setScope(scope);
        }

        libraryModel.addRoot(file, rootType);
      }
    }
  }
 private static void assertEqualElement(Element expElement, Element actElement) {
   if (!expElement.getChildren().isEmpty()) {
     final List expList = expElement.getChildren();
     for (Object expElem : expList) {
       final Element expSubElement = (Element) expElem;
       final Element actSubElement = actElement.getChild(expSubElement.getName());
       assertEqualElement(expSubElement, actSubElement);
     }
   } else {
     assertEquals(expElement.getName(), actElement.getName());
     assertEquals(expElement.getTextTrim(), actElement.getTextTrim());
   }
 }
  public void testReadAndWrite() {
    final Element xmlElement = createXmlElement(GeneralFilterBandPersistable.VERSION_1_1);

    final Object object = _generalFilterBandPersistable.createObjectFromXml(xmlElement, _product);
    _product.addBand((Band) object);

    final Element xmlFromObject = _generalFilterBandPersistable.createXmlFromObject(object);

    assertNotNull(xmlFromObject);
    final List expChildren = xmlElement.getChildren();
    final List actChildren = xmlFromObject.getChildren();
    assertEquals(expChildren.size(), actChildren.size());
    assertEqualElement(xmlElement, xmlFromObject);
  }
  @Override
  public void update(SettingManager settings, Dbms dbms) throws SQLException {

    final int MIN_HARVEST_ID = 100000;
    Element result =
        dbms.select("select * from Settings where parentid = 2 and id < " + MIN_HARVEST_ID);

    if (result.getChildren().size() > 0) {
      dbms.execute("SELECT * INTO Harvester FROM Settings WHERE parentid = 2");
      int changed = result.getChildren().size();
      while (changed > 0) {
        changed =
            dbms.execute(
                "INSERT INTO Harvester SELECT * FROM Settings WHERE parentid IN (SELECT id FROM Harvester) AND NOT id IN (SELECT id FROM Harvester)");
      }

      dbms.execute("DELETE FROM Settings WHERE id IN (SELECT id FROM Harvester)");
      int newHarvesterBaseIndex = Math.max(max(dbms), 100000);
      @SuppressWarnings("unchecked")
      List<Element> harvesterValues = dbms.select("SELECT * from Harvester").getChildren();

      Map<Integer, Integer> updates = new HashMap<Integer, Integer>();
      updates.put(2, 2); // Add harvesting node parentid to id map
      for (Element element : harvesterValues) {
        int id = Integer.parseInt(element.getChildText("id"));
        newHarvesterBaseIndex++;
        updates.put(id, newHarvesterBaseIndex);
      }
      StringBuilder builder = new StringBuilder("INSERT INTO Settings VALUES ");
      for (Element element : harvesterValues) {
        int id = Integer.parseInt(element.getChildText("id"));
        int parentid = Integer.parseInt(element.getChildText("parentid"));
        String name = element.getChildText("name");
        String value = element.getChildText("value");
        builder
            .append("(")
            .append(updates.get(id))
            .append(',')
            .append(updates.get(parentid))
            .append(",'")
            .append(name)
            .append("','")
            .append(value)
            .append("'),");
      }
      builder.deleteCharAt(builder.length() - 1);
      dbms.execute(builder.toString());
    }
  }
Example #30
0
  public void remoteRequest(Element elem) {

    String requestUrl = elem.getAttributeValue("url");
    String host = elem.getAttributeValue("host");
    if (host == null || host.length() == 0) {
      host = props.getProperty("startUrl");
    }
    String responseHandlerMode = elem.getAttributeValue("responseHandlerMode");
    List<Element> children = UtilGenerics.cast(elem.getChildren());
    List<Element> loginAs = UtilGenerics.cast(elem.getChildren("login-as"));
    logger.info("remoteRequest: children=" + children + " loginAs=" + loginAs);
    RemoteRequest loader =
        new RemoteRequest(this, children, loginAs, requestUrl, host, responseHandlerMode);
    loader.runTest();
  }