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

The following examples show how to use org.jdom2.Element#getChild() . 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
Source File: RSS094Parser.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = (Channel) super.parseChannel(rssRoot, locale);

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    final List<Element> categories = eChannel.getChildren("category", getRSSNamespace());
    channel.setCategories(parseCategories(categories));

    final Element ttl = eChannel.getChild("ttl", getRSSNamespace());
    if (ttl != null && ttl.getText() != null) {
        final Integer ttlValue = NumberParser.parseInt(ttl.getText());
        if (ttlValue != null) {
            channel.setTtl(ttlValue);
        }
    }

    return channel;
}
 
Example 2
Source File: OfferInteraction.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void parseFilters(Element e, Namespace nsYawl) throws ResourceParseException {

        // get the Filters
        Element eFilters = e.getChild("filters", nsYawl);
        if (eFilters != null) {
            List<Element> filters = eFilters.getChildren("filter", nsYawl);
            if (filters == null)
                throw new ResourceParseException(
                        "No filter elements found in filters element");

            for (Element eFilter : filters) {
                String filterClassName = eFilter.getChildText("name", nsYawl);
                if (filterClassName != null) {
                    AbstractFilter filter = PluginFactory.newFilterInstance(filterClassName);
                    if (filter != null) {
                        filter.setParams(parseParams(eFilter, nsYawl));
                        _filters.add(filter);
                    }
                    else throw new ResourceParseException("Unknown filter name: " +
                                                                   filterClassName);
                }
                else throw new ResourceParseException("Missing filter element: name");
            }
        }
    }
 
Example 3
Source File: RobotConfig.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets a map of the configured robot's skills.
 * 
 * @param index the robot's index.
 * @return map of skills (empty map if not found).
 * @throws Exception if error in XML parsing.
 */
public Map<String, Integer> getSkillMap(int index) {
	Map<String, Integer> result = new HashMap<String, Integer>();
	Element root = robotDoc.getRootElement();
	Element robotList = root.getChild(ROBOT_LIST);
	Element robotElement = (Element) robotList.getChildren(ROBOT).get(index);
	List<Element> skillListNodes = robotElement.getChildren(SKILL_LIST);
	if ((skillListNodes != null) && (skillListNodes.size() > 0)) {
		Element skillList = skillListNodes.get(0);
		int skillNum = skillList.getChildren(SKILL).size();
		for (int x = 0; x < skillNum; x++) {
			Element skillElement = (Element) skillList.getChildren(SKILL).get(x);
			String name = skillElement.getAttributeValue(NAME);
			Integer level = Integer.valueOf(skillElement.getAttributeValue(LEVEL));
			result.put(name, level);
		}
	}
	return result;
}
 
Example 4
Source File: UIConfig.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the internal window type.
 *
 * @param windowName the window name.
 * @return "unit" or "tool".
 */
public String getInternalWindowType(String windowName) {
	try {
		Element root = configDoc.getRootElement();
		Element internalWindows = root.getChild(INTERNAL_WINDOWS);
		List<Element> internalWindowNodes = internalWindows.getChildren();
		String result = "";
		for (Object element : internalWindowNodes) {
			if (element instanceof Element) {
				Element internalWindow = (Element) element;
				String name = internalWindow.getAttributeValue(NAME);
				if (name.equals(windowName))
					result = internalWindow.getAttributeValue(TYPE);
			}
		}
		return result;
	} catch (Exception e) {
		return "";
	}
}
 
Example 5
Source File: RSS093Parser.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {

    final Item item = super.parseItem(rssRoot, eItem, locale);

    final Element pubDate = eItem.getChild("pubDate", getRSSNamespace());
    if (pubDate != null) {
        item.setPubDate(DateParser.parseDate(pubDate.getText(), locale));
    }

    final Element expirationDate = eItem.getChild("expirationDate", getRSSNamespace());
    if (expirationDate != null) {
        item.setExpirationDate(DateParser.parseDate(expirationDate.getText(), locale));
    }

    final Element description = eItem.getChild("description", getRSSNamespace());
    if (description != null) {
        final String type = description.getAttributeValue("type");
        if (type != null) {
            item.getDescription().setType(type);
        }
    }

    return item;

}
 
