* <p>
* It is possible that LZN data exists but no image file can be found.
* This is typical in "LZT" (template) files, for instance.
*/
public static Interpretation read(File file) {
XmlDocument xmlDoc = null;
File imageFile = null;
ImageInfo info = ImageInfo.getInstanceFor(file);
ImageType type;
try {
type = info.getImageType();
}
catch (IOException e) {
return null;
}
catch (LightCraftsException e) {
if (file.getName().endsWith(".lzt")) {
// This is a symptom of a template file, which does have an
// Interpretation. So we continue.
type = LZNImageType.INSTANCE;
}
else {
return null;
}
}
if (type == LZNImageType.INSTANCE) {
try {
InputStream in = new FileInputStream(file);
xmlDoc = new XmlDocument(in);
LightweightDocument lwDoc = new LightweightDocument(file);
imageFile = lwDoc.getImageFile();
}
catch (IOException e) {
// Fall back to the embedded document test.
}
}
// Second try as an image with embedded document metadata:
if (xmlDoc == null) {
try {
if (type instanceof LZNDocumentProvider) {
final LZNDocumentProvider p = (LZNDocumentProvider)type;
Document lznDoc = p.getLZNDocument(info);
if (lznDoc != null) {
xmlDoc = new XmlDocument(lznDoc.getDocumentElement());
if (xmlDoc != null) {
// The original image may be in the same file,
// or referenced through a path pointer:
XmlNode root = xmlDoc.getRoot();
// (tag copied from ui.editor.Document)
XmlNode imageNode = root.getChild("Image");
// (tag written in export())
if ( imageNode.hasAttribute("self")) {
imageFile = file;