How do I get the filename programmatically to use with this code? - xpages

The code below is the computed image source for an image control on my custom control. If I run it just like it stands it puts in photo.jpg and works fine. The problem is I want to pass that value programmatically. I have an upload control (fileUpload1) and a download control (fileDownload1) on the custom control as well. I've tried document1.photo which is where the jpg file is stored. I've tried several variations of currentdocument.getitemvalue, getitem, getattachments. But, so far, I have found no way to do this. In addition, I have tried setting the value of filename to the value of the upload control and the download control with no success.
I know this is probably simple, but, as a client developer, it's not simple to me.
Any help would be greatly appreciated.
var doc:NotesDocument = currentDocument.getDocument ();
var UID:string = doc.getUniversalID().toString();
var fp:string = database.getFilePath();
var filename = "photo.jpg"
return '/0/' + UID + '/$file/' + filename
Thanks,
MJ

There may be other ways to achieve this but here's what I usually do:
with image controls I need to be aware that computed resource URLs are in most cases prepended with the database's relative path ending with the database filename. So all I have to add is the usual file attachment URL as in
/0/docUnid/$File/imageFileName
If there is a chance that you have more than one file attached to your doc I need to find out which one of them is the one I wish to display. This can be done by looping through
currentDocument.getAttachmentList(fieldName)
which delivers a java.util.List of NotesEmbeddedObject elements. Using methods like .getName() I then can find the one file you're looking for.
EDIT:
quick example using a repeat to display multiple images sattached to a single richtext field (there may be better solutions esp. regarding the way to filter unwanted file types; I'm using file extensions, only allowing .jpg, .png and .gif). Images are displayed as simple html list elements:
<ul>
<xp:repeat id="repeat1" rows="30" var="pic">
<xp:this.value><![CDATA[#{javascript:
var att:java.util.List=docCar.getAttachmentList("Body");
var it=att.listIterator();
//new empty array, to be used as the repeater's datasource
var arr=[];
//build base path for each image file
var unid=docCar.getDocument().getUniversalID();
var p="/0/" + unid + "/$File/";
while(it.hasNext()){
var e:NotesEmbeddedObject=it.next();
if(e.getName().endsWithIgnoreCase(".png") ||
e.getName().endsWithIgnoreCase(".jpg") ||
e.getName().endsWithIgnoreCase(".gif")){
//push complete filepath + image filename to array
arr.push(p + e.getName());
}
}
return arr;}]]></xp:this.value>
<li>
<xp:image url="#{javascript:pic}" id="image1">
</xp:image>
</li>
</xp:repeat>
</ul>
Hope this helps

Well, I think I have it figured out. Here is the code that now works:
var doc:NotesDocument = currentDocument.getDocument ();
var UID:string = doc.getUniversalID().toString(); var fp:string =
database.getFilePath();
var filename = #AttachmentNames()
return '/0/' + UID + '/$file/' + filename
MJ

Related

export data from panel

I read this great help 'tool' from David Leedy regarding Export to excel.:
http://notesin9.com/wp-content/uploads/2011/01/XPagesCheatSheet-85x11-v1.pdf
My scenario: I have a ftsearch modulo which offers its results into a viewpanel. I want ONLY those results to be exported into excel. I follow the steps from the .pdf but in that case it will export all the documents listed in the respective view, not the search results.
Is there any possibility to have only the search results into the excel file, after the search is submited?
var myView:NotesView = database.getView('MyView');
Here I get the view which holds the search results, but I want to get the view contents/those docs. after the Search button was submitted. The problem is I don't get the 'updated' view only with the search results, but all the DOCS contained in that view. ( Before the Search button was clicked ... )
Thanks for your time!
You say that you already have a view panel that shows the search results. I'm assuming that you're using the search attribute on the view panel object to do that. Another assumption is that you're computing the full text query in the search attribute based on an input field that's bound to a scoped variable (possibly the sessionScope). So your datasource on the search XPage would look something like this:
<xp:this.data>
<xp:dominoView
var="view1"
viewName="yourSearchView">
<xp:this.search><![CDATA[#{javascript:"[subject]=\"" + sessionScope.searchField + "*\"";}]]></xp:this.search>
</xp:dominoView>
</xp:this.data>
In the Export XPage you can restrict the entries that are exported by applying the same query to the view before exporting the results. To do that you can use the 'FTSearch()' function on the view:
myView.FTSearch("[subject]=\"" + sessionScope.searchField + "*\");
Based on the code on David's cheatsheet I tested this and it turns out that for some reasons if you add this row, the NotesViewNavigator that is constructed based on the (filtered) view isn't limited to the search results, but still contains all entries. The solution to that is to remove the NotesViewNavigator object and use a NotesViewEntryCollection:
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var myView:NotesView = database.getView('vwKlanten');
var query = "[subject]=\"em*\"";
myView.FTSearch(query);
var vec:NotesViewEntryCollection = myView.getAllEntries()
var viewEnt:NotesViewEntry = vec.getFirstEntry();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
writer.write("<table>");
writer.write("<thead><tr>");
writer.write("<td><b>Column1Header</b></td>");
writer.write("<td><b>Column2Header</b></td>");
writer.write("<td><b>Column3Header</b></td>");
writer.write("</tr></thead>");
while (viewEnt != null) {
writer.write("<tr>");
writer.write("<td>" + viewEnt.getColumnValues()[0] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[1] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[2] + "</td>");
writer.write("</tr>");
var tmp = vec.getNextEntry(viewEnt);
viewEnt.recycle();
viewEnt = tmp;
}
writer.write("</table>");
writer.endDocument();
(BTW: I added a 'recycle()' call to deal with possible memory errors)
Have You already tried http://poi4xpages.openntf.org/ ?
A custom control for exporting data to excel or word
For me, rather then trying to get ahold of the search results from the code that produces the report, I'd just have that code run the same search again. At least to get it working. Then I'd deal with trying to cut it back to 1 search call. You might find that running 2 searches just isn't a big deal.

Calculating URL of an image resource

In my xpage which is bound to a domDoc datasource I want to build a preview mechanism for images stored in the datasource's richtext field. Designer and server are V 9.0.1.
The names of the attached images are stored as an array in a viewScope var and fed as source to a repeat control. The image control sits inside the repeat. I also put a link control alongside the image offering a means to download the file. The calculated url looks like this:
/dbpath/dbfile.nsf/xsp/.ibmmodres/domino/OpenAttachment/dbpath/dbfile.nsf/docunid/rtBodyField/filename.gif
Calculation of the link works perfect, but the images are never displayed. Instead Firebug tells me that the image's source url could not be resolved. And indeed I see that the db path part has been rendered twice before the /xsp/.ibmmodres/domino/OpenAttachment/ portion of the url (but only once after it!):
/dbpath/dbfile.nsf/dbpath/dbfile.nsf/xsp/.ibmmodres/domino/OpenAttachment/dbpath/dbfile.nsf/docunid/rtBodyField/filename.gif
Here's the code I'm using to calculate the source urls for both the link (using its value property) and the image (using its url property):
var unid=context.getUrlParameter('documentId');
var p=facesContext.getExternalContext().getRequestContextPath();
return p+'/xsp/.ibmmodres/domino/OpenAttachment'+p+'/'+unid + '/rtBodyFld/'+imgEntry;
Here's what I tried so far to solve that miracle:
a) calculate the db path (facesContext...) beforePageLoad, store it in a viewScope, then reference the viewScope when build the image's source ==> same result as above
b) used the image's value property instead of url ==> same result as above
c) use a standard html <img /> tag where the src argument is built using "#{javascript:...}" with the identical code as above ==> this works fine!
So I do have a workaround with solution c), but still I'd like to learn why the path element is doubled only in the first portion of the url, and only for image resources.
EDIT:
tried two more things:
d) pulled the image control outside my repeat then added a fixed (and valid) filename to the calculated url ==> same (bad) result as above
e) calculated the entire url portion only except the image file name beforePageLoad and stored that in a viewScope var ==> this is the weirdest result: outside the image viewscope contains the correct path info, but inside I see the same bad result as above. So it appears that inside the image the viewScope variable is altered in parts???
This is so weird that I feel I must have made a very simple and stupid error here, but what could that be?
Are you looking for how to calculate attachment URLs? Try this:
function getAttachmentURL(docID:java.lang.String, attachmentName:java.lang.String) {
var base = getBaseURL();
var middle = "/xsp/.ibmmodres/domino/OpenAttachment";
if (base.substr(0,4) == "/xsp") {
middle += base.substr(4);
} else {
middle += base;
}
var result = base + middle + "/" + docID + "/$File/" + attachmentName + "?Open";
return result;
}
function getBaseURL() {
var curURL = context.getUrl();
var curAdr = curURL.getAddress();
var rel = curURL.getSiteRelativeAddress(context);
var step1 = curAdr.substr(0,curAdr.indexOf(rel));
// Now cut off the http
var step2 = step1.substr(step1.indexOf("//")+2);
var result = step2.substr(step2.indexOf("/"));
return result;
}
Hope that helps!
Alright, it is as I feared: I had not taken into account that a relative url defined for an image control is automatically prefixed with /dbpath/dbfile.nsf/.
That's why that part always appeared twice no matter how I calculated my own url. It would have worked if I had used absolute urls (http://server/path/dbfile.nsf/...)
So instead the calculated url has to be built like that:
var unid=context.getUrlParameter('documentId');
var p=facesContext.getExternalContext().getRequestContextPath();
return '/xsp/.ibmmodres/domino/OpenAttachment' + p + '/' +
unid + '/rtBodyFld/' + imgEntry;

