Pages

Wednesday, December 1, 2010

Lotusscript code to import dxl to current database

Function importDxl(dxlFilePath) As Boolean

'***********************************************************
'@Purpose : To import dxl into current database 
'@Author   : Karthikeyan A
 '@Note : The dxl file should contain the dxl that corresponds to a notes document in this case
'*********************************************************** 

'mark the flow of control moving into  the current function
importDxl=False

'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim dbdir As NotesDbDirectory
Dim db As NotesDatabase
Dim stream As NotesStream
Dim importer As NotesDXLImporter

'handle errors in case of abrupt termination
On Error Goto errHandler

REM set handle for the current database
Set db = session.CurrentDatabase

'create a stream
Set stream = session.CreateStream

'open the dxl file to be imported
If Not stream.Open(dxlFilePath) Then
Msgbox "Cannot open " & dxlFilePath, , "Error"
Exit Function
End If
'if the file is empty then inform the same to the user and exit
If stream.Bytes = 0 Then
Msgbox "File did not exist or was empty", , dxlFilePath
Exit Function
End If

REM Import DXL into current database
Set importer = session.CreateDXLImporter
importer.ReplaceDBProperties = False
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.ACLImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
Call importer.Import(stream, db)

'close the current stream
Call stream.Close

'mark the flow of control moving out of  the current function
importDxl=True
Exit Function
'display the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to importDxl"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to importDxl"
Exit Function
End Function

Hope this helps:)

Lotusscript code to export dxl of a Notes document

Function exportDocDxl(sourceDoc As NotesDocument,targetFilePath As String) As Boolean
'***********************************************************
'@Purpose : To export the dxl of a database to the specified document
'@Author   : Karthikeyan A
'*********************************************************** 

'mark the flow of control getting inside the current function
exportDocDxl=False

'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim db As NotesDatabase
Dim exporter As NotesDXLExporter
Dim opStream As NotesStream

'handle errors in case of abrupt termination
On Error Goto errHandler

'create a dxl exporter
Set exporter = session.CreateDXLExporter
'create a stream
Set opStream=session.CreateStream
'open the targetFilePath using the stream
If Not opStream.Open(targetFilePath) Then
Msgbox "Cannot open "& targetFilePath, , targetFilePath
Exit Function
End If
If opStream.Bytes <> 0 Then
Call opStream.Truncate
End If

'export the contents on the current database to the stream (i.e. the target file path)
Call opstream.WriteText(exporter.Export(sourceDoc))
'once the export is complete close the stream
Call opstream.Close

  'mark the flow of control moving out of  the current function
exportDocDxl=True
Exit Function
'display the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of selected document"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of selected document"
Exit Function
End Function


Hope this helps:)

Lotusscript code to export dxl of a database

Function exportDBDxl(sourceDB As NotesDatabase,targetFilePath As String) As Boolean
 '***********************************************************
 '@Purpose : To export the dxl of a database to the specified location
 '@Author   : Karthikeyan A
 '*********************************************************** 

'mark the flow of control getting inside the current function
exportDBDxl=False

'declare all variables and objects necessary for further manipulation
Dim session As New NotesSession
Dim db As NotesDatabase
Dim exporter As NotesDXLExporter
Dim opStream As NotesStream

'handle errors in case of abrupt termination
On Error Goto errHandler

'create a dxl exporter
Set exporter = session.CreateDXLExporter
'create a stream
Set opStream=session.CreateStream
'open the targetFilePath using the stream
Call opStream.Open(targetFilePath)
'export the contents on the current database to the stream (i.e. the target file path)
Call opstream.WriteText(exporter.Export(sourceDB))
'once the export is complete close the stream
Call opstream.Close

  'mark the flow of control moving out of  the current function
exportDBDxl=True
Exit Function
'display the errors that resulted in abrupt termination
errHandler:
Print "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of specified database"
Msgbox "Error ***" & Error & " occured on line ***" & Cstr(Erl) & "*** with error number ***" & Cstr(Err)  & "*** while attempting to export dxl of specified database"
Exit Function
End Function


Hope this helps:)

Lotusscript code to add attachment to a richtext field

The following is a lotus script code that will help you add an attachment to a rich text field

Function addAttachmentToRichTextField(doc As NotesDocument,rtField As String,filePath As String) _
As Boolean
'***********************************************************
'@Purpose : add a file denoted by the filepath to a richtext field
'@Author   : Karthikeyan A
 '@Param : doc As NotesDocument - the document which contains the rich text field
'@Param : rtField As String - the name of the rich text field in which the attachment is to added to
'@Param : filePath As String - the path of the file that needs to be attached
   '@Note : The doc specified here must not be a new one. 
' That is doc.IsNewNote must be 0
'*********************************************************** 

