URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
InputStream openURL(URL url) { try { return url.openStream(); } catch (IOException e) { if (!optional) { String errMsg = "Failed to open [" + url.toString() + "]"; addError(errMsg, e); } return null; } }
URL resourceAsURL(String resourceAttribute) { URL url = Loader.getResourceBySelfClassLoader(resourceAttribute); if (url == null) { if (!optional) { String errMsg = "Could not find resource corresponding to [" + resourceAttribute + "]"; addError(errMsg); } return null; } else return url; }
private boolean checkAttributes(Attributes attributes) { String fileAttribute = attributes.getValue(FILE_ATTR); String urlAttribute = attributes.getValue(URL_ATTR); String resourceAttribute = attributes.getValue(RESOURCE_ATTR); int count = 0; if (!OptionHelper.isEmpty(fileAttribute)) { count++; } if (!OptionHelper.isEmpty(urlAttribute)) { count++; } if (!OptionHelper.isEmpty(resourceAttribute)) { count++; } if (count == 0) { addError("One of \"path\", \"resource\" or \"url\" attributes must be set."); return false; } else if (count > 1) { addError("Only one of \"file\", \"url\" or \"resource\" attributes should be set."); return false; } else if (count == 1) { return true; } throw new IllegalStateException("Count value [" + count + "] is not expected"); }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { SaxEventRecorder recorder = new SaxEventRecorder(context); this.attributeInUse = null; this.optional = OptionHelper.toBoolean(attributes.getValue(OPTIONAL_ATTR), false); if (!checkAttributes(attributes)) { return; } InputStream in = getInputStream(ec, attributes); try { if (in != null) { parseAndRecord(in, recorder); // remove the <included> tag from the beginning and </included> from the end trimHeadAndTail(recorder); // offset = 2, because we need to get past this element as well as the end element ec.getJoranInterpreter().getEventPlayer().addEventsDynamically(recorder.saxEventList, 2); } } catch (JoranException e) { addError("Error while parsing " + attributeInUse, e); } finally { close(in); } }
URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
private InputStream getInputStreamByFilePath(String pathToFile) { try { return new FileInputStream(pathToFile); } catch (IOException ioe) { String errMsg = "File [" + pathToFile + "] does not exist."; addError(errMsg, ioe); return null; } }
URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
private InputStream getInputStreamByFilePath(String pathToFile) { try { return new FileInputStream(pathToFile); } catch (IOException ioe) { String errMsg = "File [" + pathToFile + "] does not exist."; addError(errMsg, ioe); return null; } }
URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
private InputStream getInputStreamByFilePath(String pathToFile) { try { return new FileInputStream(pathToFile); } catch (IOException ioe) { String errMsg = "File [" + pathToFile + "] does not exist."; addError(errMsg, ioe); return null; } }
InputStream openURL(URL url) { try { return url.openStream(); } catch (IOException e) { String errMsg = "Failed to open [" + url.toString() + "]"; addError(errMsg, e); return null; } }
InputStream openURL(URL url) { try { return url.openStream(); } catch (IOException e) { String errMsg = "Failed to open [" + url.toString() + "]"; addError(errMsg, e); return null; } }
InputStream openURL(URL url) { try { return url.openStream(); } catch (IOException e) { String errMsg = "Failed to open [" + url.toString() + "]"; addError(errMsg, e); return null; } }
URL resourceAsURL(String resourceAttribute) { URL url = Loader.getResourceBySelfClassLoader(resourceAttribute); if (url == null) { String errMsg = "Could not find resource corresponding to [" + resourceAttribute + "]"; addError(errMsg); return null; } else return url; }
private InputStream getInputStreamByUrl(String urlAttribute) { URL url; try { url = new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } return openURL(url); }
URL resourceAsURL(String resourceAttribute) { URL url = Loader.getResourceBySelfClassLoader(resourceAttribute); if (url == null) { String errMsg = "Could not find resource corresponding to [" + resourceAttribute + "]"; addError(errMsg); return null; } else return url; }
private InputStream getInputStreamByResource(String resourceAttribute) { URL url = Loader.getResourceBySelfClassLoader(resourceAttribute); if (url == null) { String errMsg = "Could not find resource corresponding to [" + resourceAttribute + "]"; addError(errMsg); return null; } return openURL(url); }