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.
Related
I got a Google drive picker item on my web app. Looking at Google Docs I find out the it display one option tab called "Recent".
Following the documentation at https://developers.google.com/picker/docs/reference I couldn't find any reference to this tab mode, only found "Recently Picked" for files I recently picked from the picker, but I'm looking to emulate this function.
My current code is
new google.picker.PickerBuilder()
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)
.setAppId(appId)
.setOAuthToken(oauthToken)
.addView(new google.picker.DocsView().setIncludeFolders(true).setOwnedByMe(true))
.addView(new google.picker.DocsView().setIncludeFolders(true).setOwnedByMe(false))
.addView(new google.picker.DocsView().setStarred(true).setLabel('Starred'))
finally after reading the documentation of Google picker and the google groups dedicated to it, I figured out that there is no preset or config for recent uploaded files and even trying to build a custom view with google.picker.view, the query field is quite limited and didn't allow the option to sort the files.
After reading the javascript code of docs.google.com for the file picker I found few variables that are accessible in the moment when you call the method .addView(). This field are:
El: is the filter type for the document type.
mc: this old the whole view configuration and fields. Example: mc.query is equivalent for the View.setQuery.
xd: this field manage the View title in the top nav tab title.
While this method is a bit hacky, is the only option I got in the meantime to replicate the "recent" view tab from google docs. Here is the code I used:
let recentView = new google.picker.DocsView();
recentView.xd = 'Recent';
recentView.mc.sortKey = 15;
let picker = new google.picker.PickerBuilder()
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)
.setAppId(appId)
.setOAuthToken(oauthToken)
.addView(new google.picker.DocsView().setIncludeFolders(true).setOwnedByMe(true))
.addView(new google.picker.DocsView().setIncludeFolders(true).setOwnedByMe(false))
.addView(new google.picker.DocsView().setIncludeFolders(true).setStarred(true).setLabel('Starred'))
.addView(recentView)
.addView(new google.picker.DocsUploadView().setIncludeFolders(true))
.setDeveloperKey(developerKey)
.setCallback(onFilePickerCB)
Through my own custom listener I would like to delete main files and attachment from the nuxeo document.
Deleting the document seems to be easy as you can use the below code.
doc.getCoreSession().removeDocument(doc.getRef());
doc.getCoreSession().save();
But how I can delete the file and attachment through my java code. Please provide me a snippet of code.
The code will be..
DocumentHelper.removeProperty(documentModel, path);
path = file:content for main file. For attachment "files/content[array index]"
I am looking for best way to compose an email and attach document link for notes and web client using SSJS.
We are doing it one way but I think there is some good way of doing this. I want to use complete functionality of Rich Text Item e.g. formating, styles and other which we normally do in LotusScript.
Any sample application having industry standard way of doing this will be great help.
Following is sample code how we are doing right now.
var stream = session.createStream();
stream.writeText("Application is forwarded to you for approval. ");
var var3 = '<a href =' + notesDocLink + '> Open in Rich Client (Doc Link) </a>'
var var4 = '<a href =' + webDocLink + '> Open in Internet Explorer </a>'
stream.writeText( var3 + " For web Client Use this link: " + var4 , 2);
stream.writeText("Note: This is auto-generated email and do not require any reply. ");
mailBody.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
mailDoc.replaceItemValue("SendTo",mailSendTo);
mailDoc.replaceItemValue("CopyTo",mailCopyTo);
mailDoc.send();
I am interested in something like this which is currently not working for me.
mailDoc.replaceItemValue("Form","Memo");
mailDoc.replaceItemValue("Subject" , strSubject);
var RTItem:NotesRichTextItem = mailDoc.createRichTextItem("Body");
RTItem.appendText("Leave Application is forwarded to you for approval. ");
RTItem.addNewLine(2);
RTItem.appendText("Please click on below document link for details. ");
RTItem.appendDocLink(currDoc, "Click on Link to Proceed")
RTItem.addNewLine(2);
RTItem.appendText("Note: This is auto-generated email and do not require any reply. ");
RTItem.addNewLine(2);
mailDoc.replaceItemValue("SendTo",mailSendTo);
mailDoc.replaceItemValue("CopyTo",mailCopyTo);
mailDoc.send();
For doc links, please confirm that the answer to this question doesn't solve your problem Getting an Error message when trying to appendDocLink is SSJS.
There are a couple of code examples for emails on XSnippets:
Mark Leusink's creation of email as MIME http://openntf.org/XSnippets.nsf/snippet.xsp?id=create-html-mails-in-ssjs-using-mime
Tony McGuckin's emailBean: http://openntf.org/XSnippets.nsf/snippet.xsp?id=emailbean-send-dominodocument-html-emails-cw-embedded-images-attachments-custom-headerfooter
For anyone using the OpenNTF Domino API, this has a DominoEmail class, for creating an email as well.
In R9 there is also a Send Mail simple function.
Personally, I'd prefer HTML and MIME for styling compared to the RichTextStyle classes. It also gives greater flexibility for web links as well as client. It has the added benefit of fidelity when sending outside Notes. Even for Notes users viewing on mobile devices via Traveler, I think the Traveler server will have to convert to MIME to ensure the styles are available, so it's easier to cut out that step by using MIME for a start.
I have a site which shows a teaser (image+text) on all pages.
This should be editable from admin, so I created a small backend module (a simple form) where the admin should set the image and the text and save them in Typo3's registry db table:
This is how I save the text:
$request = $this->controllerContext->getRequest();
$arguments = $request->getArguments();
$registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 't3lib_Registry' );
$extKey = $request->getControllerExtensionKey();
$registry->set( $extKey, 'text', $arguments['settings']['text'] );
but I don't know how to add an "Add image" link to display the file browser and get the url/id of the selected file.
Any ideas?
Thanks.
In order to have a file picker you will need to have a TCA for a FAL field. A TCA is usually connected to a table and I wouldn't know of any implementation with the registry as a "storage backend".
This means you would have to create TCEForms yourself and then intercept the saving process. This is possible but rarely used and rather complicated, see an example here:
https://git.typo3.org/Packages/TYPO3.CMS.git/blob/TYPO3_4-5:/typo3/sysext/version/ws/workspaceforms.php
(for TYPO3 4.x, for 6.x the class names have to be adjusted)
So I would suggest that you extend the table pages with a field for text and a FAL field instead of trying to write an own backend module for this purpose.
I have the following code snippet:
WebClient client = new WebClient();
String htmlCode = client.DownloadString(newurl);
webBrowser1.DocumentText = htmlCode;
BTW, webBrowser1 is defined globally elsewhere in the program. Likewise, "newurl" is a valid url also defined globally elsewhere.
WebClient gets the complete html which I pass to webbrowser1 using DocumentText.
This result is all kinds of link, syntax, remote javascript, and other errors as though the html is corrupted. However, if I use
webbrowser1.Navigate(newurl);
the target page displays just fine.
I am getting the source html so I can make changes before I display it.
Clearly I am missing something.
Any thoughts?
Regards,
Jim
webBrowser1.DocumentText = htmlCode; will set the HTML only, but will not load any linked-in resources, such as JS, images, CSS, ... .
If you want to do, what you seem to want to do, you can e.g. load the HTML via a WebClient, rewrite it (this includes changing relative paths to absolute ones or setting a base url), write it to a file, then webbrowser1.Navigate("file://path/to/file");