Example 6
Source File: SpecificationData.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * If the specification contains a schema library this method returns the
 * schema library as a string (in XML Schema format).
 * @return  schema library as a string.
 */
public String getSchemaLibrary() throws IOException, JDOMException {
    Document document = JDOMUtil.stringToDocument(_specAsXML);
    Element yawlSpecSetElement = document.getRootElement();

    String ns = isSecondGenSchemaVersion() ?
            "http://www.yawlfoundation.org/yawlschema" :
            "http://www.citi.qut.edu.au/yawl" ;

    Namespace yawlNameSpace = Namespace.getNamespace(ns);
    Element yawlSpecElement = yawlSpecSetElement.getChild("specification", yawlNameSpace);

    if (yawlSpecElement != null) {
        Namespace schema2SchNS = Namespace.getNamespace("http://www.w3.org/2001/XMLSchema");
        Element schemaLibraryElement = yawlSpecElement.getChild("schema", schema2SchNS);

        if (schemaLibraryElement != null) {
            return JDOMUtil.elementToString(schemaLibraryElement);
        }
    }
    return null;
}
 
Example 7
Source File: Marshaller.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String filterDataAgainstOutputParams(String mergedOutputData,
                                                   List<YParameter> outputParams)
        throws JDOMException, IOException {

    //set up output document
    Element outputData = JDOMUtil.stringToElement(mergedOutputData);
    Element filteredData = new Element(outputData.getName());

    Collections.sort(outputParams);
    for (YParameter parameter : outputParams) {
        Element child = outputData.getChild(parameter.getPreferredName());
        if (null != child) {
            filteredData.addContent(child.clone());
        }
    }
    return JDOMUtil.elementToString(filteredData);
}
 
Example 8
Source File: MediaModuleParser.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * @param e element to parse
 * @param md metadata to fill in
 */
private void parseStatus(final Element e, final Metadata md) {
    final Element statusElement = e.getChild("status", getNS());
    if (statusElement != null) {
        final Status status = new Status();
        status.setState(Status.State.valueOf(statusElement.getAttributeValue("state")));
        status.setReason(statusElement.getAttributeValue("reason"));
        md.setStatus(status);
    }
}
 
Example 9
Source File: RSS20Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void populateItem(final Item item, final Element eItem, final int index) {

    super.populateItem(item, eItem, index);

    final Element description = eItem.getChild("description", getFeedNamespace());
    if (description != null) {
        description.removeAttribute("type");
    }

    final String author = item.getAuthor();
    if (author != null) {
        eItem.addContent(generateSimpleElement("author", author));
    }

    final String comments = item.getComments();
    if (comments != null) {
        eItem.addContent(generateSimpleElement("comments", comments));
    }

    final Guid guid = item.getGuid();
    if (guid != null) {
        final Element eGuid = generateSimpleElement("guid", guid.getValue());
        if (!guid.isPermaLink()) {
            eGuid.setAttribute("isPermaLink", "false");
        }
        eItem.addContent(eGuid);
    }
}
 
Example 10
Source File: DynFormFieldAssembler.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void buildMap(String schemaStr, String dataStr) throws DynFormException {
    Element data = JDOMUtil.stringToElement(dataStr);
    Document doc = JDOMUtil.stringToDocument(schemaStr);
    Element root = doc.getRootElement();                        // schema
    Namespace ns = root.getNamespace();
    Element element = root.getChild("element", ns) ;
    _formName = element.getAttributeValue("name") ;            // name of case/task
    _fieldList = createFieldList(element, data, ns, -1);
}
 
Example 11
Source File: ReaderJdomUtil.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
public static <T extends Enum<T>> T getElementAttributeEnum(Element parentElement, String elementName, String attributeName, Class<T> enumClass) {
    Element child = parentElement.getChild(elementName, parentElement.getNamespace());
    if (child != null) {
        return getAttributeEnum(child, attributeName, enumClass);
    }
    return null;
}
 
