|
@@ -1043,141 +1043,152 @@ DriveClient.prototype.getXmlFile = function(resp, success, error, ignoreMime, re
|
|
|
var headers = {'Authorization': 'Bearer ' + this.token};
|
|
|
var url = resp.downloadUrl;
|
|
|
|
|
|
- // Loads XML to initialize realtime document if realtime is empty
|
|
|
- this.ui.editor.loadUrl(url, mxUtils.bind(this, function(data)
|
|
|
+ // Download URL is null if no option to download for viewers
|
|
|
+ if (url == null)
|
|
|
{
|
|
|
- try
|
|
|
+ if (error != null)
|
|
|
{
|
|
|
- if (data == null)
|
|
|
- {
|
|
|
- // TODO: Optional redirect to legacy if link is for old file
|
|
|
- error({message: mxResources.get('invalidOrMissingFile')});
|
|
|
- }
|
|
|
- else if (resp.mimeType == this.libraryMimeType || readLibrary)
|
|
|
+ error({message: mxResources.get('exportOptionsDisabledDetails')});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Loads XML to initialize realtime document if realtime is empty
|
|
|
+ this.ui.editor.loadUrl(url, mxUtils.bind(this, function(data)
|
|
|
+ {
|
|
|
+ try
|
|
|
{
|
|
|
- if (resp.mimeType == this.libraryMimeType && !readLibrary)
|
|
|
+ if (data == null)
|
|
|
{
|
|
|
- error({message: mxResources.get('notADiagramFile')});
|
|
|
+ // TODO: Optional redirect to legacy if link is for old file
|
|
|
+ error({message: mxResources.get('invalidOrMissingFile')});
|
|
|
}
|
|
|
- else
|
|
|
+ else if (resp.mimeType == this.libraryMimeType || readLibrary)
|
|
|
{
|
|
|
- success(new DriveLibrary(this.ui, data, resp));
|
|
|
+ if (resp.mimeType == this.libraryMimeType && !readLibrary)
|
|
|
+ {
|
|
|
+ error({message: mxResources.get('notADiagramFile')});
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ success(new DriveLibrary(this.ui, data, resp));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var importFile = false;
|
|
|
-
|
|
|
- if (/\.png$/i.test(resp.title))
|
|
|
+ else
|
|
|
{
|
|
|
- var index = data.lastIndexOf(',');
|
|
|
+ var importFile = false;
|
|
|
|
|
|
- if (index > 0)
|
|
|
+ if (/\.png$/i.test(resp.title))
|
|
|
{
|
|
|
- var xml = this.ui.extractGraphModelFromPng(data.substring(index + 1));
|
|
|
+ var index = data.lastIndexOf(',');
|
|
|
|
|
|
- if (xml != null && xml.length > 0)
|
|
|
- {
|
|
|
- data = xml;
|
|
|
- }
|
|
|
- else
|
|
|
+ if (index > 0)
|
|
|
{
|
|
|
- // Checks if the file contains XML data which can happen when we insert
|
|
|
- // the file and then don't post-process it when loaded into the UI which
|
|
|
- // is required for creating the images for .PNG and .SVG files.
|
|
|
- try
|
|
|
+ var xml = this.ui.extractGraphModelFromPng(data.substring(index + 1));
|
|
|
+
|
|
|
+ if (xml != null && xml.length > 0)
|
|
|
{
|
|
|
- var xml = data.substring(index + 1);
|
|
|
- var temp = (window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ?
|
|
|
- atob(xml) : Base64.decode(xml);
|
|
|
- var node = this.ui.editor.extractGraphModel(
|
|
|
- mxUtils.parseXml(temp).documentElement, true);
|
|
|
-
|
|
|
- if (node == null || node.getElementsByTagName('parsererror').length > 0)
|
|
|
+ data = xml;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Checks if the file contains XML data which can happen when we insert
|
|
|
+ // the file and then don't post-process it when loaded into the UI which
|
|
|
+ // is required for creating the images for .PNG and .SVG files.
|
|
|
+ try
|
|
|
{
|
|
|
- importFile = true;
|
|
|
+ var xml = data.substring(index + 1);
|
|
|
+ var temp = (window.atob && !mxClient.IS_IE && !mxClient.IS_IE11) ?
|
|
|
+ atob(xml) : Base64.decode(xml);
|
|
|
+ var node = this.ui.editor.extractGraphModel(
|
|
|
+ mxUtils.parseXml(temp).documentElement, true);
|
|
|
+
|
|
|
+ if (node == null || node.getElementsByTagName('parsererror').length > 0)
|
|
|
+ {
|
|
|
+ importFile = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ data = temp;
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ catch (e)
|
|
|
{
|
|
|
- data = temp;
|
|
|
+ importFile = true;
|
|
|
}
|
|
|
}
|
|
|
- catch (e)
|
|
|
- {
|
|
|
- importFile = true;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else if (/\.pdf$/i.test(resp.title))
|
|
|
- {
|
|
|
- var xml = Editor.extractGraphModelFromPdf(data);
|
|
|
-
|
|
|
- if (xml != null && xml.length > 0)
|
|
|
+ else if (/\.pdf$/i.test(resp.title))
|
|
|
{
|
|
|
- importFile = true;
|
|
|
- data = xml;
|
|
|
+ var xml = Editor.extractGraphModelFromPdf(data);
|
|
|
+
|
|
|
+ if (xml != null && xml.length > 0)
|
|
|
+ {
|
|
|
+ importFile = true;
|
|
|
+ data = xml;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- // Checks for base64 encoded mxfile
|
|
|
- else if (data.substring(0, 32) == 'data:image/png;base64,PG14ZmlsZS')
|
|
|
- {
|
|
|
- var temp = data.substring(22);
|
|
|
- data = (window.atob && !mxClient.IS_SF) ? atob(temp) : Base64.decode(temp);
|
|
|
- }
|
|
|
-
|
|
|
- if (Graph.fileSupport && new XMLHttpRequest().upload && this.ui.isRemoteFileFormat(data, url))
|
|
|
- {
|
|
|
- this.ui.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
|
|
|
+ // Checks for base64 encoded mxfile
|
|
|
+ else if (data.substring(0, 32) == 'data:image/png;base64,PG14ZmlsZS')
|
|
|
{
|
|
|
- try
|
|
|
+ var temp = data.substring(22);
|
|
|
+ data = (window.atob && !mxClient.IS_SF) ? atob(temp) : Base64.decode(temp);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Graph.fileSupport && new XMLHttpRequest().upload && this.ui.isRemoteFileFormat(data, url))
|
|
|
+ {
|
|
|
+ this.ui.parseFile(new Blob([data], {type: 'application/octet-stream'}), mxUtils.bind(this, function(xhr)
|
|
|
{
|
|
|
- if (xhr.readyState == 4)
|
|
|
+ try
|
|
|
{
|
|
|
- if (xhr.status >= 200 && xhr.status <= 299)
|
|
|
+ if (xhr.readyState == 4)
|
|
|
{
|
|
|
- success(new LocalFile(this.ui, xhr.responseText, resp.title + this.extension, true));
|
|
|
- }
|
|
|
- else if (error != null)
|
|
|
- {
|
|
|
- error({message: mxResources.get('errorLoadingFile')});
|
|
|
+ if (xhr.status >= 200 && xhr.status <= 299)
|
|
|
+ {
|
|
|
+ success(new LocalFile(this.ui, xhr.responseText, resp.title + this.extension, true));
|
|
|
+ }
|
|
|
+ else if (error != null)
|
|
|
+ {
|
|
|
+ error({message: mxResources.get('errorLoadingFile')});
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- catch (e)
|
|
|
- {
|
|
|
- if (error != null)
|
|
|
- {
|
|
|
- error(e);
|
|
|
- }
|
|
|
- else
|
|
|
+ catch (e)
|
|
|
{
|
|
|
- throw e;
|
|
|
+ if (error != null)
|
|
|
+ {
|
|
|
+ error(e);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }), resp.title);
|
|
|
+ }), resp.title);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ success((importFile) ? new LocalFile(this.ui, data, resp.title, true) : new DriveFile(this.ui, data, resp));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (e)
|
|
|
+ {
|
|
|
+ if (error != null)
|
|
|
+ {
|
|
|
+ error(e);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- success((importFile) ? new LocalFile(this.ui, data, resp.title, true) : new DriveFile(this.ui, data, resp));
|
|
|
+ throw e;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- catch (e)
|
|
|
- {
|
|
|
- if (error != null)
|
|
|
- {
|
|
|
- error(e);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- throw e;
|
|
|
- }
|
|
|
- }
|
|
|
- }), error, ((resp.mimeType != null && resp.mimeType.substring(0, 6) == 'image/' &&
|
|
|
- resp.mimeType.substring(0, 9) != 'image/svg')) || /\.png$/i.test(resp.title) ||
|
|
|
- /\.jpe?g$/i.test(resp.title) || /\.pdf$/i.test(resp.title),
|
|
|
- null, null, null, headers);
|
|
|
+ }), error, ((resp.mimeType != null && resp.mimeType.substring(0, 6) == 'image/' &&
|
|
|
+ resp.mimeType.substring(0, 9) != 'image/svg')) || /\.png$/i.test(resp.title) ||
|
|
|
+ /\.jpe?g$/i.test(resp.title) || /\.pdf$/i.test(resp.title),
|
|
|
+ null, null, null, headers);
|
|
|
+ }
|
|
|
}
|
|
|
catch (e)
|
|
|
{
|