Extending XMetaL Author Using the Resource Manager

28
© 2010 JustSystems Inc. © 2010 JustSystems Inc. in 37 minutes Episode 7 Extending XMetaL Author using the Resource Manager Brought to you by XMetaL Technical Services Murray Smith, Technical Services Manager

description

XML content is rarely authored in a vacuum. The Resource Manager in XMetaL Author provides a convenient piece of screen real-estate to connect the author to the rest of the world. Sitting right beside the editor pane in XMetaL Author, it’s the perfect place to present information needed by the author, collect ancillary information about the content while it’s fresh in the author’s mind, or display widgets for the author to initiate additional processing on the content. For example, you can use the Resource Manager to: * display a to-do list of changes that need to be made to a document * embed a powerful third-party image editor, e.g. to display and interact with a 3D image of a machine part * let the author search for relevant reusable content * let the author record metadata while they author a document Join us for a quick introduction to embedding Internet Explorer in the XMetaL Resource Manager and how to communicate between Internet Explorer and XMetaL Author and your back-end systems. A recording of this presentation is available at http://tinyurl.com/276qoul . Code samples used in the presentation are available at http://na.justsystems.com/files/resource_manager-demofiles.zip . This presentation is part of the free "XMetaL in 37 Minutes" webinar series. For upcoming webinars, see http://na.justsystems.com/webinars.php .

Transcript of Extending XMetaL Author Using the Resource Manager

Page 1: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.© 2010 JustSystems Inc.

in 37 minutes

Episode 7

Extending XMetaL Author using the Resource Manager

Brought to you by XMetaL Technical Services

Murray Smith, Technical Services Manager

Page 2: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Announcements

• Latest Product Releases– XMetaL Author Enterprise for Documentum Webtop– XMetaL Reviewer 6.1

• Next time: June 17, Getting to Yes: Overcoming Barriers to XML Adoption in the Enterprise.

• No 37 Minute webinar on the first Thursday of July (it’s a holiday in Canada).

Page 3: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

• System Overview• Implementation Details

– Loading Internet Explorer in the Resource Manager.– Communicating from the HTML page in IE to external systems.– Communicating from the HTML page in IE to XMetaL Author.– Communicating from XMetaL Author to your HTML page in IE.– Advanced Topic: Making sure the HTML page in IE is fully

loaded.– Advanced Topic: Parameter passing between XMetaL Author

and your HTML page in IE.

Agenda

Page 4: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

System Overview

External Systems

A key issue regarding script code is that script code in an HTML page in IE is running in IE’s script engine, while script code in an XMetaL macro file is running in XMetaL Author’s script engine.

Page 5: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Loading Internet Explorer in the Resource Manager

Demo 1

Page 6: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Loading Internet Explorer in the Resource Manager – XMetaL Script Code

ResourceManager.AddTab(“Demo_1","Shell.Explorer");

ResourceManager.SelectTab(“Demo_1");

Var msie = ResourceManager.ControlInTab( “Demo_1" );

msie.Navigate( “http://www.google.com" );

XMetaL script code from ResManDemo1.mcr

1) Load IE in Resource Manager and call the tab Demo_1.

2) Make this tab visible.

3) Get a reference to the IE control.

4) Tell the control to navigate to google.com.

ResourceManager is a global object that is accessible from script code running in XMetaL Author.

Page 7: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: HTML Page to External System

External Systems

Page 8: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: HTML Page to External System

Demo 2

Page 9: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: HTML Page to External System – XMetaL Script code

The code is the same as the previous demo, except this time we navigate to an html page on the file system.

XMetaL script code in ResManDemo2.mcr

Page 10: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: HTML Page to External System – IE Script Code

Anything you can do from an HTML page in IE, you can do from an HTML page in IE in the Resource Manager.

In this demo we use AJAX to call a server.

IE script code in ResManDemo2.html

Page 11: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: HTML Page to XMetaL Author

The key issue is that script running in IE is running in IE’s script engine and script running in XMetaL Author is running in XMetaL Author’s script engine.

Page 12: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: HTML Page to XMetaL Author

Demo 3

Page 13: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: HTML Page to XMetaL Author – IE Script Code

var xmApp = new ActiveXObject("XMetaL.Application");var doc = xmApp.ActiveDocument;if( doc == null ){ alert( "Please open a document first." );}else{ doc.Range.Text = time;}

The key line is the first one. It shows how to get a reference to the XMetaL Application object from script code in IE. Once you have it you have access to the XMetaL Application API from within your HTML page.

IE script code in ResManDemo3.html

Page 14: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: XMetaL Author to the HTML Page

Same issue as before. Script running in IE is running in IE’s script engine and script running in XMetaL Author is running in XMetaL Author’s script engine.

Page 15: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: XMetaL Author to the HTML Page

Demo 4

Page 16: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: XMetaL Author to the HTML Page – IE Script Code

The page loaded in the Resource Manager has a JavaScript function [writeMsg(msg)] that writes a message into the HTML page.

We will invoke this function from script running in XMetaL Author.

IE script code in ResManDemo4.html

Page 17: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Communication: XMetaL Author to the HTML Page – XMetaL Script Code

var msie = ResourceManager.ControlInTab( "Demo_4" );var doc = msie.document;doc.Script.execScript( "writeMsg( '" + msg + "' )", "JSCRIPT" );

1. Get a reference to the IE ActiveX control,

2. Get a reference to the HTML Document object in IE,

3. Use the execScript() method of the Script object to invoke the JavaScript function in the HTML page.

XMetaL script code in ResManDemo4.mcr

Page 18: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Advanced Topic: Make Sure the HTML Page is Fully Loaded

The issue is that if you have script code running in XMetaL Author that will make calls to your HTML page running in IE in the Resource Manager, you need to make sure the HTML page is fully loaded before you make any calls to it.

Page 19: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Advanced Topic: Make Sure the HTML Page is Fully Loaded

Demo 5

Page 20: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Advanced Topic: Make Sure the HTML Page is Fully Loaded – Overview

The solution is to have IE tell the script code running in XMetaL Author when it has finished loading the HTML page.

Script Running in XMetaL Author HTML Page in IE in Resource Manager

Load page in Resource Manager

Page initialization

Tell the script that the page is fully initialized

Now it’s safe to make call to the page

Wait for page initialization to

complete

Page 21: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Make Sure the HTML Page is Fully Loaded – Overview

• We have an additional ActiveX control that is loaded in the Resource Manager. (CritiqueUtils.WebBrowerContainer)

• Internet Explorer will be loaded inside the CritiqueUtils container which is loaded in the Resource Manager.

• The CritiqueUtils container will make a callback to your XMetaL JavaScript code once your page is fully loaded.

Page 22: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Make Sure the HTML Page is Fully Loaded – XMetaL Script Code

Callback code that is executed when IE finishes loading the HTML page.

Use CritiqueUtils.WebBrowerContainer instead of Shell.Explorer

An instance of the callback handler is passed to the Navigate2() method.

XMetaL script code in ResManDemo5.mcr

Page 23: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Advanced Topic: Parameter Passing Between XMetaL and Your HTML Page

The key issue is that you generally can’t directly pass parameters between the two because they are 2 separate script engines.

Page 24: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Parameter Passing Between XMetaL and Your HTML Page

Demo 6

Page 25: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Parameter Passing Between XMetaL and Your HTML Page – IE Script Code

var xmApp = new ActiveXObject("XMetaL.Application");xmApp.CustomProperties.Add( "msgFromHtmlPage", msg );xmApp.Run( "displayMsgFromHtmlPage" );

IE script code in ResManDemo6.html

Use XMetaL’s CustomProperties API’s to pass parameters back and forth between IE script code and XMetaL script code.

Page 26: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Summary

• Loading HTML pages running in Internet Explorer in the Resource Manager is a highly flexible way to extend XMetaL Author.

• We’ve seen that script code in IE is running in IE’s script engine and script code in XMetaL Author is running in XMetaL Author’s script engine.– Therefore, we can’t directly invoke script methods or

access script data.– Instead we need to get references to the ActiveX

controls and use the XMetaL API and IE API.

Page 27: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

Additional Resources

• Information on the Internet Explorer ActiveX control.– http://msdn.microsoft.com/en-us/library/aa752040(v=VS.85).asp

x

• Information on the XMetaL API– http://na.justsystems.com/webhelp/en/xmetaldeveloper/pg/6.0/pg.html

Page 28: Extending XMetaL Author Using the Resource Manager

© 2010 JustSystems Inc.

• Thank you for attending!

Q&A