Liferay Portal 6.1 EE - DLUtil.getPreviewURL - liferay

We create a pdf-download URL in our Liferay Portal 6.1 EE via following
method call:
String fileUrl = DLUtil.getPreviewURL(file, fileVersion, null, StringPool.BLANK, false, true);
Is it possible to remove the generated "number-letter-combination" (bold text) from the link or place it at a certain point in the url ?
documents/10180/1423151/AT0000753173_FAT.pdf/461a1fdf-6e61-4cb3-8c1d-77cb527e3609
Thanks a lot for any hints.

the "number-letter-combination" is the file uuid field and there is no way to move that calling the method DLUtil.getPreviewURL. But you can build the url yourself in this way
StringBundler sb = new StringBundler();
sb.append(PortalUtil.getPathContext());
sb.append("/documents/");
sb.append(fileEntry.getRepositoryId());
sb.append(StringPool.SLASH);
sb.append(fileEntry.getFolderId());
sb.append(StringPool.SLASH);
sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(fileEntry.getTitle())));
fileUrl = sb.toString()

Related

Liferay 7.2 render url of a portlet with instance

I have Liferay 7.2.
Jsp file for the view of a custom portlet.
I'm trying to generate a url from a custom portlet to link the document media portlet (com_liferay_document_library_web_portlet_DLPortlet).
I try
<liferay-portlet:actionURL name="newMyNew" portletName="com_liferay_document_library_web_portlet_DLPortlet" var="prueba2"></liferay-portlet:actionURL>
output:
http://localhost:8080/web/guest/home?p_p_id=com_liferay_document_library_web_portlet_DLPortlet&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&_com_liferay_document_library_web_portlet_DLPortlet_javax.portlet.action=newMyNew&p_auth=1IDKtzvU
But i need the instance ID of the Document Media portlet (com_liferay_document_library_web_portlet_DLPortlet) because i need that it receive the variables like folderId
i need this output:
http://localhost:8080/web/guest/home/-/document_library/jFOlAlmeJgMl/view/34527?_com_liferay_document_library_web_portlet_DLPortlet_INSTANCE_jFOlAlmeJgMl_redirect=http%3A%2F%2Flocalhost%3A8080%2Fweb%2Fguest%2Fhome%3Fp_p_id%3Dcom_liferay_document_library_web_portlet_DLPortlet_INSTANCE_jFOlAlmeJgMl%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview
How can i do that?
I found the solution to get the instance id of portlet
List<Portlet> portletListDUE = layoutTypePortlet.getAllPortlets();
String portletInstanceId = "";
for(Portlet portletIn : portletListDUE) {
String portletNameOfInstance = portletIn.getPortletName();
if(portletNameOfInstance.equals("com_liferay_document_library_web_portlet_DLPortlet"))
{
portletInstanceId = portletIn.getInstanceId();
}
}

Change document library document file entry type programmatically

I need to change document types (FileEntryType) for a large list of files in Liferay Document Library, but I have not been able to do so.
After hours of googeling, testing and familiarizing myself with Liferay Github repo, I decided to come here and ask for help.
This is what I have used:
ServiceContext serviceContext = new ServiceContext();
List<DLFileEntry> filesToBeUpdated = DLFileEntryServiceUtil.getFileEntries(
groupId, 0, fileEntryTypeId,
0, 10000, OrderByComparator);
for (DLFileEntry file : filesToBeUpdated) {
System.out.println("Changing file: "+ file.getName());
serviceContext.setAttribute("fileEntryTypeId", fileEntryTypeId);
DLAppServiceUtil.updateFileEntry(file.getFileEntryId(), file.getName(),
file.getMimeType(), null, file.getDescription(),
null, false, null, file.getSize(), serviceContext);
}
The files I used for testing are found correctly. The problem is with updating in the for loop: It throws always PortletException. How can I change the FileEntryType correctly?
You can also accomplish this with DLAppServiceUtil by setting the field in the ServiceContext that you pass in as the last parameter:
sc.setAttribute("fileEntryTypeId", liferayDocumentType);
Why do you use DLAppServiceUtil.updateFileEntry(...)? DLFileEntryServiceUtil has updateFileEntry method that accepts long fileEntryTypeId as a parameter.

Sharepoint 2010 OfficialFileUrl is Always NULL

