About Me

1545543_731283336882651_1110364495_n

I’m a working professional in IT sector. Working with financial institutions for providing efficient software solutions for easing critical and resource intensive operations. I worked on domain related to Capital Market, Investment Banking and Credit Evaluation. Pursuing my carrier with world class IT solution provider MNC Infosys LTD.

Document Indexing App

Below is my code I used for making and document indexing. Basically any document on windows.

AddEbookWindow.java

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import additionalpackage.Ebook;
import additionalpackage.EbooksTableModel;
import additionalpackage.IndexReader;

/**
*
*/

/**
* @author Raju
*
*/
public class AddEbookWindow extends JFrame {

// Add download text field.
private JTextField nameTextField, catTextField, locationTxtField;

private JTextArea descTextField;

private JPanel containerPanel;

private JFileChooser fileChooser;

private Ebook addedEbook;

private JButton okButton, cancelButton;

private EbookAppWindow ebookAppWindow;

public AddEbookWindow() {
fileChooser = new JFileChooser();

JPanel fieldContainerPanel = new JPanel();
containerPanel = new JPanel();
fieldContainerPanel.add(new JLabel(“Enter Name”));
nameTextField = new JTextField(14);
fieldContainerPanel.add(nameTextField);

containerPanel.add(fieldContainerPanel);
fieldContainerPanel = new JPanel();

fieldContainerPanel.add(new JLabel(“Enter Category”));
catTextField = new JTextField(12);
fieldContainerPanel.add(catTextField);

containerPanel.add(fieldContainerPanel);
fieldContainerPanel = new JPanel();

fieldContainerPanel.add(new JLabel(“Enter Description”));
descTextField = new JTextArea(4, 16);
descTextField.setLineWrap(true);
JScrollPane descContainer = new JScrollPane(descTextField);
descContainer
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
descContainer
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
// descContainer.add();
fieldContainerPanel.add(descContainer);

containerPanel.add(fieldContainerPanel);
fieldContainerPanel = new JPanel();

fieldContainerPanel.add(new JLabel(“Enter FileLocation”));
locationTxtField = new JTextField(10);
locationTxtField.setEditable(false);
fieldContainerPanel.add(locationTxtField);
JButton browseButton = new JButton(“Browse File”);
browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
browseFile();
}
});
containerPanel.add(fieldContainerPanel);

fieldContainerPanel = new JPanel();
fieldContainerPanel.add(browseButton);
containerPanel.add(fieldContainerPanel);

fieldContainerPanel = new JPanel();
okButton = new JButton(“OK”);
cancelButton = new JButton(“Cancel”);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
okAction();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cancelAction();
}
});
fieldContainerPanel.add(okButton);
fieldContainerPanel.add(cancelButton);
containerPanel.add(fieldContainerPanel);
setTitle(“Add Ebook”);
setBounds(20, 20, 350, 300);
setVisible(true);
getContentPane().add(containerPanel, BorderLayout.CENTER);

}

private void browseFile() {
JFileChooser chooser = new JFileChooser();
int ret = chooser.showOpenDialog(this);

if (ret != JFileChooser.APPROVE_OPTION) {
return;
}

File f = chooser.getSelectedFile();
if (f.isFile() && f.canRead()) {
locationTxtField.setText(f.getAbsolutePath());
}
}

public void setVisible() {
this.setVisible(true);
addedEbook = null;
}

public void okAction() {
addedEbook = new Ebook();
if (nameTextField.getText() != null
&& !nameTextField.getText().trim().equals(“”)) {
addedEbook.setName(nameTextField.getText());
} else {
JOptionPane.showMessageDialog(null, “Enter Proper Ebook Name “,
“Info”, JOptionPane.INFORMATION_MESSAGE);
return;
}
if (locationTxtField.getText() != null
&& !locationTxtField.getText().trim().equals(“”)) {
addedEbook.setFileLocation(locationTxtField.getText());
} else {
JOptionPane.showMessageDialog(null, “Enter Proper Ebook Location “,
“Info”, JOptionPane.INFORMATION_MESSAGE);
return;
}
if (catTextField.getText() != null
&& !catTextField.getText().trim().equals(“”)) {
addedEbook.setCategory(catTextField.getText());
} else {
JOptionPane.showMessageDialog(null,
“Enter Proper Ebook Category “, “Info”,
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (descTextField.getText() != null
&& descTextField.getText().equals(“”)) {
addedEbook.setDescriptionNotes(“_”);
} else {
addedEbook.setDescriptionNotes(descTextField.getText());
}
ebookAppWindow.addEbookAction(addedEbook);
setVisible(false);
}

private void cancelAction() {
setVisible(false);
}

public Ebook getAddedEbook() {
return addedEbook;
}

public void setAddedEbook(Ebook addedEbook) {
this.addedEbook = addedEbook;
}

public EbookAppWindow getEbookAppWindow() {
return ebookAppWindow;
}

public void setEbookAppWindow(EbookAppWindow ebookAppWindow) {
this.ebookAppWindow = ebookAppWindow;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AddEbookWindow ebookWindow = new AddEbookWindow();

JDesktopPane desk;
JInternalFrame iframe;
JFrame frame = new JFrame(“All Frames in a JDesktopPane Container”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// ebookWindow.setBounds(20, 20, 150, 100);
// ebookWindow.setVisible(true);
frame.add(ebookWindow);
frame.setSize(400, 400);
frame.setVisible(true);
}

}

EbookAppWindow.java

/**
* @(#)EbookAppWindow.java
*
*
* @author
* @version 1.00 2011/12/27
*/

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import additionalpackage.Ebook;
import additionalpackage.EbooksTableModel;
import additionalpackage.IndexReader;
import additionalpackage.ProgressRenderer;

public class EbookAppWindow extends JFrame implements Observer {

// Add download text field.
private JTextField addTextField;

// Download table’s data model.
private EbooksTableModel tableModel;

private IndexReader indexReader;

private Map<String, String> fileOpenCommnadsMap = new HashMap<String, String>();

private final static String localPropertiesFileLocation = “E:/downloads/e/eclipse-jee-ganymede-SR1-win32/eclipse-jee-ganymede-SR1-win32/eclipse/workspace/EbookApp/src/startup.properties”;
private final static String localPropertiesSeparator = “=”;
private final static String indexFileToken = “indexFile”;
private final static String allFileRunnerToken = “*”;

// Table listing downloads.
private JTable table;

// These are the buttons for managing the selected download.
private JButton previewButton, addButton;
private JButton editButton, deleteButton;

// Currently selected download.
private Ebook selectedDownload, modifiedEbook, deleteEbook, addEbook;

// Flag for whether or not table selection is being cleared.
private boolean clearing;

// Constructor for Download Manager.
public EbookAppWindow() {
// Set application title.
fileOpenCommnadsMap = getLocalProperties();
String indexFileLocationString = fileOpenCommnadsMap
.get(indexFileToken);
indexReader = new IndexReader(indexFileLocationString);

setTitle(“Ebook Manager”);

// Set window size.
setSize(640, 480);

// Handle window closing events.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
actionExit();
}
});

// Set up file menu.
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu(“File”);
fileMenu.setMnemonic(KeyEvent.VK_F);
JMenuItem fileExitMenuItem = new JMenuItem(“Exit”, KeyEvent.VK_X);
fileExitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionExit();
}
});
fileMenu.add(fileExitMenuItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);

