use of org.eclipse.smarthome.automation.parser.ParsingException in project smarthome by eclipse.
the class CommandlineTemplateProvider method importData.
@Override
protected Set<RuleTemplate> importData(URL url, Parser<RuleTemplate> parser, InputStreamReader inputStreamReader) throws ParsingException {
Set<RuleTemplate> providedObjects = parser.parse(inputStreamReader);
if (providedObjects != null && !providedObjects.isEmpty()) {
List<String> portfolio = new ArrayList<String>();
synchronized (providerPortfolio) {
providerPortfolio.put(url, portfolio);
}
List<ParsingNestedException> importDataExceptions = new ArrayList<ParsingNestedException>();
for (RuleTemplate ruleT : providedObjects) {
List<ParsingNestedException> exceptions = new ArrayList<ParsingNestedException>();
String uid = ruleT.getUID();
checkExistence(uid, exceptions);
if (exceptions.isEmpty()) {
portfolio.add(uid);
synchronized (providedObjectsHolder) {
notifyListeners(providedObjectsHolder.put(uid, ruleT), ruleT);
}
} else {
importDataExceptions.addAll(exceptions);
}
}
if (!importDataExceptions.isEmpty()) {
throw new ParsingException(importDataExceptions);
}
}
return providedObjects;
}
use of org.eclipse.smarthome.automation.parser.ParsingException in project smarthome by eclipse.
the class AbstractResourceBundleProvider method parseData.
/**
* This method is called from {@link #processAutomationProvider(Bundle)} to process the loading of the provided
* objects.
*
* @param vendor is a holder of information about the bundle providing data for import.
* @param parser the {@link Parser} which is responsible for parsing of a particular format in which the provided
* objects are presented
* @param url the resource which is used for loading the objects.
* @param bundle is the resource holder
* @return a set of automation objects - the result of loading.
*/
protected Set<E> parseData(Parser<E> parser, URL url, Bundle bundle) {
InputStreamReader reader = null;
InputStream is = null;
try {
is = url.openStream();
reader = new InputStreamReader(is, StandardCharsets.UTF_8);
return parser.parse(reader);
} catch (ParsingException e) {
logger.error("{}", e.getLocalizedMessage(), e);
} catch (IOException e) {
logger.error("Can't read from resource of bundle with ID {}", bundle.getBundleId(), e);
processAutomationProviderUninstalled(bundle);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
if (is != null) {
try {
is.close();
} catch (IOException ignore) {
}
}
}
return null;
}
use of org.eclipse.smarthome.automation.parser.ParsingException in project smarthome by eclipse.
the class AbstractFileProvider method importFile.
/**
* This method is responsible for importing a set of Automation objects from a specified URL resource.
*
* @param parserType is relevant to the format that you need for conversion of the Automation objects in text.
* @param url a specified URL for import.
*/
protected void importFile(String parserType, URL url) {
Parser<E> parser = parsers.get(parserType);
if (parser != null) {
InputStream is = null;
InputStreamReader inputStreamReader = null;
try {
is = url.openStream();
BufferedInputStream bis = new BufferedInputStream(is);
inputStreamReader = new InputStreamReader(bis);
Set<E> providedObjects = parser.parse(inputStreamReader);
updateProvidedObjectsHolder(url, providedObjects);
} catch (ParsingException e) {
logger.debug("{}", e.getMessage(), e);
} catch (IOException e) {
logger.debug("{}", e.getMessage(), e);
} finally {
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (IOException e) {
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
} else {
synchronized (urls) {
List<URL> value = urls.get(parserType);
if (value == null) {
value = new ArrayList<URL>();
urls.put(parserType, value);
}
value.add(url);
}
logger.debug("Parser {} not available", parserType, new Exception());
}
}
Aggregations