Java Code Examples for org.jdom2.Element#getChildren()

The following examples show how to use org.jdom2.Element#getChildren() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public ViewInterestPoints fromXml( final Element allInterestPointLists, final File basePath, final Map< ViewId, ViewDescription > viewDescriptions ) throws SpimDataException
{
	final ViewInterestPoints viewsInterestPoints = super.fromXml( allInterestPointLists );
	viewsInterestPoints.createViewInterestPoints( viewDescriptions );

	for ( final Element viewInterestPointsElement : allInterestPointLists.getChildren( VIEWINTERESTPOINTSFILE_TAG ) )
	{
		final int timepointId = Integer.parseInt( viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_TIMEPOINT_ATTRIBUTE_NAME ) );
		final int setupId = Integer.parseInt( viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_SETUP_ATTRIBUTE_NAME ) );
		final String label = viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_LABEL_ATTRIBUTE_NAME );
		final String parameters = viewInterestPointsElement.getAttributeValue( VIEWINTERESTPOINTS_PARAMETERS_ATTRIBUTE_NAME );

		final String interestPointFileName = viewInterestPointsElement.getTextTrim();

		final ViewId viewId = new ViewId( timepointId, setupId );
		final ViewInterestPointLists collection = viewsInterestPoints.getViewInterestPointLists( viewId );

		// we do not load the interestpoints nor the correspondinginterestpoints, we just do that once it is requested
		final InterestPointList list = new InterestPointList( basePath, new File( interestPointFileName ) );
		list.setParameters( parameters );
		collection.addInterestPointList( label, list );
	}

	return viewsInterestPoints;
}
 
Example 2
public List<CaseInstance> getCases() throws IOException {
    List<CaseInstance> caseList = null;
    String xml = _interfaceBClient.getCaseInstanceSummary(getEngineHandle());
    Element cases = JDOMUtil.stringToElement(xml);
    if (cases != null) {
        List<Element> children = cases.getChildren();
        if (! children.isEmpty()) {
            caseList = new ArrayList<CaseInstance>();
            for (Element child : children) {
                caseList.add(new CaseInstance(child));
            }
        }
        String startTime = cases.getAttributeValue("startuptime");
        if (startTime != null) {
            _startupTime = new Long(startTime);
        }
    }
    return caseList;
}
 
Example 3
/**
 * Loads the part packages for the simulation.
 * 
 * @param partPackageDoc the part package XML document.
 * @throws Exception if error reading XML document.
 */
private void loadPartPackages(Document partPackageDoc) {
	Element root = partPackageDoc.getRootElement();
	List<Element> partPackageNodes = root.getChildren(PART_PACKAGE);
	for (Element partPackageElement : partPackageNodes) {
		PartPackage partPackage = new PartPackage();

		partPackage.name = partPackageElement.getAttributeValue(NAME);

		List<Element> partNodes = partPackageElement.getChildren(PART);
		for (Element partElement : partNodes) {
			String partType = partElement.getAttributeValue(TYPE);
			Part part = (Part) ItemResourceUtil.findItemResource(partType);
			if (part == null)
				logger.severe(partType + " shows up in part_packages.xml but doesn't exist in parts.xml.");
			else {
				int partNumber = Integer.parseInt(partElement.getAttributeValue(NUMBER));
				partPackage.parts.put(part, partNumber);
			}
		}

		partPackages.add(partPackage);
	}

}
 
