Foros de discusión

Get the file entry dimension

Daniel Wilmes, modificado hace 11 años.

Get the file entry dimension

Regular Member Mensajes: 164 Fecha de incorporación: 23/05/11 Mensajes recientes
I have added a jpg using the liferay api, however I am unable to find a way to get the dimensions of the file that I have uploaded. I can see it in the ddmcontent table as XML in the xml field. Does anyone know if there is a utility within liferay to get the data back out?

Thanks,
Daniel
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: Get the file entry dimension

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
You'll have to call DDMContentLocalServiceImpl.getContents() to get DDMContent and then do getXML() to get the xml data and parse the xml document. I think liferay had a SAX parser utility.
Daniel Wilmes, modificado hace 11 años.

RE: Get the file entry dimension

Regular Member Mensajes: 164 Fecha de incorporación: 23/05/11 Mensajes recientes
Great thanks for the information.
Daniel Wilmes, modificado hace 11 años.

RE: Get the file entry dimension

Regular Member Mensajes: 164 Fecha de incorporación: 23/05/11 Mensajes recientes
We looked at the document library code within liferay and found this source code:



FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(rotatorImage.getFileEntryId());		 
				String documentUrl = themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + fileEntry.getRepositoryId() + StringPool.SLASH + fileEntry.getFolderId() + StringPool.SLASH + HttpUtil.encodeURL(fileEntry.getTitle(), true);
				URL url = new URL(documentUrl);



		    FileVersion fileVersion = fileEntry.getFileVersion();
	

			try {
				List<ddmstructure> ddmStructures = DDMStructureLocalServiceUtil.getClassStructures(PortalUtil.getClassNameId(DLFileEntry.class), new StructureStructureKeyComparator(true));
				for (DDMStructure ddmStructure : ddmStructures) {
					Fields fields = null;
					try {
						DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), fileVersion.getFileVersionId());
						fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());
						String width = fields.get("TIFF_IMAGE_LENGTH").getRenderedValue(LocaleUtil.getDefault());
						String height = fields.get("TIFF_IMAGE_WIDTH").getRenderedValue(LocaleUtil.getDefault());
					}
					catch (Exception e) {
					}
					if (fields != null) {
						String name = "metadata." + ddmStructure.getName(LocaleUtil.getDefault(), true);
						String value = DDMXSDUtil.getHTML(pageContext, ddmStructure.getXsd(), fields, String.valueOf(ddmStructure.getPrimaryKey()), true, locale);
					}
				}
			}
			catch (Exception e) {
			}
</ddmstructure>
Daniel Wilmes, modificado hace 11 años.

RE: Get the file entry dimension

Regular Member Mensajes: 164 Fecha de incorporación: 23/05/11 Mensajes recientes
If this helps anyone....



  public static String getWidth(FileEntry fileEntry, ThemeDisplay themeDisplay, PageContext pageContext, Locale locale) throws PortalException, SystemException{
    String width = StringPool.BLANK;  
    FileVersion fileVersion = fileEntry.getFileVersion();
			try {
				List<ddmstructure> ddmStructures = DDMStructureLocalServiceUtil.getClassStructures(PortalUtil.getClassNameId(DLFileEntry.class), new StructureStructureKeyComparator(true));
				for (DDMStructure ddmStructure : ddmStructures) {
					Fields fields = null;
					try {
						DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), fileVersion.getFileVersionId());
						fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());
            width = fields.get("TIFF_IMAGE_WIDTH").getRenderedValue(LocaleUtil.getDefault());
					}
					catch (Exception e) {
					}
				}
			}
			catch (Exception e) {
			}
    return width;
  }
  
  public static String getHeight(FileEntry fileEntry, ThemeDisplay themeDisplay, PageContext pageContext, Locale locale) throws PortalException, SystemException{
    String height = StringPool.BLANK;  
    FileVersion fileVersion = fileEntry.getFileVersion();
			try {
				List<ddmstructure> ddmStructures = DDMStructureLocalServiceUtil.getClassStructures(PortalUtil.getClassNameId(DLFileEntry.class), new StructureStructureKeyComparator(true));
				for (DDMStructure ddmStructure : ddmStructures) {
					Fields fields = null;
					try {
						DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), fileVersion.getFileVersionId());
						fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());
            height = fields.get("TIFF_IMAGE_LENGTH").getRenderedValue(LocaleUtil.getDefault());
					}
					catch (Exception e) {
					}
				}
			}
			catch (Exception e) {
			}
    return height;
  }

