Insert a Stub into a Repository
The stub
fetch action inserts a stub into a repository.
A stub is a link to a document in another repository. An application might use your connector to insert a stub when a document is moved to another repository or is deleted. The stub can point to the new location, or in the case where the document has been deleted, explain why the document is missing.
Action | Description | Method to override |
---|---|---|
/action=fetch&fetchaction=Stub
|
Inserts a stub into a repository. | Stub
|
To implement the stub
action, override the stub
method.
When your users run the Stub
action, they must set an action parameter named StubXML
. The value of this parameter is XML that describes the stub documents to insert. ConnectorLib Java uses the XML to provide DocInfo
objects, which are available through the StubTask
object provided to the stub
method.
You must use the reference, identifier, properties, and metadata contained by a DocInfo
object to determine where to insert the stub. You should instruct the users of your connector what information they must provide.
To determine the target of the stub document (the document that the stub must point to), use the method task.getTarget(doc)
. This returns a StubTarget
object that can include any of the following properties:
- The name of a connector group that can retrieve the stub target.
- A document identifier that can be used by a connector to retrieve the stub target.
- A URI that can be used to retrieve the stub target.
- A RedirectHtml string. When opened in a Web browser this should open the stub target.
If your code inserts the stub successfully, call the success
method on the relevant DocInfo
object. If there is a problem, call the failed
method with a description of the error that can be reported to the user.
Example
The following example code shows how to implement the stub action for a simple file system connector.
The code iterates over all of the DocInfo
objects provided by the task. It extracts the document reference from each DocInfo
object, and inserts a stub at that location in the file system.
public void stub(StubTask task) { for (int ii = 0; ii < task.getDocCount(); ++ii) { DocInfo doc = task.getDoc(ii); try { String reference = doc.getId().getReference(); File fileEntry = new File(reference); FileOutputStream fos = new FileOutputStream(fileEntry); fos.write(task.getTarget(doc).getRedirectHtml().getBytes()); fos.close(); doc.success(); } catch (Exception e) { doc.failed(e.getMessage()); } } }