Thursday, December 15, 2011

How to find the current logged in windows user from java?


The class NTSystem will help to retrieve the logged in user name and other credentials.

Example:

NTSystem obj = new NTSystem();
System.out.println("Logged In User Name "+obj.getName());


From the java docs :-


This class implementation retrieves and makes available NT security information for the current user.

http://docs.oracle.com/javase/6/docs/jre/api/security/jaas/spec/index.html?com/sun/security/auth/module/package-summary.html

Wednesday, November 30, 2011

Inputs and Conditional Processing in Batch File

To get input from the console in a batch file and assign it to a variable  the following syntax works very well.

set /p name=Debug Y/N?

Then you can Echo %name% to print the contents of that variable.

To conditionally check for the content of that variable

IF "%name%" == "y" (other dos commands go here...) Without the enclosing braces :-)


I found it particularly usefull to start my jboss with some agents disabled conditionally based on what options I choose, that way I can still play around with multiple agents and debugging options without having to maintain multiple copied of the run.bat files, which is messy !!!

Tuesday, November 29, 2011

Split String on every UpperCase Letter, String Modify Array and String Join the array as a single word.


For example we have a string like “thisIsTheDay”

http://stackoverflow.com/questions/3752636/java-split-string-when-an-uppercase-letter-is-found

1.String sample = “thisIsTheDay”;
2.String[] sampleArray = sample.getChartType().split("(?=\\p{Lu})");
3.sampleArray = (String[])ArrayUtils.removeElement(sampleArray, "this");
4. String newStringName  = StringUtils.join(sampleArray," ");

Line 1: Declares a sample string.

Line 2: Splits the string for every unicode character that it encounters.

Line 3: Removes any unwanted words from the new array.

Line 4: Joins the elements of the array as a new word.

Friday, November 18, 2011

Debug CSS

Debug your CSS and layouts using Yahoo Debug CSS

https://github.com/yahoo/debugCSS

debugCSS is meant to be loaded on an existing page to highlight potentially broken, malformed or legacy (X)HTML.


Visit the above link for more information.

Tool to bulk rename files in windows

This is a very usefull to bulk rename files in a folder with most pattern and extension matching options.

www.spacetornado.com/Renamer/

String substitution



To substitute words in String.

String exampleString = " There is %s disturbance in planet %s ";
String newString = String.format(exampleString,new Object[]{"a","mars."});
System.out.println(newString);

Output :  There is a disturbance in planet mars.

Alternatively you can also use the MessageFormatClass

http://download.oracle.com/javase/6/docs/api/java/text/MessageFormat.html




Thursday, November 10, 2011

JSF Icefaces Accessibility

We have a JSF based application, and this is our experience in making the website more accessible.

Accessibility guidelines from the web.



Tools to check for accessibility 



Making your website font scale and resizeable. Typically websites show three (3) A alphabets and prompt the user to resize.
AAACreate the above as links and pass in a value to resize the body font.
document.body.style.fontSize = newSize + "em";
Key issues/challenges that were faced :-

  • JSF popups with dialog boxes were not picked up by JAWS reader. Had to provide a separate entry point for those pages to be shown as a separate popup window and not within the application itself.
  • Wherever we had a drop down based change listener we had to implement an action listener with a "go" button.
  • Flash based fusion charts font sizes were not re-sizeable http://forum.fusioncharts.com/topic/10527-how-to-auto-resize-text/page__p__41271__hl__resize__fromsearch__1#entry41271
  • To resize flash movies via a script in your website please see  http://swffit.millermedeiros.com/
  • Basically flash can be set as a percentage of the parent container div to resize. 
  • Providing alt text for images. 
  • Providing table headers for tables where the th were not rendered due to improper use, the accessibility reader tools need the th to read the column headers. 
  • No multi row headers. 
  • Images pixelating if you increase the zoom of the page, but you can provide alt text for those pages.  
  • Auto complete drop downs need to have a different layout. 
Update:

For example if you have section headings in a page (not the html title of the page). What JAWS would allow you to do is to pick a list of headings on a page and navigate directly to that section that contains the heading. So it is essential for your pages to contain headings.

Update:
To make tables more accessible,
this is an awesome post on how to make it more accessible.

http://www.usability.com.au/resources/tables.cfm

Will update more on this blog.



Tuesday, November 8, 2011

CSS Cross browser shadow

.shadow {
-moz-box-shadow: 3px 3px 4px #000;
-webkit-box-shadow: 3px 3px 4px #000;
box-shadow: 3px 3px 4px #000;
/* For IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
/* For IE 5.5 - 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}

http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/

CSS Cross browser shadow for divs

Monday, October 31, 2011

Parsing XML and iterating it using XPath


How to parse XML from a string and iterate over a specific node name using Xpath

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder dBuilder = dbf.newDocumentBuilder();
String string = xmlBuffer.toString();
// not to parse a string you have to pass it in via stream
Document doc = dBuilder.parse(new InputSource(new ByteArrayInputStream(string.getBytes("utf-8"))));

XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
// match all nodes where the tag name is column and get the text content.
XPathExpression expr = xpath.compile("//column/text()");

Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
    logger.info(" "+nodes.item(i).getNodeValue());
}









Xcelsius Send and Recieve XML with Servlet


Xcelsius is a great tool to quickly wire up dashboards and reports without much coding. However there is the need to sometimes integrate it with dynamic data. You can create an XML data connection to query values from the database and associate it to your Xcelsius Model file.




  • Following are the steps :-
    • Create an XML data connection.
    • Enter an URL for the xml data connection for Example /servlet/service/BusinessInfoServlet?mode=query 
    • Click on the "+" symbol to add a variable name
    • The name that comes up on the screen is your variable name. Please note that. 
    • Click on the cell icon to select the range of cells that you want to associate your database result to your excel model.
    • Select Enable Load
    • In your servlet 
    response.setContentType("text/xml");
    PrintWriter out = response.getWriter();
    String xmlContent = ""+xmlBuffer.toString()+"";
            • The structure of your XML buffer is mapped as rows and columns.  
            •  The variable attribute name should map to the name in the XML data connection. 
            • Also note the row vs column structure, for multiple rows you need to iterate your tags like that.


            <data>
            <variable name="Range_0" >
            <row>
            <column>3.2</column>
            </row>
            <row>
            <column>1</column>
            </row>
            <row>
            <column>2</column>
            </row>
            <row>
            <column>50</column>
            </row>
            <row>
            <column>33</column>
            </row>
            </variable>

          Works on My Machine

          http://www.codinghorror.com/blog/2007/03/the-works-on-my-machine-certification-program.html

          Post on "When developers say it worked

          Friday, June 17, 2011

          Icefaces Load Testing

          The problem that I faced was the ability to load test icefaces page, and I could not find an open source tool that helped me to load test icefaces. What other open source tools that are there for this purpose? 

          Apache JMeter is fantastic for load testing, but for testing sophisticated fully ajax layouts like icefaces applications, not sure it is really easy to use JMeter. On the other hand Selenium is really easy to capture and build a test case, but to automate and scale for load testing.

          A combination of the above tools we can use to create the load testing for Icefaces application. One of the most critical features is that Icefaces generates id's dynamically on every form element, to overcome this, the developer has to set the id's normatively. That way Selenium can identify the components and able to reuse the test case.

          Once the test case is recorded through selenium, we can start JMeter and re-record the selenium test case through the JMeter proxy. Once we have a JMeter test case, at this point we should be able to load test the application. http://stackoverflow.com/questions/7817498/is-there-anyway-we-can-implement-selenium-scripts-with-jmeter

          Monday, June 13, 2011

          Oracle Certified Master Architect Java EE 5

          The following are some useful links for the oracle certified software architect master course.



          Certification Objectives: http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=326
          Study Guide: http://java.boot.by/scea5-guide/ch01.html
          Java Ranch:http://www.coderanch.com/t/540130/java-Architect-SCEA/certification/Cleared-Part-Thanks-all
          Exam Tips:http://scea5-passingpart2and3.blogspot.com/
          Java Ranch:http://www.coderanch.com/forums/f-26/java-Architect-SCEA


          Wednesday, June 1, 2011

          Architecture

          1. Definition of Architecture.
            1. What is architecture? Excerpt from Sun Tone From this link
              The terms “system architecture” and “system design” are often used interchangeably,
              but in fact deal with two very different system engineering processes. System archi-tecture focuses primarily on the overall structure of a system, identifying major com-ponents and their relationships. The systems architect seeks to define:
              1. How the overall processing should be decomposed into component parts 
              2. How the major components should be organized with respect to one another and the mechanisms underlying shared system-wide operations such as
                communication and storage.
                1. Thus, the architect focuses on issues such as which components belong together or apart; which ones should be visible to one another; which should be replicated; how they should be distributed; how they should talk to one another; where they should be stored; and so on.
          2. Infrastructure of an Architecture.
            1. Transaction Management.
            2. Security
            3. Distribution.
            4. Communication.
              1. You provide a default method for developers to implement the above features consistently.
          3. Creating an architecture means you have created an infrastructure that addresses service level requirements.
            1. When does architecture stop and design begins, there is a never clear answer.
            2. Architecture’s focus is on what is going to be built. Design’s focus is how that architecture is going to be built.
            3. For experienced designers it is not needed to provide a detailed documentation as for less experienced ones.
          4. When creating an architecture it is important to identify the system limitations.
            1. Funds
            2. Resources
            3. Time
          5. When making decisions in the architectural process, these decisions need to be documented, so that we do not have to repeat ourself over and over again.

          Tuesday, November 30, 2010

          Eclipse Ignore File From Output Folders

          Typically to  quickly open a file in eclipse most of use the open resource dialog [CTRL+Shift+R] but sometime it also shows the files from other output folders, which is very irritating.

          A quick search on google pointed out to this link

          http://robmayhew.com/eclipse-ignore-folder/