Pages

Friday, October 17, 2014

replacing newline with characters in java

I had a string named “remarks” with the following value in it

 

10/17/2014 07:14 AM test1

test1

test1

test1

10/17/2014 07:14 AM dfgdfg

 

I tried to replace all line feeds in this string with a particular character set in java and so I tried the following

 

String re = remarks1.replaceAll("\n","$#$”);

System.out.println(re);

 

This kept giving me illegal arguments exception.

 

So I tried

String re = remarks1.replaceAll("\\n","$#$");

System.out.println(re);

 

Now I felt weird. This is not normal behavior as most of my searches said this should work. Hence I felt a little irritated and I tried a different string instead of “$#$”. It was a stupid attempt though. But to my astonishment it worked fine

 

Curse compiler. Stupid same and its issue with “$” characters

 

Following worked at last

 

String re = remarks1.replaceAll("\\n","@#@");

System.out.println(re);

 

The output was

10/17/2014 07:14 AM test1@#@test1@#@test1@#@test1@#@10/17/2014 07:14 AM dfgdfg@#@

 

At ease 0.0  grrr

Thursday, August 14, 2014

error c00c0240 - "Could not complete the operation due to error c00c0240." - AJAX request in Struts

I happened to encounter this error when I was attempting to debug an Ajax call to a Struts action. It made me feel miserable for a while as both firebug as well as eclipse debuggers with console showed no trace of the origins of the error. As usual I searched out for the error number and ended up with a lot of stack overflow posts. One of these posts were typically explaining me the same issue that I was facing and had a link to a blog post which contained a solution to the same. And to my relief, my companies network restrictions prevented that page from being loaded. Wait WTF!!! Yes... that’s how grateful I felt roflJ.

 

Enough of my story, the issue in my case was that the AJAX request that I framed and tested was

 

var x= new XMLHttpRequest();x.open("GET","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText

 

This was giving me some un relevant message like the following and my debugging points never worked and neither the eclipse console had any logs printed in them through the log4j framework.

 

"
<html>
<head>
  <script type="text/javascript" src="/****/js/*****.js"></script>
   <script type="text/JavaScript">
           window.document.onkeydown=checkKeyCode;
   </script>
</head>
<body>
<table  width="100%" valign="top" height="100%">
<tr>
<td align="center"><font color="red"><h4>
There was a problem, please try again!</h4></font>
</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
</table>
</body>
</html>"

 

And I found the “THE ISSAC NEWTON” in me like most of the times, as something stuck me and I tried “POST” instead of “GET”

 

And now, I see some positive results. My debugging points in the eclipse is working.. Hurray!!!!!

 

var x= new XMLHttpRequest();x.open("POST","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText

 

Hurray!!!!! Again. But wait, WTF its just that my debugging points in eclipse are working. So wait my work is not done yet

 

L J

 

Friday, July 25, 2014

Writting run time code in eclipse for debugging as in firebug console

While debugging an application/program in eclipse , go to the display screen in the side menu items with in the eclipse and type run time variables and execute the same like you would prefer to do in firebug, where you type commands and click on run.

 

Alternatively, to bring up the Display screen, you can go to

 

window->show view ->Display or Ctrl+Shift+D

 

I have simply heard about the same and have not tried it yet. So plz don’t blame me if it does not work for you.

 

Hope this works 0.0

 

Thursday, July 24, 2014

Customizing the UNIX User Environment - Part 1 - UNIX shell configuration files - Part 1

Customizing the UNIX User Environment

**********************************************************************************

UNIX shell configuration files

**********************************************************************************

Introducing shell configuration files

---------------------------------------

 

A shell is an interactive interface that you use to communicate with the UNIX kernel. It provides a way of executing commands and getting standard feedback in the UNIX environment.

 

Kernel is a software layer that enables interaction of the HLL with the hardware

 

The most commonly used UNIX shells unclude the

- Bourne shell - is the oriinal UNIX shell, developed by Stephen Bourne. It doesnot support some of the features of the more recent shells, such as command-line editing

- Korn shell - is similar to the Bourne Shell but incorprates features from the C shell - dev by David Korn

- Bash shell - is the GNU (operating system) implementation of the Bourne shell, and stands for Bourne Again Shell. It adds features such as command-line editing to the original Bourne shell.

- C shell - is a UNIX shell developed by Bill Joy. It is similar to the Bourne shell, but its command set has been adapted syntactically to match the C language.

 

Typically a shell runs in interactive mode, meaning that you can type commands into it and get results. It's also possible to run a shell non interactively. For example, while working in the Bash shell you might need to run a shell script that required the C shell. If properly configured, the script could invoke the C shell in a noninteractive mode long enough to complete the script's running.

 

When a shell starts up, it reads several different configuration files to learn how you want it to look and behave. Typically, a shell will begin by reading the /etc/profile file. This file contains global environment variables that the root user wants constant for all users, and only root can edit this file.

 

Once the shell has processed the /etc/profile file, it reads the .profile file located in the home direcotry of the user that started the shell. The initial period indicates that the file is hidden.

 

Because UNIX generally only reads the .profile file during login, specific shells have additional startup and configuration files. Both the Korn and Bash shells have an evironment variable called ENV that points to a script that is run whenever a new shell is started, not just at login.The name of the file that ENV poins to is arbitrary. However, by convention, on Bash it is called .bashrc, and on Korn .kshrc.

Customizing the UNIX User Environment - Part 1 - UNIX shell configuration files - Part 2

Customizing the UNIX User Environment

**********************************************************************************

UNIX shell configuration files

**********************************************************************************

 

Configuring user profiles

----------------------------------------

The file that most directly affects a user's experience of a shell is the .profile file located in a user'a home directory.

This file contains variables and commands that relate to how a user's shells will look and respond

 

Following is an example of a Bash shell .profile file.

 

bash-2.05a# cat .profile

#variables

SHELL=/bin/bash              #specifies path to the executable file for this shell

ENV=$HOME/.bashrc

PS1=$PWD

PATH=/usr/java/j2sdk_1_4_01/bin:$PATH

bash-2.05a#

 

Any line of text in a .profile file that begins with a hash (#) is a comment and the system ignores it.

Note: There are no mandatory .profile variables. Each variable shown here is an example, and is not strictly required to run a functional system.

 

ENV vairable specifies the path to the script that will be run for every subsequent instance of this shell-such as non interactive subshells launched by other scripts. It references the path value stored in the shell variable HOME - set elsewhere - by placing a dollar symbol ($) in front of the variable name.

 

The PS1 variable specifies the text that should be displayed as a prompt. In this case, it references the value stored in the PWS global variable, which is the path to the current working directory

 

The PATH variable specifies paths for the system to search for executables binaries. The PATH variable is normally set in the /etc/profile file. In this case, the value of the PATH variable is appended with additional information specifically for this user.

 

Followin gis a sample .bashrc file. which would normally be referenced by the EBV variable in a user's .profile file.

 

bash-2.05a# cat .bashrc

#Aliases

alias f=finger

alias fun=/usr/games

bash-2.05a#

 

Note : There are no mandatory .bashrc commands. Each command shown here is an example, and is not stricly required to run a functional system.

 

This .bashrc file contains alias commands that allow you to assign a shortcut name to a command or path, to minimize typing.

The first command assigns an alias of "f" to the finger command, which means you could now execute the finger command simply by typing f.

If the target of an alias consists of more than a single word, you should enclose it in single quotes.

 

The next alias command assigns an alias of "fun" to the path /usr/games. This means you could now navigate to that path by typing cd fun.

 

Alias commands can be executed from the shell prompt.

When the target of an alias is longer than a single word, you need to remember to enclose it in single quotes. In this case, the full statement reads as folloes:

alias list = 'ls -l|more'

 

Summary

--------------

A shell provides an interface for users to interact with the kernel. You configure shells using the /etc/profile and .profile files.

The .profile file contains variables and commands that configure a specific user's shell, but the file is usualy only referenced at login. Any commands that should be executed for every script should be placed in a separate file and referenced using the ENV variable.

Customizing the UNIX User Environment - Part 1 - Working with UNIX environment - Part 3

Customizing the UNIX User Environment

**********************************************************************************

Working with UNIX environment

**********************************************************************************

Global and local variables

-----------------------------

 

You use variables to customize how a shell looks, behaves, and responds to user input.

There are two kinds of variables: global or environment variables and local or shell variables

 

The root user sets global variables and stores them in the /etc/profiles file. Global variables affect all users' shells, providing standard parameters for any shell environment.

Programs running in the system have access to global variables, and use them to make behavior decisions.

 

Users can set theor own local variables, storing them in .profile files in their home directories.

Local variables affect a particular user's shell session only.

 

Some common global variables include

-EDITOR  - specifies default editor to use for general text edits. Default value is the vi text editor

-PATH  - specified one or more paths that the system will search for executable files when you enter a command at the shell prompt. The default setting is /usr/bin.

-PRINTER - specifies the default pronter. By default this is not set

-PS1 - specifies the prompt displayed in the shell. Default is $

-SHELL - specifies the path to the default shell program. on most systens this would be /bin/sh.

-TERM - specifies the default terminal used to access the system. The default value is vt100.

 

Some common local variables include

-HOME - specifies the path to the user's home directory

-LOGNAME - specifies the name that the user uses to log in with

-MAIL - specifies the path to the user's mailbox

 

When you set a global variable in a local context, the global variable gets overrided. Local variables are for customizing an individual user's experience of the system, so they override global variable values - for that user only.

 

You can view all of the currently set variables in your shell using the env command. Please type env in the console and hit enter to see the currently set variables

 

You can view the value of an individual variable using the echo command.

bash-2.05a$ echo $PATH

 

You need to prefix the variable name with a $ symbol in order to reference its contents rather than just typing it's name

 

In Bourne shell derivatives, you can set individual variables from the shell prompt by simply declaring them using the form variable=value.

The code shown here sets the value of the PS1 variable - the text that the shell displays as a prompt - to the current working directory, followed by a $.

 

The PS1 variable supports several switches to make it easier to configure, including

-\h - systems hostname

-\s - reference the name of the current shell

-\t - reference the current time in 24 hour format (HH:MM:SS)

-\u - reference your current username

-\w - reference the name of the current working directory

 

Once you've set the value of a variable you can force any subshells you launch to use the same value, using the export command, as shown here.

 

bash-2.05a$ PS1='\w$'

/home/ak$ export PS1

/home/ak$

 

Setting variables in the C shell is similar to Bourne variants, but requires the use of the setenv command.

The code shown here sets the value of the ld_library_path variable to /usr/lib.

 

easynomad2$ setenv ld_library_path variable to /usr/lib

easynomad2$

 

The C shell uses a different set of variables from the Bourne derivative shells. Because some of the variable names are the same, all C shell variables are expressed in lowercase.

 

Customizing the UNIX User Environment - Part 1 - Working with UNIX environment - Part 4

Customizing the UNIX User Environment

**********************************************************************************

Working with UNIX environment

**********************************************************************************

 

User environment commands

------------------------------------------------------------

UNIX comes with many standard command programs, stored in directories such as /bin, /usr/bin, and /sbin.

Shell programs have additional commands built into them. These commands are known as user environment - or built-in - commands.

 

One of the most useful built-in commands is the su command. Executed without arguments, it allows you to become the root user while logged into any other account, as shown here.

This is extremely convenient if you find yourself in need of admin privileges while logged in as another user, as it saves you having to logout and in again as root. If you use su, you will be required to supply the root password.

 

bash-2.05a$ su

Password:

su-2.05a#

 

When you've finished your admin task, you end your su session with the exit command, which returns you to your normal shell.

 

su-2.05a# exit

exit

bash-2.05a$

 

One of the functions of groups in UNIX is to allow members of groups to share files with each other, or to access resources that belong to the group.

If you need to move a fils, directory or other resource to a different group, you can do so using the built-in command chgrp.

 

Syntax: chgrp [-R] new _groupt object

It takes atleast two arguments: the destination group and the name of the object being moved. And you can specify the -R option if you're moving a directory and you want its subdirectories and all their contents to be moved as well.

 

You can get a lost of all users currently logged into the system using who command.

You can find out more about a currently logged in user using the finger command with their username as an argument

 

The finger command produces info abt a currently logged in user, including their fullname, the path to theor home directory, and which shell they're currently using.

 

Customizing the UNIX User Environment - Part 2 - Customizing X - Part 1

Customizing the UNIX User Environment

**********************************************************************************

Customizing X

**********************************************************************************

 

In UNIX systems, the X Window System - also called X - controls the interaction between the GUI display and the programs and applications that use it. The most popular and widespread of the X window System is XFree86

 

X architecture

------------------------

The X Window System uses a client-server architecture. The X server process runs on the computer that is displaying the GUI. This is usually a terminal or workstation.

 

The X client process runs on the computer that runs the application that suppies data to the GUI. This can be the same computer that displays the GUI, but it can also be a remote computer such as a network server.

 

Because X client applications can run on central network servers, you can implement networks where the terminal computers are very simple. X terminals need to have enough RAM and disk space to run the UNIX kernel and the X server procecss, but they dont need disk space for applications. They need a network card to communicate with servers, but they dont necessarily need a modem

 

Simple terminals that run only the kernel and X are called as X terminals. They function only as display terminals, with all application processing taking place on the server.

 

Although X hanfles the interaction between the GUI and the programs that display in it, X doesn't control the way windows look and behave.

The function is taken care of by window managers. These are programs that run on X servers. They rely on X for their interaction with the Kernel

 

The window manager determines the way window look on screen and the kind of controls - such as close and maximize buttons - that they have.

The window manager also controls the way users can move windows and alternate the focus between them.

 

There are many window managers for X, including Sawfish and Blackbox. Each window manager imarts its own look and feel to the GUI

 

The look and feel of a window manager depends on the set of GUI controls - or widgets - that it includes. Widgets are elements like buttons and drop-down lists. Each window manager has a different set of widgets

 

Because the UNIX GUI is made up of the X server process, a window manager, and usually a desktop environment, it requires much more processing and system resources than a command-line shell.

 

X is well suited to end-user computers like home PCs and office workstations. It shouldn't be used on busy servers like database and web servers because it uses system resources and slows down the server's vital operations.

 

A UNIX GUI can be comprised of an X server process, a window manager, and a desktop environment.

 

The X Window System also called X running on a computer are resource intensive, so you shouldn't use them on busy servers.

 

Customizing the UNIX User Environment - Part 2 - Customizing X - Part 2

Customizing the UNIX User Environment

**********************************************************************************

Customizing X

**********************************************************************************

 

Setting up an XFree86 server

-----------------------------------

XFree86 is the most widespread version of the X Window System. The latest version of XFree86 is version 4.x. Before you set up a computer to be an XFree 86 4.x server, you need to gather information about its display hardware. You need to find out about its

 

- monitor refresh rate - the horizontal scan rate and the vertical synchronization rate of the monitor

- display adapter chipset

- display adapter memory - determines the max resoulution and color depth that X can use.

 

To set up a computer as an XFree85 4.x server, you need to generate an initial X configuration file. To do this, you log in as the superuser and type the following at the shell prompt. Which inturn checks the computer's display hardware and generates a matching configuration file called XF86Config.new

 

bash-2.05a$ XFree86 - configure

bash-2.05a$ ls -l | grep 'XF86'

-rw-r--r-- 1 root wheel 2383 Oct 31 17:08 XF86Config.new

bash-2.05a$

 

You need to test whether the configuration file is set up correctly. To do this, you type the command statement shown here.

 

bash-2.05a$ XFree86 -xf86config XF86Config.new

 

XFree86 runs a test to determine whether X works with the configuration file. If it works, you should see a gray grid background with a black X-shaped cursor in the center.

 

To exit the test, you press Ctrl+Alt+Backspace.

 

Once you've generated and tested the XFree86 configuration file, you open the file using a text editor such as vi and tune it for the hardware and display configuration that you want.

The XFree86Config file consists of several sections, each of which deals with a specific area of X configuration.

The following sections specify basic XFree86 configuration settings

-Module - specifies optional modules that X can load when it start up. Eg font modules and double buffer extension (DBE) module

-Files - allows you to specify path to RGB color code db as well as paths to font directories

-Server flags - enable/disable various X server settings including detailed error messages

 

The following section of the XFree86Config file deal with the X server's input and output devices:

-Input devices - protocols & settings for i/p devices & specify props like keyboard layout, keystrike autorepeat speed, three-button mouse emulation etc..

-Monitor - horz scan rate and vert synchronization rate for monitor

-Graphics device - disp adapter and video memory

-Screen - color depth & resolution

-ServerLayout - configuring X for multiple monitors

 

You need to configure the refresh rate, color depth, and screen resolution before you can run X reliably

 

To specify the refresh rate of your monito, you open the XFb6Config file and go to the Monitor section.

You specify the horizontal refresh rate by assigning a value in KHz to the HorizSync parameter and you specify the vertical refresh rate by assigning a value in Hz to the VertRefresh parameter.

 

Note: You can find out your monito's refresh rates from the monitor's user manual or from the plaguw at the rear of the monitor.

 

To specify color depth and screen resolution, you go to the Screen section of the XF86Config file.

The Screen section contains multiple Display subsections, each of which applies to a particular color depth. You can set different screen resoluitons for each color depth.

 

To set the screen resolution for a particular color depth, you add a line to the relevant subsection and specify the resolution using the Modes parameter

 

You set the default color depth using the DefaultColorDepth parameter at the beginning of the Screen section.

When you start X, it displays at the default color depth and uses the screen resolution that you've specified in the Display subsection corresponding to that color depth.

 

Once you've finished editing the XF86Config file, you copy it to the /etc/X11 directory. X will then use this configuration fole each time you start X.

 

bash-2.05a$ cp XF86Config.new /etc/X11/XF86Config

 

Unless a computer has been configured to load X automatically at startup, you need to start X manually from the command prompt. You type the following command to do it

 

bash-2.05a$ startx

 

When X starts up, it also loads the window manager and desktop environment that are currently configured as defaults.

 

To shut down X, you choose Logout from the desktop's main menu or press cntrl+Alt+Backspace to kill X.

Customizing the UNIX User Environment - Part 2 - Customizing X - Part 3

Customizing the UNIX User Environment

**********************************************************************************

Customizing X

**********************************************************************************

 

Installing fonts

----------------------------

X can use a variety of fonts to display text in windows and on widgets. Before you can use these fonts, however, you need to install them and configure X so that it knows where to find the font files.

XFree86 4.x supports three types of fonts:

-Type 1 fonts - use an Adobe postsscript standard. They store the character glyphs and font metrics in two separate files

-TrueType fonts - use an Apple standard. They've also been widely adopted by Microsoft. They are highly scalable and store all their font info in a single file

-antialiased fonts - new feature of XFree86 4.x. They are rendered more smoothly than other types of fonts.

 

UNIX stores Type 1 fonts in several font directories that branch from /usr/ports/x11-fonts/.

These include the urwfonts directory and the free fonts directory.

 

To install donts from a font directory, you navigate to the directory and type

make install clean.

 

bash-2.05a$ cd urwfonts

bash-2.05a$ make install clean

 

when you install a set of fonts, UNIX creates font directories in /usr/X11R6/lib/X11/fonts/

 

To configure X so that it can access these fonts, you need to edit the Files section of the XF86Config file.

 

You add a FontPath row to the Files section, specifying the location of the font directory. In this case, you specify the path to the URW font directory.

 

XFree86 4.x supports TrueType fonts using an extension module called freetype. You need to enable this module so that X can access TrueType fonts.

 

To enable the freetype module, you edit the XF86Config file, adding the following row to the Modules section:

Load "freetype"

 

XFree86 4.02 and later versions support antialiasing for all scalable font types. However, many desktop toolkits don't support antialiasing. The Qr toolkit for the KDE desktop is one of those that do.

 

To enable antialising with Qt, you need to edit the /usr/X11R6/lib/X11/XftConfig file using a text editor such as vi. You add lines defining each of the font directories for which you want to enable antialiasing

 

Because antialiasing smooths out the edges of screen fonts, it makes small fonts more readable and large fonts more attractive. However, it causes eyestrain when applied to medium-size fonts.

 

To disable antialiasing for medium-size fonts, you add a section to the XftConfig file that matches a range of font sizes - in this case 10 to 14 points - and disables antialiasing for it.

 

On a large network, it may be better to set up a font server and configure X to look for fonts on the font server.

 

To configure X to use a font server, you need to edit the XF86Config file and add a FontPath line to the Files section that specifies the port number of the font server. If font server is on port 3 you would see something line

 

FontPath "unix:/3"

 

Note: this procedure sets up a system-wide font server. To add a user-specific font server, you need to edit the .xinitrc file in the user's home directory