Editing images

Because images are quite important jRQL offers several ways to work with image elements on a page.

Let’s start with checking an image element if it is empty or a user has entered a value. What is the difference you might ask. Because for every request for a value (=filename) jRQL considers to return the default value from the content class element. Therefore it can be empty (no default value and no image choosen), can have a default value or an user has choosen an image.

String logonGuid="6EB1C39F6A584ABBB9DBB6D36E27FAD7";
String sessionKey="36E1E61495654EB8A4505AC604925FCA";
String projectGuid="73671509FA5C43ED8FC4171AD0298AD2";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

Page currentPg = project.getPageById(“4711”);
boolean empty = currentPg.isImageEmpty(“templateElementName”);
boolean entered = currentPg.isImageValueEntered(“templateElementName”);

The next lines show you how to get, set and delete an image filename on an image element of currentPg.

String filename = currentPg.getImageValue("templateElementName");
currentPg.setImageValue("templateElementName", "filename");
currentPg.deleteImageValue("templateElementName");

jRQL per default checks if the filename is in the folder and will throw a MissingFileException, if not.

I have implemented the next methods for copying image filenames from one page to another especially for migration purposes. To copy a filename (the image itself has to be in target folder) from another page with same content class element name you can use the next line:

Page sourcePg = project.getPageById("4712");
currentPg.copyImageValueFrom("templateElementName", sourcePg);

The other direction is also supported by the next methods.

Page targetPg = project.getPageById("4713");
ImageElement targetElement = targetPg.getImageElement("templateElementName");
currentPg.copyImageValueTo("sourceTemplateElementName", targetElement);
currentPg.copyImageValueTo("templateElementName", targetPg);

You can even work with references; check if an image element is source of a reference, set a reference or delete a reference.

boolean isRefSource = currentPg.isImageElementReferenceSource("templateElementName");
currentPg.referenceImageElementToImageElement("sourceImageTemplateElementName", "targetImageTemplateElementName");
currentPg.deleteImageElementReference("templateElementName");

And last but not least I implemented a way to download the image itself (from the RedDot image cache).

currentPg.downloadImage("templateElementName", "d:\\temp\\image.png");

I used it to download images from an old project under a well defined filename first, copy and import all image files than manually into the new project’s folder (in file system) and at the end use a jRQL program again to set this new image filenames on the pages in the new project.

Please refer to the javadoc for class ImageElement. It is a subclass of FileElement which is a subclass of Element for further information.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Trackbacks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: