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"

(Overview of plugging into Orion pages)
Line 1: Line 1:
 
= Overview of plugging into Orion pages =
 
= Overview of plugging into Orion pages =
  
The following services allow plugins to contribute links and other forms of connectivity between an Orion page and other web pages. Services in this section can be used on any Orion page, rather than operating on any specific page. Page authors can make use of these services to allow extensible connectivity between their page and others.
+
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 <tt>validationProperties</tt> and <tt>uriTemplate</tt> properties.
 +
 
 +
== 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
 +
:<tt>String</tt> 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 <tt>myObject.Location</tt>.  The source "Git:ContentLocation" specifies that the page object must have a subobject and property such as <tt>myObject.Git.ContentLocation</tt>.  The source "ChildrenLocation|ContentLocation" means that the page object must have either a property such as <tt>myObject.ChildrenLocation</tt> or a property such as <tt>myObject.ContentLocation</tt>.  The first property found will be used.
 +
;match
 +
:<tt>Object</tt> 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
 +
:<tt>String</tt> 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
 +
:<tt>String</tt> 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.  <tt>"all"</tt> (default) means the entire property value should be substituted for the variable.  <tt>only</tt> means only the matching part of the property value should be substituted in the URI template.  <tt>before</tt> means the part before the match is substituted in the URI template.  <tt>after</tt> means the part after the match is substituted in the URI template.
 +
;replacements
 +
:<tt>Array</tt> 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.
 +
 
 +
== 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 <tt>[text/html, text/css]</tt>can be used to express this.
  
 
= orion.core.linkScanner =
 
= orion.core.linkScanner =

Revision as of 16:41, 13 April 2012

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 and uriTemplate properties.

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 subobject 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.

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.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

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

This scanner will replace email addresses with mailto: URLs:

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

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.

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. Variables supplied to the template include {OrionHome}, the fully qualified path name of the Orion extension, {Location}, the path to the Orion resource (if applicable), {Name}, the name of the Orion resource (if applicable), {SaveURL} a URL that can be used to save content back to Orion.
saveToken
an optional String or array of Strings describing token(s) that appear in the URL of the page that saves the content. The saveToken is used to find the location of the saved content.
saveTokenTerminator
an optional String or array of Strings describing the strings that terminate the save token.

Examples

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

  provider.registerServiceProvider("orion.page.content", {}, {
     id: "orion.pixlr.content",
     name: "Pixlr",
     saveToken: ["imgapi?image=","imgapi&image="],
     saveTokenTerminator: "&",
     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.

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

The corresponding "open with" extension point is

  provider.registerServiceProvider("orion.navigate.openWith", {}, {
     editor: "orion.pixlr",
     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 implementors of this service when generating page headers for Orion.

Service methods

None.

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.
href
The anchor's hypertext reference. This should be an absolute URL because the service implementation won't know anything about the position of the pages that may choose to insert this link.

Examples

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

  var serviceImpl = {};//no service methods required
  provider.registerServiceProvider("orion.page.link", serviceImpl, {
     name: "Navigator",
     id: "orion.navigator",
     href: "/navigate/table.html#"
  });
  provider.registerServiceProvider("orion.page.link", serviceImpl, {
     name: "Sites",
     id: "orion.sites",
     href: "/sites/sites.html"
  });
  provider.registerServiceProvider("orion.page.link", serviceImpl, {
     name: "Repositories",
     id: "orion.repositories",
     href: "/git/git-repository.html#"
  });

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. Currently, a related link must first be defined as a command in "orion.navigate.command." Then, the command id should be referenced in the service definition for the "orion.page.link.related" extension. When any page is loaded in Orion, it will evaluate its resource against the validationProperties for the command. If the page's resource is valid for the command, then the command will appear in "Related pages."

Back to the top