safer xmp parsing

This commit is contained in:
Thibault Deckers 2020-04-03 10:07:56 +09:00
parent c4c95280ef
commit 44b6d30a49
5 changed files with 33 additions and 22 deletions

View file

@ -211,12 +211,23 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
}
metadataMap.put("xmpSubjects", sb.toString());
}
// double check retrieved items as the property sometimes is reported to exist but it is actually null
String titleDescription = null;
if (xmpMeta.doesPropertyExist(XMP_DC_SCHEMA_NS, XMP_TITLE_PROP_NAME)) {
XMPProperty item = xmpMeta.getLocalizedText(XMP_DC_SCHEMA_NS, XMP_TITLE_PROP_NAME, XMP_GENERIC_LANG, XMP_SPECIFIC_LANG);
metadataMap.put("xmpTitleDescription", item.getValue());
} else if (xmpMeta.doesPropertyExist(XMP_DC_SCHEMA_NS, XMP_DESCRIPTION_PROP_NAME)) {
if (item != null) {
titleDescription = item.getValue();
}
}
if (titleDescription == null && xmpMeta.doesPropertyExist(XMP_DC_SCHEMA_NS, XMP_DESCRIPTION_PROP_NAME)) {
XMPProperty item = xmpMeta.getLocalizedText(XMP_DC_SCHEMA_NS, XMP_DESCRIPTION_PROP_NAME, XMP_GENERIC_LANG, XMP_SPECIFIC_LANG);
metadataMap.put("xmpTitleDescription", item.getValue());
if (item != null) {
titleDescription = item.getValue();
}
}
if (titleDescription != null) {
metadataMap.put("xmpTitleDescription", titleDescription);
}
} catch (XMPException e) {
e.printStackTrace();

View file

@ -11,7 +11,7 @@ class ImageFileService {
try {
await platform.invokeMethod('getImageEntries');
} on PlatformException catch (e) {
debugPrint('getImageEntries failed with exception=${e.message}');
debugPrint('getImageEntries failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
@ -24,7 +24,7 @@ class ImageFileService {
}) as Map;
return ImageEntry.fromMap(result);
} on PlatformException catch (e) {
debugPrint('getImageEntry failed with exception=${e.message}');
debugPrint('getImageEntry failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return null;
}
@ -37,7 +37,7 @@ class ImageFileService {
});
return result as Uint8List;
} on PlatformException catch (e) {
debugPrint('getImage failed with exception=${e.message}');
debugPrint('getImage failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return Uint8List(0);
}
@ -53,7 +53,7 @@ class ImageFileService {
});
return result as Uint8List;
} on PlatformException catch (e) {
debugPrint('getThumbnail failed with exception=${e.message}');
debugPrint('getThumbnail failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
return Uint8List(0);
@ -65,7 +65,7 @@ class ImageFileService {
'uri': uri,
});
} on PlatformException catch (e) {
debugPrint('cancelGetThumbnail failed with exception=${e.message}');
debugPrint('cancelGetThumbnail failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
@ -76,7 +76,7 @@ class ImageFileService {
});
return true;
} on PlatformException catch (e) {
debugPrint('delete failed with exception=${e.message}');
debugPrint('delete failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return false;
}
@ -90,7 +90,7 @@ class ImageFileService {
}) as Map;
return result;
} on PlatformException catch (e) {
debugPrint('rename failed with exception=${e.message}');
debugPrint('rename failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return {};
}
@ -104,7 +104,7 @@ class ImageFileService {
}) as Map;
return result;
} on PlatformException catch (e) {
debugPrint('rotate failed with exception=${e.message}');
debugPrint('rotate failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return {};
}

View file

@ -18,7 +18,7 @@ class MetadataService {
});
return result as Map;
} on PlatformException catch (e) {
debugPrint('getAllMetadata failed with exception=${e.message}');
debugPrint('getAllMetadata failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return {};
}
@ -41,7 +41,7 @@ class MetadataService {
result['contentId'] = entry.contentId;
return CatalogMetadata.fromMap(result);
} on PlatformException catch (e) {
debugPrint('getCatalogMetadata failed with exception=${e.message}');
debugPrint('getCatalogMetadata failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return null;
}
@ -58,7 +58,7 @@ class MetadataService {
}) as Map;
return OverlayMetadata.fromMap(result);
} on PlatformException catch (e) {
debugPrint('getOverlayMetadata failed with exception=${e.message}');
debugPrint('getOverlayMetadata failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return null;
}

View file

@ -11,7 +11,7 @@ class AndroidAppService {
final result = await platform.invokeMethod('getAppNames');
return result as Map;
} on PlatformException catch (e) {
debugPrint('getAppNames failed with exception=${e.message}');
debugPrint('getAppNames failed with code=${e.code}, exception=${e.message}, details=${e.details}}');
}
return {};
}
@ -24,7 +24,7 @@ class AndroidAppService {
});
return result as Uint8List;
} on PlatformException catch (e) {
debugPrint('getAppIcon failed with exception=${e.message}');
debugPrint('getAppIcon failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return Uint8List(0);
}
@ -37,7 +37,7 @@ class AndroidAppService {
'mimeType': mimeType,
});
} on PlatformException catch (e) {
debugPrint('edit failed with exception=${e.message}');
debugPrint('edit failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
@ -49,7 +49,7 @@ class AndroidAppService {
'mimeType': mimeType,
});
} on PlatformException catch (e) {
debugPrint('open failed with exception=${e.message}');
debugPrint('open failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
@ -60,7 +60,7 @@ class AndroidAppService {
'geoUri': geoUri,
});
} on PlatformException catch (e) {
debugPrint('openMap failed with exception=${e.message}');
debugPrint('openMap failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
@ -72,7 +72,7 @@ class AndroidAppService {
'mimeType': mimeType,
});
} on PlatformException catch (e) {
debugPrint('setAs failed with exception=${e.message}');
debugPrint('setAs failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
@ -84,7 +84,7 @@ class AndroidAppService {
'mimeType': mimeType,
});
} on PlatformException catch (e) {
debugPrint('share failed with exception=${e.message}');
debugPrint('share failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
}
}

View file

@ -9,7 +9,7 @@ class ViewerService {
// return nullable map with: 'uri' 'mimeType'
return await platform.invokeMethod('getSharedEntry') as Map;
} on PlatformException catch (e) {
debugPrint('getSharedEntry failed with exception=${e.message}');
debugPrint('getSharedEntry failed with code=${e.code}, exception=${e.message}, details=${e.details}');
}
return {};
}