Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Orion/Documentation/Developer Guide/Plugging into Orion pages"

(Example)
(Fix code formatting, add note about URI Template variables and +)
Line 29: Line 29:
 
:Specifies the hostname for the Orion server instance.  This variable can be used by a plugin that is installed in another domain to reference a page location in Orion.
 
:Specifies the hostname for the Orion server instance.  This variable can be used by a plugin that is installed in another domain to reference a page location in Orion.
  
For example, the URI template <tt>{OrionHome}/content/content.html#{Location}</tt> links to a particular page (content.html) in the running Orion instance, and includes the value of the <tt>Location</tt> property in the originating page's object metadata after the hash.
+
For example, the URI template <tt>{+OrionHome}/content/content.html#{+Location}</tt> links to a particular page (content.html) in the running Orion instance, and includes the value of the <tt>Location</tt> property in the originating page's object metadata after the hash. Note that we prefix variables with <code>+</code> in the template to indicate that their value should ''not'' be percent-encoded when the template is expanded. This is required for any variables that we expect to contain raw URL characters like <code>'/'</code>, which would otherwise be encoded to <code>%2F</code> by the template engine.
  
 
== Content Types ==
 
== Content Types ==
Line 58: Line 58:
  
 
The following snippet defines an orion.page.content extension for showing the Pixlr image editor inside Orion.
 
The following snippet defines an orion.page.content extension for showing the Pixlr image editor inside Orion.
 
