tag:blogger.com,1999:blog-3895998159139632052024-03-19T21:59:04.701+02:00Blogramming in vain...Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.comBlogger34125tag:blogger.com,1999:blog-389599815913963205.post-12167899055151155982008-05-21T13:54:00.006+02:002008-05-21T14:13:30.563+02:00Installing VMware Server Console in Hardy Heron 8.04Here are the steps I followed while trying to install VMware Server Console on Hardy:
<ul><li>Install some prerequisitives:
<span class="code">sudo apt-get install build-essential linux-headers-`uname -r` xinetd</span>
</li><li>Download the <b>VMware Server Linux client package</b>, which is a zip that contains the following components components:<br/>
- Linux VMware Server Console (.tar and .rpm)<br/>
- Perl scripting API for Linux (.tar)<br/>
- Programming API (.tar)</span></li><li>Unzip the downloaded file.</li><li>Extract the file VMware-server-console-1.0.4-56528.tar.gz.</li>
<li>Enter the directory it was extracted into and run sudo ./vmware-install.pl</li><li><span class="smaller">The installer will ask some questions. Choose the default answer on all of them.</span></li><li>Running vmware-server-console will fail with the following error messages:
<div class="code"><pre>
/usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib/libcairo.so.2)
/usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib/libcairo.so.2)
/usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)
/usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib/libcairo.so.2)
/usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib/libcairo.so.2)
/usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)
/usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib/libcairo.so.2)
/usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib/libcairo.so.2)
/usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)</pre></div>
</li><li>Create the following links:
<div class="code"><pre>
sudo ln -sf /lib/libgcc_s.so.1 /usr/lib/vmware-server-console/lib/libgcc_s.so.1/libgcc_s.so.1
sudo ln -sf /usr/lib/libpng12.so.0 /usr/lib/vmware-server-console/lib/libpng12.so.0/libpng12.so.0
</pre></div>
</li></ul>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com1tag:blogger.com,1999:blog-389599815913963205.post-1465295966780548552008-05-05T11:27:00.007+02:002008-05-05T11:49:42.189+02:00Installing, configuring and using ODBC on ubuntuI wanted to use an ODBC-MySQL bridge on my linux box. Here are the steps I followed.
<ul>
<li>
First of all, <span class="code">unixodbc</span> comes installed on ubuntu. Otherwise you can install the package called <span class="code">unixodbc</span>.
</li>
<li>
I downloaded and installed the <a href="http://dev.mysql.com/downloads/connector/odbc/5.1.html">ODBC connector from the MySQL website</a>. I downloaded the <span class="code">rpm</span> package, converted it to a <span class="code">deb</span> with <span class="code">alien</span> and installed it with <span class="code">dpkg</span>.
</li>
<li>
I also found and installed these packages in the ubuntu repositories: <span class="code">mysql-connector-odbc</span> and <span class="code">libmyodbc</span>. There is probably some redundancy in this step and the previous one, but at least I didn't have any conflict issues and everything worked in the end.
</li>
<li>
Now, <span class="code">unixodbc</span> relies on two files: <span class="code">/etc/odbcinst.ini</span> and <span class="code">~/.odbc.ini</span>. The first one holds a registry with ODBC drivers for different database systems. The installer for the MySQL driver (the one from the MySQL website) registers the driver with this file, so you don't need to do that manually. The file should look like this:
<div class="code">
<pre>
[MySQL]
DRIVER = /usr/lib/libmyodbc3.so
SETUP = /usr/lib/libmyodbc3S.so
UsageCount = 1
</pre></div>
Make sure the location of the drivers is the correct one.
</li>
<li>
The <span class="code">.odbc.ini</span> is used for declaring datasources. Actually this file declares datasources on a per-user basis. Global datasources can be configured in the file <span class="code">/etc/odbc.ini</span>.
An entry on these files should look like this:
<div class="code">
<pre>
[test]
DRIVER = MySQL
SERVER = localhost
DATABASE = mysql
USER =root
PASSWORD =
PORT = 3306
SOCKET = /var/run/mysqld/mysqld.sock
</pre></div>
Needless to say that the <span class="code">DRIVER</span> name should must the name of the driver, as it was declared on <span class="code">/etc/odbcinst.ini</span>.
</li>
<li>
As you can see I also had to explicitly define the mysql socket. This was because the location of the mysql socket in ubuntu is different than in other linux systems. By default, <span class="code">unixodbc</span> uses the location <span class="code">/tmp/mysql.sock</span>, so you can either explicitly specify the socket location as above, or just create a link:
<div class="code">
sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
</div>
</li>
<li>
Now you can test the connection using
<div class="code">
isql -v test
</div>
You should get a message like this:
<div class="code"><pre>
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+</pre>
</div>followed by an <span class="code">SQL</span> prompt.
</li>
<li>
Finally this is some java code that uses this datasource:
<div class="code">
<pre>
// There are two ways we can address a datasource:
// either with the DNS of a correctly configured ODBC datasource,
// or by providing all the database information.
Connection conn = java.sql.DriverManager.getConnection(
//"jdbc:odbc:;DRIVER={MySQL};SERVER=localhost;DATABASE=mysql;",
"jdbc:odbc:test",
"root",
"");
</pre>
</div>
</li>
</ul>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-10109072705260748462008-04-28T16:34:00.007+02:002008-04-28T16:34:53.769+02:00Hide partition icons from your ubuntu desktop<a href="http://tombuntu.com/index.php/2007/10/25/hide-partition-icons-from-your-ubuntu-desktop/">http://tombuntu.com/index.php/2007/10/25/hide-partition-icons-from-your-ubuntu-desktop/</a>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-59253149012459172722008-04-28T13:24:00.004+02:002008-04-28T16:35:36.222+02:00Changing the looks of the input boxes and button on FirefoxFirefox 2 looks like crap on linux. The buttons and other input widgets just look so 90s...
Jesse "fatsheep" Cambon has created a nice little app to change the appearance of all the input controls (buttons, textfields/textareas/dropdowns/checkboxes etc). The app can be downloaded at <a href="http://www.blogger.com/img/gl.link.gif">ubuntuforums.</a>
You just have to download the archive, extract it, run <span class="code">./install</span> and restart firefox. That's all.Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-148819621389944312008-04-24T11:41:00.005+02:002008-04-24T11:51:32.798+02:00Installing MS Word 2003 on ubuntu using WINE<p>Although OpenOffice is a fairly decent suite, there are still some compatibility issues between OO and MSOffice. In my experience these have to do with formatting, which just gets messed up if you open a Word document on OO and save it as a .doc. I read somewhere that these problems can probably be overcome if you install some fonts on linux, but I didn't try that.
</p>
<p>
Instead, I thought I should finally give WINE a try so I could stop dual-booting. I found a very helpful guide on <a href="http://thesorcerer.wordpress.com/2007/10/07/guide-how-to-install-microsoft-office-2003-in-linux/">
Sorcerer's tech</a>. I am using Feisty Fawn 7.10, and I only installed and tested Word. At the time of writing this, the newest version on the ubuntu repositories was 0.9.46. When I tried it out with this version, I got an error message as soon as Word launched, saying something like this: "Microsoft Word has not been installed for the current user", and then it would just close. After a quick search on the Web, I found out that I had to use an older version of Wine, so <a href="https://launchpad.net/ubuntu/gutsy/i386/wine/0.9.37-0ubuntu3">I downloaded the 0.9.37 version</a> and everything worked fine.</p>
<p>
<b>Note:</b> Accordint to the Sorcerer's tech, this should work on all flavors of linux.
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-53334401520266752582008-04-22T17:13:00.002+02:002008-04-24T11:52:09.405+02:00Create a custom keyboard layout in linux<a href="http://blog.dotkam.com/2007/06/25/custom-keyboard-layout-in-ubuntu-or-just-linux/">This post</a> explains how you can create a custom keyboard layout in linux.Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-28763070599613039762008-04-08T09:03:00.013+02:002008-04-24T11:52:35.133+02:00Wrapping all dependencies in a jar<p>
Yesterday I encountered this issue: I have been writing a client code that contacts a web service. I wanted to implement a modularized solution by wrapping all web service related code and dependencies in a library, so that I could jsut use this library in my client code, without having to worry about the WS specifics (ie the web service location, how to establish connection with it etc).
</p>
<p>
So I created a package that operates as a middle layer between the WS and the client code and then packaged it into a jar file. However, when I tried to use that in an applet I realised that I also had to distribute all of the jar's dependencies with the applet. (This problem wasn't obvious while running the program as a Java application, cause JVM was able to locate the dependencies in the file system.)
</p>
<p>
I made a little research and I found out that it is not possible to include other jars in a jar file, just like you can do with war files. The suggested solution is to unpackage all jars and re-package them into your own jar. Of course this isn't something that you can easily do by hand, especially if you think that the whole process has to be repeated each time you compile your project.
</p>
<p>
So this process has to be automated and <span class="code">ant</span> is one way to do that. I will be demonstrating how this can be done on Netbeans.
</p>
<p>
First a few words about how Netbeans uses ant. In your project folder you will find two build files:
<ul><li>
<span class="code">$PROJ_HOME/build.xml</span>
</li><li>
<span class="code">$PROJ_HOME/nbproject/build-impl.xml</span>
</li>
</ul>
The second one is the actual build file that Netbeans automatically creates using the project properties, and is updated each time you add a new source file, or add a new JAR to the project classpath. You <b>should not</b> edit this file. (Actually even if you do, your changes might be overwritten when the file is automatically regenerated.) You should only edit the first one. This file defines a number of pre and post targets that are built just before or just after the basic targets of <span class="code">build-impl.xml</span>.
</p>
<p>
In our case we will use the <span class="code">-pre-jar</span> target. The commands of this target will extract the library jar files into the built directory just before the <span class="code">jar</span> target is called, so the latter will include them when creating the project's jar file. An example of the definition of this target is shown below.
</p>
<div class="code"><pre>
<target name="-pre-jar">
<unjar src="${file.reference.axis-ant.jar}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.activation.jar}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.axis.jar-1}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.commons-discovery-0.2.jar}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.commons-logging-1.0.4.jar}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.jaxrpc.jar-1}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.log4j-1.2.8.jar}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.saaj.jar-1}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.wsdl4j-1.5.1.jar}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.activation.jar}"
dest="${build.classes.dir}"/>
<unjar src="${file.reference.mail.jar}"
dest="${build.classes.dir}"/>
</target>
</pre></div>
<p>
We need an <span class="code">unjar</span> element for each jar we want to repackage in our jar. The <span class="code">dest</span> attributes specifies that the jars should be extracted in the project's build directory; you should leave that as it is.<br/> Now, the value of the <span class="code">src</span> attribute contains a reference to the jar file that will be unjar-ed. You can find the values you should use in the file <span class="code">$PROJ_HOME/nbproject/private/private.properties</span>. This properties file contains key-value pairs with the names used by Netbeans for library files and the actual location of these files.
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-23216056121322301222008-04-03T12:41:00.011+02:002008-04-24T11:53:01.152+02:00SOAP attachments with AXIS<p>I wanted to create a Web Service that accepts a JPEG image as the input. The preferred way to send an image in a SOAP message is using SOAP attachments.</p>
<p>
Below is a sample WSDL file for a service that accepts an image as input.
</p><div class="code">
<pre>
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="newWSDL" targetNamespace="http://www.example.com/example"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.example.com/example"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
<message name="isLabelAuthenticRequest">
<part name="labelImage" type="xsd:hexBinary"/>
</message>
<message name="isLabelAuthenticReply">
<part name="isAuthentic" type="xsd:boolean"/>
</message>
<portType name="isLabelAuthenticPortType">
<operation name="isLabelAuthenticOperation">
<input name="authenticInput" message="tns:isLabelAuthenticRequest"/>
<output name="authenticOutput"
message="tns:isLabelRegisteredOperationReply"/>
</operation>
</portType>
<binding name="isLabelAuthenticBinding" type="tns:isLabelAuthenticPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="isLabelAuthenticOperation">
<soap:operation/>
<input name="authenticInput">
<mime:multipartRelated>
<mime:part>
<soap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.example.com/example"/>
</mime:part>
<mime:part>
<mime:content part="labelImage" type="image/jpeg"/>
</mime:part>
</mime:multipartRelated>
</input>
<output name="authenticOutput">
<soap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.example.com/example"/>
</output>
</operation>
</binding>
<service name="smartLabelDemoService">
<port name="isLabelAuthenticPort" binding="tns:isLabelAuthenticBinding">
<soap:address location="http://192.168.0.156:8080/Example/authentic"/>
</port>
</service>
</definitions>
</pre>
</div>
<p></p>
<p>
The highlights of the WSDL file:
<ul><li>The following namespace for SOAP must be used to enable support for attachments:
<div class="code">xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/</div>
</li>
<li>
The message that will include an attachment is declared to be of type
<span class="code">xsd:hexBinary</span>
</li>
<li>
The actual structure of this message is specified in the <span class="code">binding</span> element. It is specified as a multipart message, with the MIME type of the second part set to <span class="code">image/jpeg</span>.
</li>
</ul>
</p>
<p>
The WSDL2Java utility offered by Axis, should be able to parse this wsdl document and generate the stubs successfully. (I have been using version 1.4 of Axis). Of course, for WSDL2Java to work, all the axis-related jars (ie all the jars in the folder <span class="code">$AXIS_HOME/lib</span>) must be present in the CLASSPATH. Furthermore, for attachment support, we also need <span class="code">mail.jar<span> and <span class="code">activation.jar</span>. The first one is part of the Java Mail API and the second on can be found in the JavaBeans Activation Framework.
</p>
<p>
However I was getting the following error message when I tried to implement and test the web service:
<div class="code">
<pre>
http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Bad envelope tag: html
org.apache.axis.message.EnvelopeBuilder.startElement(EnvelopeBuilder.java:71)
...
</pre>
</div>
</p>
<p>
I could only understand what was causing this when I used the <a href="https://tcpmon.dev.java.net/">tcpmon</a> utility to monitor the TCP connections.
This actually revealed that the server was returning an HTML document (rather than a SOAP message) containing an error message:
<div class="code">
<pre>
java.lang.RuntimeException: No support for attachments
org.apache.axis.Message.setup(Message.java:372)
...
</pre>
</div>
</p>
<p>
So, it was a matter of just enabling attachment support on the server side. This can be done by simply copying <span class="code">mail.jar</span> and <span class="code">activation.jar</span> under the location where axis has been deployed, ie under the directory <span class="code">$CATALINA_HOME/webapps/axis/lib</span>.
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-44726045240511161242008-01-15T16:49:00.006+02:002008-04-24T12:01:01.615+02:00Programmatically adding a jenia4faces Popup component to a Netbeans 6.0 VWP project<p>
This post describes how you can programmatically add a <a href="http://www.jenia.org">jenia4faces</a> PopupFrame component to a Netbeans 6.0 Visual Web project.
</p>
<p>
There are various reasons why you would need to do that. In my case the requirement was that we needed a link in each row of a dynamically-created table that brings up a popup frame that is used for editing the database entry for this table row. Since the table is created dynamically, the same must be done with the PopupFrame component.
</p>
<p>
First you need to add the Jenia servlet in your <span class="code">web.xml</span> file. This is a required step for using any Jenia component, no matter whether you add it to your page through JSP or from within Java code.
<div class="code">
<pre>
<servlet>
<servlet-name>Jenia servlet</servlet-name>
<servlet-class>org.jenia.faces.util.Servlet</servlet-class>
<load-on-startup>
</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jenia servlet</servlet-name>
<url-pattern>/jenia4faces/*</url-pattern>
</servlet-mapping>
</pre>
</div>
You also need the component jars in your project classpath.
</p>
<p>
Next you need to import the appropriate Java class in your Page bean. In the case of the PopupFrame this is
<div class="code">
import org.jenia.faces.popup.component.html.HtmlPopupFrame;
</div>
If you want to dynamically add a different Jenia component, you can easily find the fully qualified name of the appropriate class by either browsing the Jenia jar files, or simply by using the Netbeans auto-completion function.
</p>
<p>
Now you can initialize the component and set its basic properties.
<div class="code">
<pre>
// Create the popup component
HtmlPopupFrame popup = new HtmlPopupFrame();
// Set its properties
popup.setId("editPopup");
popup.setCenter("true");
popup.setWidth("550px");
popup.setHeight("400px");
popup.setTitle("Edit Task");
popup.setResizable("false");
popup.setImmediate(true);
</pre>
</div>
Again, you can use the auto-completion function in order to browse the supported properties and set any of those as required for your project.
</p>
<p>
Now it's the most tricky part: setting the method bindings for the <span class="code">actionOpen</span> and <span class="code">actionClose</span> properties.
First we get a reference to the EL Expression Factory and create a MethodExpression.
<div class="code">
<pre>
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elctx = fc.getELContext();
ExpressionFactory elFactory = fc.getApplication().getExpressionFactory();
MethodExpression openExpression = elFactory.createMethodExpression(elctx,
"#{Staff.fireEditPopup}", String.class, new Class[]{});
</pre>
</div>
Then we create a method binding using this expression and bind the <span class="code">actionOpen</span> property.
<div class="code">
<pre>
MethodBindingMethodExpressionAdapter bind1 = new MethodBindingMethodExpressionAdapter(openExpression);
popup.setActionOpen(bind1);
</pre>
</div>
Repeat the steps above for the <span class="code">actionClose</span> attribute.
</p>
<p>
The PopupFrame component renders as a <span class="code"><a></span>. It can accept either plain text or an image as a child, so that it displays as a simple (text) hyperlink or an image hyperlink. This leaves us with an option to use either a <span class="code">StaticText</span> or am <span class="code">ImageComponent</span> in Netbeans. If you are not using Netbeans, you can add the respective standard JSF components (eg. <span class="code"><h:outputText></span>).
<div class="code">
<pre>
// Create an image component
ImageComponent edit = new ImageComponent();
edit.setId("editLink");
edit.setUrl("resources/edit.png");
edit.setHeight(16);
edit.setWidth(16);
// Add the image to the popup (as a child)
popup.getChildren().add(edit);
</pre>
</div>
</p>
<p>
The Popup component is now ready. We can add it to the component tree. (In my case, I am adding it to the tablecolumn.)
<div class="code">
column8.getChildren().add(popup);
</div>
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com4tag:blogger.com,1999:blog-389599815913963205.post-72662312881936798192008-01-11T13:13:00.000+02:002008-01-11T13:27:04.200+02:00awk: Simple and combined patternsA simple usage for the <span class="code">awk</span> command is to find lines in a file or a stream match given patterns. The command
<div class="code">
awk '/<i>pattern</i>/' <i>filename</i>
</div>
is equivalent to
<div class="code">
grep <i>pattern</i> <i>filename</i>
</div>
<p/>
But <span class="code">awk</span> is more powerful than <span class="code">grep</span>, in that we can display only specific fields from the matching lines.
The command
<div class="code">
awk '/<i>pattern</i>/ {print $2}' <i>filename</i>
</div>
will only print the second field of the matching lines.
<p/>
Patterns can be combined with the <span class="code">&&</span>, <span class="code">||</span> and <span class="code">!</span> operators.
<div class="code">
awk '/foo/ && /bar/ {print $2}' example.txt
awk '/foo/ && !/bar/ {print $2}' example.txt
</div>
The first command above will print the second field of the lines in example.txt that contain both 'foo' and 'bar', while the second one will only match the lines that contain 'foo' but not 'bar'.Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-30850635270440259532007-11-29T16:14:00.005+02:002008-04-24T12:01:40.685+02:00Displaying a spinning wheel image during a Dynamic Faces Ajax transaction.<p>
I am currently building a JSF application using <a href="http://www.netbeans.org/community/releases/60">Netbeans 6.0</a>. For this project I use a wide range of <a href="http://woodstock.dev.java.net">Woodstock</a> components and also the <a href="https://jsf-extensions.dev.java.net/">Dynamic Faces</a> extension to ajaxify some of these . As some Ajax transactions may take some time to complete, I wanted to provide the user with some visual feedback that something is happening in the background.
</p>
<p>
So these are the steps you need to follow in order to display a spinning wheel gif while the client is waiting for the server response.
<ul>
<li>
Visit the <a href="">Ajax loading gif generator</a> and create a gif. There are plenty of similar sites in the web.
</li>
<li>
And an image component to the web page. This must be initially hidden, so specify <span class="code">visibility: hidden</span> in the <span class="code">style</span> attribute of the image. I suggest this property over the <span class="code">display: [<i>none</i>/<i>block</i>]</span>, because the <span class="code">visibility</span> property <a href="http://www.w3schools.com/css/pr_class_visibility.asp">reserves</a> the space occupied by a hidden component.
</li>
<li>
Create a Javascript function that toggles the image visibility and makes it visible.
<div class="code">
<pre>
var showLoading=function(element) {
var loadingImage = $(element);
loadingImage.style.visibility = 'visible';
}
</pre>
</div>
This function receives one string argument (the id of the image) and uses the prototype dollar function.
</li>
<li>
Now we need to call this method when the ajax transaction is initiated. This happens in the <span class="code">onClick</span> event action method of a button or hyperlink component, by calling the <span class="code">DynaFaces.Tx.fire(...)</span> function. So we just need to add a call to the <span class="code">showLoading</span> function right before this.
</li>
<li>
The final step is to hide the image when the transaction completes. This can be done by adding the image component to the "re-render" list of components of the AjaxTransaction component. This is enough, because when the image component is re-rendered when the response is received, it uses the initial value of the <span class="code">visibility</span> property, which is set to '<span class="code">hidden</span>'. <br/>
</li>
</ul>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com1tag:blogger.com,1999:blog-389599815913963205.post-36444854560491286652007-11-15T11:22:00.000+02:002007-11-15T11:37:25.771+02:00Internationalizing Woodstock components<p>
<a href="https://woodstock.dev.java.net/">Project Woodstock</a> offers a set of very useful JSF components, some of which are included by default in <a href="http://www.netbeans.org/community/releases/60">NetBeans 6.0</a>. The labels, messages etc used by these components can be internationalized by following these steps:
</p>
<p>
<ol>
<li>
Create a new resource bundle properties file <span class="code">woodstock.properties</span>. An existing one can be used, but it's better to keep things clean.
</li>
<li>
Declare the bundle in <span class="code">web.xml</span>.
<div class="code">
<context-param><br/>
<param-name>com.sun.webui.theme.THEME_RESOURCES</param-name><br/>
<param-value><i>my.package.woodstock</i></param-value><br/>
</context-param>
</div>
Note that you must use the fully qualified name of the properties file (if it is placed in a package).
</li>
<li>
The Woodstock Theme Doc pages include a <a href="http://webdev2.sun.com/woodstock-theme-doc/theme-properties-table.html">list</a> with all the key-value pairs for woodstock messages. You can override these in the new properties file.
</li>
</ol>
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com1tag:blogger.com,1999:blog-389599815913963205.post-24980904763501039742007-11-13T17:49:00.000+02:002007-11-13T18:38:39.423+02:00Dynamic Faces and encoding problems<p>Dynamic Faces is part of the JSF extensions project, and it offers an easy way to ajaxify plain old JSF components. However, there is a problem (I would call it a bug) with international characters. Even if you specify UTF-8 as the encoding of the HTML/JSP page, the partial AJAX response is always in ISO-8859-1. This can be easily verified with the Netbeans HTTP monitor: under the <i>Session</i> tab, the value for the <span class="code">javax.faces.request.charset</span> is UTF-8 before the request, and changes to ISO-8859-1, after the request. This results in lots of questionmarks or strange symbols in the page and it actually makes it impossible to use Dynamic Faces with an internationalized application.
</p>
<p>
The solution came from Matthias Unverzagt's comment in a number of blogs/forums, such as <a href="http://blogs.sun.com/honglu/entry/walking_through_creating_a_simple">Hong's blog</a>. Matthias suggests that the line
<div class="code">
context.getExternalContext().setResponseCharacterEncoding("UTF-8");
</div><br/>
needs to be added to the <span class="code">com.sun.faces.extensions.avatar.lifecycle.AsyncResponse</span>'s <span class="code">installOnOffResponse</span> method.
</p>
<p>
This proved quite of a challenge for me, since it required recompilation of the <span class="code">jsf-extensions-dynamic-faces-0.1.jar</span>, which was a bit tricky, as this jar appeared in a number of locations on my system:
<ul>
<li>
<span class="code">
~/.netbeans/6.0beta2/config/org-netbeans-modules-visualweb-complib/installed-complibs/dynamicfaces02
</span>
</li>
<li>
<span class="code">
${netbeans_installation_dir}/visualweb1/modules/ext
</span>
</li>
</ul>
The jars in these directories were different. The first directory also contained a jar with the sources, but NetBeans was using the jar from the second directory for my project.
</p>
<p>
So, here are the steps I followed (with NetBeans Beta2):
<ol>
<li>I extracted <span class="code">jsf-extensions-dynamic-faces-0.1-sources.jar</span>, found in the first directory above.</li>
<li>
I created a new Netbeans Java project with the extracted sources.
</li>
<li>
In order to compile this project a number of libraries and jars had to be added to the project's classpath:
<ul>
<li>
<b>libraries:</b> JSF 1.2, Web UI Components
</li>
<li>
<b>jars</b> el-api.jar, jsp-api.jar, servlet-api.jar, shale-remoting.jar
</li>
</ul>
The first 3 jars can be found in tomcat's <span class="code">lib</span> directory, while the last one is located in <span class="code">
~/.netbeans/6.0beta2/config/org-netbeans-modules-visualweb-complib/installed-complibs/dynamicfaces02
</span>
</li>
<li>
I opened the file <span class="code">AsyncResponse.java</span> file, from the <span class="code">com.sun.faces.extensions.avatar.lifecycle</span> package and added the line
<div class="code">context.getExternalContext().setResponseCharacterEncoding("UTF-8");</div>
to the <span class="code">installOnOfResponse</span> method's body. It probably doesn't matter where exactly you place this line; I added it as the second line of this method, right between the other two statements of this method.
</li>
<li>
I extracted the <span class="code">jsf-extensions-dynamic-faces-0.1.jar</span> file from the
<span class="code">
${netbeans_installation_dir}/visualweb1/modules/ext
</span> directory and replaced the .class files in the <span class="code">
lifecycle</span> subdirectory with the ones I just compiled.
</li>
<li>
That's all! I then recompiled and deployed my web application (so that the patched copy of <span class="code">jsf-extensions-dynamic-faces-0.1.jar</span> would be used) and I was set.
</ol>
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com4tag:blogger.com,1999:blog-389599815913963205.post-48721610664002389762007-11-07T18:41:00.001+02:002008-04-24T12:02:09.158+02:00Turning off the system beeper<p>This is the magic command that turns off the system beeper:
<div class="code">
sudo rmmod pcspkr
</div>
</p>
<p>
And just for completence, this is how to turn it on again:
<div class="code">
sudo modprobe pcspkr
</div>
</p>
<p>
<b>Update </b> (Thanks to the <a href=" http://www.arsgeek.com/?p=484">ArsGeek</a> site.) This only works for the current session - the beeper is only muted till the next reboot. In order to make the beeper silent for ever, you need to add the following line to the file <span class="code">/etc/modprobe.d/blacklist</span>:
<div class="code">
blacklist pcspkr
</div>
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com2tag:blogger.com,1999:blog-389599815913963205.post-44688582889589269792007-11-07T15:33:00.001+02:002008-04-24T11:53:37.113+02:00Ubuntu: Connecting to a Windows shared network drive<p>I got a new PC at work and I made a clean installation of Ubuntu Gutsy Gibbon 7.10, so I had to make some configuration from scratch. This is a quick note about how I connected to our file server, using samba</p>
<p>From the <b>Places</b> menu, select <b>Connect to server</b>. From the window that appears, select <b>Windows share</b> in the <b>Type</b> drop-down. Then provide the server's IP in the <b>Server</b> field and the folder's name in the <b>Folder</b> field and you are done.</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-26429476676019108002007-10-31T15:13:00.000+02:002007-11-12T12:16:52.271+02:00Datasources, Tomcat and Netbeans<p>
I am currently developing a JSF application using <a href="http://www.netbeans.org/community/releases/60/index.html">NetBeans 6.0</a> and Tomcat 6.0.14. When I tried to deploy the application on our production server (by just dumping the <span class="code">.war</span> file in Tomcat's <span class="code">webapps</span> directory, it didn't work properly. I could access the app's start page, but it failed to render the following pages.
</p>
<p>
A look in tomcat's log files revealed that there was a problem with the mysql driver.
<div class="code">
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
</div>
</p>
<p>
I tried to make sure that the mysql-connector jar is included in the project's imported libraries and that it can be found in <span class="code">META-INF/lib</span>, but this didn't help.
I later found out that in Netbeans, under Tools→Servers→Deployment there is a "Enable JDBC driver deployment option". Disabling this resulted in a replication of the problem on my development machine, even when using NetBeans. So I had to find out what it was that NetBeans was doing when this option was enabled and repeat it on the production server.
</p>
<p>
I started making a research on the net, based on the error message I was getting. The oslution proposed by most people was to place the mysql driver jar in tomcat's <span class="code">common/lib</span> directory <b>and nowhere else</b>, but this just wouldn't do the trick for me. I also checked that the datasource's declarations in the <span class="code">web.xml</span> and <span class="code">context.xml</span> files were correct.
</p>
<p>
A final attempt to go through the steps to create and declare a datasource <a href="http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html">as described in tomcat's website</a> revealed a small detail in step 1: the driver jar file needs to be placed in the <span class="code">$CATALINA_HOME/lib</span> directory rather than <span class="code">$CATALINA_HOME/common/lib</span>.
</p>
<p>
Still remains to check whether there is a difference in the directory structure in versions 5.5 and 6.0 of tomcat, since no <span class="code">common</span> directory appears to exist in installations of tomcat 6.0.
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com2tag:blogger.com,1999:blog-389599815913963205.post-44023352106132979732007-09-21T13:47:00.000+02:002007-11-12T12:17:04.097+02:00Setting the time on linux.<p>For some reason I find the manpage for the <span class="code">date</span> command a bit confusing. Here is how you can set the time in a linux box through the command line:
<div class="code">
date <i>MMDDhhmmYYYY</i>
</div>
where <span class="code">MM</span> is the month, <span class="code">DD</span> the day, <span class="code">hh</span> the hour, <span class="code">mm</span> the minutes and <span class="code">YYYY</span> the year.
</p>
<p>
The system's hardware clock can be synchronized with this time by executing the following command:
<div class="code">
sudo hwclock --utc --systohc
</div>
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-91903067899392372982007-09-04T11:09:00.001+02:002008-04-24T11:58:17.954+02:00Allowing ssh access with iptables.<p>This post describes how you can allow incoming ssh connections from a certain IP address, using <span class="code">iptables</span>.</p>
First of all, the current list of <span class="code">iptables</span> rules can be viewed with the command
<div class="code">
iptables --list
</div>
<p>
A new rule to allow access from the IP 100.100.100.100 can be appended to this list with the command
<div class="code">
sudo iptables -A INPUT -p tcp -s 100.100.100.100 --dport 22 -j ACCEPT
</div>
As it can be seen from the command above, root access is required to alter the iptables.
</p>
<p>
However, in my case this didn't work, because the rule was appended to the end of the list, which means that it was preceded by a DROP rule that blocked ssh access to all IP addresses that did not explicitly have an ACCEPT rule. So, I had to add the rule further up in the list. This can be achieved with the <span class="code">-I</span> switch.
<div class="code">
sudo iptables -I INPUT 11 -p tcp -s 100.100.100.100 --dport 22 -j ACCEPT
</div>
In the example above, the rule will be added to the 11th position in the list.
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com1tag:blogger.com,1999:blog-389599815913963205.post-42036993842463213422007-08-30T12:55:00.001+02:002008-04-24T11:55:28.678+02:00How to create a Datasource and a Connection Pool on Tomcat.<p>This post describes how you can setup a Connection Pool for a web application under Tomcat.
I have been using NetBeans 5.5.1, with bundled Tomcat (version 5.5.17). NetBeans does offer some visual tools to create datasources and connection pools, but as far as I understand, these only work with the Sun Application Server.</p>
<p>
Before doing anything else, the following jars are required:
<ul>
<li><span class="code">mysql-connector-java-5.0.7-bin.jar</span>
<li><span class="code">commons-dbcp-1.2.2.jar</span>
<li><span class="code">commons-collections-3.2.jar</span>
<li><span class="code">commons-pool-1.3.jar</span>
</ul>
The first one is the official mysql driver which can be downloaded from the mysql site. The other three are part of the <a href="http://commons.apache.org/">Apache Commons</a> collection.<br/>
They need to be placed in the <span class="code">WEB-INF/lib</span> subdirectory of the webapp. (Of course this can also be done through the NetBeans IDE.) Actually, although I read on various websites about the last 3 jars, I am not absolutely sure if they are definitely required. Even after I removed them, my application continued to work fine. <br/>
<b>Important:</b> The MySQL Connector/J jar needs to be placed under the Tomcat <span class="code">common/lib/</span> subdirectory. (For the bundled with the NetBeans IDE version of Tomcat, this directory is <span class="code">$NETBEANS_HOME/enterprise3/apache-tomcat-5.5.17/common/lib</span>.
</p>
<br/>
<p>
<b>1.</b> Add this to the <span class="code">context.xml</span> file (which is located in the <span class="code">META-INF</span> directory of the web-app.
<div class="code"><pre>
<Context path="/ePmashup">
<Resource
name="jdbc/dataSource"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
username="<i>username</i>"
password="<i>password</i>"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/<i>databaseName</i>"
maxWait="1000"
removeAbandoned="true"
maxActive="30"
maxIdle="10"
removeAbandonedTimeout="60"
logAbandoned="true"/>
</Context>
</pre>
</div>
The options in italics have to be substituted with the appropriate values.
</p>
<p>
<b>2.</b> Create a <span class="code">DataSource</span> object in the application code.
<div class="code">
<pre>
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
datasource = (DataSource)envContext.lookup("jdbc/dataSource");
</pre>
</div>
This snippet has to be wrapped in a try-catch block, because it might throw a <span class="code">NamingEsception</span>. In my code, I placed this piece of code in the <span class="code">init()</span> method of the Servlet that contacts the database and returns the results to the client.
<div class="code">
<pre>
public void init() throws ServletException {
super.init();
try {
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
datasource = (DataSource)envContext.lookup("jdbc/dataSource");
} catch( NamingException ne ) {
throw new RuntimeException( "Unable to aquire data source", ne );
}
}
</pre>
</div>
Obviously, the string passed in the <span class="code">lookup</span> method, needs to be the Resource name (in <span class="code">context.xml</span>).
</p>
<p>
<b>3.</b> Now, a connection from the pool can be retrieved and used like this:
<div class="code">Connection conn = dataSource.getConnection();</div>
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-88968237018161637352007-07-31T17:48:00.006+02:002008-04-24T12:01:10.573+02:00Popup windows in JSFIs is possible to raise a popup window in Java Server Faces (JSF) using Javascript, more or less the same way as in HTML.<p/>
This example shows how this can be done with a <span class="code">commandButton</span>.
<div class="code">
<h:commandButton value="Press me to bring up a popup window" onclick="window.open('popup.jsp', 'popup_window')" />
</div>
<p/>
This exact method won't work with a <span class="code">commandLink</span>, because this does not offer an <span class="code">onclick</span> option. However the <span class="code">mouseup</span> event can be used instead:
<div class="code">
<h:commandLink onclick="window.open('popup.jsp', 'popup_window')">
<br/>
Press me to bring up a popup window
<br/>
</h:commanndLink>
</div>
<p/>
Of course, both <span class="code">commandButton</span> and <span class="code">commandLink</span> items need to be enclosed in a <span class="code">form</span> element. This means that the form will be submitted when the <span class="code">commandButton</span> or <span class="code">commandLink</span> is pressed/clicked. In order to avoid it, we have to <span class="code">return false</span> from within the <span class="code">onclick</span> or <span class="code">mouseup</span> attribute.
<div class="code">
<h:commandButton value="Press me to bring up a popup window" onclick="window.open('popup.jsp', 'popup_window'); <b>return false;</b>" />
</div>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-67369860821634233202007-07-18T11:15:00.000+02:002007-11-12T12:17:17.948+02:00Javascript context menusWith Javascript it is possible to add a context menu to an object (ie a menu that displays on right-click). However, on Firefox, right-clicking on an object with a custom context menu will show both this menu and the normal Firefox context menu. The Firefox context menu is displayed on top of the custom menu, so in order to access the latter, you need to click somewhere else on the page, in order to access the custom menu.<p/>
This behaviour can be overridden by selecting the following options:<br/>
Edit → Preferences → Content → Advanced (next to Enable Javascript) → Disable or replace context menus.<br/>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-40040902959295546772007-07-16T22:55:00.000+02:002007-07-16T22:56:44.933+02:00Compilers, assemblers, linkers, translatorsGreat article:<br/><a href=http://brianwill.net/blog/2007/07/12/lost-in-translation/>
http://brianwill.net/blog/2007/07/12/lost-in-translation/</a>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-28349204899145172942007-07-01T21:35:00.001+02:002008-04-24T11:54:07.705+02:00Ubuntu: Multisession DVDs<p>At the time of writing this, Gnomebaker supports writing multisession CDs, but not DVDs. This extra functionality is provided by K3b, but this is a KDE application, and installing KDE applications on a GNOME-based distribution is not always desirable.</p>
<p>There is however a very simple-to-use command line utility that can be used to create a multisession DVD disc, append data to it and finalize it (and the disc is fully-readable before finalization). This utility is called <span class="code">growisofs</span> and its functionality can be summarized as follows:</p>
<b>Creating a multisession disc</b><br>
<div class="code">
growisofs -Z <i>/dev/dvd</i> -R -J <i>/path/to/file1 /path/to/file2 ...</i>
</div>
<p>The <span class="code">-R</span> and <span class="code">-J</span> options define that the Rock-Ridge and Joliet extension should be used (whatever that means....). <span class="code">/dev/dvd</span> should be substituted with the appropriate value for the DVD device (eg in my case it is <span class="code">/dev/cdrom</span>).</p>
<br/>
<b>Appending data to a multisession disc</b><br>
<div class="code">
growisofs -M <i>/dev/dvd</i> -R -J <i>/path/to/file1 /path/to/file2 ...</i>
</div>
<p>The only point that needs caution here is that, when adding data to a multisession disc, you have to use exactly the same options as with when creating the disc.</p>
<br/>
<b>Finalizing a multisession disc</b><br>
<div class="code">
growisofs -M <i>/dev/dvd</i>=/dev/zero
</div>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com0tag:blogger.com,1999:blog-389599815913963205.post-87857290944183441372007-06-19T22:08:00.002+02:002008-12-09T13:15:40.126+02:00Ubuntu: Enabling USB audio<p>The other day, I managed to break my speaker <a href="http://en.wikipedia.org/wiki/Jack_plug">jack plug</a> and get one piece of it stuck in the soundcard's speaker output, thus rendering it useless. My efforts to get this piece out of there led nowhere, so I started thinking of other alternatives and I ended up getting a USB external soundcard.</p>
<p>The cheapest one I could find was <a href="http://www.equip-info.net/english/index.php?main=10&gruppe=100&prod=1613">this</a> and there was no way that I would look for anything more expensive as there was the risk that it wouldn't work under linux. However the fact that the device supports MacOS-X was an encouraging fact towards portability. A quick research on the internet also revealed that (at least theoretically) all USB audio devices should work fine as they all use the USB protocol, so no special drivers are required.
</p>
<p>Indeed enabling USB audio was very straightforward:
<ol>
<li>
I first opened the <i>Sound Preferences</i> (System→Preferences→Sound) and I selected 'USB Audio' where it was available.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPjg4o-VBnRsSUIHgas5N8IBRWvJflWUKWSVsW65Z3Mdq3PA4gpEQmb9gtS6j3kqLBFkH4zMEfW5FJPvoWhDukaomBD_8PKWDF1qiASv7LVlAZAR64i13pAbFBYKhNDu9LuRNibxM44kM/s1600-h/1.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPjg4o-VBnRsSUIHgas5N8IBRWvJflWUKWSVsW65Z3Mdq3PA4gpEQmb9gtS6j3kqLBFkH4zMEfW5FJPvoWhDukaomBD_8PKWDF1qiASv7LVlAZAR64i13pAbFBYKhNDu9LuRNibxM44kM/s400/1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077876495170592354" /></a>
</li>
<li>
Then I double click on the speaker icon on the top right corner, which brings up the <i>Volume Control</i> window, I muted out all tracks for my old sound device and I closed this window.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaUqh1Cq6Ehru1vAHMUgSF27JdMUQSbelfSwMsf3FSBGI0tOhEZxYlVop3zC3BDyTDqw10qaQ2k3DoOijmwtqyJnu7vN3Ol7coum_Znl3_RKG7p53p-oGfQnkqAGk1PRpP9TPZJBX6wF4/s1600-h/2.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaUqh1Cq6Ehru1vAHMUgSF27JdMUQSbelfSwMsf3FSBGI0tOhEZxYlVop3zC3BDyTDqw10qaQ2k3DoOijmwtqyJnu7vN3Ol7coum_Znl3_RKG7p53p-oGfQnkqAGk1PRpP9TPZJBX6wF4/s320/2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077876117213470274" /></a>
</li>
<li>
Finally, I right-clicked on the icon mentioned above, and I selected <i>Preferences</i>. Then I set the device that this icon controls to 'USB Audio', so that mouse scrolling over this icon will control the volume of the USB audio device.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPMuu6tOwiSFCfCLHPuuOVf6kVXR-iHW9oOXySfH4mBXbsIur92_3uEzr29KJ-_npbgkIKSTU5t7xlQjhaeDlKNBw9Hjzf5psSm659Q2daF8LGv2xN1KiKoGztI4MR3x64-AvhcrXQWh0/s1600-h/3.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPMuu6tOwiSFCfCLHPuuOVf6kVXR-iHW9oOXySfH4mBXbsIur92_3uEzr29KJ-_npbgkIKSTU5t7xlQjhaeDlKNBw9Hjzf5psSm659Q2daF8LGv2xN1KiKoGztI4MR3x64-AvhcrXQWh0/s320/3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077876190227914322" /></a>
</li>
</ol>
</p>
<p>
This whole process was enough to get audio playback to work, but getting sound to work while playing movies required a little bit of additional effort. I actually had to manually change the output device on all video players. Here are the steps required for each one of them.
</p>
<p>
<b>totem-gstreamer</b><br/>
The configuration for totem-gstreamer is handled by a utility called <span class="code">gstreamer-properties</code>. On the Audio< tab, I set the plugin to '<i>ALSA</i>' and the device to '<i>USB Audio</i>'.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqjpImP9XOt6vGTAqSrqMSg1LiEkjly36NyBJsAy3q4VSFVWcQnTvDTnuz7WlPGkHta2m0l9P7aqRAryFZ0KFSJmnD9Tp8jZXNrPN8pUuZpFw5IoPq_pq6c7hCmr_NtCpRAz_aNR6Ruq4/s1600-h/gstreamer-properties.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqjpImP9XOt6vGTAqSrqMSg1LiEkjly36NyBJsAy3q4VSFVWcQnTvDTnuz7WlPGkHta2m0l9P7aqRAryFZ0KFSJmnD9Tp8jZXNrPN8pUuZpFw5IoPq_pq6c7hCmr_NtCpRAz_aNR6Ruq4/s320/gstreamer-properties.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5084579913702027538" /></a>
</p>
<p>
<b>VLC player</b><br/>
Go to
Settings → Preferences → Audio → Output Modules → ALSA
and select <i>USB audio: USB audio (hw:1,0)</i> as the device name. Hitting the Refresh button might be required for this option to appear.<br/>
This whole process is important because it reveals to us the actual name for the USB audio device (<i>hw:1,0</i>).
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbs2olQIXdzHnOy-QXDwxFIt_OTfdfP17eXpg4p8JiNi9JrTpVEaseUouc5AAa7DekqCluUM2LWp8z8arGr33LQ0BN4rwPqj7thmsL7-eyKydXTC94ZSYs_mOsVMbza99Vm14jx_88XZs/s1600-h/vlc.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbs2olQIXdzHnOy-QXDwxFIt_OTfdfP17eXpg4p8JiNi9JrTpVEaseUouc5AAa7DekqCluUM2LWp8z8arGr33LQ0BN4rwPqj7thmsL7-eyKydXTC94ZSYs_mOsVMbza99Vm14jx_88XZs/s320/vlc.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5084580046846013730" /></a>
</p>
<p>
<b>mplayer</b><br/>
Preferences → Audio → ALSA → Configure driver <br/>
and set the Device to 'hw=1,0'.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbMuwF2vZC2FpQvEgPcE_e_Y9uJCXt9vy-jKYD8o-UeoQBpMVC5B-uUr2XqPuomXEc1bxcIpxoCohFi9CsdFUTlaC-2XbIzB-lAU_pnCHng-7bGMc4tOoz54dms584UF1VWi0M243ZVxI/s1600-h/mplayer+(Modified+(4)).png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbMuwF2vZC2FpQvEgPcE_e_Y9uJCXt9vy-jKYD8o-UeoQBpMVC5B-uUr2XqPuomXEc1bxcIpxoCohFi9CsdFUTlaC-2XbIzB-lAU_pnCHng-7bGMc4tOoz54dms584UF1VWi0M243ZVxI/s320/mplayer+(Modified+(4)).png" border="0" alt=""id="BLOGGER_PHOTO_ID_5084582086955479378" /></a>
</p>
<p>
<b>xine</b><br/>
First we need to enable advanced configuration options:<br/>
Settings → Setup → GUI Configuration Experience Level<br/>
and set it to '<i>Master of the Universe</i>'.<br/>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqOPjHDeHlnotqWuKErBNKGuwjN-UILP-AMiRXqjMpJg6mX3o5nZIc492ayJ3tzn9fSPKClfjAtQJGRTRUK4gMPjAiFlk44fuhc35gFoAcdYAfaeZgQrMaT43cYV19QMq7Y-8ghU0dRaE/s1600-h/xine_master.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqOPjHDeHlnotqWuKErBNKGuwjN-UILP-AMiRXqjMpJg6mX3o5nZIc492ayJ3tzn9fSPKClfjAtQJGRTRUK4gMPjAiFlk44fuhc35gFoAcdYAfaeZgQrMaT43cYV19QMq7Y-8ghU0dRaE/s320/xine_master.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5084580192874901810" /></a>
Then, in order to specify the output device, select the Audio tab and set 'hw=1,0' as the value for the fields <i>Device used for mono/stereo... output</i>.
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYYUxvxVp2ktU5sDZijiU_saQ4VQ-4cJtqPyYrFhr4jYPsWgqFO_Ovtm9hK9TlyM2zRE_aqk0DaiwHli80E6_Ge8R76CksM0ICd7bYB9ftc0NcVZFGRpRvBs9tnskZSFff3sEf7_tz6mU/s1600-h/xine.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYYUxvxVp2ktU5sDZijiU_saQ4VQ-4cJtqPyYrFhr4jYPsWgqFO_Ovtm9hK9TlyM2zRE_aqk0DaiwHli80E6_Ge8R76CksM0ICd7bYB9ftc0NcVZFGRpRvBs9tnskZSFff3sEf7_tz6mU/s320/xine.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5084580326018888002" /></a>
</p>
<p>
The only thing I still haven't got to work is the Fn+↑ and Fn+↓ combinations, which really bothers me, since this was the main method I used to control the volume.
</p>
<p>
<b>Update 1:</b> <br/>
Actually these combinations suddenly started working, but I can't remember doing something that I hadn't tried before... I believe the important part is to have the correct device selected in the "Select the device and tracks to control with the keyboard" field under the Sound Preferences window, but as it can be seen in the first screenshot, I had the correct option selected right from the beginning.
</p>
<p>
<b>Update 2:</b> <br/>
Another problem that I forgot to mention in the main article, was that I didn't have sound in Flash, which meant that I couldn't use YouTube and all other video sites. I had tried to solve this problem quite a few times before, but I only succeeded today. The only thing I did was to check that the correct device is selected in <span class="code">gstreamer-properties</span> (which I am not absolutely sure if it plays a role after all) and just re-install the Flash plugin.
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com2tag:blogger.com,1999:blog-389599815913963205.post-34410132485902838572007-06-17T17:41:00.000+02:002008-12-09T13:15:40.832+02:00Ubuntu: Hot to add subtitles to an AVI file.<p>All major Linux media players (Totem, mplayer, VLC player) allow you to add subtitles to a movie while watching it. This post describes how you can permanently add the subtitles in an AVI file, which is useful if you want to burn the movie to a video DVD. (Notice however that this technique does not allow you to add more than one subtitle streams to the movie, or disable the subtitles while watching the movie; the subtitles are hard-wired to the movie).</p>
<p>The software package we are going to use is called <span class="code">avidemux</span> and it can be easily installed through <span class="code">aptitude</span> if the universe/multiverse packages are enabled. </p>
<p>The procedure required to add the subtitles is this: </p>
<p>
<ol>
<li>
Launch avidemux.<br/>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMX2_KLpeLhJLa38FUOPsEtKwHMOl0rFB_pd3GabOnNuwWQwp8a2yGmW8jeB-qGXzpbgGV22UYUJpcGT7HGavPf8XL009vh9Eh_A5QTISHPl6D0CqkX_Xc6SZtPpeToDIzETPqQNVPlkM/s1600-h/1.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMX2_KLpeLhJLa38FUOPsEtKwHMOl0rFB_pd3GabOnNuwWQwp8a2yGmW8jeB-qGXzpbgGV22UYUJpcGT7HGavPf8XL009vh9Eh_A5QTISHPl6D0CqkX_Xc6SZtPpeToDIzETPqQNVPlkM/s320/1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077465183332523490" /></a>
</li>
<li>
Open the .avi file. With all files I have tried so far, I get these warnings:</br>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWHrw7YQ5R0poLu3GlJBT29JPQ5IODCtMRep_Vfz5FGBGvFgSkwVyp5hZPJPSDLXxUbWbDaC8sYuN3QjaAFh77xchex7kIYQSxhM1OoE4DsxLzUj8TiWeheew8rVylN0YxZCyQ653zwCU/s1600-h/2.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWHrw7YQ5R0poLu3GlJBT29JPQ5IODCtMRep_Vfz5FGBGvFgSkwVyp5hZPJPSDLXxUbWbDaC8sYuN3QjaAFh77xchex7kIYQSxhM1OoE4DsxLzUj8TiWeheew8rVylN0YxZCyQ653zwCU/s200/2.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077465410965790194" /></a>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiOEhlfNLal9_dwXBAPsh4uUWNwbN1pOqENsw8FAOHjYvpwJbawZ_Fbzm0WY-QQvHTWKPzPHIIlV_B_hRszJ3Vk7lozuqmQz52hxKbH0yWwRXOt-a-OodNX4fKul5MxoAWEdmcfbfhfiM/s1600-h/3.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiOEhlfNLal9_dwXBAPsh4uUWNwbN1pOqENsw8FAOHjYvpwJbawZ_Fbzm0WY-QQvHTWKPzPHIIlV_B_hRszJ3Vk7lozuqmQz52hxKbH0yWwRXOt-a-OodNX4fKul5MxoAWEdmcfbfhfiM/s200/3.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077465475390299650" /></a>
It is best to let <span class="code">avidemux</span> do what it wants to do - it only takes a few seconds.
</li>
<li>
Select a video encoder from the pull-down menu on the left pane, where it says <b>Video</b>. I believe this can be anything, but it is preferable to choose the same encoder as the one used in the original movie. I normally use Xvid4 and it works just fine.
</li>
<li>
Configure the encoder by clicking the "Configure" button. In my opinion, no configuration is actually require in order to get an acceptable result. Even one-pass encoding works fine. The only thing that you might want to adjust is the size of the output file.
</li>
<li>
Add a subtitler filter. First click on the "Filters" button in the left pane (under <b>Video</b>). This brings up the following window:<br/>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaL_1I91r-MiLGHnOznGYir1clTnXZ4yPscovt_jJMlMeLjWUGUK6hfQObpSJIegOKRZtAXW1VePV8wTxjV7XezDkbvREk-xcxwwidIJ3h2zM6uWFCqodH1z7YkvuajY2DiMmcGeTJviw/s1600-h/5.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaL_1I91r-MiLGHnOznGYir1clTnXZ4yPscovt_jJMlMeLjWUGUK6hfQObpSJIegOKRZtAXW1VePV8wTxjV7XezDkbvREk-xcxwwidIJ3h2zM6uWFCqodH1z7YkvuajY2DiMmcGeTJviw/s320/5.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077467227736956434" /></a>
Select Subtitles→Subtitler. You can now configure your subtitles using the window shown in the image below.<br/>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFVGD3O0c7lY1Qxl6YbXplmFj9Xw4M33CPIK8tn8uxONKg_nmtHNNEV-udb12AeF1oh75KkP0GYTO7pc-2KN6tNs2tNaqokPfrBpUHVwnfMbTn8IKtRSKB1d_pL74VRha1F5CDCMMHnLE/s1600-h/6.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFVGD3O0c7lY1Qxl6YbXplmFj9Xw4M33CPIK8tn8uxONKg_nmtHNNEV-udb12AeF1oh75KkP0GYTO7pc-2KN6tNs2tNaqokPfrBpUHVwnfMbTn8IKtRSKB1d_pL74VRha1F5CDCMMHnLE/s320/6.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5077467502614863394" /></a>
This window allows you to select the subtitles file, the encoding (it supports UTF-8, so it works fine with non-latin alphabets), and the font, color, size and position of the subtitles.
</li>
<li>
It appears that there is no need to select an audio encoder; "COPY" works just fine (since we do not wish to make any changes to the sound). Make sure that the "Format" is set to "AVI". The result can be previewed by clicking on the far right icon and then pressing play.
</li>
<li>
To finalize the process, click Save and type in a name for the output file. Note that the whole process can take a while. For example in my laptop it took maybe more than an hour to encode a 40min movie file, at an average speed of 16FPS (while doing other stuff as well).
</ol>
</p>Zzzzzhttp://www.blogger.com/profile/00036901020312179850noreply@blogger.com18