Pages

Sunday, April 28, 2013

Manual Oracle Uninstall


src http://www.oracle-base.com/articles/misc/ManualOracleUninstall.php

A number of people have contacted me regarding problems uninstalling Oracle products. The two methods listed below should only be used as a last resort and will remove all Oracle software allowing a reinstall. If you make any mistakes they can be quite destructive so be careful. 

Windows

In the past I've had many problems uninstalling all Oracle products from Windows systems. Here's my last resort method:
  • Uninstall all Oracle components using the Oracle Universal Installer (OUI).( or remove HKEY_CURRENT_USER\SOFTWARE\ORACLE*  ) 
  • Run regedit.exe and delete the HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE key. This contains registry entires for all Oracle products.
  • Delete any references to Oracle services left behind in the following part of the registry:
    HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Ora*
    It should be pretty obvious which ones relate to Oracle.
  • Reboot your machine.
  • Delete the "C:\Oracle" directory, or whatever directory is your ORACLE_BASE.
  • Delete the "C:\Program Files\Oracle" directory.
  • Empty the contents of your "c:\temp" directory.
  • Empty your recycle bin.
At this point your machine will be as clean of Oracle components as it can be without a complete OS reinstall.

Remember, manually editing your registry can be very destructive and force an OS reinstall so only do it as a last resort.

UNIX

Uninstalling all products from UNIX is a lot more consistent. If you do need to resort to a manual uninstall you should do something like:
  • Uninstall all Oracle components using the Oracle Universal Installer (OUI).
  • Stop any outstanding processes using the appropriate utilities:
    # oemctl stop oms user/password
    # agentctl stop
    # lsnrctl stop
    Alternatively you can kill them using the kill -9 pid command as the root user.
  • Delete the files and directories below the $ORACLE_HOME:
    # cd $ORACLE_HOME
    # rm -Rf *
  • With the exception of the product directory, delete directories below the $ORACLE_BASE.
    # cd $ORACLE_BASE
    # rm -Rf admin doc jre o*
  • Delete the /etc/oratab file. If using 9iAS delete the /etc/emtab file also.
    # rm /etc/oratab /etc/emtab

Những công cụ hữu ích khi làm việc với CSS3

[updating...]
Trong bài post này sẽ giới thiệu cũng tool, site generator, những snippet css 3 hữu ích mà thường xuyên dùng tới.
Một yêu cầu bắt buộc với người viết css và css3 là khả năng tương thích các trình duyệt khác nhau và tương thích version của từng trình duyệt ( -webkit , -moz , -ms... )
--> việc sử dụng các site generator đã trợ giúp cho bạn giải quyết vấn đề này.

Cá  Site generator được giới thiệu ở đây sẽ làm nhiệm vụ là tự động sinh ra các css3 code qua việc lựa chọn các tùy chọn, tham số trên giao diện của site, việc sau đó của bạn là chỉ  copy code đã được sinh ra và sử dụng trong site của mình mà thôi.

http://css3generator.com/


Site đầu tiên cần phải kể đến là css3generator.com. Site chỉ sinh CSS3 Code ( không sinh html ), cho phép preview , hiển thị các browser  và min version tương tích. 
Bạn có thể style cho 
  • Border : bo góc và đổ bóng ( border-radius , border-shadow)
  • Text : đổ bóng ( text-shadow)
  • Layout : các hàng cột ( multiple columns)
  • Effect : transitions , transform , gradients 
  • .....

http://css3please.com/

site này cung cấp các class trong một script đã được tác giả viết, bạn khai báo thuộc tĩnh class trong các HTML Element và trỏ tới các class tương ứng trong script này để sử apply chúng.

http://layerstyles.org/builder.html

Site này thì cho phép kết hợp nhiều styles cho một Element cùng một lúc : shadow , border ,  background 
JUST LIKE YOUR FAVORITE GRAPHICS EDITOR
BUT IN YOUR BROWSER. AND IT CREATES CSS.
một site tương tự site này là : http://css3pie.com/
--> cho phép style : shadow , border ,  gradient

http://css-tricks.com/examples/ButtonMaker/ [ Button Generator ]