Example 4
public Map<Enchantment, Integer> parseEnchantments(Element el, String name) throws InvalidXMLException {
    Map<Enchantment, Integer> enchantments = Maps.newHashMap();

    Node attr = Node.fromAttr(el, name, StringUtils.pluralize(name));
    if(attr != null) {
        Iterable<String> enchantmentTexts = Splitter.on(";").split(attr.getValue());
        for(String enchantmentText : enchantmentTexts) {
            int level = 1;
            List<String> parts = Lists.newArrayList(Splitter.on(":").limit(2).split(enchantmentText));
            Enchantment enchant = XMLUtils.parseEnchantment(attr, parts.get(0));
            if(parts.size() > 1) {
                level = XMLUtils.parseNumber(attr, parts.get(1), Integer.class);
            }
            enchantments.put(enchant, level);
        }
    }

    for(Element elEnchantment : el.getChildren(name)) {
        Pair<Enchantment, Integer> entry = parseEnchantment(elEnchantment);
        enchantments.put(entry.first, entry.second);
    }

    return enchantments;
}
 
Example 5
Source Project: rome   File: MediaModuleParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param e element to parse
 * @param md metadata to fill in
 */
private void parseSubTitles(final Element e, final Metadata md) {
    final List<Element> subTitleElements = e.getChildren("subTitle", getNS());
    final SubTitle[] subtitles = new SubTitle[subTitleElements.size()];
    for (int i = 0; i < subTitleElements.size(); i++) {
        subtitles[i] = new SubTitle();
        subtitles[i].setType(subTitleElements.get(i).getAttributeValue("type"));
        subtitles[i].setLang(subTitleElements.get(i).getAttributeValue("lang"));
        if (subTitleElements.get(i).getAttributeValue("href") != null) {
            try {
                subtitles[i].setHref(new URL(subTitleElements.get(i).getAttributeValue("href")));
            } catch (MalformedURLException ex) {
                LOG.warn("Exception parsing subTitle href attribute.", ex);
            }
        }
    }
    md.setSubTitles(subtitles);
}
 
