I would like to convert a domino document field of Data Type: MIME Part into a Data Type: Rich Text in backend with SSJS or Java?
I have tried to work with
doc.computeWithForm(true, true);
doc.save(true, true);
but this piece of code has no effect.
Hint: I can do this conversion with a notes client in frontend (open and save the document) without any problems.
Any idea? Thanks in advance!
You may be able to do this as part of the usually-undesirable side effect of automatic MIME-to-CD conversion in the API. For example, code like this will turn the Body field of the first doc in the DB from MIME to composite data:
boolean convertMime = session.isConvertMime();
session.setConvertMime(true);
Document doc = database.getAllDocuments().getFirstDocument();
RichTextItem rtitem = (RichTextItem)doc.getFirstItem("Body");
rtitem.compact();
doc.save();
session.setConvertMime(convertMime);
By making sure that the session is converting MIME (which is true by default, but it's best to maintain any previously-existing value) and then interacting with the MIME_PART item, it will mangle it into CD for you.
Related
I have a layout web part which has a "Teaser" field. The "Teaser" field uses a "media selection" form control. In this case the field is set to an image uploaded to one of the sites media libraries.
I want to render that image, so I'm trying to get the relative URL to it in the codebehind:
if (Teaser != Guid.Empty) // Teaser is {8d7fa1ab-b304-474f-9ab9-2e17e8fee84f}
{
var mediaInfo = MediaFileInfoProvider.GetMediaFileInfo(Teaser, SiteContext.CurrentSiteName);
// mediaInfo is null so the next line crashes
var libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(mediaInfo.FileLibraryID);
string url = MediaFileURLProvider.GetMediaFileUrl(mediaInfo, SiteContext.CurrentSiteName, libraryInfo.LibraryFolder);
The "mediaInfo" variabe is null, so the code crashes.
How can I get a relative URL to my media file?
You cannot add the "Media selection" form control in combination with an field type Guid. Then you need to create an custom form control if you need to have only the Guid.
But an better solution is add an field with the data type "text" and in combination with the form control "media selection" then adds directly the relative URL inside the field when selecting an image from the media library.
If you also need the MediaInfo then you can get this object with the parameter "mediaFilePath", like described here : https://devnet.kentico.com/docs/8_2/api/html/M_CMS_MediaLibrary_MediaFileInfoProvider_GetMediaFileInfo_3.htm
Good luck and if you have more questions you can always ask them here on StackOverflow or on http://devnet.kentico.com/questions-answers.
If this answer helped you, please vote for my answer :-)
I'm trying to remove a link totally from an email body. I have no idea how by treating body as MIME entity. But I did try for a while in the body as rich text. Here is part of my codes:
RichTextNavigator nav = body.createNavigator();
RichTextRange range = body.createRange();
nav.findFIrstString("theLinkToBeRemoved");
range.setBegin(nav);
range.setEnd(nav);
range.remove();
But only the body inside anchor tags has been removed. For example:
google
actually becomes
after processing and sending email.
My question is how to remove the anchor tags completely. Thanks!
Did you also try with the FindFirstElement method of the RichTextNavigator class, looking for an element of type RichTextItem.RTELEM_TYPE_DOCLINK ?
Hmmm... I wonder, why do you need to remove links... It sounds like a managerial issue that's solved programmatically.
I found a beautiful solution: code.google.com/p/lnrt2html
It achieves the trick of conversion from rich text to html, rather than dxl/xml. And then we have many options to parse html data, such as Jsoup. After that, use this method to input your html string stream to MIMEEntity and send: MIMEEntity - setContentFromText
I need to attach a file generated by Apache POI on an Xpage to a notes document. I have been attempting to implement a solution as suggested by Knut Herrmann:
var temp = java.lang.System.getProperty("java.io.tmpdir");
var file = new java.io.File(temp + "YourFile.docx");
var fileOutputStream = new java.io.FileOutputStream(file);
xwpfdocument.write(fileOutputStream);
fileOutputStream.close();
var doc:NotesDocument = currentDocument.getDocument();
var rdoc:NotesDocument = database.createDocument();
rdoc.appendItemValue("Form", "frmRespTempl");
rdoc.appendItemValue("Subject", "Embedded Word Document");
var rtitem:RichTextItem = rdoc.createRichTextItem("Body");
rtitem.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT,"",file.getAbsolutePath(), null);
rdoc.makeResponse(doc);
rdoc.save();
POI for XPages - save Word document as attachment in rich text field
however, in order to make xwpfdocument.write(fileOutputStream) work, the java policy file needs to be modified which is a security risk.
I had no luck making the java solutions work either. Is there any other way to go about making this code work? What exactly is the risk of modifying the java policy?
Thanks
Are you running the code in a browser or in the Notes Client because the code will never work in a browser if you want to send the file to the user side. It will work on the serverside.
If you want to attach a local document in a Notes client I would suggest you start an Notes agent with the code to embed the file instead.
Instead of modifying the java.policy file, I think you could
write a class that you implement inside a jar file and place that jar file in the class path on the server and instance it from your XPage code.
I have a problem uploading an image to a form field using the built in xpages fileuploader control. The form field the image is saved to is configured like explained in this blog post by Mats Knutsen: http://devxpages.blogspot.com/2011/03/display-picture-from-rich-text-field.html . I Also plan to display the image in an xpage using the template described in the blog post, like this (http://server/MyDatabase.nsf/viewunid/docunid/imageField/M2?OpenElement).
I know my fileuploader control points to the correct field in the form, since i can see the image in the document using the Lotus Notes Client after the document is created. However; the picture can not be viewed using "http://server/MyDatabase.nsf/viewunid/docunid/imageField/M2?OpenElement" at this point.
On the other hand, if I delete the field contents (the image) from the document field in the client, go back to the xpage with the fileuploader control, and uploads the image a second time, it works perfectly, and the image can be viewed using the url mentioned above.
When I access field properties after the first upload, the Data Type of my field is set to Rich Text.
The second time I upload the same image to the same field in the same document, the field properties Data Type is set to MIME Part, as it probably should have gotten the first time around as well.
Does anyone know why my file uploader control does not work the first time i upload the image, but when I edit the docuement and upload the image a second time, everything seems to be ok?
I would try to avoid uploading images into the RichText in the first place. Would it break your application if you resort to uploading the image as a regular attachment? You then can reference it using .../$File/imgfilename.jpg (using the file name used during upload - retrieved by #AttachmentNames)
I have questions on preventing XSS attacks.
1) Question:
I have an HTML template as Javascript string (trusted) and insert content coming from a server request (untrusted). I replace placeholders within that HTML template strings with that untrusted content and output it to the DOM using innerHTML/Text.
In particular I insert texts that I output in <div> and <p> tags that are already present in the template HTML string and form element values, i.e. texts in input tag's value attribute, select option and textarea tags.
Do I understand correctly that I can treat every inserted text mentioned above as HTML subcontext thus I only encode like so: encodeForJavascript( encodeForHTML( inserted_text ) ). Or do I have to encode the texts that I insert into value attributes of the input fields for the HTML Attribute subcontext?
After reading up on this issue on OWASP I am inclined to think that latter is only necessary in case I set the attribute with unstrusted content via Javascript like so: document.forms[ 0 ].elements[ 0 ].value = encodeForHTMLAttribute, is that correct?
2) Question:
What is the added value of server side encoding server responses that enter the client side via Ajax and get handled anyway (like in question 1). In addition, don't we risk problems when double encoding the content?
Thanks
You need to encode for the context in question, so to data inserted into html context needs to be encoded for html, and data inserted into html attributes, should be html attribute encoded. This is addition to the javascript encoding you mentioned.
I would javascript encode for transfer and then encode for the correct context client side, where I know which context is the right one.