Site này khác hoàn toàn các site trên, nó cho phép bạn tạo  style <a> tag thành các Buttons rất đẹp  , không image.
-->  click lên button vừa tạo được để lấy css code. nó sinh ra một class .button --> trỏ thuộc tính class của <a> tag tới .button này ok. 
--> Cho phép down script để dùng offline.



http://www.csstablegenerator.com/  [ Table Generator ]

site cho phép chọn các option --> sẽ sinh ra css code riêng và html code riêng.


Note : nhược điểm của thằng này là html code ko chuẩn convention.

tablestyler.com [ Table Generator ]

Một Site khá ngon, html và css riêng rẽ, html code tuân thủ convention. Style cả thanh phân trang.







tham khảo :

Gradient effect

Border Shadow

Border radius 

Selector


Thursday, April 25, 2013

Default Objects in jsp page [ Liferay ]

Link src :

There are some default objects in jsp page we are using in liferay apart from the actual default objects of liferay. But unfortunately we don't know how many default objects providing by liferay.
After little investigation I came to know all the default objects which are providing by liferay.
There are two taglibs which we are including every time when we create portlet.

Portlet tag lib

The above statements will give 14 default objects :
  1. actionRequest
  2. actionResponse
  3. eventRequest
  4. eventResponse
  5. portletConfig
  6. portletName
  7. portletPreferences
  8. portletPreferencesValues
  9. portletSession
  10. portletSessionScope
  11. renderRequest
  12. renderResponse
  13. resourceRequest
  14. resourceResponse
And the type of each object as follows :

liferay-theme tag lib

The above statements will give 18 default objects :
  1. themeDisplay
  2. company
  3. account
  4. user
  5. realUser
  6. contact
  7. layout
  8. layouts
  9. plid
  10. layoutTypePortlet
  11. scopeGroupId
  12. permissionChecker
  13. locale
  14. timeZone
  15. theme
  16. colorScheme
  17. portletDisplay
  18. portletGroupId
and the type of each object as follows :
We can get these defaults objects using pageContext object which is default of the plain jsp. Below statement is the example for getting default objects.
ActionRequest actionRequest = (ActionRequest) pageContext.findAttribute(“actionRequest”);

[ Joomla ] You have an error in your SQL syntax, check the manual that corresponds to your MySQL server version for the right syntax to use near .....

Khi install joomla ( 1.5.22 ) gặp bug sau :

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near .....


