Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

How-To Tutorials

7019 Articles
article-image-java-server-faces-jsf-tools
Packt
07 Oct 2009
5 min read
Save for later

Java Server Faces (JSF) Tools

Packt
07 Oct 2009
5 min read
Throughout this article, we will follow the "learning by example" technique, and we will develop a completely functional JSF application that will represent a JSF registration form as you can see in the following screenshot. These kinds of forms can be seen on many sites, so it will be very useful to know how to develop them with JSF Tools. The example consists of a simple JSP page, named register.jsp, containing a JSF form with four fields (these fields will be mapped into a managed bean), as follows: personName – this is a text field for the user's name personAge – this is a text field for the user's age personPhone – this is a text field for the user's phone number personBirthDate – this is a text field for the user's birth date The information provided by the user will be properly converted and validated using JSF capabilities. Afterwards, the information will be displayed on a second JSP page, named success.jsp. Overview of JSF Java Server Faces (JSF) is a popular framework used to develop User Interfaces (UI) for server-based applications (it is also known as JSR 127 and is a part of J2EE 1.5). It contains a set of UI components totally managed through JSF support, like handling events, validation, navigation rules, internationalization, accessibility, customizability, and so on. In addition, it contains a tag library for expressing UI components within a JSP page. Among JSF features, we mention the ones that JSF provides: A set of base UI components Extension of the base UI components to create additional UI component libraries Custom UI components Reusable UI components Read/write application date to and from UI components Managing UI state across server requests Wiring client-generated events to server-side application code Multiple rendering capabilities that enable JSF UI components to render themselves differently depending on the client type JSF is tool friendly JSF is implementation agnostic Abstract away from HTTP, HTML, and JSP Speaking of JSF life cycle, you should know that every JSF request that renders a JSP involves a JSF component tree, also called a view. Each request is made up of phases. By standard, we have the following phases (shown in the following figure): The restore view is built Request values are applied Validations are processed Model values are updated The applications is invoked A response is rendered During the above phases, the events are notified to event listeners We end this overview with a few bullets regarding JSF UI components: A UI component can be anything from a simple to a complex user interface (for example, from a simple text field to an entire page) A UI component can be associated to model data objects through value binding A UI component can use helper objects, like converters and validators A UI component can be rendered in different ways, based on invocation A UI component can be invoked directly or from JSP pages using JSF tag libraries Creating a JSF project stub In this section you will see how to create a JSF project stub with JSF Tools. This is a straightforward task that is based on the following steps: From the File menu, select New | Project option. In the New Project window, expand the JBoss Tools Web node and select the JSF Project option (as shown in the following screenshot). After that, click the Next button. In the next window, it is mandatory to specify a name for the new project (Project Name field), a location (Location field—only if you don't use the default path), a JSF implementation (JSF Environment field), and a template (Template field). As you can see, JSF Tools offers a set of predefined templates as follows: JSFBlankWithLibs—this is a blank JSF project with complete JSF support. JSFKickStartWithLibs—this is a demo JSF project with complete JSF support. JSFKickStartWithoutLibs—this is a demo JSF project without JSF support. In this case, the JSF libraries are missing for avoiding the potential conflicts with the servers that already offer JSF support. JSFBlankWithoutLibs—this is a blank JSF project without JSF support. In this case, the JSF libraries are missing for avoiding the potential conflicts with the servers that already offer JSF support (for example, JBoss AS includes JSF support). The next screenshot is an example of how to configure our JSF project at this step. At the end, just click the Next button: This step allows you to set the servlet version (Servlet Version field), the runtime (Runtime field) used for building and compiling the application, and the server where the application will be deployed (Target Server field). Note that this server is in direct relationship with the selected runtime. The following screenshot shows an example of how to complete this step (click on the Finish button): After a few seconds, the new JSF project stub is created and ready to take shape! You can see the new project in the Package Explorer view.
Read more
  • 0
  • 0
  • 8222

article-image-installing-zenoss
Packt
07 Oct 2009
8 min read
Save for later

Installing Zenoss

Packt
07 Oct 2009
8 min read
Installing Zenoss Our first step is to choose one of the three installation methods: virtual appliance, binary installer, or source. The virtual appliance makes a good choice, if we want to evaluate or demonstrate Zenoss. The virtual appliance runs a functional Zenoss system using VMware Player or VMware Server out-of-the-box and needs no Linux knowledge. When run from VMware, the Zenoss virtual appliance may be used to monitor networks with relatively few devices. The binary installer makes a good choice if we want to avoid building Zenoss from source, and we run a supported distribution. The Supported Operating Systems section in this tutorial includes a list of distributions that have binary installation support. We can build from source on a variety of Unix-based environments, like Ubuntu and Mac OS X. A source installation gives us the ability to install Zenoss in the environment of our choice but requires more work. Of the three installation methods, a source install requires the most familiarity with your operating system and presents more points of failure. As we move beyond installing Zenoss to set up, we focus on firewall policies and Simple Network Management Protocol (SNMP) for Linux and Windows systems. Even though Zenoss can use other methods to monitor devices, SNMP is the default monitoring protocol. We are free to change how we monitor and collect information at any time. During the installation and the set up, we work from the command line because it's fast and it's consistent from one distribution to the next. If an error does occur, we can see the error immediately printed to the terminal window. When working from the command line, we assume knowledge of two basic tasks: opening the terminal window and navigating the file structure. For all other tasks, the book provides the exact command to type. After installation and set up, we spend most of our time working with Zenoss through the web interface. Let's get this installation out of the way so we can discover Zenoss. Server Specifications Actual server specifications may vary depending on the amount and frequency of the data you collect. Zenoss Inc. recommends the following hardware specifications as a starting point based on feedback from the community: Network with up to 250 devices: 4 GB RAM Core 2 Duo E6300 1.86/1066 RTL 75 GB disk storage Network with more than 250 devices : 8 GB RAM XEON 5120 DC 1.86/1066/4MB Four 75 GB drives in two RAID-1 pairs Supported Operating Systems Zenoss requires a Unix-based platform and installs on systems capable of running a GNU build environment. However, Zenoss supports only a few distributions with binary installers. The following table shows the available installation options. Installation Type   Platform   Virtual Appliance   Windows Linux   Binary Installer Red Hat Enterprise Linux 5 Fedora Core 6 SUSE   Source Ubuntu FreeBSD Solaris 10 Mac 0S X Other Linux environments   As more binary installers become available, Zenoss posts them to http://www.zenoss.com/download Zenoss Dependencies Virtual appliance users do not need to install any dependencies because they are included in the image. For all other installations, you need to install the following software packages prior to installing Zenoss: MySQL 5.0.22 or higher MySQL development environment Python 2.3.5 or 2.4 Python development environment If you plan to build a Zenoss installation from source code, you need to install the following: SWIG Autoconf GNU build environment Dependent software packages are available via your distribution's normal software package manager. However, the package names and installation commands vary based on distribution. Consult your distribution's documentation for more information. Quick Start with Virtual Appliance If we know how to download and install software in our host environment, we can get a working Zenoss system with the virtual appliance. The Zenoss virtual appliance packages a working Zenoss Core installation inside a Linux guest that can be booted from a host system, including Windows, using VMware's Player, Server, or Workstation programs. The virtual appliance is great for: Users with little or no Linux knowledge Demonstrations and Evaluations Monitoring small networks with a few devices Install Virtual Appliance We will finish the installation as fast as we can download files and install the VMware Player. Let's begin: Download the VMware Player from http://www.vmware.com/player/.Registration is required to complete the download. Install VMware Player according to VMware's installation instructions for your operating system. Download the Zenoss virtual appliance from http://www.zenoss.com/download/ Unzip the Zenoss virtual appliance download file to a working directory in your system. Open VMware Player: On Windows, select Start > Programs > VMware Player. On Linux, select VMplayer from the application menu, or type the command: vmware VMwarePlayer prompts us to load the virtual machine configuration file we previously unzipped, as shown in the following screenshot: Open the Zenoss virtual appliance we unzipped in step 4.   The Zenoss virtual appliance takes a few minutes to load depending on the performance of your system. When the appliance boots, a welcome window opens and displays the IP address of the Zenoss management console and the standard Linux login prompt, as shown in the following screenshot:                 When we connect to Zenoss through our web browser, we use the IP address of the Zenoss management console that displays on the welcome screen (e.g. http://192.168.1.125.8080/). We cannot access our virtualized Zenoss installation by navigating to localhost, which is the host name of the Zenoss virtual appliance. If the IP address of the Zenoss console does not display, we can obtain the IP address using the ifconfig command, as described in the next section: Working with The Virtual Appliance. Zenoss is ready to monitor. Our next step is to set up the servers on our network to be monitored. If you can't wait to see Zenoss in action, feel free to skip the server setup section for now and check out Tutorial 4 for an introduction to web interface. You can come back and set up your servers later.      If this is the first time you are working with VMware or Linux, take a few minutes to get acquainted with the environment.      Working with The Virtual Appliance The Zenoss virtual appliance is a streamlined but functional Linux system, which means we can log in and have access to the underlying Linux environment. Let's cover a few basic tasks.      In order to type inside the virtual appliance window, use the keyboard shortcut: Ctrl + G      To return the cursor to the host desktop, use the keyboard shortcut: Ctrl + Alt      By default, the root login does not have a password assigned. To log in to the virtual appliance, enter the following user name at the login prompt: root   To set a password for the root user, enter the command:      passwd The passwd command prompts us to enter a new password. Assigning a password to the root user makes the system more secure and allows us to connect to the virtual appliance as root via SSH.      The IP address of the Zenoss virtual appliance is displayed at the top of the terminal window when the appliance loads. The most confusing part about using the Zenoss virtual appliance may be picking the correct IP address and port number. We connect to Zenoss on port 8080. So if our virtual appliance has an IP address of 192.168.1.103, then we use http://192.168.1.103:8080/o open the Zenoss login screen. If we use port 8003, we access the rPath management console, which is the underlying system used to build the Zenoss virtual appliance. After login, we can find additional IP configuration as shown in the following screenshot, with the command: ifconfig     To shut down the virtual appliance, select Player > Exit from the VMware Player. We may also use the the command: shutdown -h now If we shut down the virtual appliance, Zenoss no longer monitors the network and the web interface is not accessible.We may now jump ahead to the Server Setup section of this tutorial for help in configuring the servers we wish to monitor. Binary Installation Zenoss provides a binary installer in RPM format for Red Hat Enterprise Linux, which covers CentOS and Fedora Core. Binaries for additional distributions are added by Zenoss as the market demands and as time allows. To install Zenoss and its dependencies on Red Hat: Download the latest RPM for Red Hat Enterprise Linux from http://www.zenoss.com/download/ Open a terminal window and become the root user: su - If you have not yet installed the Zenoss dependencies, run: yum -y install mysql mysql-server net-snmp net-snmp-utils / python python-dev Install the Zenoss RPM by running the following command from the download directory where x.x-x equals the latest version number: rpm -ivh zenoss-2.x.x-x.el5.i386.rpm Start SNMP: service snmp start Start MySQL: service mysqld start Start Zenoss: /etc/init.d/zenoss start Let's test our installation. Open a browser and enter the URL of the Zenoss server, which listens on port 8080 (for example http://192.168.115:8080/ ). A screen appears as shown in the following screenshot.  
Read more
  • 0
  • 0
  • 9064

article-image-transferring-data-ms-access-2003-sql-server-2008
Packt
07 Oct 2009
3 min read
Save for later

Transferring Data from MS Access 2003 to SQL Server 2008

Packt
07 Oct 2009
3 min read
Launching the Import and Export Wizard Click Start | All Programs| SQL Server 2008 and click on Import and Export Data (32 bit) as shown in the next figure. This brings up the - "Welcome to the SQL Server Import and Export Wizard”. Make sure you read the explanation on this window. Connecting to Source and Destination databases You will connect to the source and destination. In this example the data to be transferred is in a MS Access 2003 database. A table in the Northwind.mdb file available in MS Access will be used for the source. The destination is the 'tempdb' database (or the master database). These are chosen for no particular reason and you can even create a new database on the server at this point. Connecting to the Source Click Next. The default window gets displayed as shown. The data source is SQL Server Native Client 10.0. As we are transferring from MS Access 2003 to SQL Server 2008 we need to use an appropriate data source. Click on the drop-down handle for the data source and choose Microsoft Access as shown in the next figure. The 'SQL Server Import and Export Wizard' changes to the following. Click on the Browse... button to locate the Northwind.mdb file on your machine also as shown. For Username use the default 'Admin'. Click the Advanced button. It opens the Data Link properties window as shown. You can test the connection as well as look at other connection related properties using the Connection and Advanced tabs. Click OK to the Microsoft Data Link message as well as to the Data Link Properties window. Click Next. Choose Destination The Choose a Destination page of the wizard gets displayed. The Destination source (SQL Server Native Client 10.0) and the Server name that automatically shows up are defaults. These may be different in your case. Accept them. The authentication information is also correct (the SQL Server is configured for Windows Authentication). Click on the drop-down handle for the Database presently displaying <default> as shown. Choose tempdb and click on the Next button. Choosing a table or query for the data to be transferred You can transfer data in table or tables; view or views by copying them over, or you may create a query to collect the data you want transferred. In this article both options will described. Copying a table over to destination The Specify Table Copy or Query page of the wizard gets displayed as shown. First we will copy data from a table. Later we will see how to write a query to do data transfer. Click Next. The Select Source Tables and Views page gets displayed as shown. When you place a check mark for say, Customers, the Destination column gets an entry for the selection you made. We assume that just this table is transferred. However you can see that you can transfer all of them in one shot. This window also helps you with two more important things. First you can Preview... the data you are transferring. Secondly, you can edit the mappings, the scheme of how source columns go over to destination.
Read more
  • 0
  • 0
  • 7507

article-image-guided-rules-jboss-brms-guvnor
Packt
07 Oct 2009
7 min read
Save for later

Guided Rules with the JBoss BRMS (Guvnor)

Packt
07 Oct 2009
7 min read
Passing information in and out The main reason for the simplicity of our Hello World example was that it neither took in any information, nor passed any information out—the rule always fired, and said the same thing. In real life, we need to pass information between our rules and the rest of the system. You may remember that in our tour of the Guvnor, we came across models that solved this problem of 'How do we get information into and out of the rules?'. Here is the spreadsheet that we will use as an example in this article: If we want to duplicate this in our model/JavaBean, we would need places to hold four key bits of sales-related information. Customer Name: String (that is, a bit of text) Sales: Number Date of Sale: Date Chocolate Only Customer: Boolean (that is, a Y/N type field) We also need a description for this group of information that is useful when we have many spreadsheets/models in our system (similar to the way this spreadsheet tab is called Sales). Note that one JavaBean (model) is equal to one line in the spreadsheet. Because we can have multiple copies of JavaBeans in memory, we are able to represent the many lines of information that we have in a spreadsheet. Later, we'll loop and add 10, 100, or 1000 lines (that is, JavaBeans) of information into Drools (for as many lines as we need). As we loop, adding them one at a time, the various rules will fire as a match is made. Building the fact model We will now build this model in Java using the Eclipse editor. We're going to do it step-by-step. Open the Eclipse/JBoss IDE editor that you installed earlier. If prompted, use the default workspace. (Unless you've a good reason to put it somewhere else.) From the menu bar at the top the screen, select File | New Project. Then choose Java Project from the dialog box that appears. You can either select this by starting to type "Java Project" into the wizard, or by finding it by expanding the various menus. In the Create a new Java Project dialog that appears, give the project a name in the upper box. For our example, we'll call it SalesModel (one word, no spaces). Accept the other defaults (unless you have any other reason to change them). Our screen will now look something like this: When you've finished entering the details, click on Finish. You will be redirected to the main screen, with a new project (SalesModel) created. If you can't see the project, try opening either the Package or the Navigator tab. When you can see the project name, right-click on it. From the menu, choose New | Package. The New Java Package dialog will be displayed, as shown below. Enter the details as per the screenshot to create a new package called org.sample, and then click on Finish. If you are doing this via the navigator (or you can take a peek via Windows Explorer), you'll see that this creates a new folder org, and within it a subfolder called sample. Now that we've created a set of folders to organize our JavaBeans, let's create the JavaBean itself by creating a class. To create a new Java class, expand/select the org.sample package (folder) that we created in the previous step. Right-click on it and select New Class. Fill in the dialog as shown in the following screenshot, and then click on Finish: We will now be back in the main editor, with a newly created class called Sales.java (below). For the moment, there isn't much there—it's akin to two nested folders (a sample folder within one called org) and a new (but almost empty) file / spreadsheet called Sales. package org.sample;public class Sales {} By itself, this is not of much use. We need to tell Java about the information that we want our class (and hence the beans that it creates) to hold. This is similar to adding new columns to a spreadsheet. Edit the Java class until it looks something like the code that follows (and take a quick look of the notes information box further down the page if you want to save a bit of typing). If you do it correctly, you should have no red marks on the editor (the red marks look a little like the spell checking in Microsoft Word). package org.sample;import java.util.Date;public class Sales {private String name;private long sales;private Date dateOfSale;private boolean chocolateOnlyCustomer;public String getName() {return name;}public void setName(String name) {this.name = name;}public long getSales() {return sales;}public void setSales(long sales) {this.sales = sales;}public Date getDateOfSale() {return dateOfSale;}public void setDateOfSale(Date dateOfSale) {this.dateOfSale = dateOfSale;}public boolean isChocolateOnlyCustomer() {return chocolateOnlyCustomer;}public void setChocolateOnlyCustomer(boolean choclateOnlyCustomer) {this.chocolateOnlyCustomer = chocolateOnlyCustomer;}} Believe it or not, this piece of Java code is almost the same as the Excel Spreadsheet we saw at the beginning of the article. If you want the exact details, let's go through what it means line by line. The braces ({ and }) are a bit like tabs. We use them to organize our code. package—This data holder will live in the subdirectory sample within the directory org. import—List of any other data formats that we need (for example, dates). Text and number data formats are automatically imported. Public class Sales—This is the mould that we'll use to create a JavaBean. It's equivalent to a spreadsheet with a Sales tab. Private String name—create a text (string) field and give it a column heading of 'name'. The private bit means 'keep it hidden for the moment'. The next three lines do the same thing, but for sales (as a number/long), dateOfSale (as a date) and chocolateOnlyCustomer (a Boolean or Y/N field). The rest of the lines (for example, getName and setName) are how we control access to our private hidden fields. If you look closely, they follow a similar naming pattern. The get and set lines (in the previous code) are known as accessor methods. They control access to hidden or private fields. They're more complicated than may seem necessary for our simple example, as Java has a lot more power than we're using at the moment.Luckily, Eclipse can auto-generate these for us. (Right-click on the word Sales in the editor, then select Source | Generate Getters and Setters from the context menu. You should be prompted for the Accessor methods that you wish to create.) Once you have the text edited like the sample above, check again that there are no spelling mistakes. A quick way to do this is to check the Problems tab in Eclipse (which is normally at the bottom of the screen). Now that we've created our model in Java, we need to export it so that we can use in the Guvnor. In Eclipse, right-click on the project name (SalesModel) and select Export. From the pop-up menu, select jar (this may be under Java; you might need to type jar to bring it up). Click on Next. The screen shown above will be displayed. Fill out this screen. Accept the defaults, but give the JAR file a name (SalesModel.jar) and a location (in our case C:tempSalesModel.jar). Remember these settings as we'll need them shortly. All being well, you should get an 'export successful' message when you click on the Finish button, and you will be able to use Windows Explorer to find the JAR file that you just created.
Read more
  • 0
  • 0
  • 2477

article-image-exporting-data-ms-access-2003-mysql
Packt
07 Oct 2009
4 min read
Save for later

Exporting data from MS Access 2003 to MySQL

Packt
07 Oct 2009
4 min read
Introduction It is assumed that you have a working copy of MySQL which you can use to work with this article. The MySQL version used in this article came with the XAMPP download. XAMPP is an easy to install (and use) Apache distribution containing MySQL, PHP, and Perl. The distribution used in this article is XAMPP for Windows. You can find documentation here. Here is a screen shot of the XAMPP control panel where you can turn the services on and off and carry out other administrative tasks. You need to follow the steps indicated here: Create a database in MySQL to which you will export a table from Microsoft Access 2003 Create a ODBC DSN that helps you connecting Microsoft Access to MySQL Export the table or tables Verify the exported items Creating a database in MySQL You can create a database in MySQL by using the command 'Create Database' in MySQL or using a suitable graphic user interface such as MySQL workbench. You will have to refer to documentation that works with your version of MySQL. Herein the following version was used. The next listing shows how a database named TestMove was created in MySQL starting from the bin folder of the MySQL program folder. Follow the commands and the response from the computer. The Listing 1 and the folders are appropriate for my computer and you may find it in your installation directory. The databases you will be seeing will be different from what you see here except for those created by the installation. Listing 1: Login and create a database Microsoft Windows XP [Version 5.1.2600](C) Copyright 1985-2001 Microsoft Corp.C:Documents and SettingsJayaram Krishnaswamy>cdC:>cd xamppmysqlbinC:xamppmysqlbin>mysql -h localhost -u root -pEnter password: *********Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 2Server version: 5.1.30-community MySQL Community Server (GPL)Type 'help;' or 'h' for help. Type 'c' to clear the buffer.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || cdcol || expacc || mengerie || mydb || mysql || phpmyadmin || test || testdemo || webauth |+--------------------+10 rows in set (0.23 sec)mysql> create database TestMove;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || cdcol || expacc || mengerie || mydb || mysql || phpmyadmin || test || testdemo || testmove || webauth |+--------------------+11 rows in set (0.00 sec)mysql> The login detail that works error free is shown. The preference for host name is localhost v/s either the Machine Name (in this case Hodentek2) or the IP address. The first 'Show Databases' command does not display the TestMove we created which you can see in response to the 2nd Show Databases command. In windows the commands are not case sensitive. Creating an ODBC DSN to connect to MySQL When you install from XAMPP you will also be installing an ODBC driver for MySQL for the version of MySQL included in the bundle. In the MySQL version used for this article the version is MySQL ODBC5.1 and the file name is MyODBC5.dll. Click Start | Control Panel | Administrative Tools | Data Sources (ODBC) and open the ODBC Data Source Administrator window as shown. The default tab is User DSN. Change to System DSN as shown here. Click the Add... button to open the Create New Data Source window as shown. Scroll down and choose MySQL ODBC 5.1 Driver as the driver and click Finish. The MySQL Connector/ODBC Data Source Configuration window shows up. You will have to provide a Data Source Name (DSN) and a description. The server is the localhost. You must have your User Name/Password information to proceed further. The database is the name of the database you created earlier (TestMove) and this should show up in the drop-down list if the rest of the information is correct. Accept the default port. If all information is correct the Test button gets enabled. Click and test the connection using the Test button. You should get a response as shown. Click the OK button on the Test Result window. Click OK on the MySQL Connector/ODBC Data Source Configuration window. There are a number of other flags that you can set up using the 'Details' button. The defaults are acceptable for this article. You have successfully created a System DSN 'AccMySQL' as shown in the next window. Click OK. Verify the contents of TestMove The TestMove is a new database created in MySQL and as such it is empty as you verify in the following listing. Listing 2: Database TestMove is empty mysql> use testmove;Database changedmysql> show tables;Empty set (0.00 sec)mysql>
Read more
  • 0
  • 0
  • 9070

article-image-advanced-collaboration-using-alfresco-share
Packt
06 Oct 2009
5 min read
Save for later

Advanced Collaboration using Alfresco Share

Packt
06 Oct 2009
5 min read
Today, collaboration and team effort have become critical factors, both inside and outside of the workplace. More and more users want simplicity and familiarity with the tools they use day in and day out. They achieve this by searching in Google, reading in Wikipedia, writing on a blog, finding people on Facebook, being notified in a simple RSS reader, viewing friends, activities on Facebook, and bringing all of this together in iGoogle. Alfresco Share delivers all of this functionality to enterprise users, projects, and teams. Imagine a business user, if given the permission, being able to set up their project web site quickly, being able to invite users to the site, and assign permissions to users within that web site. What previously required a customized solution is now offered out of the box by Alfresco Share. Alfresco Share Alfresco Share (referred to simply as Share from now on) is built on the Alfresco enterprise-class document repository, and delivers out of the box collaborative content management. It simplifies the capture, sharing, and retrieval of information across virtual teams. Team members or project members can rapidly find relevant content or excerpts, look at past or similar projects, and stay on top of any relevant changes, in order to make them more efficient. Share is focused on collaboration tasks and includes integration with popular blogging, Wiki, and forum or discussion products, out of the box. It provides a great interface into more traditional document management libraries (think folders) as well. Keep in mind that all of the web site's contents and documents are still stored in the Alfresco repository. Therefore they are secured, versioned, searchable, and auditable. Share is an independent client application that accesses the repository through web scripts. It is built on the Alfresco Surf (referred to simply as Surf from now on) platform. Alfresco Share is a web application that runs on a machine that is separate from that of the repository. Share provides a paradigm for creating collaborative applications by aggregating Surf components, and incorporating new Surf components as they are developed. With Share, users can modify their workspaces to fit their collaborative requirements inside or outside of the organization. Users can invite their peers to share and collaborate on the project and the content. With the addition of Share, Alfresco delivers a Web 2.0 application that leverages Flash and AJAX with a polished interface, which any business person can enjoy. Features like Document Libraries, Search, Activity Feeds, Virtual Teams, personalized dashboard, N-tier Architecture, and draft CMIS support make it a really competent tool for collaborative content management. Share allows you to: Bulk-upload content, select content from thumbnails, and view it in a Flash viewer. The content is automatically generated in Flash format. This allows users to view content regardless of the original format. Search for people and experts to contribute to their projects as easily as searching for content. Share provides updates on what is new in a project, especially details of content that has been added, edited, or commented upon. Share can track deliverables and import the information into your personal calendar by using iCal. Use an interactive interface to configure a customizable dashboard, and sites, based on what is critical to a specific role or project. Share allows you to create a virtual team for projects and communities. Develop applications in an environment that uses lightweight scripting and reusable components, as well as deliver scalability and allow more users to access existing resources. The URL to access the Alfresco Share application is different from the URL used to access Alfresco Explorer. The Alfresco Share application can be launched in the web browser by visiting the URL, http://<server name> /share/ If you have already installed Alfresco in Windows, then you can invoke the Alfresco Share application by selecting the application, as shown in the following screenshot: You need to provide your authentication credentials, which are similar to those used in the Alfresco Share application. For the administrator, the default username and password are both admin. Once you have been authenticated, the Administrator Dashboard will be displayed, as shown in the following screenshot. At the top of the page you will find the application toolbar. This toolbar contains links to the various Share pages. Your Administrator Dashboard will look similar to the following screenshot: These components are as follows: Getting Started: This dashlet displays the instructions for getting started, and provides you with links to perform common tasks My Profile: This dashlet contains a summary of the personal details provided in your user profile Sites: This component displays the Site Finder page, where you can search for specific sites and manage the membership of Share sites People: This component displays the People Finder page, where you search for specific Share users Help: This component displays the online help available for Alfresco Share Logout: This component logs you out of the Alfresco Share application Search: This component enables you to perform a quick search for content in the current site, or across all of the sites
Read more
  • 0
  • 0
  • 2851
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at €18.99/month. Cancel anytime
article-image-common-recovery-tools-active-directory-part-1
Packt
06 Oct 2009
8 min read
Save for later

Common Recovery Tools in Active Directory: Part 1

Packt
06 Oct 2009
8 min read
Software for your DCs and administration Although the software packages installed on the DCs might not be a specific recovery step in the true sense, when you are hard-pressed for time you don't want to start looking for tools and programs; you want to have them installed and ready to work on, anywhere you need. There are many tools. Instead of copying the specific executables to your DCs, it is much easier to install the toolkits as part of the deployment when you install a DC. Windows support tools For both Windows 2000 and Windows 2003, the support tools package is a must-have. This is included on the installation CD under Support/Tools, as shown in the following screenshot, which shows the contents of a 64-bit installation CD. The location of Windows 2003 Small Business Server Support Tools is on CD 2 of the SDS CD set. As you can see, what Microsoft considers the most essential tools, namely DcDiag.exe and Repadmin.exe, are available as standalone executables. Among many medium and large-sized organizations, it is considered a best practice to install the support tools on every DC. This is so because the support tools package provides you with essential tools that you can use for troubleshooting when errors appear in the event log, or the DC starts behaving strangely. Once you have the Support Tools installed, you will have an additional entry in your Start menu for Windows support tools, which contains a link to the Help file and a shortcut to the command prompt. Windows Resource Kit tools The Windows Resource Kit traditionally only came as books in the NT 4.0 era. With Windows 2000, Microsoft started making the tools that are included in the Resource Kit available online for free download. You can still purchase the books as well, which are quite useful because they describe each tool and its application in great detail. However, the tools themselves can easily be downloaded. The links are listed here: For Windows 2000 (Server and Advanced Server): http://support.microsoft.com/kb/927229. For Windows Server 2003 32bit: http://www.microsoft.com/Downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en. For Windows Server 2003 64bit, there is no Resource Kit because Microsoft's website clearly states that the tools are not supported on 64-bit platforms. Given that the tools can be run from any XP client as well, this is not much of an issue unless you want to run a complete 64-bit server environment, and would like to distribute the tools with the DCs. One option is to have a virtual DC that runs Windows Server 2003 in 32-bit mode. As only a handful of tools are necessary for Disaster Recovery, and you can run the tools from a client, it does not matter that much. The main point is that the tools should be available somewhere close to the DCs in every location. So, if you run them from a client, it might be a good idea to copy the tools onto the administration PC. A good option is to keep a CD copy of these tools stored with the Disaster Recovery Guide. Adminpack for Windows XP/Vista Clients The Administrative Tools package (Adminpack) is the least-used administrator tool in most organizations. Although it is considered a best practice to install Adminpack onto the administrative PCs or the PCs of the IT department, this is rarely done. In several cases, a lot of the administrative tasks are performed via Remote Desktop, directly on the DCs. This, of course, means that you have to give all of the people who make even small changes in the AD access to log on to the DCs. This might not be a good idea from a security perspective and can lead to actions that could have been prevented, such as downloading things directly to the DC, and installing or copying/modifying settings on the DC directly. As DCs are the heart that make AD work, these machines should be as secure and isolated as possible. The Adminpack is actually a file called adminpack.msi, which can be found in the i386 folder on the 32-bit installation CD of Windows 2000 and Windows server 2003. It is also in the same directory on the 64-bit installation CD, but there it is called wadminpack.msi. The Adminpack contains the necessary snap-ins for the Microsoft Management Console (MMC), and puts them into your Administrative tools folder. These snap-ins are the normal tools you would have on a DC in order to administer the AD (shown in the following screenshot). It is, however, possible to run them directly from your client instead of on the DC. Using the Adminpack also allows you to re-target the tools to different DCs and you don't have to log on every time. Diagnosing and troubleshooting tools In this section we are going through some of the more advanced uses and possibilities of three tools that will undoubtedly be of great help in diagnosing either AD problems or replication problems. The three tools that almost every person who needs to perform troubleshooting on Windows Server 2003 should be familiar with are NetDiag.exe, DcDiag.exe, and Repadmin.exe. All three are command-line utilities, which implies that they can be run from a Windows XP Professional or Windows Vista workstation, and that they are standalone executables that can be copied from one machine to another. A nice feature of these tools is that they connect remotely to the DCs via the Remote Procedure Call service (RPC) and therefore you do not need to log on to the DCs. The only requirement for most of them is that they need to run from a machine that is a member of the domain and has access to the network. DcDiag DcDiag is the domain controller diagnostic utility. It allows you to diagnose a domain controller, and check if everything is ok. If it is not, then the tests will run until failure, and based on which tests fail, you can go about finding the cause. Even though this may sound rather simple, this utility, even if run without any flags or options, will execute a set of very meaningful tests, and based on pass or fail, you will have a very good idea of where to start looking. The tests performed are listed in the following tables: Primary tests Descriptions Connectivity Tests whether or not the DC is connected to the network Replications Tests to ensure replications can be started, and are run on time NCSecDesc Checks that the security descriptors on the naming context heads have appropriate permissions for replication NetLogons Tests if the DC allows the appropriate logons to initiate replication Advertising Tests if the DC can advertise itself (DNS) KnowsOfRoleHolders Tests if the DC knows which servers hold the FSMO roles RidManager Tests if the DC can contact the RidManager Machine Account Tests if the DC has a valid Machine Account Services Tests if the necessary services are running on the DC ObjectsReplicated Tests whether or not the DSA and Machine Account objects have ever been replicated frssysvol Checks if the sysvol share is listed in the File Replication Service (FRS) frsevent Tests if FRS errors have been generated kccevent Tests if KCC errors have been generated systemlog Tests if there are system errors VerifyReferences Tests if AD FRS records are intact and correct for the replication infrastructure DNS Partition tests Descriptions Forest DNS tests CrossRefValidation Checks if the replication cross-references are intact in the forest DNS zone CheckSDRefDom Checks if the Security descriptors for the forest are intact Domain DNS tests CrossRefValidation Checks if the replication cross-references are intact in the domain DNS zone CheckSDRefDom Checks if the Security descriptors for the domain are intact Schema, Configuration, and Enterprise tests Descriptions Schema tests CrossRefValidation Checks if the replication cross-references are intact in the schema itself CheckSDRefDom Checks if the Security descriptors within the schema are intact Configuration CrossRefValidation Checks if the replication cross-references are intact in the current forest configuration CheckSDRefDom Checks if the Security descriptors within the configuration are intact Partition tests CrossRefValidation Checks if the replication cross-references are intact in the current application partition CheckSDRefDom Checks if the Security descriptors for the application partition are intact Enterprise tests Intersite Checks if the inter-site replication can be initiated FSMOCheck Checks that all FSMO roles are assigned and can be contacted As you can see, DCDiag performs a lot of tests. But bear in mind that most of these are run locally on the DC with the data held by that DC. This means that any error in the DNS, Schema, configuration or partition tests can be working on another DC. It is possible that only this particular replica of the DC is malfunctioning.
Read more
  • 0
  • 0
  • 1655

article-image-finding-and-fixing-joomla-15x-customization-problems
Packt
06 Oct 2009
12 min read
Save for later

Finding and Fixing Joomla! 1.5x Customization Problems

Packt
06 Oct 2009
12 min read
Understanding common errors There are five main areas that cause the majority of problems for Joomla! sites. Understanding these areas and the common problems that occur with in each of them is a very important part of fixing them and thus, our site. Even though there is a practically unlimited number of potential issues and problems that can occur, there are certain problems which occur much more regularly than others. If we understand these main problems, we should be able to take care of many of the problems that will occur on our site without needing to resort to hiring people to fix them, or waiting for extension developers to provide support. The five areas are: PHP code JavaScript code CSS/HTML code Web server Database We will now look at the two most common error sources, PHP and JavaScript. PHP code Because PHP code is executed on the server, we usually have some control over the conditions that it is subject to. Most PHP errors originate from one of four sources: Incorrect extension parameters PHP code error PHP version Server settings Incorrect extension parameters It is often easy to misunderstand what the correct value for an extension parameter is, or if a particular parameter is required or not. These misunderstandings are behind a large number of PHP "errors" that developers experience when building a site. Diagnosis In a well-coded extension, putting the wrong information into a parameter shouldn't result in an error, but will usually result in the extension producing strange or unexpected output, or even no output at all. In a poorly coded extension, an incorrect parameter value will probably cause an error. These errors are often easy to spot, especially in modules, because our site will output everything it processed up until the point of the error, giving our page the appearance of being cut off. Some very minor errors may even result in the whole page, except for the error causing extension, being output correctly, and error messages appearing in the page, where the extension with the error was supposed to appear. A critical error, however, may cause the site to crash completely, and output only an error message. In extreme cases not even an error message will be output, and visitors will only see a white screen. The messages should always appear in our PHP log though. Fixing the problem Incorrect extension parameters are the easiest problems to fix, and are often solved simply by going through the parameter screens for the extensions on the page with the errors, and making sure they all have correct values. If they all look correct, then we may want to try changing some parameters to see if that fixes the issue. If this still doesn't work, then we have a genuine error. PHP code error Extension developers aren't perfect, and even the best ones can overlook or miss small issues in the code. This is especially true with large, complex extensions so please remember that even if an extension has PHP code error, it may not necessarily mean that the whole extension is poorly coded. Diagnosis Similar to incorrect extension parameters, a PHP coding error will usually result in a cut-off page, or a white screen, sometimes with an error message displayed, sometimes without. Whether an error message is displayed or not depends partly on the configuration of your server, and partly on how severe the error was. Some servers are configured to suppress error output of certain types of errors. Regardless of the screen output, all PHP errors should be output to the PHP log. So, if we get a white screen, or even get a normal screen but strange output, checking our PHP log can often help us to find the problem. PHP logs can reside in different places on differently configured servers, although it will almost always be in a directory called logs. We may also not have direct access to the log, again depending on our server host. We should ask our web hosting company's support staff for the location of our PHP log, if we can't easily find it. Some common error messages and causes are: Parse error: parse error, unexpected T_STRING in... This is usually caused by a missing semi-colon at the end of a line, or a missing double quote (") or end bracket ()) after we opened one. For quotes and semicolons, the problem is usually the line above the one reported in the error. For missing brackets, the error will sometimes occur at the end of the script, even though the problem code is much earlier in the script. Parse error: syntax error, unexpected $end in... We are most likely missing a closing brace (}) somewhere. Make sure that each open brace ({) we have has been closed with a closing brace (}). Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in... There may be double quotes within double quotes. They either need to be escaped, using a forward slash before the inside quote, or changed to single quotes. Fixing the problem Fixing a PHP code error is possible but can be difficult depending on the extension. Usually when there is a PHP code error, it will give a brief description of the error, and a line number. If nothing is being output at all, then we may need to turn error reporting up as described later. We will then go to the line specified to examine it and the lines around it to try and find our problem. If we can't find an obvious error, then it might be better to take the error back to the developer and ask them for support. PHP version The current version of PHP is 5.x.x and version 6.x is expected soon, but because many older, but still popular, applications only run on PHP version 4.x.x. It is still very common to find many Web hosting companies still using PHP 4 on their servers. This problem is even more unfortunate due to the fact that PHP 4 isn't even supported anymore by the PHP developers. In PHP 5, there are many new functions and features that don't exist in PHP 4. As a result, using these functions in an extension will cause it to error when run on a PHP 4 server. Diagnosis Diagnosing if we have the wrong PHP version is not obvious, as it will usually result in an error about an unknown function when the extension tries to call a function that doesn't exist in the version of PHP installed on our server. Sometimes, the error will not be that the function is unknown, but that the number of parameters we are sending it is incorrect if they were changed between PHP 4 and PHP 5. Fixing the problem The only real way to fix the problem is to upgrade our PHP version. Some web hosts offer PHP 4 or 5 as an option and it might be as simple as checking a box or clicking a button to turn on PHP 5. In case if our host doesn't offer PHP 5 at all, the only solution is to use a different extension or change our web host. This may actually be a good idea anyway, because if our host is still using an unsupported PHP version with no option to upgrade, then what other unsupported, out of date software is running those servers? Server settings One of the most common problems encountered by site owners in regards to server settings is file permissions. Many web hosting companies run Linux, which uses a three-part permission model, on their servers. Using this model, every file can have separate permissions set for: The user who owns the particular file Other users in the same user group as the owner Everyone else (in a web site situation this is mainly the site visitors) Each file also has three permissions that enable, or disable, certain actions on the file. These permissions are read, write, and execute. Permissions are usually expressed in one of two ways, first as single characters in a file listing or as a three digit number. For example, a file listing on a Linux server might look like this: drwxr-x--- 2 auser agroup 4096 Dec 28 04:09 tmp-rwxr-x--- 1 auser agroup 345 Sep 1 04:12 somefile.php-rwxr--r-- 1 auser agroup 345 Sep 1 04:12 foo The very first character to the left, a d or – in this case, indicates if this is a directory (the d) or a file (the -). The next nine characters indicate the permissions and who they apply to. The first three belong to the file owner, next three to those in the same group as the owner, and the final three to everyone else. The letters used are: r—read permission w—write permission x—execute permission A dash (-) indicates that this permission hasn't been given to those particular people. So in our example above, tmp.php can be read, written to, or executed by the owner (a user). It can be read or executed (but not written to) by other users in the same group (agroup) as the owner, but the file cannot be used at all by people outside the group.foo however, can be read by people in the owners group, and also read by everyone else, but it cannot be executed by them. As mentioned above, permissions are also often expressed as a three-digit number. Each of the digits represents the sum of the numbers that represent the permissions granted. For example: r = 4, w = 2, and x = 1. Adding these together gives us a number from 0-7, which can indicate the permission level. So a file with a permission level of 644 would translate as: 6 = 4 + 2 = rw4 = r4 = r or -rw-r--r-- in the first notation that we looked at. Most servers are set by default to one of the following: 644 -rw-r--r--755 -rwxr-xr-x775 -rwxrwxr-x All of this looks fine so far. The problems start to creep in depending on how the server runs their PHP. PHP can either be set up to run as the same user who owns all the files (usually our FTP user or hosting account owner), or it can be set up to run as a different user, but in the same group as the owner. Or it can be set up to be a completely different user and group, as illustrated here: The ideal setup, from a convenience point of view, is the first one where PHP is executed as the same user who owns the files. This setup should have no problems with permissions. But the ideal setup for a very security-conscious web host is the third one since the PHP engine can't be used to hack the web site files, or the server itself. A web server with this setup though used to have a difficult time running a Joomla! site. It was difficult because changing the server preferences requires that files be edited by the PHP user, uploading extensions means that folders and files need to be created by the PHP user, and so on. If the PHP engine isn't even in the same group as the file owner, then it gets treated the same as any site visitor and can usually only read, and probably execute files, but not change them. This prevents us from editing preferences or uploading new extensions. However, if we changed the files so that the PHP engine could edit and execute them (permission 777, for example) then anyone who can see our site on the internet can potentially edit and execute our files by themselves, making our site very vulnerable to being hacked by even a novice hacker. We should never give files or directories a permission of 777 (read, write, and execute to all three user types) because it is almost guaranteed that our site will be hacked eventually as a result. If, for some reason, we need to do it for testing, or because we need to in order to install extensions, then we should change it back as soon as possible. Diagnosis To spot this problem is relatively simple. If we can't edit our web site configuration, or install any extensions at all, then nine times out of ten, server permissions will be the problem. Fixing the problem We can start by asking our web host if they allow PHP to be run as CGI, or install suEXEC (technical terms for running it as the same user who owns the files) and if so, how do we set it up. If they don't allow this, then the next best situation is to enable the Joomla! FTP layer in our configuration. This will force Joomla! to log into our site as the FTP user, which is almost always the same user that uploaded the site files, and edit or install files. We can enable the FTP layer by going to the Site | Global Configuration page and then clicking on the server item in the menu below the heading. We can then enter the required information for the FTP layer on this screen. The FTP layer should only be used on Linux-based servers. More information about the FTP layer can be found in the official Joomla! documentation at http://help.joomla.org/content/view/1941/302/1/2/ If for some reason the FTP layer doesn't work, we only have two other options. We could change our web hosting provider as one option. Or, whenever we want to install a new extension or change our configuration, we need to change the permissions on our folders, perform our tasks, and then change the permissions back to their original settings.
Read more
  • 0
  • 0
  • 5739

article-image-data-access-methods-flex-3
Packt
06 Oct 2009
4 min read
Save for later

Data Access Methods in Flex 3

Packt
06 Oct 2009
4 min read
Flex provides a range of data access components to work with server-side remote data. These components are also commonly called Remote Procedure Call or RPC services. The Remote Procedure Call allows you to execute remote or server-side procedure or method, either locally or remotely in another address space without having to write the details of that method explicitly. (For more information on RPC, visit http://en.wikipedia.org/wiki/Remote_procedure_call.) The Flex data access components are based on Service Oriented Architecture (SOA). The Flex data access components allow you to call the server-side business logic built in Java, PHP, ColdFusion, .NET, or any other server-side technology to send and receive remote data. In this article by Satish Kore, we will learn how to interact with a server environment (specifically built with Java). We will look at the various data access components which includes HTTPService class and WebService class. This article focuses on providing in-depth information on the various data access methods available in Flex. Flex data access components Flex data access components provide call-and-response model to access remote data. There are three methods for accessing remote data in Flex: via the HTTPService class, the WebService class (compliant with Simple Object Access Protocol, or SOAP), or the RemoteObject class. The HTTPService class The HTTPService class is a basic method to send and receive remote data over the HTTP protocol. It allows you to perform traditional HTTP GET and POST requests to a URL. The HTTPService class can be used with any kind of service-side technology such as JSP, PHP, ColdFusion, ASP, and so on. The HTTP service is also known as a REST-style web service. REST stands for Representational State Transfer. It is an approach for getting content from a web server via web pages. Web pages are written in many languages such as JSP, PHP, ColdFusion, ASP, and so on that receive POST or GET requests. Output can be formatted in XML instead of HTML, which can be used in Flex applications for manipulating and displaying content. For example, RSS feeds output standard XML content when accessed using URL. For more information about REST, see www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm. Using the HTTPService tag in MXML The HTTPService class can be used to load both static and dynamic content from remote URLs. For example, you can use HTTPService to load an XML fi le that is located on a server, or you can also use HTTPService in conjunction with server-side technologies that return dynamic results to the Flex application. You can use both the HTTPS and the HTTP protocol to access secure and non-secure remote content. The following is the basic syntax of a HTTPService class: <mx:HTTPService id="instanceName" method="GET|POST|HEAD|OPTIONS|PUT|TRACE|DELETE" resultFormat="object|array|xml|e4x|flashvars|text" url="http://www.mydomain.com/myFile.jsp" fault="faultHandler(event);" result="resultHandler(event)"/> The following are the properties and events: id: Specifies instance identifier name method: Specifies HTTP method; the default value is GET resultFormat: Specifies the format of the result data url: Specifies the complete remote URL which will be called fault: Specifies the event handler method that'll be called when a fault or error occurs while connecting to the URL result: Specifies the event handler method to call when the HttpService call completed successfully and returned results When you call the HTTPService.send() method, Flex will make the HTTP request to the specified URL. The HTTP response will be returned in the result property of the ResultEvent class in the result handler of the HTTPService class. You can also pass an optional parameter to the send() method by passing in an object. Any attributes of the object will be passed in as a URL-encoded query string along with URL request. For example: var param:Object = {title:"Book Title", isbn:"1234567890"}myHS.send(param); In the above code example, we have created an object called param and added two string attributes to it: title and isbn. When you pass the param object to the send() method, these two string attributes will get converted to URL-encoded http parameters and your HTTP request URL will look like this: http://www.domain.com/myjsp.jsp?title=Book Title &isbn=1234567890. This way, you can pass any number of HTTP parameters to the URL and these parameters can be accessed in your server-side code. For example, in a JSP or servlet, you could use request.getParameter("title") to get the HTTP request parameter.
Read more
  • 0
  • 0
  • 3037

article-image-social-media-magento
Packt
06 Oct 2009
4 min read
Save for later

Social Media in Magento

Packt
06 Oct 2009
4 min read
Integrating Twitter with Magento Twitter (http://twitter.com) is a micro-blogging service, which allows its users to send short messages to their followers, answering the question "what are you doing now?" After registering a Twitter account, you can begin to follow other Twitter users. When they update their status, you will see it in your timeline of what people you follow say. When you sign up for a Twitter account, it is usually best to sign up as the name of your store—for example, "Cheesy Cheese Store" rather than "RichardCarter", simply because your customers are more likely to search for the name of the store rather than your own name. Tweeting: Ideas for your store's tweets If you look at other businesses on Twitter, you'll see that there are a number of ways to promote your store on Twitter without losing followers by being too "spammy". Some companies give voucher codes to Twitter followers—a good way to entice new customers Others use Twitter to host competitions for free items—a good way to reward existing customers You can also release products to your Twitter followers before releasing them to other customers Displaying your Twitter updates on your Magento store Twitter can be a powerful tool for your store on its own, but you can integrate Twitter with your Magento store to drive existing customers to your Twitter account, which can help to generate repeat customers. There are a few ways Twitter can be used with Magento, the most versatile of which is the LazzyMonks Twitter module. Installing the LazzyMonks Twitter module To install the LazzyMonks module, visit its page on the Magento Commerce web site (http://www.magentocommerce.com/extension/482/lazzymonks-twitter, and retrieve the extension key, after agreeing to the terms and conditions. Log in to your Magento store's administration panel, and open the Magento Connect Manager in the Magento Connect option under the System tab. Once this has loaded, paste the extension key in to the text box next to the Paste extension key to install label, as shown in the following screenshot: This will install the module for you. Return to your Magento store's administration panel, and you will see a Twitter option in the navigation. The View Tweets option allows you to view updates made to your Twitter account. The Post Update option allows you to update Twitter from your store's administration panel. Firstly, you will need to configure the module's settings, which can be found under the Twitter option of the Configuration section of your store's administration panel, under the System tab. The Twitter Login options are of particular interest. Here you will need to enter your Twitter account's username and password. Once this has been saved, you can post a status update to your Twitter account through Magento's administration panel: This then appears on your Twitter account: Your tweets will also be displayed on your store, as a block beneath other content and can be styled with CSS in your Magento theme by addressing div.twitter. Other ways to integrate Twitter with Magento The other way to integrate your Twitter feed with Magento is by embedding Twitter's widgets into your site. To use these, log in to your Twitter account, and go to http://twitter.com/widgets. You can then use the HTML provided within the Magento templates to insert your Twitter updates into your store. Adding your Twitter feed through Magento's CMS Alternatively, you can insert your Twitter account's updates into any page managed through Magento's Content Management System. In Magento's administration panel, select CMS | Manage Pages, and select the page that you want your Twitter stream to appear in. Within your page, simply paste the code that Twitter produces when you select the type of Twitter "badge", which you want to display on your store. Consider creating a new block for your Twitter statuses, so that it can be removed from pages where it is likely to be distracting (for example, the checkout page).
Read more
  • 0
  • 0
  • 9129
article-image-modifying-system-using-microsoft-dynamics-nav-2009-part-1
Packt
06 Oct 2009
7 min read
Save for later

Modifying the System using Microsoft Dynamics Nav 2009: Part 1

Packt
06 Oct 2009
7 min read
"The best investment is in the tools of one's own trade." Benjamin Franklin Understanding the tools Have you ever held a chainsaw in your hands? Go try it, hear it roar. Quite a beast, eh? Now, what can you do with it? Was felling timber the first image that popped up? We had something else in mind. Have you ever seen any of those ice sculptures? Did you know that sculptors often use chainsaws to carve them out? Carving them slowly over days with fine tools is often not an option—the ice can start melting in a matter of minutes. To be able to finish in time before physics takes over, power tools must be used, and specially equipped chainsaws have been selected as a tool of choice of many ice carvers. Modifying a big system, one like Microsoft Dynamics NAV 2009, requires a lot of skill, knowledge, and experience. While skill and experience can't be learned from a book, knowledge for the better part of it can. There are two kinds of knowledge: the knowledge of the tools, and the knowledge of the product. If you only know the tools, and don't know the object you will work on with these tools, you can easily mess up. If you only know the product, but don't know the tools, you are missing many opportunities. When you know the tools, and what they can do, and how the product will behave when it has been touched, you are on the right path. If you are an application consultant, and you know the product and how it works, but haven't ever dared to open it up in Object Designer and shape it to your liking, this chapter is for you. You already have the knowledge of the product, what it is and how it works; you only need the knowledge of the tools to become a true artist. A chainsaw artist, if you wish. The tools you are about to master are quite powerful: they can craft beautifully architectured state-of-the-art solutions, or they can leave a complete mess. Let's become artists. Modifications for non-programmers In Microsoft Dynamics NAV 2009, it is possible to create a fully functioning modification without really writing a single line of code. As a matter of fact, it happens quite often. Often, customers will demand changes that are simple in nature: adding a field to a report, or rearranging the screen elements. You don't need to be a programmer to be able to accomplish that mission. Microsoft Dynamics NAV comes with a comprehensive set of tools aimed at modifying the solution and every aspect of it, from the data model, via business logic, all the way to the user interface. Many steps along this way can be done without any programming knowledge. Let's take a look at what can be done without writing code: Extending the data model: Application data is stored in tables, which are specifically designed to store exactly that information which is required by the application, no more, no less. When your customer presents you with new requirements, these will often spawn many changes to the underlying data model, to accommodate all those types of information that weren't originally supposed to be stored, because nobody knew they existed. You can do all of these data model modifications using special data design tools, without writing any code. True, some business logic is usually associated with data, so called business rules, but these should be written much later, after the model has been completed. Modifying the user interface: To put a functional user interface together requires a good understanding of the underlying data model, and of various user interface controls that can be put on screen, what they can do, and what they can't. You can compose hundreds of fully functional data-enabled pages or forms, and establish complex navigation rules between them, without ever coming anywhere close to the C/AL code editor. Reporting: Again, to compose reports mainly requires good knowledge of the underlying data, and the knowledge of tools. While some complex reports may require extensive coding, the vast majority of reports will be prepared by simply laying out fields in the report designer. Data import and export: When data needs to go in and out of the system, you can reach for built-in development tools that can create data migration objects in a matter of minutes. One of those times when knowing how to shape the system matters, while coding doesn't at all, is prototyping. Imagine how quickly you could get the requirements straight with a customer if you were able to quickly compose a usable user interface prototype! Object Designer basics All of the development in Microsoft Dynamics NAV is done through the Object Designer feature of the Classic client. To invoke the Object Designer from anywhere within the application, simply press Shift+F12, or go to main menu, click Tools, then Object Designer. It looks like the following screenshot: To the left there is a series of buttons, which you can use to switch between the lists of objects of various types: Type   Description   Tables are used to store information in the system.   Forms are used to provide access to information by displaying it on screen and allowing data entry and modification. Forms can only be used by Classic client.   Reports are primarily used to display information in printable form, but can also be used to execute batch jobs.   Dataports are used to export and import information to and from the system in fixed width or variable length text format.   Dataports on steroids, XMLports are RoleTailored and can get information into or out of the system in XML and text format. XMLports can also be used to automate communication with external application in a way transparent to the users, such as with Business Notifications functionality.   Codeunits contain blocks of application code: the part of the system popularly called business logic.   MenuSuites define what the navigation pane in Classic client and the Departments page in the RoleTailored client look like.   Pages are the forms of the RoleTailored client: they are used to present the information to users and provide means for data entry using RoleTailored or any other service-tier clients (such as SharePoint client).   On the right, there is a table displaying all the objects of the selected type. The following columns are on show: Column Description Type This is actually displayed as an icon, which can represent any of the eight object types described in the previous table. ID An integer number representing the unique identifier of an object. Every object in the system is uniquely distinguished from every other by its type and ID. Name A textual identifier of the object, which has to be unique for each object type. You typically refer to objects by their names when you are declaring C/AL variables. Caption A localized version of the name, aware of the multi-language capabilities of Microsoft Dynamics NAV. Modified Tells if the object was modified. Upon saving, every object will automatically get a checkmark in this field. Version List A textual list of version tags, explaining which product releases, add-ons, or customizations have changed the object. Date Date of the last save operation in Object Designer. Time Time of the last save operation in Object Designer. BLOB Size Size of BLOB representation of the object in the database. The definition, and for all compiled objects an executable version of it, are saved in the database. This makes for a very portable solution, where the database is, so are the application objects. Compiled Flag that tells if the object was compiled, either during the last save operation, or manually by calling the Compile command. Only compiled objects can be executed. On the bottom right, you have a few basic command buttons: New to create a new object of the selected type, Design to open an existing one, Run to execute the selected object, and Help to answer any questions that we might come across in the process of modifying the system.
Read more
  • 0
  • 0
  • 2721

article-image-development-iphone-applications
Packt
06 Oct 2009
6 min read
Save for later

Development of iPhone Applications

Packt
06 Oct 2009
6 min read
Introduction to iPhone It has been quite some time since Apple launched iPhone mobile and made a big wave across the world. Initially it got introduced in US market and within a year's time it was available all over the world. Though there are many who use iPhone mobile, I feel it is important to have an introduction to the device in general, its capabilities and what potential it has for programmers to get the full value for the money. If you have not held an iPhone, I suggest you should do that first. This will motivate you to know more about the device like how Apple implemented it. Some may like the curves, many would like the way it functions, but for me, its sleek, big yet compact form, touch technology and the biggest screen are some of the really cool things. Everyone knows about the "touch technology” of the device, especially the multi-touch which takes care of two fingers touching the screen at the same time at different places. But there is more to iPhone than touch. Other important features are: Location finding: using GPS it figures out where it is at that point of time in the world Accelerometer and Orientation: which give it the ability to detect motion in three dimensions Programmable Vibrator, Camera, address book Such features make iPhone more than a just a phone. Technically, the iPhone exists in two largely similar versions: the 2007 original release and the 2008 3G release. It is a 4.7- or 4.8-ounce computing device. Each device contains a 620 MHz ARM CPU that has been under clocked to improve battery performance and reduce heat. Both devices include 128 MB of dynamic RAM (DRAM), and from 4 to 16 GB of Flash memory. The primary difference between the two devices centers on the global positioning system (GPS) and networking. Some technical specifications: iPhone is built on Apple’s OS X, which itself is built on Unix. iPhone has 480 x 320 touch screen Supports a mobile version of Safari browser Supports LAN and WAN networking using Wi-Fi Uses GPS over Wi-Fi Programming Basics In 2008, Apple released the iPhone SDK, a developer toolkit that allows programmers to develop iPhone application. iPhone SDK lets you develop two type of applications—Web development and Native iPhone Application development. Web applications primarily run on a browser using HTML, CSS and some programming language that can generate dynamic content (Java, ASP, .NET, JSP, Ruby….). Native applications run on iPhone like any other application on the device. They use iPhone software development kit (SDK) released by Apple with the inbuilt frameworks and other frameworks that it support. Ignoring for a while that web and native applications have vast difference in the way they are build and they look, the fact is, they both can produce similar result and for some users it may not be easy to differentiate between them. Interesting isn’t it? Later in this article we will discuss about native application development using the tools and programming language iPhone supports. iPhone SDK uses the Objective-C language, which is an extension to the C language. Like any other mobile, iPhone too has a different programming platform; Windows Mobile (VB.NET/C#) and Android (Java) use object-oriented languages and are identical in syntax. However, Objective-C takes a totally different approach. Being different it creates a learning barrier especially for beginners dealing with Mac OS for the first time. Objective-C as implemented by Apple is built entirely around Objects. It is used throughout the iPhone OS’s frameworks. Windows, views, buttons, sliders and controllers exchange information with each other in the form of events and actions in order to make the program run. A header file (.h) and a source code (.m) file together represent each object in Objective-C. iPhone OS frameworks provide many standard classes that come with the framework, but sometimes you may have to write your own subclasses. When you do this, you’ll need a new header and source code class together to represent the new subclass in your project. The iPhone OS is divided in to four layers (Cocoa touch, Media, Core Services, Core OS), as represented in the diagram. Each layer contains variety of frameworks that you can use in your application/program. Initially, you would be dealing with the top layer. Cocoa touch - the base framework, that you will deal most of the time. It contains the UI-Kit framework which includes window support, event support and user-interface management. Media – the framework that provide the protocols to deal with audio and video build in iPhone. Core Services – the frameworks used in all applications, data types. Core Operating System – the kernel level software. Dealing with threading, networking, I/O, memory etc… What you need for iPhone Development To get started with iPhone programming, you would need the following: An Intel Mac running Mac OS X Leopard v10.5.4 or higher The iPhone SDK for iPhone OS, which you can download from http://developer.apple.com/iphone. The iPhone SDK contains all the tools and utilities you need to develop iPhone applications. In particular, it comes with Xcode 3.1(the development IDE) and the iPhone Simulator that allows you to test your application without needing a real device. Though, you can test the applications on the simulator, it is a good idea to register yourself on the iPhone developer program with a nominal fee. This registration gets you a secured certificate issued by Apple and can be used to test developed applications on the device itself. Hence, two more things are essential if the application has to be tested on the device iPhone mobile device iPhone develop program registration If you are serious about taking up iPhone development, I suggest that you to go for the registration process first before anything else. The registration process in itself is free, but to get the certificate you may have to pay a nominal fee ($100 for individuals). All this process could take up quite some time and meanwhile, you can gear up with all the skills and know-how to proceed with the first application. For more information, see "Accessing the iPhone Developer Program Portal.” The best way to learn iPhone programming is to get your hands dirty and start coding. To start coding, you’ll need iPhone SDK and XCode IDE that comes along with the SDK. Assuming, you are already done with the installation, you can find XCode application icon in the /developer/applications folder. Before starting with the application, take a second and think what you would like to name the first application, I will call it "FirstApp". This point is important to keep in mind as the name of the application, subsequent to installation on device, appears on the home screen. The purpose of the application could be anything, but what you want to call it and what you want it to appear as on the home screen starts by naming the application.
Read more
  • 0
  • 0
  • 3076

article-image-modifying-system-using-microsoft-dynamics-nav-2009-part-2
Packt
06 Oct 2009
4 min read
Save for later

Modifying the System using Microsoft Dynamics Nav 2009: Part 2

Packt
06 Oct 2009
4 min read
Customizing pages Pages are the RoleTailored client's equivalent of forms, and are the building blocks of the RoleTailored user interface. They are used primarily to display information from the database and to allow data entry, but we can use them simply to put anything we wish on screen for the user to interact with. To create a page, in Object Designer select Pages, then click the New button. The New Page form will assist you through the creation process: Page properties Unlike the New Form dialog, here you can only choose the source table and the type of page; but as soon as you make your choice, a blank Page Designer is shown, with only two properties filled out: SourceTable and PageType. Most page properties are called exactly the same and exhibit the same behavior as form properties, but there are four additional ones: Property Description PageType Specifies the type of the page. Types affect the behavior of pages, and we will discuss page types in more detail later on. InstructionalTextML Declares the multi-language text label that will be displayed on the page before any other user interface element. It only has effect on ConfirmationDialog type forms. CardFormID Defines the card form that is used to display, edit, or create records of the type that is displayed in a list. For example, in Customer List, this property defines that Customer Card is invoked every time a user calls the Edit, View, or New action. This property affects only list type forms. LinksAllowed Specifies whether links functionality will be available for this page or not. Page types The most important of these properties is PageType, because it defines the behavior of the form when displayed in the RoleTailored client. There are exactly ten types of pages: Card, List, RoleCenter, CardPart, ListPart, Document, Worksheet, ListPlus, ConfirmationDialog and NavigatePage. Let's take a closer look at their purpose, functionality, and anatomy. Card Similar to the card form, this type of page displays information about one record of a single table, such as one customer, one vendor, or one item. Typical examples of a card page are 21 Customer Card, or 30 Item Card. The following is what a typical page looks like: At the top of the page there are actions. Actions can be grouped into menus, or into toolbars. The majority of the screen is used for information display and entry. The left part of the screen is occupied with a ContentArea, which consists of groups of fields called FastTabs. Values of fields in FastTabs are typically taken from a single record of a table. The right part of the screen is occupied by the FactBoxArea, which contains several FactBoxes. List Similar to the list form, List pages display multiple records from the same table at once, such as a list of customers, list of vendors, or list of items. Typical examples are 22 Customer List, or 27 Vendor List. This is what a List page looks like: It has exactly the same elements as a card page, except its ContentArea is consumed by a single repeater group, which lists all information in a table. RoleCenter Pages of this type are used as home screens for different roles. They consist of different parts, and are used to provide quick access to the functionality most used by a user role, as well as the most relevant information, all at a glance. Examples of RoleCenter pages are 9005 Sales Manager Role Center and 9010 Production Planner Role Center. The following is what a RoleCenter looks like: It consists of groups displayed as vertical columns. In each group it is possible to have several page parts, such as Activities, My Items, and many more.
Read more
  • 0
  • 0
  • 2085
article-image-common-recovery-tools-active-directory-part-2
Packt
06 Oct 2009
6 min read
Save for later

Common Recovery Tools in Active Directory: Part 2

Packt
06 Oct 2009
6 min read
{literal} Monitoring with Sonar and Ultrasound Monitoring your AD is something that needs to be done regularly, and there are many commercial utilities out there that will help you achieve this. However, it might be worth investigating tools that are available for free from Microsoft, and even from some other vendors. Introducing Sonar Sonar and Ultrasound are two utilities that allow you to monitor the File Replication Service (FRS), and both utilities are good at detecting problems beforehand, or issues with replication from certain DCs. Sonar can be downloaded from the Microsoft Download Center at http://www.microsoft.com/downloads. You will need to have the .Net Framework 1.1 installed on the machine where Sonar will run. Also, please be aware that if you have .Net Framework 2.0 installed, it does not include 1.1, and you need to install 1.1 as well. Once installed, Sonar will not create a program menu entry, so you will need to search for it. For some reason, it will install itself into the Resource Kit folder (C:Program FilesResource Kit) and it is called Sonar.exe. Once you run it, you will be presented with the following dialog box: At this point, you can see two buttons, which can be used either for default querying (that is, all of the DCs within your domain) or for loading the settings with the Load Query button, if you have a specific query or setup saved. In our example, we will view the results and you will see the screen that you have seen in the previous figure. Also note the drop-down for Replica Set. This allows you to monitor DFS replications within your domain. So this tool is not just used to monitor the SYSVOL replications. From the top part, you can easily select a very wide range of Filters via a drop-down list, and the Columns can be used to select the columns to be displayed. This relates to a group of columns, so there are more columns than just the ones selected from the drop-down. To illustrate the extent of information that you can get with this little utility, the following screenshot shows both of the menus expanded. As you can see, you can use this tool to find out any information regarding the replication. Once you select the filters and columns that you want, you can click Refresh All and it will fetch that information from all DCs within your domain. You can see the disk usage of the AD database on all different DCs including any DC that has low disk space, is too slow, is backlogged with AD replications, and so on. This small utility, when used periodically, will help you to keep your AD in good healthy, shape and might help you find trouble-spots such as low bandwidth or wrongly configured replication schedules. Introducing Ultrasound Although Sonar is a good utility that is small and does its job very well, some organizations either have many FRS points that they want to monitor, or want much more information. This is where Ultrasound comes in. This utility is also a free download from Microsoft. However, it has much steeper requirements. Namely, it requires an SQL server as a backend. Even the SQL Server 2000 Desktop engine, or the free SQL Server 2005 Express Edition, downloadable from the Microsoft Download Center, will serve this purpose, but they would require a two-step setup and more resources. It also does collections periodically via agents that are deployed using WMI from within the Ultrasound interface. Although the free Desktop Engine has limitations, such as allowing only few connections, it does provide enough database functionality for Ultrasound. SQL Server 2005 Express edition will work perfectly fine with no problems. If Sonar can be compared to a sonar on a boat, which gives you a lot of information about what's ahead and what's going on around you, then Ultrasound has all of the features of Sonar, plus an additional feature for radar and satellite surveillance. Getting familiar with Ultrasound may take some time. As Ultrasound is a Microsoft utility, it can be downloaded from the Microsoft Download Center. Once you install the SQL server, or prepare a database on an existing server, you can proceed to installing Ultrasound. You will be asked which server to use and you can just enter the name of the PC where your SQL server is running. After deploying the database structure, which can take a few minutes, the installation will finish, and you will have a new program menu entry, called FRS Monitoring, where Ultrasound is located. Once you launch Ultrasound for the first time, you will be asked to add an FRS replica to Ultrasound. At this point, you should click Yes and you will be prompted for your domain name and the available FRS replicas. In our case, this is similar to the example shown in the following screenshot. By simply clicking the replica set, and then clicking on Add, you can add it to the list of FRS replicas to the list of FRS replicas to be monitored. Next, you click OK, and Ultrasound will collect the Schema data from the selected replica set, and then ask you to add all Servers found, add only the highly connected, hub, servers or add none, and you will select your own. There is also an option to install the WMI collectors, which you want to do (shown in the following screenshot). Once you have selected your approach, a whole world of information will open up. The tool may appear confusing simply because of the volume of information you can gather with it, but the learning curve quickly flattens, and the data that it provides becomes invaluable. After the initial WMI collector deployment is done, you can close the screen. Henceforth you will find that the screen shown in the following screenshot is always displayed when you start Ultrasound: At first, you are given a health rating, which is generally accurate as only critical errors, or errors that could cause problems, change this rating. You can expand the replica set and see each server's health rating as well. This allows you to quickly identify any critical issues with the DCs. Details On the second tab, Details, you will find information about the replications of the servers you have selected. We selected only DC1, DC2, and DC30, and details of the ongoing replications and which DCs have the most inbound and outbound connections are displayed, as shown in the following screenshot. On the top, you can also change the details to be displayed, for example the files contained within this Replica Set that are replicated. Right-clicking on a server opens up a context menu that either allows you to collect data from a specific server, or opens up the replica set and displays the details of the replica set for the server, depending on the context. Right-clicking on the inbound or outbound connection windows will allow you to collect data, or see details regarding a specific inbound, outbound, or replica member.
Read more
  • 0
  • 0
  • 2351

article-image-creating-dynamic-reports-databases-using-jasperreports-35-2
Packt
05 Oct 2009
10 min read
Save for later

Creating Dynamic Reports from Databases Using JasperReports 3.5

Packt
05 Oct 2009
10 min read
Datasource definition A datasource is what JasperReports uses to obtain data for generating a report. Data can be obtained from databases, XML files, arrays of objects, collections of objects, and XML files. In this article, we will focus on using databases as a datasource. Database for our reports We will use a MySQL database to obtain data for our reports. The database is a subset of public domain data that can be downloaded from http://dl.flightstats.us. The original download is 1.3 GB, so we deleted most of the tables and a lot of data to trim the download size considerably. MySQL dump of the modified database can be found as part of code download at http://www.packtpub.com/files/code/8082_Code.zip. The flightstats database contains the following tables: aircraft aircraft_models aircraft_types aircraft_engines aircraft_engine_types The database structure can be seen in the following diagram: The flightstats database uses the default MyISAM storage engine for the MySQL RDBMS, which does not support referential integrity (foreign keys). That is why we don't see any arrows in the diagram indicating dependencies between the tables. Let's create a report that will show the most powerful aircraft in the database. Let's say, those with horsepower of 1000 or above. The report will show the aircraft tail number and serial number, the aircraft model, and the aircraft's engine model. The following query will give us the required results: SELECT a.tail_num, a.aircraft_serial, am.model as aircraft_model, ae.model AS engine_model FROM aircraft a, aircraft_models am, aircraft_engines ae WHERE a.aircraft_engine_code in (select aircraft_engine_code from aircraft_engines where horsepower >= 1000) AND am.aircraft_model_code = a.aircraft_model_code AND ae.aircraft_engine_code = a.aircraft_engine_code The above query retrieves the following data from the database: Generating database reports There are two ways to generate database reports—either by embedding SQL queries into the JRXML report template or by passing data from the database to the compiled report through a datasource. We will discuss both of these techniques. We will first create the report by embedding the query into the JRXML template. Then, we will generate the same report by passing it through a datasource containing the database data. Embedding SQL queries into a report template JasperReports allows us to embed database queries into a report template. This can be achieved by using the <queryString> element of the JRXML file. The following example demonstrates this technique: <?xml version="1.0" encoding="UTF-8" ?> <jasperReport xsi_schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="DbReport"> <queryString> <![CDATA[select a.tail_num, a.aircraft_serial, am.model as aircraft_model, ae.model as engine_model from aircraft a, aircraft_models am, aircraft_engines ae where a.aircraft_engine_code in ( select aircraft_engine_code from aircraft_engines where horsepower >= 1000) and am.aircraft_model_code = a.aircraft_model_code and ae.aircraft_engine_code = a.aircraft_engine_code]]> </queryString> <field name="tail_num" class="java.lang.String" /> <field name="aircraft_serial" class="java.lang.String" /> <field name="aircraft_model" class="java.lang.String" /> <field name="engine_model" class="java.lang.String" /> <pageHeader> <band height="30"> <staticText> <reportElement x="0" y="0" width="69" height="24" /> <textElement verticalAlignment="Bottom" /> <text> <![CDATA[Tail Number: ]]> </text> </staticText> <staticText> <reportElement x="140" y="0" width="79" height="24" /> <text> <![CDATA[Serial Number: ]]> </text> </staticText> <staticText> <reportElement x="280" y="0" width="69" height="24" /> <text> <![CDATA[Model: ]]> </text> </staticText> <staticText> <reportElement x="420" y="0" width="69" height="24" /> <text> <![CDATA[Engine: ]]> </text> </staticText> </band> </pageHeader> <detail> <band height="30"> <textField> <reportElement x="0" y="0" width="69" height="24" /> <textFieldExpression class="java.lang.String"> <![CDATA[$F{tail_num}]]> </textFieldExpression> </textField> <textField> <reportElement x="140" y="0" width="69" height="24" /> <textFieldExpression class="java.lang.String"> <![CDATA[$F{aircraft_serial}]]> </textFieldExpression> </textField> <textField> <reportElement x="280" y="0" width="69" height="24" /> <textFieldExpression class="java.lang.String"> <![CDATA[$F{aircraft_model}]]> </textFieldExpression> </textField> <textField> <reportElement x="420" y="0" width="69" height="24" /> <textFieldExpression class="java.lang.String"> <![CDATA[$F{engine_model}]]> </textFieldExpression> </textField> </band> </detail> </jasperReport> The <queryString> element is used to embed a database query into the report template. In the given code example, the <queryString> element contains the query wrapped in a CDATA block for execution. The <queryString> element has no attributes or subelements other than the CDATA block containing the query. Text wrapped inside an XML CDATA block is ignored by the XML parser. As seen in the given example, our query contains the > character, which would invalidate the XML block if it wasn't inside a CDATA block. A CDATA block is optional if the data inside it does not break the XML structure. However, for consistency and maintainability, we chose to use it wherever it is allowed in the example. The <field> element defines fields that are populated at runtime when the report is filled. Field names must match the column names or alias of the corresponding columns in the SQL query. The class attribute of the <field> element is optional; its default value is java.lang.String. Even though all of our fields are strings, we still added the class attribute for clarity. In the last example, the syntax to obtain the value of a report field is $F{field_name}, where field_name is the name of the field as defined. The next element that we'll discuss is the <textField> element. Text fields are used to display dynamic textual data in reports. In this case, we are using them to display the value of the fields. Like all the subelements of <band>, text fields must contain a <reportElement> subelement indicating the text field's height, width, and x, y coordinates within the band. The data that is displayed in text fields is defined by the <textFieldExpression> subelement of <textField>. The <textFieldExpresson> element has a single subelement, which is the report expression that will be displayed by the text field and wrapped in an XML CDATA block. In this example, each text field is displaying the value of a field. Therefore, the expression inside the <textFieldExpression> element uses the field syntax $F{field_name}, as explained before. Compiling a report containing a query is no different from compiling a report without a query. It can be done programmatically or by using the custom JasperReports jrc ANT task. Generating the report As we have mentioned previously, in JasperReports terminology, the action of generating a report from a binary report template is called filling the report. To fill a report containing an embedded database query, we must pass a database connection object to the report. The following example illustrates this process: package net.ensode.jasperbook; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.HashMap; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperFillManager; public class DbReportFill { Connection connection; public void generateReport() { try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql: //localhost:3306/flightstats?user=user&password=secret"); System.out.println("Filling report..."); JasperFillManager.fillReportToFile("reports/DbReport. jasper", new HashMap(), connection); System.out.println("Done!"); connection.close(); } catch (JRException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } public static void main(String[] args) { new DbReportFill().generateReport(); } } As seen in this example, a database connection is passed to the report in the form of a java.sql.Connection object as the last parameter of the static JasperFillManager.fillReportToFile() method. The first two parameters are as follows: a string (used to indicate the location of the binary report template or jasper file) and an instance of a class implementing the java.util.Map interface (used for passing additional parameters to the report). As we don't need to pass any additional parameters for this report, we used an empty HashMap. There are six overloaded versions of the JasperFillManager.fillReportToFile() method, three of which take a connection object as a parameter. For simplicity, our examples open and close database connections every time they are executed. It is usually a better idea to use a connection pool, as connection pools increase the performance considerably. Most Java EE application servers come with connection pooling functionality, and the commons-dbcp component of Apache Commons includes utility classes for adding connection pooling capabilities to the applications that do not make use of an application server. After executing the above example, a new report, or JRPRINT file is saved to disk. We can view it by using the JasperViewer utility included with JasperReports. In this example, we created the report and immediately saved it to disk. The JasperFillManager class also contains methods to send a report to an output stream or to store it in memory in the form of a JasperPrint object. Storing the compiled report in a JasperPrint object allows us to manipulate the report in our code further. We could, for example, export it to PDF or another format. The method used to store a report into a JasperPrint object is JasperFillManager.fillReport(). The method used for sending the report to an output stream is JasperFillManager.fillReportToStream(). These two methods accept the same parameters as JasperFillManager.fillReportToFile() and are trivial to use once we are familiar with this method. Refer to the JasperReports API for details. In the next example, we will fill our report and immediately export it to PDF by taking advantage of the net.sf.jasperreports.engine.JasperRunManager.runReportToPdfStream() method. package net.ensode.jasperbook; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.sql.Connection; import java.sql.DriverManager; import java.util.HashMap; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.jasperreports.engine.JasperRunManager; public class DbReportServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection connection; response.setContentType("application/pdf"); ServletOutputStream servletOutputStream = response .getOutputStream(); InputStream reportStream = getServletConfig() .getServletContext().getResourceAsStream( "/reports/DbReport.jasper"); try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql: //localhost:3306/flightstats?user=dbUser&password=secret"); JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, new HashMap(), connection); connection.close(); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // display stack trace in the browser StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); response.setContentType("text/plain"); response.getOutputStream().print(stringWriter.toString()); } } } The only difference between static and dynamic reports is that for dynamic reports we pass a connection to the report for generating a database report. After deploying this servlet and pointing the browser to its URL, we should see a screen similar to the following screenshot:  
Read more
  • 0
  • 0
  • 9406
Modal Close icon
Modal Close icon