Skip to main content

Posts

Showing posts from 2014

Liferay Migration form 5.2.3 to 6.2

Liferay Migration form 5.2.3 to 6.2 Liferay Migration from 5.2.3. to 6.2 Step 1. Migration to 6.0.6 1. Create 5.2.3 DB dump (db.sql). 2. Create database for LR 6.0.6 (db606). 3. Load 5.2.3 dump into 6.0.6 database: mysql -uroot -p1 db606 < db.sql; Delete all database views (if any). 4. Unzip clean Liferay 6.0.6. 5. Delete all folders from ' webapps ' (except ' ROOT ' and ' tunnel-web '); delete jre from tomcat folder. 6. Copy 'data' folder from Liferay 5.2.3 to Liferay 6.0.6. 7. Startup Liferay 6.0.6 (with default Hypersonic database settings). 8. Shutdown Liferay 6.0.6. 9. Create  portal-ext.properties  file: jdbc.default.driverClassName=com.mysql.jdbc.Driver jdbc.default.url=jdbc:mysql://localhost:3306/db606?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false jdbc.default.username=root jdbc.default.password=1 permissions.user.check.algorithm=5 image.hook.impl=com.

java numbers to Text Statement

package ms.utils; import java.text.DecimalFormat; public class EnglishDecimalFormat { private static final String[] majorNames = {    "",    " Thousand",    " Million",    " Billion",    " Trillion",    " Quadrillion",    " Quintillion"    };  private static final String[] tensNames = {    "",    " Ten",    " Twenty",    " Thirty",    " Fourty",    " Fifty",    " Sixty",    " Seventy",    " Eighty",    " Ninety"    };  private static final String[] numNames = {    "",    " One",    " Two",    " Three",    " Four",    " Five",    " Six",    " Seven",    " Eight",    " Nine",    " Ten",    " Eleven&q

java html to pdf

package testpdf; import com.itextpdf.text.Document; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.tool.xml.XMLWorkerHelper; import java.io.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; public class HtmlToPdf {     public static void main(String[] args)             throws IOException { try {         String content = readFile("c:/temp/html.html", StandardCharsets.UTF_8);     OutputStream file = new FileOutputStream(new File("C:/temp/Test.pdf"));     Document document = new Document();     PdfWriter writer = PdfWriter.getInstance(document, file);     document.open();     InputStream is = new ByteArrayInputStream(content.getBytes());     XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);     document.close();     file.close(); } catch (Exception e) {     e.printStackTrace(); }                           }         static Str

Java send email with attachment via exchange server

      public void sendMailWithAttachment(String from,List<String> toList, String subject ,String body,String filePath) throws MessagingException{          Properties props = new Properties(); props.put("mail.smtp.host", "exchange.company.com");//         props.put("mail.smtp.user", "sender user name");         props.put("mail.smtp.password", "sender password"); //mail.smtp.ssl.enable         props.put("mail.smtp.ssl.enable", "false"); Session session = Session.getDefaultInstance(props, null); session.setDebug(true); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from));         InternetAddress ia=null;         List<InternetAddress> addresees=new ArrayList<InternetAddress>();         for(String to :toList ){             ia=new InternetAddress(to);             addresees.add(ia);         }         InternetAddress[] array = new InternetAddress[add

Java Date Formatter table

G Era designation Text AD y Year Year 1996 ; 96 M Month in year Month July ; Jul ; 07 w Week in year Number 27 W Week in month Number 2 D Day in year Number 189 d Day in month Number 10 F Day of week in month Number 2 E Day in week Text Tuesday ; Tue a Am / pm marker Text PM H Hour in day ( 0 - 23 ) Number 0 k Hour in day ( 1 - 24 ) Number 24 K Hour in am / pm ( 0 - 11 ) Number 0 h Hour in am / pm ( 1 - 12 ) Number 12 m Minute in hour Number 30 s Second in minute Number 55 S Millisecond Number 978 z Time zone General time zone Pacific Standard Time ; PST ; GMT - 08 : 00 Z Time zone RFC 822 t

count occurrences of a word in a statement

public static int countOccurance (String word, String sentence) {          Pattern pattern = Pattern.compile(word ,Pattern.CASE_INSENSITIVE);          Matcher  matcher = pattern.matcher(sentence);          int count = 0; while (matcher.find())     count++;          return count;  } 

simplest java code to upload files in LIFERAY portal

1 in the jsp  make a form to handle the upload <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%@ page import="java.util.List"%> <%@ page import="java.util.ArrayList"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%> <form action="<portlet:actionURL/>" method="post" name="form1" ID="form1" enctype="multipart/form-data"> <input type="file" name ="file"/> <input type="submit" value="submit" /> </form> 2- in the process action  method in the portlet class @Override public void processAction(ActionRequest req, ActionResponse res) throws PortletException, IOException { //getting the file

issue resolved ..Java EE Dependency Injection doesn't work while JNDI look up works

just add this configuration file  beans.xml inside your project's WEB-INF  folder <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> </beans> have fun

install apache maven 3.2.1 on mac pro

1- Download Maven binaries from  Maven Download Page . 2- add the invironment variables M2_HOME and also append the PATH $ cd $HOME $ vi .bash_profile #Add below lines in the profile export M2_HOME=/Users/yourname/apache-maven-3.2.1 export PATH=$PATH:$M2_HOME/bin #save and quit $ source .bash_profile that's it ...test it now ;) $ mvn --version

unix ubuntu clear the full boot

1- get the current version uname -r 2- check the space in boot df -h 3- list all installed linux images dpkg --list | grep linux-image 3- Purge the ones we don’t need any more.  for example  this one "linux-image-3.2.0-23-generic" sudo apt-get purge linux-image-3.2.0-23-generic if this command didn't work then try to do it  manually by this cd /boot sudo rm -f *-3.5.0-21-* 4-Verify If everything worked, you can run these commands without errors. sudo update-grub2 && sudo update-initramfs -u Then update everything to ensure that our system is clean and up-to-date sudo aptitude safe-upgrade && sudo reboot now

Java Swing JTable the proper way to remove rows

Problem .. removing the last row is throwing array out of index exception in the GUI scope! solution ... make the removing action inside invokeLater block , this will make the GUI listeners work correctly final DefaultTableModel model=   ((DefaultTableModel)jTable.getModel());                      SwingUtilities.invokeLater(new Runnable() {                 @Override                 public void run() {                      model.removeRow(_row);                 }                 } );

Android read from bar-code scanner

private TextView result; private String barCode=""; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { char pressedKey = (char) event.getUnicodeChar(); if(result==null){ // System.out.println("result=null"); result=(TextView)findViewById(R.id.scanResult); } barCode+=pressedKey; if(event.getKeyCode()==KeyEvent.KEYCODE_ENTER){ result.setText(barCode); barCode=""; } return super.onKeyDown(keyCode, event); }

windows 7 fix "user profile has failed and loading the default profile"

thanks to microsoft support i fixed that issue in my windows 7 link   http://support.microsoft.com/kb/947215 Symptoms When you log on to a Windows 7-based or a Windows Vista-based computer by using a temporary profile, you receive the following error message: The User Profile Service failed the logon. User profile cannot be loaded. Back to the top  |  Give Feedback Resolution Occasionally, Windows might not read your user profile correctly, such as if your antivirus software is scanning your computer while you try to log on. Before you follow the methods here, try restarting your computer and logging on with your user account again to resolve the issue. If you restart your computer and it does not resolve this issue, use the following methods to resolve this issue. Note  You must be able to log on to an administrator account to fix your user profile or copy your data to a new account. Before you resolve the issue, log on to Windows by using another account tha