'mark the flow of control moving into  the current function
addAttachmentToRichTextField=False

'declare variables and objects necessary for further manipulation
Dim rtItem As NotesRichTextItem

'handle errors in case of abrupt termination
On Error Goto errHandler

'set the handle of the richtext item associated with the rtfield name
Set rtItem=doc.GetFirstItem(rtField)
'embedd the file as an attachment to the richtext field
Call rtitem.EmbedObject ( EMBED_ATTACHMENT, "", filePath)
'save the document
Call doc.Save( True, False )

'mark the flow of control moving into  the current function
addAttachmentToRichTextField=True

Exit Function
'inform the user regarding the error that results in abrupt termination
errHandler:
Print "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***"   _
& Cstr(Err) & "*** in Method ""addAttachmentToRichTextField"" "
Msgbox "Error ***" & Error & "*** occured on line ***" & Cstr(Erl) & "*** with error number ***"   _
& Cstr(Err) & "*** in Method ""addAttachmentToRichTextField"" "
Exit Function
End Function


Hope this helps :)

Wednesday, November 24, 2010

Send HTML Content As Mail using Lotus Script

The following function will help you send html content as a mail


****************************************************************************
Function sendHTMLContentAsMail(recipients As Variant,ccTo As Variant,bccTo As Variant, _
Subject As String,bodyHtmlContent As String)
'Declare Variables 
Dim s As New NotesSession
Dim db As NotesDatabase
Dim body As NotesMIMEEntity
Dim stream As NotesStream
Dim host As String
Dim message As  NotesDocument 

On Error Goto errHandler

Set db = s.CurrentDatabase
Set message=db.CreateDocument
'Capture the server name and filepath for use in URLs
Dim ServerName As New NotesName( db.Server )
host = "http://" + ServerName.Common & ".com"

s.ConvertMIME = False ' Do not convert MIME to rich text
Set stream = s.CreateStream
Set body = message.CreateMIMEEntity
message.Subject =Subject
message.SendTo =recipients
message.CopyTo =ccTo
message.BlindCopyTo =bccTo
message.RecNoOutOfOffice = "1"   
Call stream.WriteText (bodyHtmlContent)
' Ensure the MIME content will be recognized as HTML   (Must be after the stream is written)
Call body.SetContentFromText (stream, "text/html;charset=iso-8859-1", ENC_NONE) 
Call message.Send (False)  

s.ConvertMIME = True ' Restore conversion
Exit Function
errHandler:
Msgbox Error,,Cstr(Erl)
Exit Function
End Function
********************************************************************************


Hope this helps :)

Tuesday, November 23, 2010

Lotusscript code to append hotspot to a richtext field

My aim is to append a Link hotspot to the rich text field of a notes document as illustrated in the following image on a button click



The following code helped me perform the same
/***************************************************************************/
Function AppendHotspotLink (rtitem As NotesRichTextItem, url As String) As String
'** This function will attempt to append a button to a given
'** NotesRichTextItem, using code that has been assigned
'** to this object after it has been created (using the SetCode
'** method). The code language (as set with the SetLanguageType
'** method) can be either LotusScript or Formula language.

'** If there is an error creating the button (often because the code
'** doesn't compile correctly), this function will return the error
'** message. If the button is created properly, an empty string
'** will be returned.
On Error Goto processError

'** if no rich text item was given to us, just exit without doing anything
If (rtitem Is Nothing) Then
Exit Function
End If

Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim importer As NotesDXLImporter

Dim buttonCode As String
Dim buttonTag As String
Dim dxl As String

'** set up the DXL to be used for the code in the button
%REM
If (buttonLanguage = RTB_LOTUSSCRIPT) Then
buttonCode = |<lotusscript>Sub Click(Source As Button)
| & XmlConvert(code) & |
End Sub</lotusscript>|
Else
buttonCode = |<formula>| & XmlConvert(code) & |</formula>|
End If



buttonTag = |<button width='2in' widthtype='fitcontent' wraptext='true' |
If (edgeType = RTB_SQUARE) Then
buttonTag = buttonTag & | edge='square' |
Else
buttonTag = buttonTag & | edge='rounded' |
End If
buttonTag = buttonTag & | bgcolor='system'>|
%END REM

'** DXL that will create a temporary doc with the button we want.
'** We're adding the current user name in an Author field on
'** this temporary document because we'll be deleting it at the end
'** of this function, and the user may only have Author access to
'** this database.
dxl = |<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE document SYSTEM 'xmlschemas/domino_8_5.dtd'>
<document xmlns='http://www.lotus.com/dxl' version='8.5.1'
 replicaid='0123456789ABCDEF' form='ButtonMaker'>
