org.jdom2.DataConversionException Java Examples

The following examples show how to use org.jdom2.DataConversionException. 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: ExtractionTest.java    From emissary with Apache License 2.0 6 votes vote down vote up
protected void checkAnswers(Document answers, IBaseDataObject payload, List<IBaseDataObject> attachments, String tname)
        throws DataConversionException {
    Element root = answers.getRootElement();
    Element parent = root.getChild("answers");
    if (parent == null) {
        parent = root;
    }

    // Check the payload
    checkAnswers(parent, payload, attachments, tname);

    // Check each attachment
    for (int attNum = 1; attNum <= attachments.size(); attNum++) {
        String atname = tname + Family.SEP + attNum;
        Element el = parent.getChild("att" + attNum);
        if (el != null) {
            checkAnswersPreHook(el, payload, attachments.get(attNum - 1), atname);
            checkAnswers(el, attachments.get(attNum - 1), null, atname);
            checkAnswersPostHook(el, payload, attachments.get(attNum - 1), atname);
        }
    }
}
 
Example #2
Source File: BuildingConfig.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the relative location in the building of a parking location.
 * 
 * @param buildingType the type of the building.
 * @param parkingIndex the parking location index.
 * @return Point object containing the relative X & Y position from the building
 *         center.
 */
public Point2D.Double getParkingLocation(String buildingType, int parkingIndex) {
	Element buildingElement = getBuildingElement(buildingType);
	Element functionsElement = buildingElement.getChild(FUNCTIONS);
	Element groundVehicleMaintenanceElement = functionsElement.getChild(GROUND_VEHICLE_MAINTENANCE);
	List<?> parkingLocations = groundVehicleMaintenanceElement.getChildren(PARKING_LOCATION);
	if ((parkingIndex >= 0) && (parkingIndex < parkingLocations.size())) {
		Element parkingLocation = (Element) parkingLocations.get(parkingIndex);
		try {
			Point2D.Double point = new Point2D.Double();
			double xLocation = parkingLocation.getAttribute(X_LOCATION).getDoubleValue();
			double yLocation = parkingLocation.getAttribute(Y_LOCATION).getDoubleValue();
			point.setLocation(xLocation, yLocation);
			return point;
		} catch (DataConversionException e) {
			throw new IllegalStateException(e);
		}
	} else {
		return null;
	}
}
 
Example #3
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void loadFromDocument(Document nameSet) throws DataConversionException
{
	Element generator = nameSet.getRootElement();
	java.util.List<?> rulesets = generator.getChildren("RULESET");
	java.util.List<?> lists = generator.getChildren("LIST");
	ListIterator<?> listIterator = lists.listIterator();

	while (listIterator.hasNext())
	{
		Element list = (Element) listIterator.next();
		loadList(list);
	}

	for (final Object ruleset : rulesets)
	{
		Element ruleSet = (Element) ruleset;
		RuleSet rs = loadRuleSet(ruleSet);
		allVars.addDataElement(rs);
	}
}
 
Example #4
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void loadFromDocument(Document nameSet) throws DataConversionException
{
	Element generator = nameSet.getRootElement();
	java.util.List<?> rulesets = generator.getChildren("RULESET");
	java.util.List<?> lists = generator.getChildren("LIST");
	ListIterator<?> listIterator = lists.listIterator();

	while (listIterator.hasNext())
	{
		Element list = (Element) listIterator.next();
		loadList(list);
	}

	for (final Object ruleset : rulesets)
	{
		Element ruleSet = (Element) ruleset;
		RuleSet rs = loadRuleSet(ruleSet);
		allVars.addDataElement(rs);
	}
}
 
Example #5
Source File: DatasetScanConfigBuilder.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DatasetScanConfig.AddLatest readDatasetScanAddLatest(Element addLatestElem) {

    String latestName = "latest.xml";
    String serviceName = "Resolver";
    boolean latestOnTop = true;
    boolean isResolver = true;

    String tmpLatestName = addLatestElem.getAttributeValue("name");
    if (tmpLatestName != null)
      latestName = tmpLatestName;

    String tmpserviceName = addLatestElem.getAttributeValue("serviceName");
    if (tmpserviceName != null)
      serviceName = tmpserviceName;

    // Does latest go on top or bottom of list.
    Attribute topAtt = addLatestElem.getAttribute("top");
    if (topAtt != null) {
      try {
        latestOnTop = topAtt.getBooleanValue();
      } catch (DataConversionException e) {
        latestOnTop = true;
      }
    }

    // Get lastModifed limit.
    String lastModLimitVal = addLatestElem.getAttributeValue("lastModifiedLimit");
    long lastModLimit = -1;
    if (lastModLimitVal != null)
      lastModLimit = Long.parseLong(lastModLimitVal) * 60 * 1000; // convert minutes to millisecs

    return new DatasetScanConfig.AddLatest(latestName, serviceName, latestOnTop, lastModLimit);
  }
 