I am trying to Get the RecordCenterURL from Sharepoint2010,
I have created Connection to Connect RecordCenter or DocumentRepository. I used this LINK
When I try to Retrieve the OfficialFileUrl from Application, Its always return NULL value.
I have used this sample Code , Please help me for this Issue.
string URL = "http://inblr-iifw8sv03:31521";
SPSite site = new SPSite(URL);
string recordCenterUrl = string.Empty;
if (site.WebApplication.OfficialFileUrl != null)// This is Always NULL
{
recordCenterUrl = site.WebApplication.OfficialFileUrl.ToString().
Replace("_vti_bin/officialfile.asmx", string.Empty);
}
Console.WriteLine("URL Found " + recordCenterUrl);
Console.ReadLine();
Is the Send To Recordcenter showing up in the site collection when you choose "Send to" context menu on e.g. document? Please double check General Settings -> Configure Send to Connections (in Central Admin), perhaps you configured it for wrong webapplication?

How to set URL when a wiki site is created programmatically in SharePoint 2010?

I am creating a new site with:
SPSite currentContext = SPContext.GetContext(HttpContext.Current).Site;
SPWeb parentID = currentContext.OpenWeb(new Guid(parentSiteValue));
newWeb = parentID.Webs.Add(newSiteUrl, newSiteName, null, (uint)1033, siteTemplate, true, false);
siteTemplate is a template I select in a dropdown and it works fine to create sites when I create a site from a team site template or similiar but when a wiki site is created the actual URL is /pages/home.aspx under the parent site but if I add this to newSiteUrl I get errors such as can't have trailing slash, the folder doesn't exist and so on.
How can I create a wiki site and set the url programmatically?
Thanks in advance.
EDIT
set the URL to
newSiteUrl = newSiteName + "/pages/"
gives me
"testpage/pages/" contains leading or trailing slash, which is invalid.
newSiteUrl = newSiteName + "/pages"
The folder that would hold URL '/dept/class/wikitest/pages'
does not exist on the server.
newSiteUrl = newSiteName + "/pages/home.aspx"
The URL '/dept/class/wikitest/pages/home.aspx' is invalid.
It may refer to a nonexistent file or folder,
or refer to a valid file or folder that is not in the current Web.
I've posted an answer to your question here: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/e25f10ef-bdd9-4445-8508-67b58c2396f9 hope this helps!
joel
joelblogs.co.uk
you may set the url in this way:
using (SPSite site = new SPSite("http://localhost"))
{
string parentWebName = "MyOrganization";
using (SPWeb parentWeb = site.OpenWeb())
{
string webTitle = "DepartMent Wiki";
string webDesc = "DepartMent Wiki"; string webName = "HRWiki";
string webUrl = String.Format("{0}/{1}", parentWebName, webName);
uint webLcid = parentWeb.Language;
// Name value for the Document Workspace template.
string webTemplateName = "STS#4";
SPWeb newWeb = null;
// Create the new web.
try
{
newWeb = site.AllWebs.Add(webUrl, webTitle, webDesc, webLcid, webTemplateName, false, false);
SPFolder rootFolder = newWeb.RootFolder;
rootFolder.WelcomePage = "My Wiki Library/MyWelcome.aspx";
rootFolder.Update();
}
catch (ArgumentException ex)
{
}
}
}
hope this help.

Programmatically adding portlets

Is it possible to add a portlet programmatically? If yes, please help me to understand the steps for that.
Liferay CE comes with the "sevencogs-hook" that contains code to set up the demo content, e.g. the "Seven Cogs" virtual company used to demo a Liferay site. This sets up a complete site programmatically. You can read that code and learn how users and pages are created, portlets are added to pages and configured to show what they are supposed to show. More than that: It's running code that can easily be read and is - as side effect - a nice piece of documentation.
http://svn.liferay.com/repos/public/plugins/trunk/hooks/sevencogs-hook/
Login: "guest", no password
or download the source for the version you're referring to.
Something like:
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
Layout layout = themeDisplay.getLayout();
long plid = layout.getPlid();
long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
long companyId = themeDisplay.getCompanyId();
String portletIdInc = layoutTypePortlet.addPortletId(userId, thisPortletID);
// Retrieve the portlet preferences portlet instance just created
PortletPreferences prefs = PortletPreferencesLocalServiceUtil
.getPreferences(companyId, ownerId, ownerType, plid, portletIdInc);
// set desired language
String languageId = LanguageUtil.getLanguageId(request);
String urlImage = .... ;
prefs.setValue("portlet-setup-title-" + languageId, report.getName());
prefs.setValue("portlet-setup-use-custom-title", "true");
prefs.setValue("src", report.getUrl());
prefs.setValue("img", urlImage);
prefs.store();
String targetColumn = "column-1";
// update the portlet preferences
PortletPreferencesLocalServiceUtil.updatePreferences(ownerId,
ownerType, plid, portletIdInc, prefs);
if (Validator.isNotNull(targetColumn) && Validator.isNotNull(portletIdInc)) {
layoutTypePortlet.movePortletId(userId, portletIdInc, targetColumn, 2);
}
LayoutServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(),
layout.getLayoutId(), layout.getTypeSettings());

Resources