<item name='DocAuthor' authors='true' names='true'>
<text>| & XmlConvert(session.CommonUserName) & |</text></item>
<item name='Body'><richtext>
<pardef id="1" />
 <par def="1">
 <actionhotspot>
<code event="click">
  <formula>@URLOpen("|& url &|")</formula>
  </code>
  Document Link
  </actionhotspot>
  </par>
</richtext>
</item>
</document>|


'** create a new doc using the DXL above
Set db = session.CurrentDatabase
Set importer = session.CreateDXLImporter(dxl, db)
importer.ReplicaRequiredForReplaceOrUpdate = False
importer.DocumentImportOption = DXLIMPORTOPTION_CREATE
Call importer.Process

'** get the button from the doc we just created and append it to
'** the rich text item we were given
Set doc = db.GetDocumentByID(importer.GetFirstImportedNoteId)
Set body = doc.GetFirstItem("Body")
Call rtitem.AppendRTItem(body)

'** try to delete the temporary doc. In case we can't delete it for some
'** reason, a scheduled agent should be written to globally delete
'** docs that use the form name specified in the DXL above.
On Error Resume Next
Call doc.RemovePermanently(True)

Exit Function


processError:
If (importer.Log <> "") Then
AppendHotspotLink = importer.Log
Else
AppendHotspotLink = "Error " & Err & " on line " & Erl & ": " & Error$
End If
Exit Function
End Function




Function XmlConvert (txt As String) As String
'** get rid of the text characters that XML doesn't like (accented
'** characters are usually okay, as long as you use an encoding
'** like ISO-8859-1
XmlConvert = txt
XmlConvert = Replace(XmlConvert, "&", "&amp;")
XmlConvert = Replace(XmlConvert, "<", "&lt;")
XmlConvert = Replace(XmlConvert, ">", "&gt;")
End Function

Note: Use the following code to test the above function

%rem


Dim session As New NotesSession
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem

Dim result As String

'** grab the first selected doc in the view
Set doc = session.CurrentDatabase.UnprocessedDocuments.GetFirstDocument
Set rtitem = doc.GetFirstItem("Body")
If (rtitem Is Nothing) Then
Set rtitem = New NotesRichTextItem(doc, "Body")
End If

Call AppendHotspotLink(rtitem,"http://www.google.com")

'** save and exit
Call doc.Save(True, True)


%end rem

Wednesday, November 10, 2010

get Current Folder Path in Java

The following function helps you get the current folder path of your project


@SuppressWarnings("finally")
public String getCurrentFolderPath() {
String path = "";
try {
path = new java.io.File(".").getCanonicalPath();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
return path;
}
}

Hope this helps :)

CopyDirectory Function in Java

The following function will help you copy a directory from one location to an other.I got this good function with the help of my friend google :)


public void copyDirectory(File sourceLocation , File targetLocation)
   throws IOException {
       
       if (sourceLocation.isDirectory()) {
           if (!targetLocation.exists()) {
               targetLocation.mkdir();
           }
           
           String[] children = sourceLocation.list();
           for (int i=0; i<children.length; i++) {
               copyDirectory(new File(sourceLocation, children[i]),
                       new File(targetLocation, children[i]));
           }
       } else {
           
           InputStream in = new FileInputStream(sourceLocation);
           OutputStream out = new FileOutputStream(targetLocation);
           
           // Copy the bits from instream to outstream
           byte[] buf = new byte[1024];
           int len;
           while ((len = in.read(buf)) > 0) {
               out.write(buf, 0, len);
           }
           in.close();
           out.close();
       }
   }

Usage:

                File source=new File("c:\\ak");
File target=new File("c:\\bk");
try {
copyDirectory(source,target);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Hope this helps :)

Tuesday, November 9, 2010

Setting up Offline Password in Domino Quickr

In order for a user to go offline in Quickr-D, his/her offline password needs to be configured.

If in case a user proceeds further with out configuring a offline password he/she might experience the following error message when attempting to create a offline station in quickr-D
“error requesting offline configuration from the server”

To configure the offline password follow the following steps,
  • 1.       Open up the place which the user wants to go offline with
  • 2.       Go to the member’s section and open up the member profile


  •    Edit the Member profile by clicking the Edit button
  •    Scroll down and configure the offline password for the user and click next




Tuesday, November 2, 2010

Open Xpage from a Notes Form or View on Notes Client 8.5.1

In order to open a xpage ( say a document on a xpage) from a Notes Form or View from the notes client, use a button or a hot spot that contains a code fragment similar to the following,

@URLOpen("notes://servername/databasepath/XpageName.xsp?openXPage&documentId=documentUniqueID&action=editDocument")

Note the usage of the word openXPage in the query string. Ensure that it is present there, 'cos the XPage wont open up if it does not have this part in the url and instead it will open up the default view of the database instead.


Hope this Helps  :)