Example 12
Source File: TimeLimitModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private @Nullable TimeLimitDefinition parseTimeLimit(Element el) throws InvalidXMLException {
    el = el.getChild("time");
    if(el == null) return null;

    final Duration duration = XMLUtils.parseDuration(Node.of(el));
    if(Comparables.greaterThan(duration, TimeLimit.MAX_DURATION)) {
        throw new InvalidXMLException("Time limit cannot exceed " + TimeLimit.MAX_DURATION.toDays() + " days", el);
    }

    return new TimeLimitDefinition(
        duration,
        parseVictoryCondition(Node.tryAttr(el, "result")),
        XMLUtils.parseBoolean(el.getAttribute("show"), true)
    );
}
 
Example 13
Source File: MediaModuleParser.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * @param e element to parse
 * @param md metadata to fill in
 */
private void parseHash(final Element e, final Metadata md) {
    try {
        final Element hash = e.getChild("hash", getNS());

        if (hash != null) {
            md.setHash(new Hash(hash.getAttributeValue("algo"), hash.getText()));
        }
    } catch (final Exception ex) {
        LOG.warn("Exception parsing hash tag.", ex);
    }
}
 
Example 14
Source File: RSS094Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateItem(final Item item, final Element eItem, final int index) {
    super.populateItem(item, eItem, index);

    final Description description = item.getDescription();
    if (description != null && description.getType() != null) {
        final Element eDescription = eItem.getChild("description", getFeedNamespace());
        eDescription.setAttribute(new Attribute("type", description.getType()));
    }
    eItem.removeChild("expirationDate", getFeedNamespace());
}
 
Example 15
Source File: YSpecificationParser.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * adds the XML schema library to the specification.
 * @param specificationElem
 */
private void addSchema(Element specificationElem) throws YSyntaxException {

    Element schemaElem = specificationElem.getChild("schema");
    if (schemaElem != null) {
        _specification.setSchema(JDOMUtil.elementToString(schemaElem));
    }
}
 
Example 16
Source File: ComplexityMetric.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public double getWeightedUDTCount(Document doc) {
    double weight = Config.getUDTComplexityWeight();
    if (doc == null || weight <= 0) return 0;
    Element root = doc.getRootElement();
    Element spec = root.getChild("specification", YAWL_NAMESPACE);
    Element dataSchema = spec.getChild("schema", XSD_NAMESPACE);
    return dataSchema.getChildren().size() * weight;
}
 
Example 17
Source File: YDecompositionParser.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void linkElements() {
    if (_decomposition instanceof YNet) {
        YNet decomposition = (YNet) _decomposition;
        for (YExternalNetElement currentNetElement : decomposition.getNetElements().values()) {
            List<FlowStruct> postsetIDs = _postsetIDs.getQPostset(currentNetElement.getID());
            if (postsetIDs != null) {
                for (FlowStruct flowStruct : postsetIDs) {
                    YExternalNetElement nextElement = decomposition.getNetElement(flowStruct._flowInto);
                    YFlow flow = new YFlow(currentNetElement, nextElement);
                    flow.setEvalOrdering(flowStruct._predicateOrdering);
                    flow.setIsDefaultFlow(flowStruct._isDefaultFlow);
                    flow.setXpathPredicate(flowStruct._flowPredicate);
                    flow.setDocumentation(flowStruct._label);
                    currentNetElement.addPostset(flow);
                }
            }
        }

        for (YTask externalTask : _removeSetIDs.keySet()) {
            List<YExternalNetElement> removeSetObjects = new Vector<YExternalNetElement>();
            for (String id : _removeSetIDs.get(externalTask)) {
                removeSetObjects.add(decomposition.getNetElement(id));
            }
            if (removeSetObjects.size() > 0) {
                externalTask.addRemovesTokensFrom(removeSetObjects);
            }
        }

        for (YTask taskWithRemoveSet : _removeSetForFlows.keySet()) {
            for (Element removesTokensFromFlowElem : _removeSetForFlows.get(taskWithRemoveSet)) {
                Element flowSourceElem = removesTokensFromFlowElem.getChild("flowSource", _yawlNS);
                Element flowDestElem = removesTokensFromFlowElem.getChild("flowDestination", _yawlNS);
                String flowSourceID = flowSourceElem.getAttributeValue("id");
                String flowDestID = flowDestElem.getAttributeValue("id");
                YExternalNetElement flowSource = decomposition.getNetElement(flowSourceID);
                YExternalNetElement flowDest = decomposition.getNetElement(flowDestID);
                for (YExternalNetElement maybeImplicit : flowSource.getPostsetElements()) {
                    if (((YCondition) maybeImplicit).isImplicit()) {
                        Set<YExternalNetElement> oneTaskInThisList = maybeImplicit.getPostsetElements();
                        YTask taskAfterImplicit = (YTask) oneTaskInThisList.iterator().next();
                        if (taskAfterImplicit.equals(flowDest)) {
                            List<YExternalNetElement> additionalRemoves =
                                    new ArrayList<YExternalNetElement>();
                            additionalRemoves.add(maybeImplicit);
                            taskWithRemoveSet.addRemovesTokensFrom(additionalRemoves);
                        }
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: MedicalConfig.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Treatment> getTreatmentList() {
	
	if (treatmentList == null) {
		treatmentList = new ArrayList<Treatment>();
		
		Element root = medicalDoc.getRootElement();
		Element medicalTreatmentList = root.getChild(TREATMENT_LIST);
		List<Element> treatments = medicalTreatmentList.getChildren(TREATMENT);
		
		for (Element medicalTreatment : treatments) {	
			// Get name.
			String treatmentName = medicalTreatment.getAttributeValue(NAME);
			
			// Get skill. (optional)
			int skill = 0;
		    Element skillElement = medicalTreatment.getChild(SKILL);
		    
		    if(skillElement != null)
		    skill = Integer.parseInt(skillElement.getAttributeValue(VALUE));
		
			
			// Get medical tech level. (optional)
			int medicalTechLevel = 0;
			Element medicalTechLevelElement = medicalTreatment.getChild(MEDICAL_TECH_LEVEL);
			
			if(medicalTechLevelElement != null)
			medicalTechLevel = Integer.parseInt(medicalTechLevelElement.getAttributeValue(VALUE));
		
			
			// Get treatment time., optional
			double treatmentTime = -1D;
			Element treatmentTimeElement = medicalTreatment.getChild(TREATMENT_TIME);
			
			if(treatmentTimeElement != null)
			treatmentTime = Double.parseDouble(treatmentTimeElement.getAttributeValue(VALUE));
		
			// Get self-admin. (optional)
			boolean selfAdmin = false;
			
			Element selfAdminElement = medicalTreatment.getChild(SELF_ADMIN);
			
			if (selfAdminElement != null) {
			    String selfAdminStr = selfAdminElement.getAttributeValue(VALUE);
			    selfAdmin = (selfAdminStr.toLowerCase().equals("true"));
			}
			
			
			Treatment treatment = new Treatment(treatmentName, skill, 
			                      treatmentTime, selfAdmin, medicalTechLevel);
			
			treatmentList.add(treatment);
		}
	}
	
	return treatmentList;
}
 
Example 19
Source File: BuildingConfig.java    From mars-sim with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the base heat requirement for the building.
 * 
 * @param buildingType the type of the building
 * @return base heat requirement (J)
 * @throws Exception if building type cannot be found or XML parsing error.
 */
public double getBaseHeatRequirement(String buildingType) {
	Element buildingElement = getBuildingElement(buildingType);
	Element heatElement = buildingElement.getChild(HEAT_REQUIRED);
	return Double.parseDouble(heatElement.getAttributeValue(BASE_HEAT));
}
 
Example 20
Source File: BuildingConfig.java    From mars-sim with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the base power-down power requirement for the building.
 * 
 * @param buildingType the type of the building
 * @return base power-down power (kW)
 * @throws Exception if building type cannot be found or XML parsing error.
 */
public double getBasePowerDownPowerRequirement(String buildingType) {
	Element buildingElement = getBuildingElement(buildingType);
	Element powerElement = buildingElement.getChild(POWER_REQUIRED);
	return Double.parseDouble(powerElement.getAttributeValue(BASE_POWER_DOWN_POWER));
}