List of usage examples for org.jdom2 Attribute getLongValue
public long getLongValue() throws DataConversionException
long
form, and if no conversion can occur, throws a DataConversionException
From source file:ca.nrc.cadc.caom2.xml.ObservationReader.java
License:Open Source License
private void assignEntityAttributes(Element e, CaomEntity ce, ReadContext rc) throws ObservationParsingException { Attribute aid = e.getAttribute("id", e.getNamespace()); Attribute alastModified = e.getAttribute("lastModified", e.getNamespace()); Attribute amaxLastModified = e.getAttribute("maxLastModified", e.getNamespace()); Attribute mcs = e.getAttribute("metaChecksum", e.getNamespace()); Attribute acc = e.getAttribute("accMetaChecksum", e.getNamespace()); try {// w w w.jav a 2 s . c o m UUID uuid; if (rc.docVersion == 20) { Long id = new Long(aid.getLongValue()); uuid = new UUID(0L, id); } else { uuid = UUID.fromString(aid.getValue()); } CaomUtil.assignID(ce, uuid); if (alastModified != null) { Date lastModified = rc.parseTimestamp(alastModified.getValue()); CaomUtil.assignLastModified(ce, lastModified, "lastModified"); } if (rc.docVersion >= 23) { if (amaxLastModified != null) { Date lastModified = rc.parseTimestamp(amaxLastModified.getValue()); CaomUtil.assignLastModified(ce, lastModified, "maxLastModified"); } if (mcs != null) { URI metaCS = new URI(mcs.getValue()); CaomUtil.assignMetaChecksum(ce, metaCS, "metaChecksum"); } if (acc != null) { URI accCS = new URI(acc.getValue()); CaomUtil.assignMetaChecksum(ce, accCS, "accMetaChecksum"); } } } catch (DataConversionException ex) { throw new ObservationParsingException("invalid id: " + aid.getValue()); } catch (ParseException ex) { throw new ObservationParsingException("invalid lastModified: " + alastModified.getValue()); } catch (URISyntaxException ex) { throw new ObservationParsingException("invalid checksum uri: " + aid.getValue()); } }
From source file:io.wcm.handler.commons.dom.AbstractElement.java
License:Apache License
/** * Gets attribute value as long.//from ww w.j a v a2 s. c o m * @param attributeName Attribute name * @return Attribute value as long or 0 if not set. */ public final long getAttributeValueAsLong(String attributeName) { Attribute attribute = getAttribute(attributeName); if (attribute == null) { return 0; } else { try { return attribute.getLongValue(); } catch (DataConversionException ex) { return 0; } } }
From source file:org.esa.snap.core.dataop.downloadable.FtpDownloader.java
License:Open Source License
public static Map<String, Long> readRemoteFileList(final FtpDownloader ftp, final String server, final String remotePath) { boolean useCachedListing = true; final File listingFile = new File(SystemUtils.getCacheDir(), server + ".listing.xml"); if (!listingFile.exists()) useCachedListing = false;/* w w w. j av a2 s .c om*/ final Map<String, Long> fileSizeMap = new HashMap<>(900); if (useCachedListing) { Document doc = null; try { doc = XMLSupport.LoadXML(listingFile.getAbsolutePath()); } catch (IOException e) { useCachedListing = false; } if (useCachedListing) { final Element root = doc.getRootElement(); boolean listingFound = false; final List<Content> children1 = root.getContent(); for (Object c1 : children1) { if (!(c1 instanceof Element)) continue; final Element remotePathElem = (Element) c1; final Attribute pathAttrib = remotePathElem.getAttribute("path"); if (pathAttrib != null && pathAttrib.getValue().equalsIgnoreCase(remotePath)) { listingFound = true; final List<Content> children2 = remotePathElem.getContent(); for (Object c2 : children2) { if (!(c2 instanceof Element)) continue; final Element fileElem = (Element) c2; final Attribute attrib = fileElem.getAttribute("size"); if (attrib != null) { try { fileSizeMap.put(getFileName(fileElem.getName()), attrib.getLongValue()); } catch (Exception e) { // } } } } } if (!listingFound) useCachedListing = false; } } if (!useCachedListing) { try { final FTPFile[] remoteFileList = ftp.getRemoteFileList(remotePath); if (remoteFileList != null) { writeRemoteFileList(remoteFileList, server, remotePath, listingFile); for (FTPFile ftpFile : remoteFileList) { fileSizeMap.put(ftpFile.getName(), ftpFile.getSize()); } } } catch (Exception e) { SystemUtils.LOG.warning("Unable to get remote file list " + e.getMessage()); } } return fileSizeMap; }
From source file:org.esa.snap.framework.dataop.downloadable.ftpUtils.java
License:Open Source License
public static Map<String, Long> readRemoteFileList(final ftpUtils ftp, final String server, final String remotePath) { boolean useCachedListing = true; final String tmpDirUrl = SystemUtils.getApplicationDataDir().getAbsolutePath(); final File listingFile = new File(tmpDirUrl + "//" + server + ".listing.xml"); if (!listingFile.exists()) useCachedListing = false;// ww w . j a v a 2 s. com final Map<String, Long> fileSizeMap = new HashMap<>(900); if (useCachedListing) { Document doc = null; try { doc = XMLSupport.LoadXML(listingFile.getAbsolutePath()); } catch (IOException e) { useCachedListing = false; } if (useCachedListing) { final Element root = doc.getRootElement(); boolean listingFound = false; final List children1 = root.getContent(); for (Object c1 : children1) { if (!(c1 instanceof Element)) continue; final Element remotePathElem = (Element) c1; final Attribute pathAttrib = remotePathElem.getAttribute("path"); if (pathAttrib != null && pathAttrib.getValue().equalsIgnoreCase(remotePath)) { listingFound = true; final List children2 = remotePathElem.getContent(); for (Object c2 : children2) { if (!(c2 instanceof Element)) continue; final Element fileElem = (Element) c2; final Attribute attrib = fileElem.getAttribute("size"); if (attrib != null) { try { fileSizeMap.put(fileElem.getName(), attrib.getLongValue()); } catch (Exception e) { // } } } } } if (!listingFound) useCachedListing = false; } } if (!useCachedListing) { try { final FTPFile[] remoteFileList = ftp.getRemoteFileList(remotePath); if (remoteFileList != null) { writeRemoteFileList(remoteFileList, server, remotePath, listingFile); for (FTPFile ftpFile : remoteFileList) { fileSizeMap.put(ftpFile.getName(), ftpFile.getSize()); } } } catch (Exception e) { System.out.println("Unable to get remote file list " + e.getMessage()); } } return fileSizeMap; }
From source file:org.esa.snap.util.ftpUtils.java
License:Open Source License
public static Map<String, Long> readRemoteFileList(final ftpUtils ftp, final String server, final String remotePath) { boolean useCachedListing = true; final String tmpDirUrl = ResourceUtils.getApplicationUserTempDataDir().getAbsolutePath(); final File listingFile = new File(tmpDirUrl + "//" + server + ".listing.xml"); if (!listingFile.exists()) useCachedListing = false;//from w ww.j a va 2 s.c om final Map<String, Long> fileSizeMap = new HashMap<>(900); if (useCachedListing) { Document doc = null; try { doc = XMLSupport.LoadXML(listingFile.getAbsolutePath()); } catch (IOException e) { useCachedListing = false; } if (useCachedListing) { final Element root = doc.getRootElement(); boolean listingFound = false; final List children1 = root.getContent(); for (Object c1 : children1) { if (!(c1 instanceof Element)) continue; final Element remotePathElem = (Element) c1; final Attribute pathAttrib = remotePathElem.getAttribute("path"); if (pathAttrib != null && pathAttrib.getValue().equalsIgnoreCase(remotePath)) { listingFound = true; final List children2 = remotePathElem.getContent(); for (Object c2 : children2) { if (!(c2 instanceof Element)) continue; final Element fileElem = (Element) c2; final Attribute attrib = fileElem.getAttribute("size"); if (attrib != null) { try { fileSizeMap.put(fileElem.getName(), attrib.getLongValue()); } catch (Exception e) { // } } } } } if (!listingFound) useCachedListing = false; } } if (!useCachedListing) { try { final FTPFile[] remoteFileList = ftp.getRemoteFileList(remotePath); writeRemoteFileList(remoteFileList, server, remotePath, listingFile); for (FTPFile ftpFile : remoteFileList) { fileSizeMap.put(ftpFile.getName(), ftpFile.getSize()); } } catch (Exception e) { System.out.println("Unable to get remote file list " + e.getMessage()); } } return fileSizeMap; }