Skip to content

Instantly share code, notes, and snippets.

@antonio-junior
Created April 8, 2014 21:26
Show Gist options
  • Save antonio-junior/10195140 to your computer and use it in GitHub Desktop.
Save antonio-junior/10195140 to your computer and use it in GitHub Desktop.
public String replaceImportDLReferences(
PortletDataContext portletDataContext, Element entityElement,
String content, boolean importReferencedContent)
throws Exception {
List<Element> referenceDataElements =
portletDataContext.getReferenceDataElements(
entityElement, FileEntry.class,
PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
for (Element referenceDataElement : referenceDataElements) {
String fileEntryUUID = referenceDataElement.attributeValue("uuid");
if (fileEntryUUID == null) {
continue;
}
String path = referenceDataElement.attributeValue("path");
if (!content.contains("[$dl-reference=" + path + "$]")) {
continue;
}
FileEntry fileEntry =
(FileEntry)portletDataContext.getZipEntryAsObject(path);
StagedModelDataHandlerUtil.importStagedModel(
portletDataContext, fileEntry);
Map<Long, Long> fileEntryIds =
(Map<Long, Long>)portletDataContext.getNewPrimaryKeysMap(
DLFileEntry.class);
String uuid = referenceDataElement.attributeValue("uuid");
long importGroupId = GetterUtil.getLong(
referenceDataElement.attributeValue("group-id"));;
if (importGroupId == portletDataContext.getSourceCompanyGroupId()) {
importGroupId = portletDataContext.getCompanyGroupId();
}
else if (importGroupId == portletDataContext.getSourceGroupId()) {
importGroupId = portletDataContext.getGroupId();
}
FileEntry importedFileEntry = null;
try {
importedFileEntry =
DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(
uuid, importGroupId);
}
catch (NoSuchFileEntryException nsfee) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to reference " + path);
}
continue;
}
String url = DLUtil.getPreviewURL(
importedFileEntry, importedFileEntry.getFileVersion(), null,
StringPool.BLANK, false, false);
content = StringUtil.replace(
content, "[$dl-reference=" + path + "$]", url);
}
return content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment