Pages

Wednesday, March 31, 2010

strRight in javascript

String.prototype.strRight=function(seperator)    {
    //stringValue
    var pos=this.(seperator);
    var result=this.substring(pos+1,this.length)
    return result;
}

alert("xkr".strRight('k'));  // will alert 'r'

function strRightBack(stringValue,seperator)    {
    var pos=stringValue.indexOflastIndexOf(seperator);
    var result=stringValue.substring(pos+1,stringValue.length)
    return result;
}

alert(strRightBack("xkr",'k')); // will alert 'r'

My Ideas to work upon

The following is a list of ideas that I might possibly work on in the near future.

1. Creating a javascript library that would hold most of the String Manipulation commands in the Lotusscript.

2. To Ensure all scripts developed for #1 can be used to extend the native Javascript String class

3. To create a custom javascript class that can be used to parse XMLs in a simpler way

4. To summarize ways that I can use to crash lotus notes

5. To learn more about Javascript blink statement and create a useful tool implementing the same

6. To learn more about z-index and create a useful tool implementing the same

7. A LEI starters guide

8. SQL and Lotus Notes Integration

9. To create a Javascript  logger plugin for Lotus Notes

10. To create XPage logger custom control - i think it is already available in OpenNtf

11. To create a simple API that shall help to work on the new HTML Canvas nodes

12. To create a progress bar that with a nice look and feel as in Windows Vista which would keep track of the Synchronous XMLHTTP Requests 

13. To prepare a documents that will help begineers in lotus notes to quickly understand the concepts

Sizing Backgroung Image Of a Button According To The Size Of The Button

The following is a fragment of html code that will help you to create button like features whose background images will automatically adjust according to the text length.

I honestly believe that u can use it as such, in most of the scenarios. However you may have to tweak the code if your expectation differs

<div style="position:relative; float: left;">
    <div style="z-index: -1">
        <img src="redButton.jpg" width="70px" height="30px">
    </div>

    <div style="position: absolute; top: 5px; left: 15px;">
        <a href="#" target="frTarget" width="10%" style="color:white;font-family:Verdana,Geneva,Arial,Helvetica,sans-serif;font-size:11px;font-weight:bold;text-decoration:none;">Search</a>
    </div>

</div> 

The background image that I have used here is as follows,
The Button that I have got using this code is as follows,

As you can see, the original size of the image has adjusted to the text size...

Hope this helps :)

Tuesday, March 30, 2010

strRightBack in javascript

The following is a function equivalent to lotus script's strRightBack function.

Code
 function strRightBack(stringValue,seperator)    {
    var pos=stringValue.lastIndexOf(seperator);
    var result=stringValue.substring(pos+1,stringValue.length)
    return result;
}

Illustriation
var x="My Name~ My Friend Name";
alert(strRightBack(x,"~"));    // this will alert " My Friend Name"

Following is a code that will help you extend native javascript's String class with this function

Code
String.prototype.strRightBack=function(seperator)    {
    //stringValue
    var pos=this.lastIndexOf(seperator);
    var result=this.substring(pos+1,this.length)
    return result;
}

Illustriation
var x="My Name~ My Friend Name";
alert(x.strRightBack("~"));    // this will alert " My Friend Name"

Wednesday, March 24, 2010

Creating links on XPage which executes server side scripts

Honestly, I dont know if links on XPages created using anchor tags be coded to execute server side scripts. I have tried it but I get exceptions when I attempt to preview my XPage on client or browser.

So here is a work around to do the same.

1.Assume that you want to create a link by the name "My XPage Link"

2. Create a label on the XPage with the label mentioned in #1. Now move to the source code panel in the XPage.

3.Let me assume that the xsp code created for the label that you have just dopped in is <xp:label blah blah blah></xp:label>

4.  Code the label with the server side script on its on click event. and ensure where it works fine.

5. Now locate the label in the source code panel and modify the label's code to suit the following,
<a href='#" class="your style class if any>
  
<xp:label blah blah blah></xp:label>
</a>


6. Now you got the link on the xpage that will execute the server side script.

Use case: It feels a little wearied to convert a label code on its onclick event, and then convert it into a link etc... You may ask y can't we use it as such and apply styles for the label directly.

Remember with links, you can write code that will support- hover, active and visited properties. Especially when u use links with in list then they can help you create beautiful menus etc....

And in these cases direct labels would not be of much use

Hope it makes sense to you :)

Friday, March 19, 2010

Style Overflow for div

If you like to see scrolls inside a div tag when the contents of the same exceed ,
you can mention the following style for that specific div tag,

overflow: auto;
overflow-x:  auto;<- for horizontal scrolling
overflow-y:  auto;<- for vertical scrolling

If you always want to see a scroll then,

overflow: scroll;

overflow-x:  scroll;<- for horizontal scrolling
overflow-y:  scroll;<- for vertical scrolling

If you never like a scroll in your div tag no matter what then,

overflow: hidden;

overflow-x:  hidden;<- for horizontal scrolling
overflow-y:  hidden;<- for vertical scrolling

Hope this helps ;-)

Wednesday, March 17, 2010

History.go(-1) -> redirect to home page if no history found

//This code will work fine in IE and firefox. Have not tested with others

//create a refernce variable which gets the value 0 if the the browser is ie and 1 if its not

var ref=document.all?0:1;

 //if the page has been initiated from an other page then get back to the previous page or if its fresh
//then redirect to home page

if (window.history.length==ref) {    
   location.href="home page url";
} else    {    
   history.go(-1);
}

Tuesday, March 16, 2010

getDesignElementNames (in Java)

/**
     * Method to return the names of a particular set or all design elements from a database
     * depending upon the user's input
     * @param    targetDB-    The database from which the design elements needs to be obtained
     * @param    DESIGN_ELEMENT_TYPE - An integer representation of the design element type
     * @return    String[]
     * @author    karthikeyan_a
     * @since    29-April-2009
     * @see        NotesCollection selectDesigns(Database targetDB,int DESIGN_ELEMENT_TYPE)
     * @see        ArrayList filterHiddenElements(ArrayList designElementNames)
     * @see        ArrayList removeAlias(ArrayList designElementNames)
     * @see        String[] CreateStringArrayFromVector(ArrayList stringVector)
     */   
    public String[] getDesignElementNames(Database targetDB,int DESIGN_ELEMENT_TYPE)    {
       
        if (targetDB==null) return null;

        String noteID=null;
        String noteIDTemp=null;
        Document dsgnDoc=null;
        NoteCollection nc=null;
        ArrayList designElementNames=null;
        //initialize the return value
        String[] designElementNamesString=null;

        try {
            //create an empty note collection
            nc =selectDesigns(targetDB,DESIGN_ELEMENT_TYPE);
            //initiate return value
            designElementNames=new ArrayList();
           
            if (nc.getCount()>0){
                noteID=nc.getFirstNoteID();
                //check if the noteID is neither empty nor null and get the design doc's name associated with the id
                while (noteID!=null && !noteID.equals(""))    {     //start of noteID while       
                    try {       
                        noteIDTemp = noteID;
                        dsgnDoc=targetDB.getDocumentByID(noteIDTemp);
                        //add the names of the design elements into the vector
                        designElementNames.add(dsgnDoc.getItemValueString("$TITLE"));
                        noteID=nc.getNextNoteID(noteID);
                    } catch (NotesException ne)    {
                        ne.printStackTrace();
                    }   
                }    //end of noteID while
            }
        } catch (NotesException e) {
            e.printStackTrace();
        }       
       
        // remove alias names of design elements
        designElementNames=removeAlias(designElementNames);
        //filter hidden design elements
        designElementNames=filterHiddenElements(designElementNames);
        //create a string array of the resultant design elements name
        designElementNamesString=arrayListToStringArray(designElementNames);
       
        //recycle objects
        noteID=null;
        nc=null;
        noteIDTemp=null;
        dsgnDoc=null;
        targetDB=null;
        designElementNames=null;
       
        //return the array of names
        return designElementNamesString;
    }    //end of function::getDesignElementNames

    /**
     * Method to return a particular set or all design elements from a database
     * depending upon the user's input
     * @param    targetDB-    The database from which the design elements needs to be obtained
     * @param    DESIGN_ELEMENT_TYPE - An integer representation of the design element type
     * @return    NoteCollection
     * @author    karthikeyan_a
     * @since    29-April-2009
     */   
    public NoteCollection selectDesigns(Database targetDB,int DESIGN_ELEMENT_TYPE) throws NotesException    {
        NoteCollection nc=null;
        nc = targetDB.createNoteCollection(false);
        if (DESIGN_ELEMENT_TYPE==1)    {
            nc.setSelectForms(true);
        } else if(DESIGN_ELEMENT_TYPE==2)    {
            nc.setSelectViews(true);
            nc.setSelectFolders(true);
        } else    {
            nc=null;
            return nc;
        }
        //build the design document collection of the resultant collection
        nc.buildCollection();
        //return the design collection
        return nc;
    }    //end of function::selectDesigns

    /**
     * Method to remove the strings from a string vector (Vector) which corresponds
     * to the name of an hidden element
     * @param    designElementNames  - an ArrayList with String Objects
     * @return    ArrayList
     * @author    karthikeyan_a
     * @since    29-April-2009
     */
    public ArrayList filterHiddenElements(ArrayList designElementNames)    {
        //if the input param in null then return null
        if (designElementNames==null)return null;
        //initialize the return value
        ArrayList filteredDsgnElements=new ArrayList();
        String dsgnName=null;   
        Object[] buffer=designElementNames.toArray();
        int countItr=0;
        /**
         *    loop through all the string objects in the input vector and remove the string objects
         *    that correspond to the name of an hidden design element
         */
        for(countItr=0;countItr
            dsgnName=buffer[countItr].toString().trim();
            if ( !( (dsgnName.indexOf("(")==0) && (dsgnName.indexOf(")")==(dsgnName.length()-1)) ) )    {
                 filteredDsgnElements.add(dsgnName);
            }   
        }
        //recycle objects
        dsgnName=null;
        designElementNames=null;
       
        return filteredDsgnElements;
    }    //end of function::filterHiddenElements

    /**
     * Method to remove the part of strings from string objects in a string vector (Vector)
     * which correspond to the alias names of the design elements
     * @param    designElementNames  - an ArrayList with String Objects
     * @return    ArrayList
     * @author    Karthikeyan_a
     * @since    29-April-2009
     */   
    public ArrayList removeAlias(ArrayList designElementNames)    {
        //if the input parameter in null then return null
        if (designElementNames==null)return null;
        //initialize the return value
        ArrayList filteredDsgnElements=new ArrayList();       
        String dsgnName=null;       
        Object[] buffer=designElementNames.toArray();
        int countItr=0;
        /**
         *    loop through all the string objects in the input vector and remove the part of stirngs in
         *    string objects that correspond to the alias names of the design elements
         */
        for(countItr=0;countItr
            dsgnName=buffer[countItr].toString().trim();
            if(dsgnName.indexOf("|")==-1)    {
                filteredDsgnElements.add(dsgnName);
            }    else    {
                filteredDsgnElements.add(dsgnName.substring(0, dsgnName.indexOf("|")).trim());
            }   
        }   
        //recycle objects
        dsgnName=null;   
        designElementNames=null;
       
        return filteredDsgnElements;
    }    //end of function::removeAlias

    /**
     * Method to assimilate the contents of a string Array List into a string array
     * @param    arrList  - an array list with string objects
     * @return    String[]
     * @author    karthikeyan_a
     * @since    30-April-2009  
     */
    public String[] arrayListToStringArray(ArrayList arrList){
        String[] strArray=null;
        Object[] elements=arrList.toArray();
        strArray=new String[elements.length];
        int countItr=0;
        for (countItr=0;countItr
            strArray[countItr]=elements[countItr].toString();
        }
        //recycle objects       
        elements=null;
        arrList=null;
       
        return strArray;
    }

    /**
     * Method to obtain a collection of all documents from a specified view in a specified database
     * @param    targetDB  - the database from which the document collection is to be obtained
     * @param    viewName  - the name of the view from which the document collection is to be obtained
     * @return    DocumentCollection
     * @author    karthikeyan_a
     * @since    30-April-2009       
     */
    public DocumentCollection getViewDocuments(Database targetDB, String viewName)    {
        //if any of the input parameters in undefined then return null
        if ((targetDB==null)|| (viewName==null) || (viewName.trim().equals("")))    {
            return null;
        }
        //mark the return value and initialize other variables
        DocumentCollection viewDocs=null;
        Document viewDoc=null;
        ViewEntryCollection viewEntries=null;
        ViewEntry viewEntry=null;
        View chosenView=null;
        try {
            //set the handle for the view mentioned by the view name
            chosenView=targetDB.getView(viewName);
            //if the view handle is not set then return null
            if (chosenView==null)    {
                return null;
            }
           
            //ensure that an empty document collection is created
            Random generator = new Random();
            viewDocs=chosenView.getAllDocumentsByKey(".~^$#$^&~."+generator.toString());
           
            /**
             * loop through all the entries in the view and push their associated
             * documents into the document collection
             */
            viewEntries= chosenView.getAllEntries();
            //get the handle for the first entry in the collection
            viewEntry=viewEntries.getFirstEntry();
            while(viewEntry!=null)    {
                if (viewEntry.isDocument())    {
                    viewDoc=viewEntry.getDocument();
                    /*
                     * If the document concerned with the entry is already present in the
                     * collection then a duplicate exception is thrown. So catch the same and
                     * dont allow that to hurt the process
                     */
                    try {
                        viewDocs.addDocument(viewDoc);
                    }
                    catch (NotesException duplicateException) {
                        //by pass exception
                        duplicateException=null;
                    }
                }
                //push the handle to the next entry in the collection
                viewEntry=viewEntries.getNextEntry(viewEntry);
            }
           
        } catch (NotesException e) {
            e.printStackTrace();
        }
        //return the collection of documents thus obtained
        return viewDocs;
    }

Function to open a CSV file in Java

    public void openCSV(String csvFileName){
        try    {
            String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",csvFileName};
            Runtime.getRuntime().exec(commands);
        }    catch(Exception e)    {
            e.printStackTrace();
        }
    } //END OF openCSV

Check whether a windows file exists or not (in Java)

    public boolean fileExists(String filePath)    {    //Start of fileExists function
        boolean flagExists=false;
        java.io.File file=new java.io.File(filePath);
        flagExists=file.exists();
        return flagExists;
    }//END of fileExists function