Example 6
Source Project: wildfly-camel   File: ConfigSupport.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Element findElementWithAttributeValue(Element element, String name, String attrName, String attrValue, Namespace... supportedNamespaces) {
    for (Namespace ns : supportedNamespaces) {
        if (element.getName().equals(name) && element.getNamespace().equals(ns)) {
            Attribute attribute = element.getAttribute(attrName);
            if (attribute != null && attrValue.equals(attribute.getValue())) {
                return element;
            }
        }
        for (Element ch : (List<Element>) element.getChildren()) {
            Element result = findElementWithAttributeValue(ch, name, attrName, attrValue, supportedNamespaces);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example 7
Source Project: CardinalPGM   File: Database.java    License: MIT License 5 votes vote down vote up
private Element getKey(Element element, String key) {
    for (Element child : element.getChildren("data")) {
        if (key.equals(child.getAttributeValue("key"))) return child;
    }
    Element newElement = new Element(("data")).setAttribute(new Attribute("key", key)).setAttribute("value", "");
    element.addContent(newElement);
    return newElement;
}
 
Example 8
/**
 * Construct a tree for each task specified in the rules file
 * @param e - the Element containing the rules of each task
 */
private void buildItemLevelTree(Map<RuleType, RdrTreeSet> treeMap,
                                RuleType ruleType, Element e, boolean newSet) {
    RdrTreeSet treeSet = new RdrTreeSet(ruleType);
    for (Element eChild : e.getChildren()) {
        RdrTree tree = buildTree(eChild, newSet);
        if (tree != null) treeSet.add(tree);
    }
    if (! treeSet.isEmpty()) {
        treeMap.put(ruleType, treeSet);
    }
}
 
Example 9
private void extractEmptyComplexTypeFlagTypeNames(Element schemaElem) {
    if (schemaElem != null) {
        for (Element elem : schemaElem.getChildren()) {
            if (elem.getName().equals("complexType") && elem.getChildren().isEmpty()) {
                _emptyComplexTypeFlagTypes.add(elem.getAttributeValue("name"));
            }
        }
    }
}
 
Example 10
private void add(Element elem, Element parent) {
  if (elem.getName().equals("object")) {
    parent.addContent(elem.clone());
    return;
  }

  for (Object child : elem.getChildren()) {
    add((Element) child, parent);
  }
}
 
Example 11
private void removeSourceExtension(Element resultingMODS) {
    for (Element extension : resultingMODS.getChildren("extension", MCRConstants.MODS_NAMESPACE)) {
        for (Element source : extension.getChildren("source")) {
            source.detach();
        }
        if (extension.getChildren().isEmpty()) {
            extension.detach();
        }
    }
}
 
Example 12
Source Project: rome   File: RSS091UserlandGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void checkChannelConstraints(final Element eChannel) throws FeedException {

    checkNotNullAndLength(eChannel, "title", 1, 100);
    checkNotNullAndLength(eChannel, "description", 1, 500);
    checkNotNullAndLength(eChannel, "link", 1, 500);
    checkNotNullAndLength(eChannel, "language", 2, 5);
    checkLength(eChannel, "rating", 20, 500);
    checkLength(eChannel, "copyright", 1, 100);
    checkLength(eChannel, "pubDate", 1, 100);
    checkLength(eChannel, "lastBuildDate", 1, 100);
    checkLength(eChannel, "docs", 1, 500);
    checkLength(eChannel, "managingEditor", 1, 100);
    checkLength(eChannel, "webMaster", 1, 100);

    final Element skipHours = eChannel.getChild("skipHours");

    if (skipHours != null) {

        final List<Element> hours = skipHours.getChildren();
        for (final Element hour : hours) {

            final int value = Integer.parseInt(hour.getText().trim());

            if (isHourFormat24()) {
                if (value < 1 || value > 24) {
                    throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24");
                }
            } else {
                if (value < 0 || value > 23) {
                    throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23");
                }
            }

        }

    }

}
 
Example 13
protected SchemaMap assembleMap(String schema) {
    SchemaMap map = new SchemaMap();
    if (schema != null) {
        Element dataSchema = JDOMUtil.stringToElement(schema);
        for (Element child : dataSchema.getChildren()) {
            String name = child.getAttributeValue("name");
            if (name != null) {
                map.put(name, child);
            }    
        }
    }
    return map;
}
 
Example 14
@Override
public KitModule parse(MapFactory factory, Logger logger, Document doc)
    throws InvalidXMLException {
  for (Element kitsElement : doc.getRootElement().getChildren("kits")) {
    for (Element kitElement : kitsElement.getChildren("kit")) {
      factory.getKits().parse(kitElement);
    }
  }
  return new KitModule();
}
 
Example 15
/**
 * validates element and their children recursively
 *
 * @param element
 * @return
 */
private void validateAllElements(Element element)
        throws DatatypeConfigurationException, IOException, JDOMException {
    if (element != null) {
        validateElement(element, new ArrayList<Element>());
        for (Element child : (List<Element>) element.getChildren()) {
            validateAllElements(child);
        }
    }
}
 
Example 16
private void parseDynParams(Element e, Namespace nsYawl) {

        // ... and input parameters
        for (Element eParam : e.getChildren("param", nsYawl)) {
            String name = eParam.getChildText("name", nsYawl);
            String refers = eParam.getChildText("refers", nsYawl);
            int pType = refers.equals("role") ? ROLE_PARAM : USER_PARAM;
            addInputParam(name, pType);
        }
    }
 
Example 17
Source Project: yawl   File: Utils.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static List<Element> string2Elements(String s)
{
	List<Element> list = new ArrayList<Element>();
	Element tmp = string2Element("<tmp>" + s + "</tmp>");
	for (Element e : tmp.getChildren())
	{
		// list.add((Element)e.detach());
		list.add(Utils.string2Element(Utils.element2String(e, false)));
	}
	return list;
}
 
Example 18
NcmlCollectionReader(String ncmlLocation, Element netcdfElem) {

    if (netcdfElem.getNamespace().equals(Catalog.ncmlNSHttps)) {
      this.ncmlNS = Catalog.ncmlNSHttps;
    } else {
      this.ncmlNS = Catalog.ncmlNS;
    }
    Element aggElem = netcdfElem.getChild("aggregation", ncmlNS);
    String recheck = aggElem.getAttributeValue("recheckEvery");

    // get the aggregation/scan element
    Element scanElem = aggElem.getChild("scan", ncmlNS);
    if (scanElem == null)
      scanElem = aggElem.getChild("scanFmrc", ncmlNS);

    if (scanElem == null) {
      // no directory scan going on here - look for explicitly named datasets
      Map<String, String> realLocationRunTimeMap = new HashMap<>();
      List<String> realLocationList = new ArrayList<>();
      java.util.List<Element> ncList = aggElem.getChildren("netcdf", ncmlNS);
      for (Element netcdfElemNested : ncList) {
        String location = netcdfElemNested.getAttributeValue("location");
        if (location == null)
          location = netcdfElemNested.getAttributeValue("url");
        if (location != null)
          location = AliasTranslator.translateAlias(location);

        String runTime = netcdfElemNested.getAttributeValue("coordValue");
        if (runTime == null) {
          Formatter f = new Formatter();
          f.format("runtime must be explicitly defined for each netcdf element using the attribute coordValue");
          log.error(f.toString());
        }

        String realLocation = URLnaming.resolveFile(ncmlLocation, location);
        // for realLocation on windows, need to standardize path we put into the map
        // for example, C:\data\file.nc will become C:/data/file.nc
        // Hacky hacky hacky hack

        realLocation = StringUtil2.replace(realLocation, '\\', "/");
        realLocationRunTimeMap.put(realLocation, runTime);
      }
      datasetManager = MFileCollectionManager.openWithRecheck(ncmlLocation, recheck);
      datasetManager.setFilesAndRunDate(realLocationRunTimeMap);

    } else {
      String dirLocation = scanElem.getAttributeValue("location");
      dirLocation = URLnaming.resolve(ncmlLocation, dirLocation); // possible relative location

      String regexpPatternString = scanElem.getAttributeValue("regExp");
      String suffix = scanElem.getAttributeValue("suffix");
      String subdirs = scanElem.getAttributeValue("subdirs");
      String olderThan = scanElem.getAttributeValue("olderThan");

      datasetManager = MFileCollectionManager.openWithRecheck(ncmlLocation, recheck);
      datasetManager.addDirectoryScan(dirLocation, suffix, regexpPatternString, subdirs, olderThan, null);

      String dateFormatMark = scanElem.getAttributeValue("dateFormatMark");
      DateExtractor dateExtractor = null;
      if (dateFormatMark != null)
        dateExtractor = new DateExtractorFromName(dateFormatMark, true);
      else {
        String runDateMatcher = scanElem.getAttributeValue("runDateMatcher");
        if (runDateMatcher != null)
          dateExtractor = new DateExtractorFromName(runDateMatcher, false);
      }
      datasetManager.setDateExtractor(dateExtractor);

    }

    hasOuter = hasMods(netcdfElem);
    hasInner = hasMods(aggElem);

    if (hasOuter)
      this.netcdfElem = netcdfElem;
    if (hasInner)
      this.aggElem = aggElem;
  }
 
Example 19
static public List<RadarConfigEntry> readXML(String filename) {
  List<RadarConfigEntry> configs = new ArrayList<>();

  SAXBuilder builder = new SAXBuilder();
  File f = new File(filename);
  try {
    Document doc = builder.build(f);
    Element cat = doc.getRootElement();
    Namespace catNS = cat.getNamespace();
    Element topDS = cat.getChild("dataset", cat.getNamespace());
    for (Element dataset : topDS.getChildren("datasetScan", catNS)) {
      RadarConfigEntry conf = new RadarConfigEntry();
      configs.add(conf);

      Element collection = dataset.getChild("radarCollection", catNS);
      conf.dateParseRegex = collection.getAttributeValue("dateRegex");
      conf.dateFmt = collection.getAttributeValue("dateFormat");
      conf.layout = collection.getAttributeValue("layout");
      String crawlItems = collection.getAttributeValue("crawlItems");
      if (crawlItems != null) {
        conf.crawlItems = Integer.parseInt(crawlItems);
      } else {
        conf.crawlItems = 5;
      }

      Element meta = dataset.getChild("metadata", catNS);
      conf.name = dataset.getAttributeValue("name");
      conf.urlPath = dataset.getAttributeValue("path");
      conf.dataPath = getPath(dataset.getAttributeValue("location"));
      conf.dataFormat = meta.getChild("dataFormat", catNS).getValue();
      conf.stationFile = meta.getChild("stationFile", catNS).getAttributeValue("path");
      conf.doc = meta.getChild("documentation", catNS).getValue();

      conf.timeCoverage = readTimeCoverage(meta.getChild("timeCoverage", catNS));

      conf.spatialCoverage = readGeospatialCoverage(meta.getChild("geospatialCoverage", catNS));

      Element variables = meta.getChild("variables", catNS);
      conf.vars = new ArrayList<>();
      for (Element var : variables.getChildren("variable", catNS)) {
        RadarConfigEntry.VarInfo inf = new RadarConfigEntry.VarInfo();
        conf.vars.add(inf);

        inf.name = var.getAttributeValue("name");
        inf.vocabName = var.getAttributeValue("vocabulary_name");
        inf.units = var.getAttributeValue("units");
      }
    }
  } catch (IOException | JDOMException e) {
    e.printStackTrace();
  }

  return configs;
}
 
Example 20
/**
 * validates element of resource utilisation plan against type element from
 * schema return cs class for element
 */
public static String validateElement(Element element, Element typeElement, List<Element> restrictions,
		boolean withValidation) throws DatatypeConfigurationException, IOException, JDOMException
{
	String cssClass = null;

	String type = typeElement.getAttributeValue("type");
	if (type == null)
	{
		type = typeElement.getAttributeValue("base");
		if (typeElement.getName().equals("restriction"))
		{
			restrictions.addAll(typeElement.getChildren());
			// logger.debug("found restrictions: "+Utils.toString(restrictions));
		}
	}

	if (type == null)
	{
		for (Element schemaVarChild : (List<Element>) typeElement.getChildren())
		{
			if (!schemaVarChild.getName().equals("element"))
			{
				cssClass = validateElement(element, schemaVarChild, restrictions, withValidation);
			}
		}
		return cssClass;
	}

	Object o = null;
	if (isDatatypeXSD(type, XSDDatatypes_Int))
	{
		o = getIntegerValue(element, withValidation);
		cssClass = CSS_INTINPUT;
	}
	else if (isDatatypeXSD(type, XSDDatatypes_Long))
	{
		o = getLongValue(element, withValidation);
		cssClass = CSS_INTINPUT;
	}
	else if (isDatatypeXSD(type, XSDDatatypes_Double))
	{
		o = getDoubleValue(element, withValidation);
		cssClass = CSS_INTINPUT;
	}
	else if (isDatatypeXSD(type, XSDDatatypes_DateTime))
	{
		o = getDateValue(element, withValidation);
		cssClass = CSS_DATEINPUT;
	}
	else if (isDatatypeXSD(type, XSDDatatypes_Duration))
	{
		o = getDurationValueInMinutes(element, withValidation);
		cssClass = CSS_DURATIONINPUT;
	}
	else if (isDatatypeXSD(type, XSDDatatypes_Boolean))
	{
		o = getBooleanValue(element, withValidation);
		cssClass = CSS_BOOLEANINPUT;
	}
	else if (isDatatypeXSD(type, XSDDatatypes_String))
	{
		o = getStringValue(element, withValidation);
		cssClass = CSS_TEXTINPUT;
	}
	else
	{
		cssClass = validateType(element, type, restrictions, withValidation);
	}

	validateRestrictions(element, type, o, restrictions, withValidation);

	return cssClass;
}