+
<source lang="javascript" enclose="div" line>
 
   provider.registerServiceProvider("orion.page.content", {}, {
 
   provider.registerServiceProvider("orion.page.content", {}, {
 
       id: "orion.pixlr.content",
 
       id: "orion.pixlr.content",
 
       name: "Pixlr",
 
       name: "Pixlr",
 
       saveToken: [{token: "imgapi?image=", terminator: "&"},
 
       saveToken: [{token: "imgapi?image=", terminator: "&"},
       uriTemplate: "http://pixlr.com/editor/?image={OrionHome}{Location}&referrer=Orion&title={Name}&locktype=true&exit={ExitURL}&target={SaveURL}imgapi&locktitle=true,contentProvider=orion.pixlr.content"});
+
       uriTemplate: "http://pixlr.com/editor/?image={+OrionHome}{+Location}&referrer=Orion&title={Name}&locktype=true&exit={+ExitURL}&target={+SaveURL}imgapi&locktitle=true,contentProvider=orion.pixlr.content"});
 
+
</source>
The URL to open this page is <tt>/content/content.html#{Location},contentProvider=orion.pixlr.content</tt>
+
The URL to open this page is <tt>/content/content.html#{+Location},contentProvider=orion.pixlr.content</tt>
  
 
If the page content requires a resource location (for example, it is an editor), then typically the page would be linked using the orion editor extension point.  This ensures that the page were opened with a specified location parameter in the URL.  The pixlr plugin contributes an editor in this way.
 
If the page content requires a resource location (for example, it is an editor), then typically the page would be linked using the orion editor extension point.  This ensures that the page were opened with a specified location parameter in the URL.  The pixlr plugin contributes an editor in this way.
 
+
<source lang="javascript" enclose="div" line>
 
   provider.registerServiceProvider("orion.edit.editor", {}, {
 
   provider.registerServiceProvider("orion.edit.editor", {}, {
 
       id: "orion.pixlr",
 
       id: "orion.pixlr",
 
       name: "Pixlr Image Editor",
 
       name: "Pixlr Image Editor",
       uriTemplate: "{OrionHome}/content/content.html#{Location},contentProvider=orion.pixlr.content"});
+
       uriTemplate: "{OrionHome}/content/content.html#{+Location},contentProvider=orion.pixlr.content"});
 
+
</source>
 
The corresponding "open with" extension point is
 
The corresponding "open with" extension point is
 
+
<source lang="javascript" enclose="div" line>
 
   provider.registerServiceProvider("orion.navigate.openWith", {}, {
 
   provider.registerServiceProvider("orion.navigate.openWith", {}, {
 
       editor: "orion.pixlr",
 
       editor: "orion.pixlr",
 
       contentType: ["image/gif", "image/jpeg", "image/ico", "image/png","image/tiff"]});
 
       contentType: ["image/gif", "image/jpeg", "image/ico", "image/png","image/tiff"]});
 
+
</source>
 
= orion.page.link =
 
= orion.page.link =
  
Line 100: Line 100:
  
 
The following snippet defines the some of the main links that are shown in a default Orion installation.
 
The following snippet defines the some of the main links that are shown in a default Orion installation.
 
+
<source lang="javascript" enclose="div" line>
 
   var serviceImpl = {};//no service methods required
 
   var serviceImpl = {};//no service methods required
 
   provider.registerServiceProvider("orion.page.link", serviceImpl, {
 
   provider.registerServiceProvider("orion.page.link", serviceImpl, {
Line 117: Line 117:
 
       uriTemplate: "{OrionHome}/git/git-repository.html#"
 
       uriTemplate: "{OrionHome}/git/git-repository.html#"
 
   });
 
   });
 
+
</source>
 
= orion.page.link.related =  
 
= orion.page.link.related =  
  
Line 144: Line 144:
  
 
The following related page link will determine if the current page's target has a <tt>GitUrl</tt> that conforms to the URL of git repositories hosted at github.com.  If so, then parts of the URL are assigned to variables that are used to build the associated github URL.
 
The following related page link will determine if the current page's target has a <tt>GitUrl</tt> that conforms to the URL of git repositories hosted at github.com.  If so, then parts of the URL are assigned to variables that are used to build the associated github URL.
 
+
<source lang="javascript" enclose="div" line>
 
  provider.registerServiceProvider("orion.page.link.related", null, {
 
  provider.registerServiceProvider("orion.page.link.related", null, {
 
     id: "orion.git.gotoGithub",
 
     id: "orion.git.gotoGithub",
Line 158: Line 158:
 
     uriTemplate: "https://{GitHubLocation}"
 
     uriTemplate: "https://{GitHubLocation}"
 
  });
 
  });
+
</source>
 
If the service extension does not describe a name, tooltip, and uriTemplate, the implementation will look for a command extension of the same id.  In this way, commands added to the navigator that link to other pages may be considered for the Related pages menu.
 
If the service extension does not describe a name, tooltip, and uriTemplate, the implementation will look for a command extension of the same id.  In this way, commands added to the navigator that link to other pages may be considered for the Related pages menu.
  
Line 181: Line 181:
  
 
The following scanner will replace text of the form "bug 123456" with links of the form "https://bugs.eclipse.org/123456
 
The following scanner will replace text of the form "bug 123456" with links of the form "https://bugs.eclipse.org/123456
 
+
<source lang="javascript" enclose="div" line>
 
  var provider = new eclipse.PluginProvider();
 
  var provider = new eclipse.PluginProvider();
 
  var serviceImpl = {};
 
  var serviceImpl = {};
Line 191: Line 191:
 
  provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
 
  provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
 
  provider.connect();
 
  provider.connect();
 +
</source>
  
 
This scanner will replace email addresses with mailto: URLs:
 
This scanner will replace email addresses with mailto: URLs:
  
 +
<source lang="javascript" enclose="div" line>
 
  var provider = new eclipse.PluginProvider();
 
  var provider = new eclipse.PluginProvider();
 
  var serviceImpl = {};
 
  var serviceImpl = {};
Line 203: Line 205:
 
  provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
 
  provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
 
  provider.connect();
 
  provider.connect();
 
+
</source>
 
= orion.core.content =
 
= orion.core.content =
  
Line 232: Line 234:
  
 
Here is a sample plug-in that defines a content zip file that is colocated with the Orion plugin.
 
Here is a sample plug-in that defines a content zip file that is colocated with the Orion plugin.
<pre>
+
<source lang="javascript" enclose="div" line>
 
var provider = new orion.PluginProvider();
 
var provider = new orion.PluginProvider();
 
var temp = document.createElement('a');
 
var temp = document.createElement('a');
Line 244: Line 246:
 
});
 
});
 
