List of usage examples for java.text ParseException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java
private Document cropDocumentForNode(Node xmlDoc) throws ParseException { if (xmlDoc.getParentNode() != null) { // if node is not document root node try {// www. ja v a 2s. co m Document nodeXmlDoc; synchronized (builder) { nodeXmlDoc = builder.newDocument(); } Node importedNode = nodeXmlDoc.importNode(xmlDoc, true); nodeXmlDoc.appendChild(importedNode); return nodeXmlDoc; } catch (Exception exc) { ParseException pe = new ParseException(StreamsResources.getString( StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityXmlParser.xmlDocument.parse.error"), 0); pe.initCause(exc); throw pe; } } return null; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java
@Override protected ActivityContext prepareItem(TNTInputStream<?, ?> stream, Object data) throws ParseException { Node xmlDoc;// w w w .java 2s .co m String xmlString = null; try { if (data instanceof Document) { xmlDoc = (Document) data; } else if (data instanceof Node) { xmlDoc = (Node) data; } else { xmlString = getNextActivityString(data); if (StringUtils.isEmpty(xmlString)) { return null; } synchronized (builder) { xmlDoc = builder.parse(IOUtils.toInputStream(xmlString, Utils.UTF8)); } } } catch (Exception e) { ParseException pe = new ParseException(StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityXmlParser.xmlDocument.parse.error"), 0); pe.initCause(e); throw pe; } if (xmlString == null) { try { xmlString = Utils.documentToString(xmlDoc); } catch (Exception exc) { logger().log(OpLevel.WARNING, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityXmlParser.xmlDocument.toString.error"), exc); } } ActivityContext cData = new ActivityContext(stream, data, xmlDoc); cData.setMessage(xmlString); return cData; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java
/** * Gets field raw data value resolved by locator and formats it according locator definition. * * @param locator/*from ww w. j a va 2s.c o m*/ * activity field locator * @param cData * activity object XML DOM document * @param formattingNeeded * flag to set if value formatting is not needed * @return value formatted based on locator definition or {@code null} if locator is not defined * * @throws ParseException * if exception occurs while resolving raw data value or applying locator format properties to specified * value * * @see ActivityFieldLocator#formatValue(Object) */ @Override protected Object resolveLocatorValue(ActivityFieldLocator locator, ActivityContext cData, AtomicBoolean formattingNeeded) throws ParseException { Object val = null; String locStr = locator.getLocator(); Node xmlDoc = cData.getData(); if (ActivityField.isDynamicAttr(locStr)) { ActivityInfo ai = cData.getActivity(); locStr = StreamsCache.fillInKeyPattern(locStr, ai, this.getName()); } if (StringUtils.isNotEmpty(locStr)) { Document nodeDocument = cropDocumentForNode(xmlDoc); try { XPathExpression expr; synchronized (xPath) { expr = xPath.compile(locStr); } if (nodeDocument != null) { // try expression relative to node val = resolveValueOverXPath(nodeDocument, expr, formattingNeeded); } if (val == null) { // otherwise try on complete document val = resolveValueOverXPath(xmlDoc, expr, formattingNeeded); } if (val instanceof Node) { Node node = (Node) val; if (!isNodeSupportedByStackedParser(cData.getField(), node)) { val = getTextContent(locator, node); } } } catch (XPathExpressionException exc) { ParseException pe = new ParseException(StreamsResources .getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityXMLParser.xPath.exception"), 0); pe.initCause(exc); throw pe; } } return val; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java
@Override protected ActivityInfo parsePreparedItem(ActivityContext cData) throws ParseException { if (cData == null || cData.getData() == null) { return null; }// w w w .j av a 2 s . c o m ActivityInfo ai = new ActivityInfo(); ActivityField field = null; cData.setActivity(ai); try { String[] savedFormats = null; String[] savedUnits = null; String[] savedLocales = null; // apply fields for parser Object[] values; for (ActivityField aField : fieldList) { values = null; cData.setField(aField); field = aField; List<ActivityFieldLocator> locators = field.getLocators(); if (locators != null) { // need to save format and units specification from config // in case individual entry in activity data overrides it if (ArrayUtils.getLength(savedFormats) < locators.size()) { savedFormats = new String[locators.size()]; savedUnits = new String[locators.size()]; savedLocales = new String[locators.size()]; } values = parseLocatorValues(locators, cData); for (int li = 0; li < locators.size(); li++) { ActivityFieldLocator loc = locators.get(li); savedFormats[li] = loc.getFormat(); savedUnits[li] = loc.getUnits(); savedLocales[li] = loc.getLocale(); if (values[li] == null && (loc.isRequired() || (requireAll && loc.isDefaultRequire()))) { logger().log(OpLevel.WARNING, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityXmlParser.required.locator.not.found"), loc, field); cData.setActivity(null); return null; } } } applyFieldValue(field, Utils.simplifyValue(values), cData); if (locators != null && savedFormats != null) { for (int li = 0; li < locators.size(); li++) { ActivityFieldLocator loc = locators.get(li); loc.setFormat(savedFormats[li], savedLocales[li]); loc.setUnits(savedUnits[li]); } } } } catch (Exception e) { ParseException pe = new ParseException(StreamsResources.getStringFormatted( StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityParser.parsing.failed", field), 0); pe.initCause(e); throw pe; } return ai; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.GenericActivityParser.java
/** * Parse the specified prepared activity data, converting each field in prepared data to its corresponding value of * activity info item./*from ww w .j a v a 2 s. c o m*/ * * @param cData * prepared activity data item context to parse * @return converted activity info, or {@code null} if activity data is {@code null} * @throws ParseException * if exception occurs applying locator format properties to specified value */ protected ActivityInfo parsePreparedItem(ActivityContext cData) throws ParseException { if (cData == null || cData.getData() == null) { return null; } ActivityInfo ai = new ActivityInfo(); ActivityField field = null; cData.setActivity(ai); try { // apply fields for parser Object value; for (ActivityField aField : fieldList) { field = aField; cData.setField(aField); value = Utils.simplifyValue(parseLocatorValues(field, cData)); applyFieldValue(field, value, cData); } } catch (Exception e) { ParseException pe = new ParseException(StreamsResources.getStringFormatted( StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityParser.parsing.failed", field), 0); pe.initCause(e); throw pe; } return ai; }
From source file:com.jkoolcloud.tnt4j.streams.parsers.GenericActivityParser.java
/** * Sets the value for the dynamic fields in the specified activity entity. * <p>// www .j a v a 2s.co m * If field has stacked parser defined, then field value is parsed into separate activity using stacked parser. If * field can be parsed by stacked parser, can be merged or added as a child into specified (parent) activity * depending on stacked parser reference 'aggregation' attribute value. * * @param cData * parsing context data package * @param field * field to apply value to * @param value * value to apply for dynamic fields * @throws IllegalStateException * if parser has not been properly initialized * @throws ParseException * if an error parsing the specified value * * @see #applyFieldValue(TNTInputStream, ActivityInfo, ActivityField, Object) */ protected void applyDynamicValue(ActivityContext cData, ActivityField field, Object value) throws ParseException { Map<String, Object> dValMap = parseDynamicValues(cData, field.getDynamicLocators()); Object[] fValues = Utils.makeArray(value); List<ActivityField> tFieldsList = new ArrayList<>(); for (int vi = 0; vi < fValues.length; vi++) { ActivityField tField = field.createTempField(dValMap, vi); tFieldsList.add(tField); } reviewTempFieldsNames(tFieldsList); ActivityField tField = null; try { for (int tfi = 0; tfi < tFieldsList.size(); tfi++) { tField = tFieldsList.get(tfi); Object fValue = fValues[tfi]; applyFieldValue(cData.getStream(), cData.getActivity(), tField, Utils.simplifyValue(fValue)); } } catch (Exception e) { ParseException pe = new ParseException(StreamsResources.getStringFormatted( StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityParser.parsing.failed", tField), 0); pe.initCause(e); throw pe; } }