org.docx4j.openpackaging.parts.opendope.ConditionsPart Maven / Gradle / Ivy
package org.docx4j.openpackaging.parts.opendope;
import javax.xml.bind.JAXBContext;
import org.docx4j.model.datastorage.InputIntegrityException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.parts.PartName;
import org.opendope.conditions.Condition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ConditionsPart extends JaxbCustomXmlDataStoragePart {
private static Logger log = LoggerFactory.getLogger(ConditionsPart.class);
public ConditionsPart(PartName partName) throws InvalidFormatException {
super(partName);
init();
}
public ConditionsPart(PartName partName, JAXBContext jc) throws InvalidFormatException {
super(partName, jc);
init();
}
/**
* For performance reasons, avoid using this method if you have a lot of Conditions
*
* @param conditions
* @param id
* @return
*/
public static Condition getConditionById(
org.opendope.conditions.Conditions conditions,
String id) {
for (Condition c : conditions.getCondition() ) {
if (c.getId().equals(id))
return c;
}
throw new InputIntegrityException("No Condition with id " + id );
}
// /**
// * Extracts xpath object from condition.
// *
// * Note: this does NOT build an xpath corresponding to the condition
// * value, but rather, is typically used to identify
// * questions associated with the condition.
// * @param c
// * @param xPaths
// * @return
// * @throws InputIntegrityException
// */
// public static List getXPathsUsedInCondition(Condition c, org.opendope.xpaths.Xpaths xPaths)
// throws InputIntegrityException {
//
// List xpaths = new ArrayList();
//
// if (c.getXpathref()!=null) {
// xpaths.add(XPathsPart.getXPathById(xPaths, c.getXpathref().getId()));
// return xpaths;
// } else if (c.getNot()!=null) {
//
// if (c.getNot().getXpathref()!=null) {
// xpaths.add(XPathsPart.getXPathById(xPaths, c.getNot().getXpathref().getId()));
// return xpaths;
// } else {
// throw new InputIntegrityException("Couldn't extract xpath from not in condition " + XmlUtils.marshaltoString(c, true) );
// }
// }
// throw new InputIntegrityException("Couldn't extract xpath from condition " + XmlUtils.marshaltoString(c, true) );
// // TODO handle complex conditions
// }
//
// public static String buildEffectiveXPath(Condition c, org.opendope.xpaths.Xpaths xPaths)
// throws InputIntegrityException {
//
// //StringBuilder effectiveXPath = new StringBuilder();
//
// if (c.getXpathref()!=null) {
// return XPathsPart.getXPathById(xPaths, c.getXpathref().getId()).getDataBinding().getXpath();
// } else if (c.getNot()!=null) {
//
// if (c.getNot().getXpathref()!=null) {
// return "not(" + XPathsPart.getXPathById(xPaths, c.getNot().getXpathref().getId()).getDataBinding().getXpath()
// + ")";
// } else {
// throw new InputIntegrityException("Couldn't extract xpath from not in condition " + XmlUtils.marshaltoString(c, true) );
// }
// }
// throw new InputIntegrityException("Couldn't extract xpath from condition " + XmlUtils.marshaltoString(c, true) );
// // TODO handle complex conditions
// }
}