provider.connect();
 
provider.connect();
</pre>
+
</source>
  
 
When this plug-in is installed, the user will be offered "Another Exemplary Sample Site" as possible content for a project.
 
When this plug-in is installed, the user will be offered "Another Exemplary Sample Site" as possible content for a project.

Revision as of 13:45, 28 October 2013

Overview of plugging into Orion pages

An important part of plugging into Orion pages is supplying links that connect the user to other pages inside and outside of Orion. Page-level linking services allow plugins and page authors to contribute links and other forms of connectivity between an Orion page and other web pages. The most general of these services can be used on any Orion page.

When specifying links to other pages, a service may need to use some information about the page to decide whether a link is applicable and how the link is composed. This is accomplished for many services by using the validationProperties, uriTemplate, and contentType properties in the service definition.

Validation Properties

Validation properties describe the properties of a page object that should be analyzed to determine whether a particular service applies to the page. They can optionally store information from page objects into variables that can be referenced in a URI template. Linking services generally specify one or more of these properties in an array. The general format of an individual validation property is as follows:

source
String The name of a property to look for in the target object. The ":" character represents nested properties, and the "|" character represents OR'ed properties. For example, the source Location specifies that the page object must have a "Location" property, such as myObject.Location. The source Git:ContentLocation specifies that the page object must have a sub-object and property such as myObject.Git.ContentLocation. The source ChildrenLocation|ContentLocation means that the page object must have either a property such as myObject.ChildrenLocation or a property such as myObject.ContentLocation. The first property found will be used.
match
Object A value used to validate the source property. In general, the value of the page object's property will be compared against this value. However, if this value is a string, the string is assumed to specify a regular expression that will be passed to the RegExp constructor.
variableName
String Optional. The name of a variable that represents the value of the source property. If specified, then an associated URI template may use a variable of this name, and it will contain the value of the matched source property.
variableMatchPosition
String Optional. A string that specifies what part of a matching string is used in the variable value when a regular expression was used to match the property.
  • "all" (default) means the entire property value should be substituted for the variable.
  • only means only the matching part of the property value should be substituted in the URI template.
  • before means the part before the match is substituted in the URI template.
  • after means the part after the match is substituted in the URI template.
replacements
Array Optional. Specifies an array of replacements (pattern and replace strings) that can be used to further modify a variable value used in a URI template.

URI Templates

URI templates describe the link to another page. Variables in the URI template can refer to the page object metadata, to variables named in the validation properties, or to special variables defined in Orion. Variables are referenced using curly brackets. The following variables are system wide variables (independent of the page object or variable names in the validation properties).

OrionHome
Specifies the hostname for the Orion server instance. This variable can be used by a plugin that is installed in another domain to reference a page location in Orion.

For example, the URI template {+OrionHome}/content/content.html#{+Location} links to a particular page (content.html) in the running Orion instance, and includes the value of the Location property in the originating page's object metadata after the hash. Note that we prefix variables with + in the template to indicate that their value should not be percent-encoded when the template is expanded. This is required for any variables that we expect to contain raw URL characters like '/', which would otherwise be encoded to %2F by the template engine.

Content Types

Content types may be used to further validate file-based metadata. For example, if a page link should only be visible when the page is showing HTML or CSS, a content type of [text/html, text/css]can be used to express this.

orion.page.content

Plugins can contribute page content for a page that is framed by the common Orion banner and equipped with standard Orion page services, such as the related pages menu. The page content itself is rendered in an iframe inside the page. Pages contributed in this way are opened in a URL that specifies the id of the extension.

Service methods

None. This service is purely declarative.

Service attributes

Implementations of orion.page.content must define the following attributes:

