try {
ITextService service = document.getTextService();
ITextContentService contentService = service
.getTextContentService();
if (contentService != null) {
IParagraph newParagraph = contentService
.constructNewParagraph();
ITextRange range = null;
if (ITextRange.class.isAssignableFrom(position.getType())) {
range = (ITextRange) position.getDestinationObject();
}
if (range != null) {
contentService.insertTextContent(range, newParagraph);
} else {
contentService.insertTextContentAfter(paragraph,
newParagraph);
}
if (adoptContent) {
newParagraph.setParagraphText(paragraphText);
}
String[] propertyKeysToCopy = null;
if (propertyKeysContainer != null) {
propertyKeysToCopy = propertyKeysContainer
.getPropertyKeys(IParagraphProperties.TYPE_ID);
} else {
// use default
propertyKeysToCopy = ParagraphProperties
.getDefaultPropertyKeys();
}
if (propertyKeysToCopy != null) {
IParagraphProperties paragraphProperties = newParagraph
.getParagraphProperties();
((IPropertyStore) paragraphPropertyStore).getProperties()
.copyTo(propertyKeysToCopy, paragraphProperties);
}
if (generateReturnValue)
return new ClonedObject(newParagraph, newParagraph
.getClass());
else
return null;
} else {
throw new CloneException(