use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.
the class KBArticleMarkdownConverter method processAttachmentsReferences.
public String processAttachmentsReferences(long userId, KBArticle kbArticle, ZipReader zipReader, Map<String, FileEntry> fileEntriesMap) throws PortalException, SystemException {
Set<Integer> indexes = new TreeSet<Integer>();
int index = 0;
while ((index = _html.indexOf("<img", index)) > -1) {
indexes.add(index);
index += 4;
}
if (indexes.isEmpty()) {
return _html;
}
StringBundler sb = new StringBundler();
int previousIndex = 0;
for (int curIndex : indexes) {
if (curIndex < 0) {
break;
}
if (curIndex > previousIndex) {
// Append text from previous position up to image tag
String text = _html.substring(previousIndex, curIndex);
sb.append(text);
}
int pos = _html.indexOf("/>", curIndex);
if (pos < 0) {
if (_log.isDebugEnabled()) {
_log.debug("Expected close tag for image " + _html.substring(curIndex));
}
sb.append(_html.substring(curIndex));
previousIndex = curIndex;
break;
}
String text = _html.substring(curIndex, pos);
String imageFileName = KBArticleImporterUtil.extractImageFileName(text);
FileEntry imageFileEntry = KBArticleImporterUtil.addImageFileEntry(imageFileName, userId, kbArticle, zipReader, fileEntriesMap);
if (imageFileEntry == null) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to find image source " + text);
}
sb.append("<img alt=\"missing image\" src=\"\" ");
} else {
String imageSrc = StringPool.BLANK;
try {
imageSrc = DLUtil.getPreviewURL(imageFileEntry, imageFileEntry.getFileVersion(), null, StringPool.BLANK);
} catch (PortalException pe) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to obtain image URL from file entry " + imageFileEntry.getFileEntryId());
}
}
sb.append("<img alt=\"");
sb.append(HtmlUtil.escapeAttribute(imageFileEntry.getTitle()));
sb.append("\" src=\"");
sb.append(imageSrc);
sb.append("\" ");
}
previousIndex = pos;
}
if (previousIndex < _html.length()) {
sb.append(_html.substring(previousIndex));
}
return sb.toString();
}
use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.
the class ClpSerializer method translateThrowable.
public static Throwable translateThrowable(Throwable throwable) {
if (_useReflectionToTranslateThrowable) {
try {
UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(unsyncByteArrayOutputStream);
objectOutputStream.writeObject(throwable);
objectOutputStream.flush();
objectOutputStream.close();
UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(unsyncByteArrayOutputStream.unsafeGetByteArray(), 0, unsyncByteArrayOutputStream.size());
Thread currentThread = Thread.currentThread();
ClassLoader contextClassLoader = currentThread.getContextClassLoader();
ObjectInputStream objectInputStream = new ClassLoaderObjectInputStream(unsyncByteArrayInputStream, contextClassLoader);
throwable = (Throwable) objectInputStream.readObject();
objectInputStream.close();
return throwable;
} catch (SecurityException se) {
if (_log.isInfoEnabled()) {
_log.info("Do not use reflection to translate throwable");
}
_useReflectionToTranslateThrowable = false;
} catch (Throwable throwable2) {
_log.error(throwable2, throwable2);
return throwable2;
}
}
Class<?> clazz = throwable.getClass();
String className = clazz.getName();
if (className.equals(PortalException.class.getName())) {
return new PortalException();
}
if (className.equals(SystemException.class.getName())) {
return new SystemException();
}
if (className.equals("com.liferay.knowledgebase.DuplicateKBArticleUrlTitleException")) {
return new com.liferay.knowledgebase.DuplicateKBArticleUrlTitleException();
}
if (className.equals("com.liferay.knowledgebase.DuplicateKBFolderNameException")) {
return new com.liferay.knowledgebase.DuplicateKBFolderNameException();
}
if (className.equals("com.liferay.knowledgebase.InvalidKBArticleUrlTitleException")) {
return new com.liferay.knowledgebase.InvalidKBArticleUrlTitleException();
}
if (className.equals("com.liferay.knowledgebase.InvalidKBFolderNameException")) {
return new com.liferay.knowledgebase.InvalidKBFolderNameException();
}
if (className.equals("com.liferay.knowledgebase.KBArticleContentException")) {
return new com.liferay.knowledgebase.KBArticleContentException();
}
if (className.equals("com.liferay.knowledgebase.KBArticleImportException")) {
return new com.liferay.knowledgebase.KBArticleImportException();
}
if (className.equals("com.liferay.knowledgebase.KBArticleParentException")) {
return new com.liferay.knowledgebase.KBArticleParentException();
}
if (className.equals("com.liferay.knowledgebase.KBArticlePriorityException")) {
return new com.liferay.knowledgebase.KBArticlePriorityException();
}
if (className.equals("com.liferay.knowledgebase.KBArticleSourceURLException")) {
return new com.liferay.knowledgebase.KBArticleSourceURLException();
}
if (className.equals("com.liferay.knowledgebase.KBArticleTitleException")) {
return new com.liferay.knowledgebase.KBArticleTitleException();
}
if (className.equals("com.liferay.knowledgebase.KBCommentContentException")) {
return new com.liferay.knowledgebase.KBCommentContentException();
}
if (className.equals("com.liferay.knowledgebase.KBTemplateContentException")) {
return new com.liferay.knowledgebase.KBTemplateContentException();
}
if (className.equals("com.liferay.knowledgebase.KBTemplateTitleException")) {
return new com.liferay.knowledgebase.KBTemplateTitleException();
}
if (className.equals("com.liferay.knowledgebase.NoSuchKBArticleSelectorException")) {
return new com.liferay.knowledgebase.NoSuchKBArticleSelectorException();
}
if (className.equals("com.liferay.knowledgebase.NoSuchArticleException")) {
return new com.liferay.knowledgebase.NoSuchArticleException();
}
if (className.equals("com.liferay.knowledgebase.NoSuchCommentException")) {
return new com.liferay.knowledgebase.NoSuchCommentException();
}
if (className.equals("com.liferay.knowledgebase.NoSuchFolderException")) {
return new com.liferay.knowledgebase.NoSuchFolderException();
}
if (className.equals("com.liferay.knowledgebase.NoSuchTemplateException")) {
return new com.liferay.knowledgebase.NoSuchTemplateException();
}
return throwable;
}
use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.
the class ArtistLocalServiceImpl method updateArtist.
@Indexable(type = IndexableType.REINDEX)
public Artist updateArtist(long userId, long artistId, String name, String bio, InputStream inputStream, ServiceContext serviceContext) throws PortalException, SystemException {
// Event
User user = userPersistence.findByPrimaryKey(userId);
validate(name);
Artist artist = artistPersistence.findByPrimaryKey(artistId);
artist.setModifiedDate(serviceContext.getModifiedDate(null));
artist.setName(name);
artist.setBio(bio);
artist.setExpandoBridgeAttributes(serviceContext);
artistPersistence.update(artist);
if (inputStream != null) {
Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(serviceContext.getScopeGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY);
if (repository != null) {
try {
PortletFileRepositoryUtil.deletePortletFileEntry(repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(artist.getArtistId()));
} catch (Exception e) {
if (_log.isDebugEnabled()) {
_log.debug("Cannot delete artist image");
}
}
}
PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Artist.class.getName(), artist.getArtistId(), Constants.JUKEBOX_PORTLET_REPOSITORY, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, inputStream, String.valueOf(artist.getArtistId()), StringPool.BLANK, true);
}
// Asset
updateAsset(userId, artist, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
return artist;
}
use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.
the class ArtistLocalServiceImpl method deleteArtist.
@Indexable(type = IndexableType.DELETE)
public Artist deleteArtist(long artistId) throws PortalException, SystemException {
Artist artist = artistPersistence.findByPrimaryKey(artistId);
List<Album> albums = albumLocalService.getAlbumsByArtistId(artistId);
for (Album album : albums) {
albumLocalService.deleteAlbum(album.getAlbumId());
}
try {
PortletFileRepositoryUtil.deletePortletFileEntry(artist.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(artistId));
} catch (Exception e) {
}
return artistPersistence.remove(artistId);
}
use of com.liferay.portal.kernel.exception.PortalException in project liferay-ide by liferay.
the class LegacyAPIsAntPortlet method doView.
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
try {
long groupId = PortalUtil.getScopeGroupId(renderRequest);
int count = JournalArticleLocalServiceUtil.getArticlesCount(groupId);
renderRequest.setAttribute("groupJournalArticlesCount", count);
JournalArticleLocalService service = JournalArticleLocalServiceUtil.getService();
int journalArticlesCount = service.getJournalArticlesCount();
renderRequest.setAttribute("journalArticlesCount", journalArticlesCount);
} catch (PortalException | SystemException e) {
e.printStackTrace();
}
super.doView(renderRequest, renderResponse);
}
Aggregations