public class DelegatingStorageMerger extends Object implements IStorageMerger
The target storage is used to look for an appropriate merger. If the target
is an IFile
, the content type of the file is used. Otherwise, the
IContentTypeManager
is used to find an appropriate content type. If an
appropriate merger is not found, a status containing the
CONFLICT
is returned.
Clients may use this class directly or subclass it.
CONFLICT, INTERNAL_ERROR, OK, UNSUPPORTED_ENCODING
Constructor and Description |
---|
DelegatingStorageMerger()
Default no-arg constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canMergeWithoutAncestor()
Return whether this merger can merge the two contributors
without an ancestor.
|
protected IStorageMerger |
createDelegateMerger(IStorage target)
Create a merger for the given storage or return
null
if an appropriate merger could not be created. |
static IStorageMerger |
createTextMerger()
Return the storage merger associated with the
IContentTypeManager.CT_TEXT
content type. |
static IContentType |
getContentType(IStorage target)
A helper method that finds the content type for the given storage or returns
null if a content
type cannot be found. |
static String |
getExtension(String name)
Helper method for returning the extension of a file name
|
static IStorageMerger |
getInstance()
Helper method that returns a singleton instance that can be used to merge
two
IStorage instances. |
protected int |
getType(IStorage target)
Return the Team content type associated with the given
target.
|
IStatus |
merge(OutputStream output,
String outputEncoding,
IStorage ancestor,
IStorage target,
IStorage other,
IProgressMonitor monitor)
Performs a merge operation on the given storage instances and writes the merge result to the output stream.
|
public DelegatingStorageMerger()
public static IStorageMerger createTextMerger()
IContentTypeManager.CT_TEXT
content type.IContentTypeManager.CT_TEXT
content typepublic static IStorageMerger getInstance()
IStorage
instances.public IStatus merge(OutputStream output, String outputEncoding, IStorage ancestor, IStorage target, IStorage other, IProgressMonitor monitor) throws CoreException
IStorageMerger
IStatus.OK
is returned, on error a status IStatus.ERROR
.
If the merge operation cannot deal with conflicts, the code of the error status has the value IStreamMerger.CONFLICT
.
For text oriented mergers the encoding for the input and output is honored if they implement
IEncodedStorage
.
It is the responsibility of callers to close the output stream.
The provided ancestor may be null
if this merger
returns true
from IStorageMerger.canMergeWithoutAncestor()
.
merge
in interface IStorageMerger
output
- the byte stream to which the merge result is written; the merger will not close the streamoutputEncoding
- the encoding to use when writing to the output streamancestor
- the storage from which the common ancestor is readtarget
- the storage containing the target of the mergeother
- the storage containing the target of the mergemonitor
- reports progress of the merge operationCoreException
- if an error occursprotected IStorageMerger createDelegateMerger(IStorage target) throws CoreException
null
if an appropriate merger could not be created. This method is called
by merge(OutputStream, String, IStorage, IStorage, IStorage, IProgressMonitor)
to create the merger to which the merge should be delegated.target
- the storage that contains the target contents of the merge.null
CoreException
protected int getType(IStorage target)
target
- the storage that contains the target contents for the merge.Team.getFileContentManager()
,
IFileContentManager.getType(IStorage)
public static String getExtension(String name)
name
- the file namenull
if the file name does not have an extensionpublic static IContentType getContentType(IStorage target) throws CoreException
null
if a content
type cannot be found. Any exceptions that occur when trying to determine
the content type are propagated.target
- the storage that contains the target contents of the merge.null
CoreException
- if an exception occurspublic boolean canMergeWithoutAncestor()
IStorageMerger
canMergeWithoutAncestor
in interface IStorageMerger
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.