</ddmstructure></ddmstructure>
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: Get the file entry dimension

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Thanks Daniel for posting your solution. I'm sure it'll help somebody looking for a answer with a similar question. :-)
Jonathan Mattox, modificado hace 10 años.

RE: Get the file entry dimension

New Member Mensajes: 13 Fecha de incorporación: 5/11/13 Mensajes recientes
Hello, I am trying to pull values from a custom metadata set and display it as an additional column on the view/gridview along with Title, Size, Created Date. And I am having a hard time figuring out exactly what to do in my hook. I see bits and pieces of code all over the place, but I'm not sure exactly how to extend the classes to add this. I've been able to add a column to be seen on the gridview by adding an entry to the init.jsp file by adding the following around line number 151:

Before:
String defaultEntryColumns = "name,size";

After:
String defaultEntryColumns = "name,size,myNewColumn";

Then I found where you add a condition for it in view_entries.jsp, but when I output fileEntryTypeId in this if statement, I keep getting a "-1"

if (columnName.equals("myNewColumn")) {
//Logic code here
}

Also in view_entries.jsp I see the following code which gets the fileEntryTypeId, which is one of the keys I need to tap into getting the metadata since the DLFileEntry doesn't have a property for this, but I'm not sure how to tap into this to get what I need and post in in the view/gridview:

List results = null;
//List metaDataresults = null;
int total = 0;

if (fileEntryTypeId >= 0) {
Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

if (fileEntryTypeId > 0) {
DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);

dlFileEntryTypeName = dlFileEntryType.getName();
}

Also, in edit_file_entry, I see the following code which looks like it pertains, but I don't understand how to use it (starting at line 334):

<%
if (fileEntryTypeId > 0) {
try {
List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures();

for (DDMStructure ddmStructure : ddmStructures) {
Fields fields = null;

try {
DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), fileVersionId);

fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());
}
catch (Exception e) {
}
%>

<%= DDMXSDUtil.getHTML(pageContext, ddmStructure.getXsd(), fields, String.valueOf(ddmStructure.getPrimaryKey()), locale) %>

I also see that the table "DDMContent" gets populated with two rows when you add a document that has metadata fields. One row is for the automatically extracted data, and the other has the custom data from my custom metadata set.

I am trying to implement the following class solutions:

public class MyDLAppLocalService implements DLAppLocalService {}

and

public class MyDLFileEntryMetadataLocalService implements
DLFileEntryMetadataLocalService {}

and

public class MyDLAppLocalServiceImpl extends DLAppLocalServiceWrapper {

public MyDLAppLocalServiceImpl(DLAppLocalService dlAppLocalService) {
super(dlAppLocalService);
// TODO Auto-generated constructor stub
}
}

and

public MyDLAppLocalServiceWrapper(FileEntry fileEntry){
super((DLAppService) fileEntry);
}
}
Here is my liferay-hook.xml:

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">

<hook>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
<service>
<service-type>com.liferay.portlet.documentlibrary.service.DLAppLocalService</service-type>
<service-impl>com.liferay.sample.hook.MyDLAppLocalServiceImpl</service-impl>
</service>
</hook>


I find all this stuff very confusing. I don't know what to do to which class and where. I see a lot of tutorials about modifying the User's classes, but not much about this and what posts I do find, they only give a tiny snippet of code. I have no idea where that snippet came from (which file and where in that file). I'm trying to figure out all this java and liferay stuff. I've been to the liferay training classes and I'm working through the books, along with Liferay In Action. I just don't see a very clear explanation from start to finish of how to do something like this can anyone please help me?

Thanks in advance emoticon