Parse attribute of Media Element

I want to parse url attribute from the XML and show image in image control (the one reffered to by the URL) in listbox from the following feed link: http://feeds.bbci.co.uk/news/rss.xml
My code is:
var ComingNewsFromUri = from rss in XElement.Parse(e.Result).Descendants("item")
select new NewsItems
{
Title = rss.Element("title").Value,
PubDate = rss.Element("pubDate").Value,
Description = rss.Element("description").Value
};
For RSS, I would recommend using SyndicationFeed and SyndicationItem....does all the parsing and converting to objects automatically and brilliantly for you.
http://ryanhayes.net/blog/how-to-build-an-rss-feed-reader-in-windows-phone-7part-i-retrieving-parsing-and-displaying-post-titles/
I have an RSS feed app on the store myself using SyndicationFeed and it is very reliable and convenient.
Here is another sample by Microsoft
http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f

Pass pdf url to pdf.js in query string

I'm new to node/pdf js. I just install node and run pdf.js.
Now I want know how can I open pdf files using pdf js by passing pdf file url as parameter in query string?
Try adding ?file=document.pdf to the viewer url. See also https://github.com/mozilla/pdf.js/issues/2496
It will require some changes in the viewer.js:
Move parseQueryString: function pdfViewParseQueryString(query) outside var PDFView so it's a standalone function: function pdfViewParseQueryString(query)
Replace all occurences of PDFView.parseQueryString(..) to pdfViewParseQueryString(..)
Change var DEFAULT_URL = '' to var urlParm = pdfViewParseQueryString(document.location.search.substring(1)); var DEFAULT_URL = urlParm.url;
You should now be able to call the viewer with somethin like $("actualViewer").src = 'pdfViewer?url=' + encodeURIComponent(pathToFile);
On a further note, it is important to know that the file=document.pdf argument must come before the hash sign:
http://myserver.com/web/viewer.html?file=test.pdf#page=6&zoom=page-fit,0,540
HTH

SharePoint 2010 Two search boxes on the master page

I would like to have two search boxes on my master page.
One that would search for content and the other one that would search for people.
I see the code in the master page that searches for content:
How would i do to add another box that searches for people?
if you know or have info on how to achieve this I would appreciate it.
thank you much
W
You can do something simple which is to put an HTML text box directly in your master page. It may not be as elegant as writing a customer user control that reads the location of the Search site, but if the URL to your search results page is static then something like this might work for you:
<script type="text/javascript">
function SearchPeople()
{
var termArr = document.getElementById("SearchTextBoxPeople").value.split(" ");
var retStr = "";
for (var i = 0; i < termArr.length; i++) {
retStr += termArr[i] + "* ";
}
document.location.href = "/Search/Pages/peopleresults.aspx?k=" + retStr;
}
</script>
<input type="text" id="SearchTextBoxPeople" />
Search People
One additional benefit of this is that you can control the input to include wildcards (which are horrible out-of-the-box for people searches). The JavaScript is simply including * in the search which allows wildcard searches. So a search for jo sm will actually send jo* sm* to the search page which will then match on John Smith.

Resources