- Problem ?
The keyword ‘TYPE’ was introduced as deprecated since ENGINE was added in MySQL 4.0.18.
in the CREATE TABLE structure manaul page (http://dev.mysql.com/doc/refman/4.1/en/create-table.html) that the TYPE keyword will be removed in future versions.

Do vậy khi install joomla trên mysql v 5.x sẽ có bug này. tham khảo create command được run khi install joomla.
CREATE TABLE `#__bannertrack` (
`track_date` date NOT NULL,
`track_type` int(10) unsigned NOT NULL,
`banner_id` int(10) unsigned NOT NULL
) TYPE=MyISAM CHARACTER SET `utf8`;
- Giải quyết :tham khảo http://www.devraju.com/programming/joomla-1-5-22-installation-sql-problem-typemyisam-solution-enginemyisam/
==> Tóm tắt : tìm Joomlafolder/installation/sql/mysql/joomla.sql và replace all : ‘TYPE=MyISAM’ to ‘ENGINE=MyISAM’

[ Liferay config ]Connect to SQL Server 2008 using Windows Authentication Mode

LF vs SQLServer
ta có hai option là  sử dùng jsdt driver  được lf cung cấp sẵn ( trong TOMCAT_HOME/lib/ext) hoặc dùng driver do MS cung cấp. chú ý khi sử dụng driver cùng phiên bản sql server đang sử dụng, với SQL Server 2008 cần bộ driver 3.0 mới nhất do MS cung cấp. 
đọc thêm jdts document http://jtds.sourceforge.net/doc.html
 portal-ext.properties :

    #
    # SQL Server
    #
    #jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
    #jdbc.default.url=jdbc:jtds:sqlserver://localhost/lportal;domain=your-domain
    #jdbc.default.username=sa
    #jdbc.default.password=
or

## SQL Server

jdbc.default.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.default.url=jdbc:sqlserver://localhost;database=lportal6;integratedSecurity=true;
#jdbc.default.username=sa
#jdbc.default.password=sa


Nếu connect với chế độ win authen của sql server thì ta ko cần cũng cấp username & pass , thay vào đó ta cần cũng cấp các properties như trên ( chữ đỏ ) và cung cấp thêm lib :sqljdbc_auth.dll ( có cùng driver khi download ở trên , tôi đáp luôn nó vào bin  dir khi deploy trên tomcat)
nếu dùng option 2 ta cần đưa thêm sqljdbc4.jar


Note : instanceName  property

Dynamically creates images with Servlet




Get the Next Highest zIndex in Javascript


Đang mắc cái popup nó không nổ lên được với cái flash do z-index của nó nhỏ hơn --> đơn giản nhất là ko mò z-index của flash làm j mà lấy z-index lớn nhất của page là ok .
src : http://greengeckodesign.com/blog/2007/07/get-highest-z-index-in-javascript.html
thanks author .

z-index lớn nhất của một Object


z-index của document

undeploy Ext Plugin [ Liferay ]


- đáp file war vào TOMCAT_HOME/deploy --> tự động được deploy , nếu deploy lần đầu thì yêu cầu reset tomcat ( "You must reboot the server and redeploy all other plugins."), các lần sau deploy ext plugin đó thì không cần reste
trong trường hợp deploy tiếp theo của ext plugin đó mà nó không apply ta thực hiện undeploy qua ant command hoặc manual mà undeploy như dưới. 
Ext Plugin can't be undeployed
Ext Plugin can't be nowadays even redeployed :(
Workaround:
  1. call
    ant clean
    from your ext-plugin directory, see Ext plugin thread
  2. or delete ext plugin from your Tomcat (similar for any other app server, sometimes you must undeploy the web application, not just delete it)
TOMCAT_HOME/lib/ext/
TOMCAT_HOME/....webapps/ROOT/WEB-INF ( tìm xml file )
TOMCAT_HOME/....webapps/ROOT/WEB-INF/lib/
TOMCAT_HOME/....webapps/
TOMCAT_HOME/....temp/liferay/com/liferay/portal/deploy/dependencie
Trong  thư mục trên tìm các jar file có pre_fix là ext ( ext-nameextplugin-ext.jar... ) mà del . 

Linux - Tomcat:

cd your-tomcat-install
# deleting web application
rm -rf webapps/*-ext
# deleting jars and config files from Liferay
find -name "ext-*" | xargs rm -rf
# stopping Liferay
bin/shutdown.sh ps ax | grep life
#... wait until life ends ;) ....
# # Starting Liferay
bin/startup.sh tail -f logs/catalina.out

Windows - Tomcat: 

delete all following files & directory and reboot Tomcat (assuming your Ext Plugin is named ehlo-ext):
./webapps/ehlo-ext ./lib/ext/ext-ehlo-ext-service.jar
./webapps/ROOT/WEB-INF/lib/ext-ehlo-ext-util-bridges.jar
./webapps/ROOT/WEB-INF/lib/ext-ehlo-ext-util-taglib.jar
./webapps/ROOT/WEB-INF/lib/ext-ehlo-ext-util-java.jar
./webapps/ROOT/WEB-INF/lib/ext-ehlo-ext-impl.jar
./webapps/ROOT/WEB-INF/ext-ehlo-ext.xml
./temp/liferay/com/liferay/portal/deploy/dependencies/ext-ehlo-ext-util-bridges.jar ./temp/liferay/com/liferay/portal/deploy/dependencies/ext-ehlo-ext-util-taglib.jar
./temp/liferay/com/liferay/portal/deploy/dependencies/ext-ehlo-ext-util-java.jar

My script 

on windows ( bat script ) : 
@echo off
set app_name=%MyProj
if "%app_name%" == "" goto end
set tomcat_home=D:\LIFERAY\liferay-portal-tomcat-6.1.0-ce-ga1\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23
rmdir /S /Q %tomcat_home%\webapps\%app_name%-ext
del /F /S /Q %tomcat_home%\lib\ext\ext-%app_name%-ext-service.jar
del /F /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-util-bridges.jar
del /F /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-util-taglib.jar
del /F /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-util-java.jar
del /F /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\lib\ext-%app_name%-ext-impl.jar
del /F /S /Q %tomcat_home%\webapps\ROOT\WEB-INF\ext-%app_name%-ext.xml
del /F /S /Q %tomcat_home%\temp\liferay\com\liferay\portal\deploy\dependencies\ext-%app_name%-ext-util-bridges.jar
del /F /S /Q %tomcat_home%\temp\liferay\com\liferay\portal\deploy\dependencies\ext-%app_name%-ext-util-taglib.jar
del /F /S /Q %tomcat_home%\temp\liferay\com\liferay\portal\deploy\dependencies\ext-%app_name%-ext-util-java.jar
rmdir /S /Q %tomcat_home%\work\
rmdir /S /Q %tomcat_home%\temp\
:end

 on linux ( sh script )

#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: clean-my-ext [ext-name]"
exit 1
fi
tomcat_home="/local/mnt/apps/liferay/tomcat-6.0.29"
app_name="$1"
rm -rf $tomcat_home/temp
rm -rf $tomcat_home/webapps/$app_name-ext
rm -rf $tomcat_home/webapps/ROOT/html/portlet/ext
rm -f $tomcat_home/lib/ext/ext-$app_name-ext-service.jar
rm -f $tomcat_home/webapps/ROOT/WEB-INF/lib/ext-$app_name-ext-util-bridges.jar
rm -f $tomcat_home/webapps/ROOT/WEB-INF/lib/ext-$app_name-ext-util-taglib.jar
rm -f $tomcat_home/webapps/ROOT/WEB-INF/lib/ext-$app_name-ext-util-java.jar
rm -f $tomcat_home/webapps/ROOT/WEB-INF/lib/ext-$app_name-ext-impl.jar
rm -f $tomcat_home/webapps/ROOT/WEB-INF/ext-$app_name-ext.xml
rm -f $tomcat_home/webapps/ROOT/WEB-INF/tiles-defs-ext.xml
rm -f $tomcat_home/temp/liferay/com/liferay/portal/deploy/dependencies/ext-$app_name-ext-util-bridges.jar
rm -f $tomcat_home/temp/liferay/com/liferay/portal/deploy/dependencies/ext-$app_name-ext-util-taglib.jar
rm -f $tomcat_home/temp/liferay/com/liferay/portal/deploy/dependencies/ext-$app_name-ext-util-java.jar

Monday, April 22, 2013

P6Spy - Log SQL statements along with Parameter Values [ Liferay & Hibernate ]


Description

P6Spy is a framework that enables database data to be seamlessly intercepted and manipulated with no code changes to existing application. The P6Spy distribution includes P6Log, an application which logs all JDBC transactions for any Java application us.

P6Spy official  site : http://sourceforge.net/projects/p6spy/

--> Hiểu đơn giản P6Spy là một framework cho phép chúng ta log toàn bộ JDBC Transactions trong ứng dụng mà không phải đưa thêm/thay đổi bất kỳ dòng code nào vào trong ứng dụng -> việc log hoàn toàn độc lập với ứng dụng. 
--> P6Spy không chỉ log các SQL Statement (  Trong JDBC tạo ra các Statement là câu query với các dấu  ? , mỗi dấu ? đại diện cho một tham số ) mà nó cho phép log toàn bộ các Parameter Values đã được pass vào, tức là câu SQL hoàn chính với giá trị của param sẽ thực hiện cuối cùng với DB. 

==> Rất tiện lợi cho mục đích debug. 

Một ví dụ khi  một Statement được log : 
SELECT COUNT(*) AS COUNT_VALUE
FROM Users_Roles WHERE userId = ? AND roleId = ?
Note :  với Hibernate thiết lập  show_sql  property  là true để show ra các câu SQL . 

--> Với P6Spy nó còn cho phép biết được các giá trị của các dấu ? là gì . 
1366824587058|1|1|statement|SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = ? AND roleId = ? 
|SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = '10195' AND roleId = '10163'

Tích hợp P6Spy trong liferay [ Hibernate]


Liferay sử dụng hibernate, do vậy  việc tích hợp p6spy là khá tương đồng. 

1. download file p6spy-install.jar từ http://sourceforge.net/projects/p6spy/
--> thực hiện giải nén và lấy hai file : p6spy.jar và spy.properties 
sử dụng lastest version  1.3 ( modified 2003-12-01)

2. copy p6spy.jar  vào thư mục lib của server,
ví dụ với tomcat  tôi copy vào : liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\lib\ext
Note : trong thư mục giải nén có chứa cả guide --> có thể tham khảo cho các server khác nhau.

3. Đưa file spy.properties vào ClassPath.
file spy.properties chứa các thông tin cấu hình cho p6spy. để p6spy có thể đọc được thì ta cần đưa nó vào classpath. 
ta có hai cách: 
-- các đơn gian là đặt nó vào root folder của project: với liferay tôi copy nó vào :\liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\webapps\ROOT\WEB-INF\classes
==> nó được load tương tự các file portal-*.properties  hay service-*.properties.
-- các hai là thiết lập   -Dp6.home   vào JAVA_OPTS  để chỉ ra folder chứa file spy.properties. 
ví dụ với tomcat trên window  --> tìm vào thêm dòng in đậm với đường dẫn thích hợp trên máy của bạn 
  .....\liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\bin\setenv.bat

set "JAVA_OPTS=%JAVA_OPTS%  -Dp6.home=D:/apps/liferay/liferay-portal-tomcat-6.1/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/lib/ext 
 -Dfile.encoding=UTF8 -Djava.net.preferIPv4Stack=true -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m"

4. edit spy.properties 
- Có một property bắt buộc cần edit đó là : realdriver  --> tương ứng với driver của db bạn đang connect tới
ví dụ  với MYSQL: 
# mysql Connector/J driver
 realdriver=com.mysql.jdbc.Driver
- thuộc tính thứ hai cần lưu ý  là  chỉ ra vị trí của  file log
ví dụ  : 
logfile     = D:/apps/liferay/liferay-portal-tomcat-6.1/liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/logs/spy.log

-  thuộc tính khác là : log4j.logger.p6spy  chỉ ra Level được log 
ví dụ log4j.logger.p6spy=INFO,STDOUT

5. Cầu hình JDBC trong portal-ext.properties với driver class là P6SpyDriver class của p6spy.
jdbc.default.driverClassName=com.p6spy.engine.spy.P6SpyDriver
jdbc.default.username=root
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
#
# Set other miscellaneous Hibernate properties.
#
hibernate.show_sql=true

final : Run server và tay sẽ thấy file  spy.log tương ứng ở vị trí đã config khi thực hiện các query thì chúng sẽ được log tại đây. Điều chính Log Level cho phù hợp với mục địch.

Lưu ý : việc tích hợp p6spy giảm thiểu tối đa thời gian cho việc debug, và sử dụng nó trong môi develop, khi ứng dụng được triển khai trên môi trường product thì cần loại bỏ  p6spy.
---------------------------------------------------------------------------------------------------------

Một số framework khác

LOG4JDBC

https://code.google.com/p/log4jdbc/
JDBC proxy driver for logging SQL and other interesting information.
log4jdbc is a Java JDBC driver that can log SQL and/or JDBC calls (and optionally SQL timing information) for other JDBC drivers using theSimple Logging Facade For Java (SLF4J) logging system.
2012-02-17: log4jdbc 1.2 final release! (It's about time, huh?) Full changelist here.

JDBC SQL Profiler

http://sourceforge.net/projects/sqlprofiler/?source=recommended
Description
Have you ever wondered which database indexes you should create for your JDBC-based application ? This Swing-based SQL profiler tries to offer a tool to monitor which tables and columns are accessed the most in SQL queries to recommend index creation

JDBC Logger

http://sourceforge.net/projects/jdbclogger/?source=recommended
Description
jdbclogger is a Java tool that intercepts and logs all database statements that use JDBC.
JDBC Logger Web Site

Elvyx

http://sourceforge.net/projects/elvyx/?source=recommended
Description
Elvyx is a tool designed to monitor and profile the jdbc activity on java projects. This jdbc profiler has a server with a built-in db and a client to improve the experience.


Tuesday, April 9, 2013

Cấu hình Proxy cho Aptitude ( apt-get ) [Debian]

Hôm vừa phải ngồi ngẩn ngơ một hồi với con LMDE (Linux Mint Debain Edition) trên máy cty, vì tội cty cũ thì chẳng bao jo` mình dùng proxy, sang bên này bắt buộc phải xài proxy mới ra inter được, nên đúng là núng túng. Đã config proxy cho network thông quan network manager, và tưởng thế là ok cho cả terminal nhưng nào ngờ với trên Terminal không thể nào ping được bất kỳ site nào, repos thể không thể nào hit được nên cũng chẳng thể install được app qua terminal.


output : can't connecting to debain.linuxmint.com/lastest

Ngẩn ngơ ko biết vì sao và cũng chẳng có ai hỏi, cuối cùng search gg thì được biết  cần phải config proxy cho aptitude(apt-get) ở một nơi khác thì nó mới nhận biết dc.


Mọi người tham khảo một số link bên dứoi,tôi cũng đơn giản làm theo và ok với nó. Cụ thể


  1. Tạo apt.conf trong /etc/apt nếu nó chưa có 

    2. Đưa thêm thông tin cấu hình Proxy vào file apt.conf ở trên.

Cú pháp như sau : 



Nếu không cần phải authen với username và pass ta có thể viết ngắn gọn ở dạng ( bỏ phần ProxyLogin ): 



Trong đó : 
  • XXX : là giao thức trỏ tới proxy server - có thể là HTTP, HTTPS, FTP ....
  • proxyIP/Hostname : có thể là địa chỉ IP hoặc domain
ví dụ :



NOTE: để apt.conf này có hiệu lục ngay lập tức ta sử dụng lệnh source : 



link tham khảo: 



Friday, April 5, 2013

Tích hợp SyntaxHighlighter cho các code snippet

Trang chủ : http://alexgorbatchev.com/SyntaxHighlighter/
Version hiện tại là 3.0.38, nhưng ở đây tôi sử dụng version 2.1.364 theo link tham khảo dưới đây
http://geektalkin.blogspot.com/2009/11/embed-code-syntax-highlighting-in-blog.html

Đặc điểm nổi bật SyntaxHighlighter :
  • Cho phép highlight nhiều ngôn ngữ lập trình khác nhau, cụ thể các language đã được support theo list  http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/.
    Để biết highlight theo ngôn ngữ nào ta chỉ việc thay đổi brush tương ứng.
     (eg ngôn ngữ là javascript : class="brush: js" , ngôn ngữ là java  class="brush: java" )
  • Hỗ trợ theme, có nhiều theme cho ta lựa chọn, cụ thể : http://alexgorbatchev.com/SyntaxHighlighter/manual/themes/
    Việc thay đổi theme đơn gian là việc thay đổi các css file tương ứng: 
Note : SyntaxHighlighter  có sử dụng một file flash để xử lý copy button ("copy to clipboard"),ta nên check xem link file flash này còn ok ko nhé.

Cấu hình cơ bản để sử dụng SyntaxHighlighter

Các bước để tích hợp và sử dụng SyntaxHighlighter cơ bản gồm :
  1. Khai báo hai file shCore.js and shCore.css
  2. Khai báo các Brushes muốn  sử dụng ( chính là việc khao báo tương ứng cho các language muốn dùng ).
  3. Khai báo theme muốn dùng : eg shThemeDefault.css
  4. Tạo các code snippet với một trong hai cách sử dụng : <pre> tag , và <script> tag 
  5. Thiết lập các options config và Call SyntaxHighlighter.all() JavaScript method để SyntaxHighlighter apply vào các code snippet trên trang.
Eg :  Với blogspot ta copy và past đoạn mã dưới đây ngay trước thẻ </head> của mã HTML của blog ( phần Template --> Edit HTML trong "Live on Blog" ). 



 




 

 
 
 
 
 
 
 
 
 
 
 
 
 
 





Ví dụ sử dụng <pre >Tag  với mã java trong các post
public class NewClass {
 
 public static void main(String[] args) {
  System.out.println("Hello !");
 }

}
Kết quả của đoạn mã trên:

public class NewClass {
 
 public static void main(String[] args) {
  System.out.println("Hello !");
 }

}
Tương tự các sử dụng <script /> tag:


Lưu ý : ta phải chuyển chế độ HTML thay vì Compose vì đây là mã HTML cần render chứ ko phải content view.

Đặc điểm hai cách dùng <pre> và <script> :

  1. Không thể nồng hai tag <script>, <pre> có thể nồng, <pre> cỏ thể bao <script>.
  2. Nội dung bên trong <pre></pre> phải là   HTML escaped. Ví dụ  toàn bộ các dấu nhỏ hơn "<" phải được chuyển sang dạng "&lt;" để đảm bảo render chính xác.Ta có thể tham khảo site dưới đây để biết từ Html source code được render thành các html tag trên trình duyệt nó sẽ biến đổi như thế nào :http://accessify.com/tools-and-wizards/developer-tools/quick-escape/default.php
  3. Cách dùng <script> thì toàn bộ nội dung đặt bên trong CDATA block nên không cần escape. Điều này thích hợp khi ta copy/past các snippet để đưa vào blog.Nhược điểm là ko thể nồng hai hay nhiều các <script>.
Tùy từng trường hợp, yêu cầu mà ta có thể lựa chọn cho phù hợp.

Tham khảo thêm : 
install step 
SyntaxHighlighter.config

Thursday, April 4, 2013

[Struts 2] upload file

Ứng dụng upload file lên server với Struts 2.

Trong ví dụ dưới đấy sẽ refer tới  FileUploadInterceptor để thực hiện ứng dụng upload file.
Lưu ý rằng  FileUploadInterceptor được based trên MultiPartRequestWrapper,do vậy mọi request có refer tới file upload interceptor sẽ được tư động áp dụng tới các file element trên HTML Form.

JSP page.
Action Class ( extends ActionSupport Class ).
Trong action class ta cần tương ứng 3 biến như trên, ý nghĩa mỗi trường : 
ý nghĩa :
  • [File Name] : File - the actual File
  • [File Name]ContentType : String - the content type of the file
  • [File Name]FileName : String - the actual name of the file uploaded (not the HTML name)
cú pháp 3 setter phải theo convention sau : trong đó X = thuộc tính name của file upload Element trên HTML Form.
Method SignatureDescription
setX(File file)The file that contains the content of the uploaded file. This is a temporary file and file.getName() will not return the original name of the file
setXContentType(String contentType)The mime type of the uploaded file
setXFileName(String fileName)The actual file name of the uploaded file (not the HTML name)

Struts action mapping
Note : fileUpload interceptor cho phép ta pass một số param liên quan tới file upload như : content type của file cho phép, kích thước file upload....

Mores :
http://struts.apache.org/release/2.0.x/struts2-core/apidocs/org/apache/struts2/interceptor/FileUploadInterceptor.html

http://struts.apache.org/release/2.0.x/docs/file-upload.html
http://struts.apache.org/release/2.0.x/struts2-core/apidocs/org/apache/struts2/dispatcher/multipart/MultiPartRequestWrapper.html

[Maven - POM file] javax.servlet:jsp-api:jar:2.1 is missing, no dependency information available

Trong maven web app project. 

BUILD FAILURE : The POM for javax.servlet:jsp-api:jar:2.1 is missing, no dependency information available

Với cấu hình maven dependency trong pom.xml.
Nguyên nhân : Servlet 2.5 đi với jsp 2.1, lỗi do groupId của jsp-api không đúng. Từ jsp 2.1 groupId sẽ là javax.servlet.jsp thay cho javax.servlet như các version trước.

Fixed :
Hoặc ta có thể sử dụng cặp  servlet 2.4 đi với jsp 2.0