name
The name of the content, which is shown as the page title in the Orion banner.
id
A symbolic id for referencing this extension point.
uriTemplate
a URI Template that defines the href for the iframe content. When content is opened, it might be targeted against a particular file or folder. In this case, the template variables can refer to file or folder metadata from the target file. In addition to the standard variables used in Orion and the file/folder metadata, some special variables are used:
  • {SaveURL} refers to a URL that can be used to save content back to Orion.
  • {ExitURL} refers to a URL that can be used if the user chooses to exit the embedded application.
saveToken
Optional. An Array of objects describing token(s) that appear in the URL of the page that saves the content. The saveToken is used to find the location of any content stored by the plugin.

Examples

The following snippet defines an orion.page.content extension for showing the Pixlr image editor inside Orion.

  1.    provider.registerServiceProvider("orion.page.content", {}, {
  2.       id: "orion.pixlr.content",
  3.       name: "Pixlr",
  4.       saveToken: [{token: "imgapi?image=", terminator: "&"},
  5.       uriTemplate: "http://pixlr.com/editor/?image={+OrionHome}{+Location}&referrer=Orion&title={Name}&locktype=true&exit={+ExitURL}&target={+SaveURL}imgapi&locktitle=true,contentProvider=orion.pixlr.content"});

The URL to open this page is /content/content.html#{+Location},contentProvider=orion.pixlr.content

If the page content requires a resource location (for example, it is an editor), then typically the page would be linked using the orion editor extension point. This ensures that the page were opened with a specified location parameter in the URL. The pixlr plugin contributes an editor in this way.

  1.    provider.registerServiceProvider("orion.edit.editor", {}, {
  2.       id: "orion.pixlr",
  3.       name: "Pixlr Image Editor",
  4.       uriTemplate: "{OrionHome}/content/content.html#{+Location},contentProvider=orion.pixlr.content"});

The corresponding "open with" extension point is

  1.    provider.registerServiceProvider("orion.navigate.openWith", {}, {
  2.       editor: "orion.pixlr",
  3.       contentType: ["image/gif", "image/jpeg", "image/ico", "image/png","image/tiff"]});

orion.page.link

The link service provides a mechanism for plugins to add links that should appear in the main header of Orion pages. Clients supply the link name and URL. The header code will look for implementers of this service when generating page headers for Orion.

Service methods

None. This service is purely declarative.

Service attributes

Implementations of orion.page.link must define the following attributes:

name
A human readable link name, typically used as an HTML anchor element body, or in a tooltip.
id
A symbolic id for referencing this link.
uriTemplate
A URI Template that defines the link. This template may use the standard Orion URI template variables.

Examples

The following snippet defines the some of the main links that are shown in a default Orion installation.

  1.    var serviceImpl = {};//no service methods required
  2.    provider.registerServiceProvider("orion.page.link", serviceImpl, {
  3.       name: "Navigator",
  4.       id: "orion.navigator",
  5.       uriTemplate: "{OrionHome}/navigate/table.html#"
  6.    });
  7.    provider.registerServiceProvider("orion.page.link", serviceImpl, {
  8.       name: "Sites",
  9.       id: "orion.sites",
  10.       uriTemplate: "{OrionHome}/sites/sites.html"
  11.    });
  12.    provider.registerServiceProvider("orion.page.link", serviceImpl, {
  13.       name: "Repositories",
  14.       id: "orion.repositories",
  15.       uriTemplate: "{OrionHome}/git/git-repository.html#"
  16.    });

orion.page.link.related

The related link service provides a mechanism for plugins to contribute links to the "Related pages" menu in the Orion page header. Clients can specify when the link is applicable using validationProperties and contentType.

Service methods

None. This service is purely declarative.

Service attributes

Implementations of orion.page.link.related must define the following attributes:

id
A symbolic id for referencing this link.
name
A human readable link name, used in the "Related pages" menu.
tooltip
A tooltip used to describe the link.
uriTemplate
A URI Template that defines the link. This template may use page object metadata, declared variable names, or standard Orion URI template variables.
contentType
Optional. An array of Content Type IDs for which this link is applicable.
validationProperties
Optional. An array of Validation Properties describing whether the link is applicable, and optionally declaring variables to be used in the URI template.

Examples

The following related page link will determine if the current page's target has a GitUrl that conforms to the URL of git repositories hosted at github.com. If so, then parts of the URL are assigned to variables that are used to build the associated github URL.

  1.  provider.registerServiceProvider("orion.page.link.related", null, {
  2.     id: "orion.git.gotoGithub",
  3.     name: "Show in GitHub",
  4.     tooltip: "Show this repository at GitHub",
  5.     validationProperties: [{
  6.        source: "GitUrl",
  7.        match: "github\.com.*\.git",
  8.        variableName: "GitHubLocation",
  9.        variableMatchPosition: "only",
  10.        replacements: [{pattern: ":", replacement: "/"}, {pattern: ".git$", replacement: ""}]
  11.     }],
  12.     uriTemplate: "https://{GitHubLocation}"
  13.  });

If the service extension does not describe a name, tooltip, and uriTemplate, the implementation will look for a command extension of the same id. In this way, commands added to the navigator that link to other pages may be considered for the Related pages menu.

orion.core.linkScanner

Link scanners are declarative services that specify patterns of text to replace with link anchors. Scanners contribute a regular expression pattern to match in the source text. They then provide a link to be inserted for each match. These scanners are used by the text link service to convert text into a DOM node with appropriate anchor and text nodes as children.

Service methods

None.

Service attributes

Implementations of orion.core.linkScanner must define the following attributes:

pattern
A regular expression string to locate links in the source text
words
A Number identifying the number of white-space delimited words in each match
anchor
A template of the URL for each match. The template may contain variables of the form %1, %2, etc, which are substituted by each of the words in the match.

Examples

The following scanner will replace text of the form "bug 123456" with links of the form "https://bugs.eclipse.org/123456

  1.  var provider = new eclipse.PluginProvider();
  2.  var serviceImpl = {};
  3.  var serviceProperties = {
  4.    pattern: "bug\\s\\d{4,7}",
  5.    words: 2,
  6.    anchor: "https://bugs.eclipse.org/%2"
  7.  };
  8.  provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
  9.  provider.connect();

This scanner will replace email addresses with mailto: URLs:

  1.  var provider = new eclipse.PluginProvider();
  2.  var serviceImpl = {};
  3.  var serviceProperties = {
  4.    pattern: "\\b[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b",
  5.    words: 1,
  6.    anchor: "mailto:%1"
  7.  };
  8.  provider.registerServiceProvider("orion.core.linkScanner", serviceImpl, serviceProperties);
  9.  provider.connect();

orion.core.content

The orion.core.content service is used to define files that can be imported into a user's project folder. The service describes a contentURITemplate that can be imported into a folder. If the content is a zip file, it can be unzipped into the folder. If the content is to be generated by simply linking to another page, a uriTemplate can be used to specify the link instead of a contentURITemplate.

The user interface for this feature is not specified. The ability to generate content into a project may appear in multiple places.

Service methods

None. This service is purely declarative.

Service attributes

Implementations of orion.core.content may define the following attributes:

name
The user visible name of the content
id
The extension point id.
description
The user visible description which explains what the content contains.
uriTemplate
Optional. A URI Template that defines a link to another page that can generate the content. If this property is specified, then the contentURIProperty property will be ignored.
contentURITemplate
Optional. A URI Template that defines a link to content that should be imported into a project.

Example

Here is a sample plug-in that defines a content zip file that is colocated with the Orion plugin.

  1. var provider = new orion.PluginProvider();
  2. var temp = document.createElement('a');
  3. temp.href = "testContent.zip";
  4.  
  5. provider.registerService("orion.core.content", null, {
  6.         id: "orion.content.test",
  7.         name: "Another Exemplary Sample Site",
  8.         description: "Generate a sample site from Susan's test plugin.",
  9.         contentURITemplate: temp.href
  10. });
  11. provider.connect();

When this plug-in is installed, the user will be offered "Another Exemplary Sample Site" as possible content for a project.

Back to the top