Example #6
Source File: ChaiResponseSet.java    From ldapchai with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Challenge parseResponseElement( final Element loopResponseElement )
        throws DataConversionException
{
    final boolean required = loopResponseElement.getAttribute( XML_ATTRIBUTE_REQUIRED ).getBooleanValue();
    final boolean adminDefined = loopResponseElement.getAttribute( XML_ATTRIBUTE_ADMIN_DEFINED ).getBooleanValue();

    final String challengeText = loopResponseElement.getChild( XML_NODE_CHALLENGE ).getText();
    final int minLength = loopResponseElement.getAttribute( XNL_ATTRIBUTE_MIN_LENGTH ).getIntValue();
    final int maxLength = loopResponseElement.getAttribute( XNL_ATTRIBUTE_MAX_LENGTH ).getIntValue();

    return new ChaiChallenge( required, challengeText, minLength, maxLength, adminDefined, 0, false );
}
 
Example #7
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #8
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private RuleSet loadRuleSet(Element ruleSet) throws DataConversionException
{
	RuleSet rs = new RuleSet(allVars, ruleSet.getAttributeValue("title"), ruleSet.getAttributeValue("id"),
		ruleSet.getAttributeValue("usage"));
	java.util.List<?> elements = ruleSet.getChildren();
	ListIterator<?> elementsIterator = elements.listIterator();
	int num = 0;

	while (elementsIterator.hasNext())
	{
		Element child = (Element) elementsIterator.next();
		String elementName = child.getName();

		if (elementName.equals("CATEGORY"))
		{
			loadCategory(child, rs);
		}
		else if (elementName.equals("RULE"))
		{
			rs.add(loadRule(child, rs.getId() + num));
		}

		num++;
	}

	return rs;
}
 
Example #9
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #10
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private RuleSet loadRuleSet(Element ruleSet) throws DataConversionException
{
	RuleSet rs = new RuleSet(allVars, ruleSet.getAttributeValue("title"), ruleSet.getAttributeValue("id"),
		ruleSet.getAttributeValue("usage"));
	java.util.List<?> elements = ruleSet.getChildren();
	ListIterator<?> elementsIterator = elements.listIterator();
	int num = 0;

	while (elementsIterator.hasNext())
	{
		Element child = (Element) elementsIterator.next();
		String elementName = child.getName();

		if (elementName.equals("CATEGORY"))
		{
			loadCategory(child, rs);
		}
		else if (elementName.equals("RULE"))
		{
			rs.add(loadRule(child, rs.getId() + num));
		}

		num++;
	}

	return rs;
}
 
Example #11
Source File: SSE091Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
private Integer parseIntegerAttribute(final Element sharingChild, final String attrName) {
    final Attribute integerAttribute = sharingChild.getAttribute(attrName);
    Integer integerAttr = null;
    if (integerAttribute != null) {
        try {
            integerAttr = new Integer(integerAttribute.getIntValue());
        } catch (final DataConversionException e) {
            // dont use the data
        }
    }
    return integerAttr;
}
 
Example #12
Source File: SSE091Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
private Boolean parseBooleanAttr(final Element sharingChild, final String attrName) {
    final Attribute attribute = sharingChild.getAttribute(attrName);
    Boolean attrValue = null;
    if (attribute != null) {
        try {
            attrValue = Boolean.valueOf(attribute.getBooleanValue());
        } catch (final DataConversionException e) {
            // dont use the data
        }
    }
    return attrValue;
}
 
Example #13
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
private String loadRule(Element rule, String id) throws DataConversionException
{
	Rule dataRule = new Rule(allVars, id, id, rule.getAttribute("weight").getIntValue());
	java.util.List<?> elements = rule.getChildren();

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

           switch (elementName)
           {
               case "GETLIST":
                   String listId = child.getAttributeValue("idref");
                   dataRule.add(listId);
                   break;
               case "SPACE":
                   SpaceRule sp = new SpaceRule();
                   allVars.addDataElement(sp);
                   dataRule.add(sp.getId());
                   break;
               case "HYPHEN":
                   HyphenRule hy = new HyphenRule();
                   allVars.addDataElement(hy);
                   dataRule.add(hy.getId());
                   break;
               case "CR":
                   CRRule cr = new CRRule();
                   allVars.addDataElement(cr);
                   dataRule.add(cr.getId());
                   break;
               case "GETRULE":
                   String ruleId = child.getAttributeValue("idref");
                   dataRule.add(ruleId);
                   break;
           }
	}

	allVars.addDataElement(dataRule);

	return dataRule.getId();
}
 
Example #14
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
private String loadRule(Element rule, String id) throws DataConversionException
{
	Rule dataRule = new Rule(allVars, id, id, rule.getAttribute("weight").getIntValue());
	java.util.List<?> elements = rule.getChildren();

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

           switch (elementName)
           {
               case "GETLIST":
                   String listId = child.getAttributeValue("idref");
                   dataRule.add(listId);
                   break;
               case "SPACE":
                   SpaceRule sp = new SpaceRule();
                   allVars.addDataElement(sp);
                   dataRule.add(sp.getId());
                   break;
               case "HYPHEN":
                   HyphenRule hy = new HyphenRule();
                   allVars.addDataElement(hy);
                   dataRule.add(hy.getId());
                   break;
               case "CR":
                   CRRule cr = new CRRule();
                   allVars.addDataElement(cr);
                   dataRule.add(cr.getId());
                   break;
               case "GETRULE":
                   String ruleId = child.getAttributeValue("idref");
                   dataRule.add(ruleId);
                   break;
           }
	}

	allVars.addDataElement(dataRule);

	return dataRule.getId();
}