// Set up add panel.
JPanel addPanel = new JPanel();
addTextField = new JTextField(30);
addPanel.add(addTextField);
JButton searchButton = new JButton(“Search”);
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchAction();
}
});
addPanel.add(searchButton);

// Set up Downloads table.
tableModel = new EbooksTableModel();
table = new JTable(tableModel);
table.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
tableSelectionChanged();
}
});
// Allow only one row at a time to be selected.
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setAutoResizeMode(JTable. AUTO_RESIZE_ALL_COLUMNS);

// Set up ProgressBar as renderer for progress column.
ProgressRenderer renderer = new ProgressRenderer(0, 100);
renderer.setStringPainted(true); // show progress text
// table.setDefaultRenderer(JProgressBar.class, renderer);
//
// // Set table’s row height large enough to fit JProgressBar.
// table.setRowHeight((int) renderer.getPreferredSize().getHeight());

// Set up downloads panel.
JPanel downloadsPanel = new JPanel();
downloadsPanel.setBorder(BorderFactory.createTitledBorder(“Ebooks”));
downloadsPanel.setLayout(new BorderLayout());
downloadsPanel.add(new JScrollPane(table), BorderLayout.CENTER);

// Set up buttons panel.
JPanel buttonsPanel = new JPanel();
previewButton = new JButton(“Preview”);
previewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
previewEbook();
}
});
// previewButton.setEnabled(false);
buttonsPanel.add(previewButton);
addButton = new JButton(“Add”);
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addEbook();
}
});
// addButton.setEnabled(false);
buttonsPanel.add(addButton);
editButton = new JButton(“Edit”);
editButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
modifyEbook();
}
});
// editButton.setEnabled(false);
buttonsPanel.add(editButton);
deleteButton = new JButton(“Delete”);
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteEbook();
}
});

// deleteButton.setEnabled(false);
buttonsPanel.add(deleteButton);
// Add panels to display.
getContentPane().setLayout(new BorderLayout());
getContentPane().add(addPanel, BorderLayout.NORTH);
getContentPane().add(downloadsPanel, BorderLayout.CENTER);
getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
}

