Show TOC Start of Content Area

Syntax documentation Handling Links Locate the document in its SAP Library structure

There is no special class that represents links. You handle links in the same way as resources, using the IResource interface that offers all the methods you need. If a link is involved in an operation, the repository framework automatically recognizes it and adapts processing accordingly. Although there is no special class that represents links, there are some methods in the IResource interface which are defined specifically for links. These are, for example:

 

Method

Description

createLink

Creates a link

getTargetResource()

Returns the target resource of an internal link if the link exists and is not broken.

getTargetURL()

Returns the URL of the target of an external link or the RID of the target of an internal link.

getLinkType()

Returns the link type which can be internal or external.

Creating Links

When you create a link, you can specify whether it is internal or external. You create a link as follows:

 

IResource link = parent.createLink(″link″, ″/documents/file″, LinkType.INTERNAL, null);

 

Identifying the Link Type

It is useful to know the link type because it gives an indication of the operations that are possible on the link target. The repository framework distinguishes between internal and external links. Internal links refer to resources that are integrated in the repository framework, whereas external links refer to objects that are not integrated in the repository framework, for example, documents stored on a web site. If a link is internal, you can access the target as a resource that offers the operations associated with repository framework resources. If a link is external, you can only access the target as a URL and not as a resource object. As a consequence, most of the operations associated with resources are not available. Determining the link type is therefore often a prerequisite for handling a link target effectively.

The code extract shows how you can find out what type of link is involved.

if( LinkType.INTERNAL.equals(resource.getLinkType()) ) {
  // resource is an internal link to another resource
  IResource target = resource.getTargetResource();
  if( target == null ) {
    // link is broken, because target does not exist anymore as a resource,
    // so use the RID of the internal link’s target instead.
    URL targetURL = resource.getTargetURL();
  }
} else if( LinkType.EXTERNAL.equals(resource.getLinkType()) ) {
  // resource is an external link to an URL
  URL target = resource.getTargetURL();
} else { // if( LinkType.NONE.equals(resource.getLinkType()) )
  // resource is not a link
}

 

The repository framework also distinguishes between internal links that are static and dynamic. Dynamic links follow their target after the execution of operations like copy and move, whereas static links do not. When you create a link, the repository framework decides whether it will be static or dynamic.

To determine whether an internal link is dynamic link, you cast IResource to the IInternalLinkResource semantic object as shown in the code extract:

if( LinkType.INTERNAL.equals(resource.getLinkType()) ) {

  if( resource.isA(IInternalLinkResource.class) ) {

    IInternalLinkResource internalLink = (IInternalLinkResource)resource

                                         .as(IInternalLinkResource.class);

    if( internalLink.isDynamic() ) {

      // it is a flexible link (dynamic internal link), which is never broken

    } else {

      // it is a static internal link which can be broken

    }

  }

}

 

End of Content Area