private Map<String, String> getLocalProperties() {
Map<String, String> localProperties = new HashMap<String, String>();
StringBuilder contents = new StringBuilder();

try {
File aFile = new File(localPropertiesFileLocation);
// use buffering, reading one line at a time
// FileReader always assumes default encoding is OK!
BufferedReader input = new BufferedReader(new FileReader(aFile));
try {
String line = null; // not declared within while loop
/*
* readLine is a bit quirky : it returns the content of a line
* MINUS the newline. it returns null only for the END of the
* stream. it returns an empty String if two newlines appear in
* a row.
*/
while ((line = input.readLine()) != null) {
contents.append(line);
String[] propertiesToken = line
.split(localPropertiesSeparator);
if (propertiesToken != null && propertiesToken.length == 2) {
localProperties.put(propertiesToken[0],
propertiesToken[1]);
}
}
} finally {
input.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
return localProperties;
}

// Exit this program.
private void actionExit() {
System.exit(0);
}

// Add a new download.
private void searchAction() {
List<Ebook> searchedEbookList = null;
tableModel.clearAll();
/*
* URL verifiedUrl = verifyUrl(addTextField.getText()); if (verifiedUrl
* != null) { tableModel.addDownload(new Ebook(verifiedUrl));
* addTextField.setText(“”); // reset add text field } else {
* JOptionPane.showMessageDialog(this, “Invalid Download URL”, “Error”,
* JOptionPane.ERROR_MESSAGE); }
*/
String searchedKeyword = addTextField.getText();
if (searchedKeyword != null && searchedKeyword.trim().equals(“”)) {
searchedEbookList = indexReader.getAllEbook();
} else if (searchedKeyword != null) {
searchedEbookList = indexReader.searchEbook(searchedKeyword.trim());
}
if (searchedEbookList != null && searchedEbookList.size() > 0) {
for (Ebook ebook : searchedEbookList) {
tableModel.addEbook(ebook);
}
}
}

// Verify download URL.
private URL verifyUrl(String url) {
// Only allow HTTP URLs.
if (!url.toLowerCase().startsWith(“http://&#8221;))
return null;

// Verify format of URL.
URL verifiedUrl = null;
try {
verifiedUrl = new URL(url);
} catch (Exception e) {
return null;
}

// Make sure URL specifies a file.
if (verifiedUrl.getFile().length() < 2)
return null;

return verifiedUrl;
}

// Called when table row selection changes.
private void tableSelectionChanged() {
/*
* Unregister from receiving notifications from the last selected
* download.
*/
// if (selectedDownload != null)
// selectedDownload.deleteObserver(EbookAppWindow.this);
/*
* If not in the middle of clearing a download, set the selected
* download and register to receive notifications from it.
*/
// if (!clearing) {
// selectedDownload = tableModel.getDownload(table
// .getSelectedRow());
// // selectedDownload.addObserver(EbookAppWindow.this);
// updateButtons();
// }
}

// Pause the selected download.
private void actionPause() {
// selectedDownload.pause();
updateButtons();
}

private void addEbook()
{
try{
AddEbookWindow ebookWindow=new AddEbookWindow();
ebookWindow.setEbookAppWindow(this);
}catch(Exception e)
{
System.out.println(“Exception is “+e);
}
}

public void addEbookAction(Ebook addedEbook)
{
if(addedEbook!=null)
{
indexReader.addEbook(addedEbook);
}
}

public void modifyEbookAction(Ebook modifiedEbook)
{
if(modifiedEbook!=null)
{
indexReader.modifyEbook(modifiedEbook);
}
}

private void modifyEbook()
{
Ebook previewBook = tableModel.getEbook(table.getSelectedRow());
if (previewBook != null) {
ModifyEbookWindow ebookWindow=new ModifyEbookWindow(previewBook);
ebookWindow.setVisible(true);
ebookWindow.setEbookAppWindow(this);
}
else
{
JOptionPane.showMessageDialog(null,
“Please Select An Ebook To Modify”, “Info”,
JOptionPane.INFORMATION_MESSAGE);
}
}

private void previewEbook() {
Ebook previewBook = tableModel.getEbook(table.getSelectedRow());
if (previewBook != null) {
System.out.println(“previewing ebook ” + previewBook.getName());
try {
SystemRunApp sys = new SystemRunApp();
sys.setEbookFileLocation(previewBook.getFileLocation());
sys
.setSysRunnerApp(getSystemApp(previewBook
.getFileLocation()));
Thread t = new Thread(sys);
t.start();
t.join();
} catch (Exception e) {
System.out.println(“Exception is e:” + e.getMessage());
}
}
}

private String getSystemApp(String fileLocation) {
if (fileLocation != null && !fileLocation.trim().equals(“”)) {
Set<String> keySet = fileOpenCommnadsMap.keySet();
for (String key : keySet) {
String fileType = fileOpenCommnadsMap.get(key);
if (fileType != null && !fileType.trim().equals(“”)
&& fileType.equals(allFileRunnerToken)) {
return key;
} else if (fileType != null
&& !fileType.trim().equals(“”)
&& fileLocation.toLowerCase().contains(
fileType.toLowerCase())) {
return key;
}
}
}
return null;
}

// Resume the selected download.
private void actionResume() {
// selectedDownload.resume();
updateButtons();
}

// Cancel the selected download.
private void actionCancel() {
// selectedDownload.cancel();
updateButtons();
}

// Clear the selected download.
private void actionClear() {
clearing = true;
tableModel.clearDownload(table.getSelectedRow());
clearing = false;
selectedDownload = null;
updateButtons();
}

private void deleteEbook() {
Ebook previewBook = tableModel.getEbook(table.getSelectedRow());
if (previewBook != null) {
JOptionPane optionDialog = new JOptionPane();
int selected = JOptionPane.showConfirmDialog(null,
“Are You Sure You Want To Delete Ebook”, “Warning”,
JOptionPane.OK_CANCEL_OPTION);
if (selected == 0) {
indexReader.removeEbook(previewBook);
}
} else {
JOptionPane.showMessageDialog(null,
“Please Select An Ebook To Delete”, “Info”,
JOptionPane.OK_OPTION);
}
}

/*
* Update each button’s state based off of the currently selected download’s
* status.
*/
private void updateButtons() {
/*
* if (selectedDownload != null) { int status =
* selectedDownload.getStatus(); switch (status) { case
* Ebook.DOWNLOADING: previewButton.setEnabled(true);
* addButton.setEnabled(false); editButton.setEnabled(true);
* deleteButton.setEnabled(false); break; case Ebook.PAUSED:
* previewButton.setEnabled(false); addButton.setEnabled(true);
* editButton.setEnabled(true); deleteButton.setEnabled(false); break;
* case Ebook.ERROR: previewButton.setEnabled(false);
* addButton.setEnabled(true); editButton.setEnabled(false);
* deleteButton.setEnabled(true); break; default: // COMPLETE or
* CANCELLED previewButton.setEnabled(false);
* addButton.setEnabled(false); editButton.setEnabled(false);
* deleteButton.setEnabled(true); } } else { // No download is selected
* in table. previewButton.setEnabled(false);
* addButton.setEnabled(false); editButton.setEnabled(false);
* deleteButton.setEnabled(false); }
*/
}

/*
* Update is called when a Download notifies its observers of any changes.
*/
public void update(Observable o, Object arg) {
// Update buttons if the selected download has changed.
if (selectedDownload != null && selectedDownload.equals(o))
updateButtons();
}

public Ebook getModifiedEbook() {
return modifiedEbook;
}

public void setModifiedEbook(Ebook modifiedEbook) {
this.modifiedEbook = modifiedEbook;
}

public Ebook getDeleteEbook() {
return deleteEbook;
}

public void setDeleteEbook(Ebook deleteEbook) {
this.deleteEbook = deleteEbook;
}

public Ebook getAddEbook() {
return addEbook;
}

public void setAddEbook(Ebook addEbook) {
this.addEbook = addEbook;
}

// Run the Download Manager.
public static void main(String[] args) {
EbookAppWindow manager = new EbookAppWindow();
manager.setVisible(true);
}
}

ModifyEbookWindow.java

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import additionalpackage.Ebook;

/**
*
*/

/**
* @author Raju
*
*/
public class ModifyEbookWindow extends JFrame {

// Add download text field.
private JTextField nameTextField, catTextField, locationTxtField;

private JTextArea descTextField;

private JPanel containerPanel;

private JFileChooser fileChooser;

private Ebook modifiedEbook;

private JButton okButton,cancelButton;

private EbookAppWindow ebookAppWindow;

public ModifyEbookWindow(Ebook ebook) {
fileChooser = new JFileChooser();

JPanel fieldContainerPanel = new JPanel();
containerPanel = new JPanel();
fieldContainerPanel.add(new JLabel(“Enter Name”));
nameTextField = new JTextField(14);
fieldContainerPanel.add(nameTextField);
nameTextField.setText(ebook.getName());

containerPanel.add(fieldContainerPanel);
fieldContainerPanel = new JPanel();

fieldContainerPanel.add(new JLabel(“Enter Category”));
catTextField = new JTextField(12);
fieldContainerPanel.add(catTextField);
catTextField.setText(ebook.getCategory());

containerPanel.add(fieldContainerPanel);
fieldContainerPanel = new JPanel();

fieldContainerPanel.add(new JLabel(“Enter Description”));
descTextField = new JTextArea(4, 16);
descTextField.setLineWrap(true);
if(ebook.getDescriptionNotes()!=null && ebook.getDescriptionNotes().equals(“_”))
{
descTextField.setText(“”);
}
else {
descTextField.setText(ebook.getDescriptionNotes());
}
JScrollPane descContainer = new JScrollPane(descTextField);
descContainer
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
descContainer
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
// descContainer.add();
fieldContainerPanel.add(descContainer);

containerPanel.add(fieldContainerPanel);
fieldContainerPanel = new JPanel();

fieldContainerPanel.add(new JLabel(“Enter FileLocation”));
locationTxtField = new JTextField(10);
locationTxtField.setEditable(false);
locationTxtField.setText(ebook.getFileLocation());
fieldContainerPanel.add(locationTxtField);
containerPanel.add(fieldContainerPanel);

fieldContainerPanel = new JPanel();
containerPanel.add(fieldContainerPanel);

fieldContainerPanel = new JPanel();
cancelButton=new JButton(“Cancel”);
okButton = new JButton(“OK”);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
okAction();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cancelButton();
}
});
fieldContainerPanel.add(okButton);
fieldContainerPanel.add(cancelButton);
containerPanel.add(fieldContainerPanel);
setTitle(“Modify Ebook”);
setBounds(20, 20, 350, 300);
setVisible(true);
getContentPane().add(containerPanel, BorderLayout.CENTER);

}

private void browseFile() {
JFileChooser chooser = new JFileChooser();
int ret = chooser.showOpenDialog(this);

if (ret != JFileChooser.APPROVE_OPTION) {
return;
}

File f = chooser.getSelectedFile();
if (f.isFile() && f.canRead()) {
locationTxtField.setText(f.getAbsolutePath());
}
}

public void setVisible() {
this.setVisible(true);
modifiedEbook = null;
}

public void okAction() {
modifiedEbook = new Ebook();
if (nameTextField.getText() != null
&& !nameTextField.getText().trim().equals(“”)) {
modifiedEbook.setName(nameTextField.getText());
} else {
JOptionPane.showMessageDialog(null, “Enter Proper Ebook Name “,
“Info”, JOptionPane.INFORMATION_MESSAGE);
return;
}
if (locationTxtField.getText() != null
&& !locationTxtField.getText().trim().equals(“”)) {
modifiedEbook.setFileLocation(locationTxtField.getText());
} else {
JOptionPane.showMessageDialog(null, “Enter Proper Ebook Location “,
“Info”, JOptionPane.INFORMATION_MESSAGE);
return;
}
if (catTextField.getText() != null
&& !catTextField.getText().trim().equals(“”)) {
modifiedEbook.setCategory(catTextField.getText());
} else {
JOptionPane.showMessageDialog(null,
“Enter Proper Ebook Category “, “Info”,
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (descTextField.getText() != null
&& descTextField.getText().equals(“”)) {
modifiedEbook.setDescriptionNotes(“_”);
} else {
modifiedEbook.setDescriptionNotes(descTextField.getText());
}
ebookAppWindow.modifyEbookAction(modifiedEbook);
setVisible(false);
}

private void cancelButton()
{
setVisible(false);
}

public Ebook getModifiedEbook() {
return modifiedEbook;
}

public void setModifiedEbook(Ebook modifiedEbook) {
this.modifiedEbook = modifiedEbook;
}

public EbookAppWindow getEbookAppWindow() {
return ebookAppWindow;
}

public void setEbookAppWindow(EbookAppWindow ebookAppWindow) {
this.ebookAppWindow = ebookAppWindow;
}

/**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
Ebook ebook = new Ebook();
ebook.setCategory(“cat1 “);
ebook.setDescriptionNotes(“desc1”);
ebook.setFileLocation(“loc1”);
ebook.setName(“name1”);
ModifyEbookWindow ebookWindow = new ModifyEbookWindow(ebook);

JInternalFrame iframe;
JFrame frame = new JFrame(“All Frames in a JDesktopPane Container”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// ebookWindow.setBounds(20, 20, 150, 100);
ebookWindow.setVisible(true);
}

}

startup.properties

indexFile=/home/Raju/ebookApp_dist/testIndex_back.txt
xchm=.chm
evince=.pdf

SystemRunApp.java

/**
* @(#)SystemRunApp.java
*
*
* @author
* @version 1.00 2011/12/26
*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

public class SystemRunApp implements Runnable {

/**
* Creates a new instance of <code>SystemRunApp</code>.
*/
// load all below settings at the time of startup automatically
private String systemType = “windows”;

private String windowSystemApp = “explorer”;

private String ebookFileLocation;

private String sysRunnerApp;

private String arguments;

// private HashMap<String,HashMap<String,ArrayList<String>>>;

public SystemRunApp() {
}

public void openInSystemFile(String ebookFileLocation, String sysRunnerApp,
String arguments) {

if(arguments==null)
{
arguments=””;
}
if(sysRunnerApp==null)
{
sysRunnerApp=””;
}
if (ebookFileLocation != null
&& !ebookFileLocation.equalsIgnoreCase(“”)) {
try {

Runtime r = Runtime.getRuntime();
Process p = null;
/*p = r.exec(sysRunnerApp + ” ” + arguments + ” “
+ ebookFileLocation);*/

String command=windowSystemApp + ” ” + arguments + ” “
+ ebookFileLocation;
System.out.println(“command executed “+command);
p = r.exec(command);

BufferedOutputStream wr = new BufferedOutputStream(p
.getOutputStream());
BufferedInputStream a = new BufferedInputStream(p
.getInputStream());
BufferedInputStream de = new BufferedInputStream(p
.getErrorStream());
Integer t = new Integer(2);
byte d = t.byteValue();
int c = a.read();

while (c != -1) {
System.out.print((char) c);
c = a.read();
}
wr.write(d);
int fe = de.read();
while (c != -1) {
System.out.println((char) fe);
fe = a.read();
}
} catch (Exception e) {
System.out.println(“exception is ” + e);
}
}
}

public String getEbookFileLocation() {
return ebookFileLocation;
}

public void setEbookFileLocation(String ebookFileLocation) {
this.ebookFileLocation = ebookFileLocation;
}

public String getSysRunnerApp() {
return sysRunnerApp;
}

public void setSysRunnerApp(String sysRunnerApp) {
this.sysRunnerApp = sysRunnerApp;
}

public String getArguments() {
return arguments;
}

public void setArguments(String arguments) {
this.arguments = arguments;
}

/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
SystemRunApp sys = new SystemRunApp();
sys.openInSystemFile(“9.chm”, null, null);
}

@Override
public void run() {
// TODO Auto-generated method stub
openInSystemFile(ebookFileLocation, sysRunnerApp, arguments);
}
}

Ebook.java

package additionalpackage;

/**
* @(#)Download.java
*
*
* @author
* @version 1.00 2011/7/19
*/

import java.io.*;
import java.net.*;
import java.util.*;

// This class downloads a file from a URL.
public class Ebook {

private String name;

private String category;

private String fileLocation;

private String descriptionNotes;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public String getFileLocation() {
return fileLocation;
}

public void setFileLocation(String fileLocation) {
this.fileLocation = fileLocation;
}

public String getDescriptionNotes() {
return descriptionNotes;
}

public void setDescriptionNotes(String descriptionNotes) {
this.descriptionNotes = descriptionNotes;
}

}

EbooksTableModel.java

package additionalpackage;
/**
* @(#)DownloadTableModel.java
*
*
* @author
* @version 1.00 2011/7/19
*/

import java.util.*;
import javax.swing.*;
import javax.swing.table.*;

// This class manages the download table’s data.
public class EbooksTableModel extends AbstractTableModel{

// These are the names for the table’s columns.
private static final String[] columnNames = {“Name”, “Category”,
“Description”, “File Location”};

// These are the classes for each column’s values.
private static final Class[] columnClasses = {String.class,
String.class, String.class, String.class};

// The table’s list of downloads.
private ArrayList downloadList = new ArrayList();

// Add a new download to the table.
public void addEbook(Ebook ebook) {

// Register to be notified when the download changes.

downloadList.add(ebook);

// Fire table row insertion notification to table.
fireTableRowsInserted(getRowCount() – 1, getRowCount() – 1);
}

// Get a download for the specified row.
public Ebook getEbook(int row) {
return (Ebook) downloadList.get(row);
}

// Remove a download from the list.
public void clearDownload(int row) {
downloadList.remove(row);

// Fire table row deletion notification to table.
fireTableRowsDeleted(row, row);
}

public void clearAll()
{
downloadList=new ArrayList<Ebook>();
}

// Get table’s column count.
public int getColumnCount() {
return columnNames.length;
}

// Get a column’s name.
public String getColumnName(int col) {
return columnNames[col];
}

// Get a column’s class.
public Class getColumnClass(int col) {
return columnClasses[col];
}

// Get table’s row count.
public int getRowCount() {
return downloadList.size();
}

// Get value for a specific row and column combination.
public Object getValueAt(int row, int col) {

Ebook ebook = (Ebook) downloadList.get(row);
switch (col) {
case 0: // Name
return ebook.getName();
case 1: // Category
return ebook.getCategory();
case 2: // Description
return ebook.getDescriptionNotes();
case 3: // FileLocation
return ebook.getFileLocation();
}
return “”;
}

/* Update is called when a Download notifies its
observers of any changes */
public void update(Observable o, Object arg) {
int index = downloadList.indexOf(o);

// Fire table row update notification to table.
fireTableRowsUpdated(index, index);
}
}

IndexReader.java

/**
*
*/
package additionalpackage;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* @author Raju
*
*/
public class IndexReader {

private String indexFileLocation = null;
final private static String rowContentSeparator = “%%”;
final private static String rowSeparator = “–“;

public IndexReader(String indexFileLocation) {
this.indexFileLocation = indexFileLocation;
}

public void setIndexFileLocation(String indexFileLocation) {
this.indexFileLocation = indexFileLocation;
}

public List<Ebook> searchEbook(String searchKeyWord) {
List<Ebook> finalSearchResult = new ArrayList<Ebook>();
List<Ebook> indexedEbookList = getIndexedEbooks();
if (indexedEbookList != null && indexedEbookList.size() > 0) {
for (Ebook indexedEbook : indexedEbookList) {
if (indexedEbook.getCategory().toLowerCase().contains(searchKeyWord.toLowerCase())) {
finalSearchResult.add(indexedEbook);
continue;
}
if (indexedEbook.getDescriptionNotes().toLowerCase().contains(searchKeyWord.toLowerCase())) {
finalSearchResult.add(indexedEbook);
continue;
}
if (indexedEbook.getName().toLowerCase().contains(searchKeyWord.toLowerCase())) {
finalSearchResult.add(indexedEbook);
continue;
}
}
}
return finalSearchResult;
}

public List<Ebook> getAllEbook() {
List<Ebook> indexedEbookList = getIndexedEbooks();
if (indexedEbookList != null && indexedEbookList.size() > 0) {
return indexedEbookList;
} else {
return null;
}
}

public void addEbook(Ebook newEbook) {

List<Ebook> searchResult = getAllEbook();
if (newEbook != null) {
if (searchResult != null && searchResult.size() > 0) {
searchResult.add(newEbook);
} else {
searchResult = new ArrayList<Ebook>();
searchResult.add(newEbook);
}

try {

File aFile = new File(indexFileLocation);
// use buffering, reading one line at a time
// FileReader always assumes default encoding is OK!
BufferedWriter writer = new BufferedWriter(
new FileWriter(aFile));

try {

for (Ebook ebook : searchResult) {

String ebookName = ebook.getName();
String ebookCategory = ebook.getCategory();
String ebookLocation = ebook.getFileLocation();
String ebookDescription = ebook.getDescriptionNotes();
StringBuffer ebookRowContent = new StringBuffer();
ebookRowContent.append(ebookName.trim());
ebookRowContent.append(rowContentSeparator);
ebookRowContent.append(ebookLocation.trim());
ebookRowContent.append(rowContentSeparator);
ebookRowContent.append(ebookCategory.trim());
ebookRowContent.append(rowContentSeparator);
ebookRowContent.append(ebookDescription.trim());
ebookRowContent.append(rowSeparator);
ebookRowContent.append(System
.getProperty(“line.separator”));
String line = null; // not declared within while loop
/*
* readLine is a bit quirky : it returns the content of
* a line MINUS the newline. it returns null only for
* the END of the stream. it returns an empty String if
* two newlines appear in a row.
*/
/*
* while ((line = input.readLine()) != null) {
* contents.append(line);
* contents.append(System.getProperty
* (“line.separator”)); }
*/
writer.write(ebookRowContent.toString());
writer.flush();
}

} catch (IOException ex) {
ex.printStackTrace();
} finally {
writer.close();
}

} catch (Exception e) {
System.out.println(“Exception while adding is “
+ e.getMessage());
}

}
}

public void modifyEbook(Ebook modifiedBook)
{
removeEbook(modifiedBook);
addEbook(modifiedBook);
}

public void removeEbook(Ebook delEbook) {

List<Ebook> searchResult = getAllEbook();
int delEbookIndex = 0;
if (delEbook != null) {
if (searchResult != null && searchResult.size() > 0) {
for (Ebook ebook : searchResult) {
if (delEbook.getFileLocation().equalsIgnoreCase(
ebook.getFileLocation())) {
delEbookIndex = searchResult.indexOf(ebook);
}
}
if (delEbookIndex != 0) {
searchResult.remove(delEbookIndex);

try {

File aFile = new File(indexFileLocation);
// use buffering, reading one line at a time
// FileReader always assumes default encoding is OK!
BufferedWriter writer = new BufferedWriter(
new FileWriter(aFile));

try {

for (Ebook ebook : searchResult) {

String ebookName = ebook.getName();
String ebookCategory = ebook.getCategory();
String ebookLocation = ebook.getFileLocation();
String ebookDescription = ebook
.getDescriptionNotes();
StringBuffer ebookRowContent = new StringBuffer();
ebookRowContent.append(ebookName.trim());
ebookRowContent.append(rowContentSeparator);
ebookRowContent.append(ebookLocation.trim());
ebookRowContent.append(rowContentSeparator);
ebookRowContent.append(ebookCategory.trim());
ebookRowContent.append(rowContentSeparator);
ebookRowContent.append(ebookDescription);
ebookRowContent.append(rowSeparator);
ebookRowContent.append(System
.getProperty(“line.separator”));
String line = null; // not declared within while
// loop
/*
* readLine is a bit quirky : it returns the
* content of a line MINUS the newline. it
* returns null only for the END of the stream.
* it returns an empty String if two newlines
* appear in a row.
*/
/*
* while ((line = input.readLine()) != null) {
* contents.append(line);
* contents.append(System.getProperty
* (“line.separator”)); }
*/
writer.write(ebookRowContent.toString());
writer.flush();
}

} catch (IOException ex) {
ex.printStackTrace();
} finally {
writer.close();
}

} catch (Exception e) {
System.out.println(“Exception while adding is “
+ e.getMessage());
}

}
}
}
}

private List<Ebook> getIndexedEbooks() {
List<Ebook> ebookList = new ArrayList<Ebook>();
String fileContent = readIndexContent();
if (fileContent != null) {
String[] downloadUrlStringList = fileContent.split(rowSeparator);
if (downloadUrlStringList != null
&& downloadUrlStringList.length > 0) {
for (String indexRowContent : downloadUrlStringList) {
String[] rowContent = indexRowContent
.split(rowContentSeparator);
if (rowContent != null && rowContent.length > 3) {
Ebook ebook = new Ebook();
ebook.setName(rowContent[0]);
ebook.setFileLocation(rowContent[1]);
ebook.setCategory(rowContent[2]);
ebook.setDescriptionNotes(rowContent[3]);
ebookList.add(ebook);
}
}
}
}
return ebookList;
}

private String readIndexContent() {
if (indexFileLocation != null) {
// …checks on aFile are elided

StringBuilder contents = new StringBuilder();

try {
File aFile = new File(indexFileLocation);
// use buffering, reading one line at a time
// FileReader always assumes default encoding is OK!
BufferedReader input = new BufferedReader(new FileReader(aFile));
try {
String line = null; // not declared within while loop
/*
* readLine is a bit quirky : it returns the content of a
* line MINUS the newline. it returns null only for the END
* of the stream. it returns an empty String if two newlines
* appear in a row.
*/
while ((line = input.readLine()) != null) {
contents.append(line);
contents.append(System.getProperty(“line.separator”));
}
} finally {
input.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}

return contents.toString();
} else {
return null;
}
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
IndexReader indexer = new IndexReader(“C://testIndex.txt”);
/*
* List<Ebook> searchResult=indexer.searchEbook(“JSP”);
* if(searchResult!=null && searchResult.size()>0) { for(Ebook
* searchedEbook:searchResult) {
* System.out.println(“Ebook Name:”+searchedEbook
* .getName()+”|Category:”+
* searchedEbook.getCategory()+”|Description:”+searchedEbook
* .getDescriptionNotes()); } }
*/
/*Ebook ebook = new Ebook();
ebook.setCategory(“cat1 “);
ebook.setDescriptionNotes(“desc1”);
ebook.setFileLocation(“loc1”);
ebook.setName(“name1”);
indexer.addEbook(ebook);

List<Ebook> searchResult = indexer.getAllEbook();
if (searchResult != null && searchResult.size() > 0) {
for (Ebook searchedEbook : searchResult) {
System.out
.println(“Ebook Name:” + searchedEbook.getName()
+ “|Category:” + searchedEbook.getCategory()
+ “|Description:”
+ searchedEbook.getDescriptionNotes());
}
}*/
Ebook ebook = new Ebook();
ebook.setCategory(“cat1 “);
ebook.setDescriptionNotes(“desc1”);
ebook.setFileLocation(“loc1”);
ebook.setName(“name1”);
indexer.removeEbook(ebook);
List<Ebook> searchResult = indexer.getAllEbook();
if (searchResult != null && searchResult.size() > 0) {
for (Ebook searchedEbook : searchResult) {
System.out
.println(“Ebook Name:” + searchedEbook.getName()
+ “|Category:” + searchedEbook.getCategory()
+ “|Description:”
+ searchedEbook.getDescriptionNotes());
}
}
}

}

ProgressRenderer.java

package additionalpackage;

/**
* @(#)ProgressRenderer.java
*
*
* @author
* @version 1.00 2011/7/19
*/

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;

// This class renders a JProgressBar in a table cell.
public class ProgressRenderer extends JProgressBar
implements TableCellRenderer {

// Constructor for ProgressRenderer.
public ProgressRenderer(int min, int max) {
super(min, max);
}

/* Returns this JProgressBar as the renderer
for the given table cell. */
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
// Set JProgressBar’s percent complete value.
setValue((int) ((Float) value).floatValue());
return this;
}
}

 

Getting input values from gxt grid row expander plugin

Gxt has provided a really good API over the gwt framework simplifying the work by providing most commonly used widgets with some customizable structure and flexibility. But some of the features have limitations if its matter of their usability. If you ever have to use the row expander plugin of grids you will quickly realise that embedding html contents becomes really difficult keeping content or expander dynamic and its really becoming heck of a job if it comes to getting value from one or more input fields in the expander. As everybody I faced the same problem and came up with a solution which I hope help out
some readers satisfactorly.

1.First you are suppose to know how to make a simple gxt application and run it so if you doesn’t know this then please first
learn about it.
2.Now make your own row expander grid widget or you can choose to copy paste from the gxt demo example code and customize
according to your choice but in case if you are in real hurry to try out you can copy the code which I used for this demo.

import java.util.ArrayList;
import java.util.List; import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.grid.RowExpander;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window; public class GridExpanderDemo extends LayoutContainer {

private VerticalPanel panel;
private GridCellRenderer<Stock> gridNumber;
private GridCellRenderer<Stock> change;
List<Stock> stocks;

public GridExpanderDemo() {
final NumberFormat currency = NumberFormat.getCurrencyFormat();
final NumberFormat number = NumberFormat.getFormat(“0.00”);

final NumberCellRenderer<Grid<Stock>> numberRenderer = new NumberCellRenderer<Grid<Stock>>(
currency);

change = new GridCellRenderer<Stock>() {
public String render(Stock model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<Stock> store, Grid<Stock> grid) {
double val = (Double) model.get(property);
String style = val < 0 ? “red” : “green”;
return “<span style=’color:” + style + “‘>”
+ number.format(val) + “</span>”;
}
};

gridNumber = new GridCellRenderer<Stock>() {
public String render(Stock model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<Stock> store, Grid<Stock> grid) {
return numberRenderer.render(null, property, model
.get(property));
}
};

panel = new VerticalPanel();
panel.setSpacing(20);

}

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

createExpander();
add(panel);
}

private void createExpander() {
stocks = TestData.getStocks();
for (Stock s : stocks) {
s
.set(
“desc”,
“<label>Name:</label><input type=’text’ value=” id='”
+ s.getName()
+ “_text’ onchange=’document.getElementById(\””
+ s.getName()
+ “_input\”).setAttribute(\”value\”,this.value);’><input type=’hidden’ value=” id='”
+ s.getName()
+ “_input’>”
+ “<input type=’button’ value=’submit’ onclick=’window.alert(\”value is \”+document.getElementById(\””
+ s.getName()
+ “_input\”).getAttribute(\”value\”));’>”);
}

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

XTemplate tpl = XTemplate.create(“<p>{desc}</p>”);

RowExpander expander = new RowExpander();
expander.setTemplate(tpl);

configs.add(expander);

ColumnConfig column = new ColumnConfig();
column.setId(“name”);
column.setHeader(“Company”);
column.setWidth(200);
configs.add(column);

column = new ColumnConfig();
column.setId(“symbol”);
column.setHeader(“Symbol”);
column.setWidth(100);
configs.add(column);

column = new ColumnConfig();
column.setId(“last”);
column.setHeader(“Last”);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(75);
column.setRenderer(gridNumber);
configs.add(column);

column = new ColumnConfig(“change”, “Change”, 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setRenderer(change);
configs.add(column);

column = new ColumnConfig(“date”, “Last Updated”, 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
configs.add(column);

ListStore<Stock> store = new ListStore<Stock>();
store.add(stocks);

ColumnModel cm = new ColumnModel(configs);

ContentPanel cp = new ContentPanel();
cp.setHeading(“Expander Rows, Collapse and Auto Fill”);
cp.setAnimCollapse(false);
cp.setCollapsible(true);
cp.setLayout(new FitLayout());
cp.setSize(600, 300);

Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.addPlugin(expander);
grid.setColumnReordering(true);
grid.getView().setAutoFill(true);
grid.getAriaSupport().setLabelledBy(cp.getHeader().getId() + “-label”);
cp.add(grid);

panel.add(cp);
//setShowTrigger(this);
}
}
}
}

3.Now append this part of the code into your class and dont forget to put the setTrigger(this); statement in the end of
onrender method call.

public void gwtTargetFunction(String id, String value) {
Window
.alert(“Call for object of name :” + id + ” with value :”
+ value);
for (Stock s : stocks) {
if (s.getName().equalsIgnoreCase(id)) {
s.set(“newProperty”, value); }
}
} public native void setShowTrigger(GridExpanderDemo x)/*-{
$wnd.showBlueApp = function (id,value) {
x.@com.raju.newgxt.client.demogxt.GridExpanderDemo::gwtTargetFunction(Ljava/lang/String;Ljava/lang/String;)(id,value);
};
}-*/;


4.Now run this application as per your convenience by compiling and deploying or running in hosted mode.
*Please notice that in the JSNI code correctly mention the package structure or it may cause error at compilation or running
the application.


5.If you got your code right you might get a alert window showing what value you had input in the text field along with id
in my case its the name and you can choose anything too but make sure that it should give a unique reference to the field
in the whole DOM.You can even pass two or more arguments its upto the requirement. So I hope this might be enough to get
your thing done in case if you have any feedbacks or questions please put them in the comments below.

PHP ON LINUX FOR BEGINNERS

RUNNING PHP ON APACHE SERVER


Earlier I posted about how to run php on windows, this time I’ll explain how to execute php scripts on linux distributions. I wont’t be explaining about php as I already explained in earlier post whatever I know. So these are the steps to follow.

1.When you are trying php on your linux machine ensure that you have installed the “httpd” server and php supports for mysql, perl etc at the time of os installation which comes along with normal distributions or you can install it later as it is possible in Ubuntu.

2.Now after logging into your user account check in your browser if this URL  is working “http://localhost&#8221;. If you get an page showing apache home page then your server is ready to go otherwise you will get a “Page Cannot load” or a offline showing error message, this shows that the service for the httpd server is stopped on your machine so to start it again from yourProgram Launcher(it may defer depending on the version or distribution of linux you are using) select System then Administration  and then select the Services and from there search and start the httpd service and save it so that you need not to start the service every time you login.

3.Now type some example of php script in a file named with an extension ‘.php’ and save the file into the filesystem ‘/var/wwwroot/html’ using gedit, vi, vim,nano or any editor you like. There may be a case that the system won’t allow you to save the file in the filesystem as it doesn’t have permissions to read/write for normal users and can be accessed by root only, so to tackle this you can change its permissino or you need to have the su(super user) or root password and then open a terminal and login as a root (type simply su on terminal ) and enter password when asked then you can save the php script you type in the editor from terminal or if you are lucky try to type gedit ( if you had installed gnu editor) and can edit even in GUI. For Ubuntu try “sudo <editor name>” on terminal.

4.Now for executing a php script go to your browser and type ‘http://localhost/<php script file name>’. If everthing (syntax etc) are ok then you will see your script running or you will have some error meessage but in some distributions you can’t even see the errors but if  you know php you can try some scripts to show error messages occured during execution .

5.Some distributions like fedora 2 which I used also have some documentation(HTML) for php scripting or there are php installers available which could be installed on linux (refer site php.net). During installation of os it provides many package support for php depending upon your distribution select the appropriate one which you required.

If you find here any info misleading, wrong or want to feedback some suggestions etc kindly reply here.

WINDOWS PRANK-LOGOUT USER

This is a Windows prank that anybody could play with his/her pals or family.

PLEASE READ ALL THE STEPS GIVEN BELOW DON’T TRY THIS WITHOUT READING ALL STEPS

1. First login as the user in windows which is used by your target(consider this word is not meant for violence).

2.Now go to the command prompt and go to the the following filesystem.

Document and Settings/<user name>/Programs/Start/Startup

use following commands :-

cd Programs/Start/Startup

now open a file and write down this in that file “shutdown -l -t 00”

4.Now save the file with any name but with extension .bat or <file name>.bat .

5.Now logout the user and enjoy and of course how to remove it read below.

6.Login as other user and go to command prompt go to the other filesystem

“Document & Setting/<target user name>/Programs/Start/Startup”

and delete the file with .bat extension (It is neccessary that you have two users account on your PC otherwise you have to reinstall you PC).

Or if you are using dual boot PC with a Linux os along with Xp then mount the XP system drive and manually delete the .bat file.

If you still don’t understand refer to the youtube video follow this link http://www.youtube.com/watch?v=xPY8YrXw-wY

———————————————————Enjoy——————————————–

RUNNING PHP ON WINDOWS

HOW TO RUN PHP ON WINDOWS IIS SERVER

HOW TO RUN PHP IN WINDOWS?

WHAT IS PHP?
PHP (PREPROCESSOR HYPERTEXT LANGUAGE) or there are many acronyms of this language it was actually discovery of Rasmus Ledorf who made this language for the purpose for tracking the users who visit his online resume but actually realized many more uses of it and it was further developed to a server side language with adding functionality of object orientation and compatible on zend engine (not much known about that ). This language at its time was a tough competitor in server side and it still competing although people usually blame about its clumsiness and less implementation of object orientation approach.

WHY PHP?
Anybody may ask why php they could prefer ASP.NET or JSP or AJAX instead but what I feel and usually answer to the people that if you have a big high processing power commercial server for whom you write programs then its ok
to go with the ASP and JSP but if you want compatibility with the multi platform like the less costly Ubuntu servers for commercial or your personal web site hosting (as word press gaining popularity in bloggers it is written
in php) so you can write its script functionality yourself or want to add some cool stuff you will thank to it with its feature of PEAR DB to connect to databases like mysql (most database administrative tools available for mysql)
. So its depend upon the people’s personal and professional choices, if you are good in .net then you can have faster site development or likes java’s designing and thread features then you will be happy with JSP but if you want it simple and short php can be good option.

THE FOLLOWING ARE THE STEPS FOR RUNNING PHP SCRIPTS ON IIS WINDOWS XP (FOR PCs)
1.First you had to ensure that the IIS is installed on your XP (as I am a PC user
this is for simple users only not for other OSs ) by typing the URL in your web
browser “http://localhost&#8221; and you will see the default page.
2. If it is there it is good otherwise autorun your XP bootable select the
windows component and select the check box for IIS and install it (NOTE: you can use your iis server for other services like SMTP programs testing or as a simple server for web hosting for your personal use, the PC game OPEN ARENA
from QUAKE uses it as gaming server). After installation check the localhost as in step 1.
3.Now install the php software (you can get the latest version from php.net) install all the needed optional features you need such as it provides compatibility with many other extensions and PEAR DB select according to your requirement and in the server option select IIS4+CGI so that the php will get installed for IIS.
4.Now how to run php? You can write your php script with a simple text editor but with an extension .php only and then place it into Inetpub/wwwroot/ . The Inetpub folder is created in your windows drive when IIS was installed and access your php script through the web browser by URL “http://localhost/. You can save the script with any name and yes as I told above you can simply place a file in wwwroot folder and access the
file through web browser by URL “http://localhost/&#8221;. I used it for accessing my personal pdf ebook library. So here is a simple script in php you can try.

IMPORTANT DISCLAIMER
All the above information is may not be correct as I m still learning php and not have any industrial experience and the procedure and methods defined above are may be not standard (as they work better in normal circumstances ) can harm your hardware or software so author will not be responsible for any damage caused. If you encounter any spelling or grammatical or any knowledge related mistakes please forgive me and notify me and feedbacks about this blog and query regarding more info or using php on linux are invited.