Skip to content
Snippets Groups Projects
Commit 55c6f099 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci
Browse files

Merge remote branch 'server/master'

parents 9f4dff56 ece31aa7
No related branches found
No related tags found
No related merge requests found
Showing
with 4890 additions and 0 deletions
# SEED2 SERVER
C3SL - Centro de Computacao Cientifica e Software Livre
Agtha Cristina de Nadai
Bruno Cesar Ribas
Carlos Carvalho
Daniel Weingaertner
Danilo Kiyoshi Simizu Yorinori
Diego Giovane Pasqualin
Edson Ramiro Lucas Filho
Eduardo Cunha de Almeida
Erik Alexandre Pucci
Fabiano Silva
Jorge Augusto Meira
Josiney de Souza
Juliana Bueno
Lucio Foltran da Silva
Luis Carlos Erpen de Bona
Marcos Castilho
Renan Franca De Miranda
Ricardo Tavares De Oliveira
Rubens Massayuki Suguimoto
Thiago Henrique Dos Santos Picharski
Tiago Rodrigo Kepe
Vinicius Kwiecien Ruoso
This diff is collapsed.
SEED2 SERVER ChangeLog
v1.0.0:
- initial release
Installation Steps
==================
Dependencies:
apache-tomcat-6.0.20
axis-1_4
Before installation, be sure you have installed at $CATALINA_HOME/lib the
following packages:
* postgresql-*.jar (http://jdbc.postgresql.org/);
* xercesImpl.jar (http://xerces.apache.org/mirrors.cgi);
* jdom.jar (http://www.jdom.org/index.html).
After, move Seed2.jws file to $AXIS_HOME/webapps/axis/, copy the version file
to the same directory and write its full path in Seed2.jws (line 453)
=============================================================================
Prerequisite:
To install these web services you need JAVA (+1.6, we don't recommend GCJ);
Apache ANT (to compile Java code automatically);
Apache AXIS and Apache TOMCAT to deploy services
Set environment variables:
- CATALINA_HOME -> Tomcat home directory
- AXIS_HOME -> Axis home directory
- AXIS_CLASSPATH -> Axis lib directory
Compiling:
To compile our JAVA code you can use ANT in the same directory where
"build.xml" can be found:
#ant
or
#ant compile
To copy the classes, copy configuration files and deploy services in Axis, do:
#ant install
The deploy step service needs Tomcat (with Axis) initialization. To deploy, do:
#ant deploy
By default, the deploy mechanism use port 8888. You can change this port
number in "build.xml" file.
!!!Be sure to set environment variables correctly, otherwise the !!!
!!! installation process will fail !!!
To check if your service has been deployed correctly, go to the axis web page
and check the services list:
http://localhost:8888/axis/
Configuration:
The configuration file should be in $CATALINA_HOME/bin/seed2 directory. You
need to change database informations and links. All fields are explained above:
Database configuration:
- Database host
<host>localhost</host>
- Database port
<port>5432</port>
- Database pgpool port
<sa_port>9999</sa_port>
- Database schema
<schema>db_schema</schema>
- Database user
<user>user</user>
- Database user's password
<passwd>password</passwd>
Document service configuration:
- Documents information file path
<doc_path>/path/to/docFile.xml</doc_path>
Install service configuration:
- Database table used to find school id
<table_school>school_table</table_school>
- Package generator script path
<package_gen>/path/to/pkgGenerator.sh</package_gen>
- Package generator script output path (agent package)
<package_dest>/path/to/pkgGeneratedDir</package_dest>
- Host used to create agent package
<host>host.local.net</host>
Seed service configuration:
- Database table used to find school id
<table_school>school_table</table_school>
- Database table used to insert informations sent by agents
<table_sa>stagin_area_table</table_sa>
- Version file path
<version_file>/path/to/versionFile</version_file>
- Update URL base link
<update_link_base_url>http://local.net/dir/</update_link_base_url>
- Update package name
<update_link_pkg_name>updatePackage_version</update_link_pkg_name>
- Update package extension
<update_link_ext>.run</update_link_ext>
Dump service configuration:
- Dump file path
<dump_path>Path/to/dumpFile</dump_path>
- Dump update file path
<dump_update_date>path/to/dumpUpdateDate/file</dump_update_date>
=============================================================================
For more information about installation of components
see the Tomcat, Axis, Ant and JAVA installation guide.
########################################################
# SEED2 SERVER
########################################################
SEED2 SERVER provides services for validation,
availabitity and version.
For installation support read "INSTALL".
For changes read "ChangeLog".
For new features and other news read "NEWS".
For credits read "AUTHORS".
For copyright information read "COPYING".
- Store inventory
- Check bugs
<?xml version="1.0"?>
<project name="Seed2ws" default="compile" basedir=".">
<!-- Define properties -->
<property environment="env"/>
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="conf" value="conf"/>
<property name="seed2.bin" value="${basedir}/SEED2-run"/>
<property name="pkg.gen" value="${basedir}/bin"/>
<property name="axis_cp" value="${env.AXISCLASSPATH}"/>
<property name="axis_home" value="${env.AXIS_HOME}"/>
<property name="catalina_home" value="${env.CATALINA_HOME}"/>
<property name="axis_ws" value="${axis_home}/webapps/axis"/>
<property name="axis_webinf" value="${axis_ws}/WEB-INF"/>
<property name="axis_ws_classes" value="${axis_webinf}/classes"/>
<property name="axis_dir" value="axis"/>
<!-- Define paths -->
<path id="classpath">
<fileset dir="${axis_home}/lib/" includes="**/*.jar"/>
</path>
<!-- Define targets -->
<target name="init">
<echo>Axis classpath: ${axis_cp}</echo>
<echo>Axis home: ${axis_home}</echo>
<echo>Tomcat home: ${catalina_home}</echo>
<echo>Create ${build} directory</echo>
<mkdir dir="${build}"/>
<echo>Create ${build}/bin directory</echo>
</target>
<!-- Compile Java Files -->
<target name="FileUtil" description="Builds FileUtil">
<echo>Doing FileUtil</echo>
<javac srcdir="${src}" destdir="${build}" includes="FileUtil.java"/>
</target>
<target name="DBConnection"
description="Builds DBConnection">
<echo>Doing DBConnection</echo>
<javac srcdir="${src}" destdir="${build}" includes="DBConnection.java"
classpathref="classpath"/>
</target>
<target name="Seed2Document"
description="Builds Seed2Document">
<echo>Doing Seed2Document</echo>
<javac srcdir="${src}" destdir="${build}" includes="Seed2Document.java"/>
</target>
<target name="Seed2School"
description="Builds Seed2School">
<echo>Doing Seed2School</echo>
<javac srcdir="${src}" destdir="${build}" includes="Seed2School.java"/>
</target>
<target name="XmlUtil"
description="Builds XmlUtil">
<echo>Doing XmlUtil</echo>
<javac srcdir="${src}" destdir="${build}" includes="XmlUtil.java"/>
</target>
<target name="Seed2Package"
description="Builds Seed2Package">
<echo>Doing Seed2Package</echo>
<javac srcdir="${src}" destdir="${build}" includes="Seed2Package.java"/>
</target>
<target name="Seed2" depends="XmlUtil" description="Builds Seed2 service">
<echo>Doing Seed2 Receive Data Service</echo>
<javac srcdir="${src}" destdir="${build}" includes="Seed2.java"
classpathref="classpath"/>
</target>
<target name="Seed2Doc" depends="Seed2Document, XmlUtil"
description="Builds Seed2Doc">
<echo>Doing Seed2Doc</echo>
<javac srcdir="${src}" destdir="${build}" includes="Seed2Doc.java"/>
</target>
<target name="Seed2Install" depends="Seed2School, Seed2Package, FileUtil, DBConnection, XmlUtil"
description="Builds Seed2Install">
<echo>Doing Seed2Install</echo>
<javac srcdir="${src}" destdir="${build}" includes="Seed2Install.java"
classpathref="classpath"/>
</target>
<target name="Seed2Dump" depends="FileUtil, XmlUtil"
description="Builds Seed2Dump">
<echo>Doing Seed2Dump</echo>
<javac srcdir="${src}" destdir="${build}" includes="Seed2Dump.java"
classpathref="classpath"/>
</target>
<!-- Ant general actions -->
<target name="compile" depends="init,Seed2School,Seed2Install,Seed2Doc,Seed2,Seed2Dump">
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="clean" description="Removes previous build">
<delete verbose="true" includeemptydirs="true">
<fileset dir="${build}/bin"/>
<fileset dir="${build}"/>
</delete>
</target>
<!-- Deploy and Undeploy Services-->
<target name="deploy" description="Deploy services">
<echo> Axis classpath: ${axis_cp}</echo>
<echo>Deploy service: DocService</echo>
<java fork="true" failonerror="true" classname="org.apache.axis.client.AdminClient">
<arg value="deploySeed2DocService.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
<echo>Deploy service: InstallService</echo>
<java classname="org.apache.axis.client.AdminClient" fork="true" failonerror="true">
<arg value="deploySeed2InstallService.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
<echo>Deploy service: Seed2Service</echo>
<java classname="org.apache.axis.client.AdminClient" fork="true" failonerror="true">
<arg value="deploySeed2Service.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
<echo>Deploy service: Seed2Dump</echo>
<java classname="org.apache.axis.client.AdminClient" fork="true" failonerror="true">
<arg value="deploySeed2DumpService.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
</target>
<target name="undeploy" >
<echo>Undeploy service: DocService</echo>
<java classname="org.apache.axis.client.AdminClient" fork="true" failonerror="true">
<arg value="undeploySeed2DocService.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
<echo>Undeploy service: InstallService</echo>
<java classname="org.apache.axis.client.AdminClient" fork="true" failonerror="true">
<arg value="undeploySeed2InstallService.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
<echo>Undeploy service: Seed2Service</echo>
<java classname="org.apache.axis.client.AdminClient" fork="true" failonerror="true">
<arg value="undeploySeed2Service.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
<echo>Undeploy service: Seed2Dump</echo>
<java classname="org.apache.axis.client.AdminClient" fork="true" failonerror="true">
<arg value="undeploySeed2DumpService.wsdd"/>
<classpath>
<pathelement location="${axis_home}/lib/axis.jar"/>
<pathelement path="${axis_cp}"/>
</classpath>
</java>
</target>
<!-- Compile and deploy services -->
<target name="install" description="Copy and deploy services" depends="copyClasses, copyBin, deploy">
<echo>Compiling and Deploying services</echo>
</target>
<target name="copyClasses" depends="check_axis_install, doCopyClasses"/>
<target name="check_axis_install">
<echo>Check Axis WEB-INF dir: ${axis_home}</echo>
<available type="dir" file="${axis_home}" property="axis_installed"/>
<echo> Value of axis_installed: ${axis_installed}</echo>
</target>
<target name="doCopyClasses" if="axis_installed">
<echo message="Copying classes to Axis WEB-INF classes dir."/>
<copy todir="${axis_ws_classes}/">
<fileset dir="${build}/"/>
</copy>
</target>
<!-- Deploy Seed2.jws service -->
<target name="jws" description="Compile and deploy services" depends="copySeedJws">
<echo>Deploying Seed2.jws service</echo>
</target>
<target name="copySeedJws" depends="check_axis_install, doCopySeedJws"/>
<target name="doCopySeedJws" if="axis_installed">
<echo message="Copying Seed2.jws to Axis WEB-INF classes dir."/>
<copy todir="${axis_ws}" file="${src}/Seed2.jws" />
</target>
<!-- Copy binaries and configuration files to Catalina dir -->
<target name="copyBin" description="Copy generate package scripts and configurations files" depends="copySeedBin">
<echo>Copying generate package scripts and configurations files</echo>
</target>
<target name="copySeedBin" depends="check_catalina_install, doCopySeedBin"/>
<target name="check_catalina_install">
<echo>Check Catalina dir: ${catalina_home}</echo>
<available type="dir" file="${catalina_home}" property="catalina_installed"/>
<echo> Value of catalina_installed: ${catalina_installed}</echo>
</target>
<target name="doCopySeedBin" if="catalina_installed">
<echo message="Copying binaries and configurations file to Catalina binary dir."/>
<echo> Copy ${pkg.gen}/* to ${catalina_home}/bin directory</echo>
<copy todir="${catalina_home}/bin/">
<fileset dir="${pkg.gen}"/>
</copy>
<mkdir dir="${catalina_home}/bin/seed2"/>
<echo> Copy ${conf}/* to ${catalina_home}/bin/seed2 directory</echo>
<copy todir="${catalina_home}/bin/seed2">
<fileset dir="${conf}"/>
</copy>
</target>
<!--
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
-->
</project>
<?xml version="1.0" encoding="utf-8"?>
<general>
<db_config>
<host>localhost</host>
<port>5432</port>
<sa_port>9999</sa_port>
<schema>db_schema</schema>
<user>user</user>
<passwd>password</passwd>
</db_config>
<doc_config>
<doc_path>/path/to/docFile.xml</doc_path>
</doc_config>
<install_config>
<table_school>school_table</table_school>
<package_gen>/path/to/pkgGenerator.sh</package_gen>
<package_dest>/path/to/pkgGeneratedDir</package_dest>
<host>host.local.net</host>
</install_config>
<seed_config>
<table_school>school_table</table_school>
<table_sa>stagin_area_table</table_sa>
<version_file>/path/to/versionFile</version_file>
<update_link_base_url>http://host.local.net/pkg/dir/</update_link_base_url>
<update_link_pkg_name>updatePackage_version</update_link_pkg_name>
<update_link_ext>.run</update_link_ext>
</seed_config>
<dump_config>
<dump_path>Path/to/dumpFile</dump_path>
<dump_update_date>path/to/dumpUpdateDate/file</dump_update_date>
</dump_config>
</general>
<?xml version="1.0" encoding="utf-8"?>
<documents>
<document>
<name>User's manual</name>
<desc>This is the user's manual</desc>
<size>189324</size>
<date>22/12/2009</date>
<url>http://local.host.net/doc/user_man.pdf</url>
</document>
<document>
<name>Use manual</name>
<desc>System's use manual</desc>
<size>9302831</size>
<date>09/11/2009</date>
<url>http://local.host.net/doc/system_man.pdf</url>
</document>
<document>
<name>Admin's manual</name>
<desc>This is a administrator's manual</desc>
<size>149283</size>
<date>09/11/2009</date>
<url>http://local.host.net/doc/admin_man.pdf</url>
</document>
</documents>
1.0.0
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="Seed2DocService" provider="java:RPC">
<parameter name="className" value="Seed2Doc"/>
<parameter name="allowedMethods" value="getDocuments"/>
<parameter name="wsdlTargetNamespace" value="http://seed2Doc.c3sl"/>
<typeMapping
xmlns:ns="http://seed2Doc.c3sl"
qname="ns:Seed2Document"
type="java:Seed2Document"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
/>
<typeMapping
xmlns:ns="http://seed2Doc.c3sl"
qname="ns:Seed2DocumentArray"
type="java:Seed2Document[]"
serializer="org.apache.axis.encoding.ser.ArraySerializerFactory"
deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
/>
<operation name="getDocuments" qname="test:getDocuments"
xmlns:test="http://seed2Doc.c3sl"
returnQName="getDocumentsReturn"
xmlns:ns="http://seed2Doc.c3sl"
returnType="ns:Seed2DocumentArray">
</operation>
</service>
</deployment>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="Seed2DumpService" provider="java:RPC">
<parameter name="className" value="Seed2Dump"/>
<parameter name="allowedMethods" value="getDump getLastDumpDate"/>
<parameter name="wsdlTargetNamespace" value="http://seed2Dump.c3sl"/>
<operation name="getDump" qname="seed2:getDump"
xmlns:seed2="http://seed2Dump.c3sl"
returnQName="seed2:getDumpReturn"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
returnType="xsd:string">
</operation>
<operation name="getLastDumpDate" qname="seed2:getLastDumpDate"
xmlns:seed2="http://seed2Dump.c3sl"
returnQName="seed2:getLastDumpDateReturn"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
returnType="xsd:string">
</operation>
</service>
</deployment>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="Seed2InstallService" provider="java:RPC">
<parameter name="className" value="Seed2Install"/>
<parameter name="allowedMethods" value="getINEPInfo makePackage verifyId"/>
<parameter name="wsdlTargetNamespace" value="http://seed2Install.c3sl"/>
<typeMapping
xmlns:ns="http://seed2Install.c3sl"
qname="ns:Seed2SchoolType"
type="java:Seed2School"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
/>
<typeMapping
xmlns:ns="http://seed2Install.c3sl"
qname="ns:Seed2PackageType"
type="java:Seed2Package"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
/>
<operation name="getINEPInfo" qname="test:getINEPInfo"
xmlns:test="http://seed2Install.c3sl"
returnQName="test:getINEPInfoReturn"
xmlns:ns="http://seed2Install.c3sl"
returnType="ns:Seed2SchoolType">
<parameter qname="pns:INEP" xmlns:pns="http://seed2Install.c3sl"
type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
</operation>
<operation name="makePackage" qname="test:makePackage"
xmlns:test="http://seed2Install.c3sl"
returnQName="http://seed2Install.c3sl"
xmlns:ns="http://seed2Install.c3sl"
returnType="ns:Seed2PackageType">
<parameter qname="pns:INEP" xmlns:pns="http://seed2Install.c3sl"
type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
<parameter qname="pns:Host" xmlns:pns="http://seed2Install.c3sl"
type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
<parameter qname="pns:Port" xmlns:pns="http://seed2Install.c3sl"
type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
<parameter qname="pns:User" xmlns:pns="http://seed2Install.c3sl"
type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
<parameter qname="pns:Passwd" xmlns:pns="http://seed2Install.c3sl"
type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
</operation>
<operation name="verifyId" qname="seed2:verifyId"
xmlns:seed2="http://seed2.c3sl"
returnQName="seed2:verifyId"
xmlns:ns="http://www.w3.org/2001/XMLSchema"
returnType="ns:string">
<parameter qname="pns:INEP" xmlns:pns="http://seed2.c3sl" type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
</operation>
</service>
</deployment>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="Seed2Service" provider="java:RPC">
<parameter name="className" value="Seed2"/>
<parameter name="allowedMethods" value="setInventory getAgentVersion verifyId setAvailability getUpdateLink"/>
<parameter name="wsdlTargetNamespace" value="http://seed2.c3sl"/>
<operation name="setInventory" qname="seed2:setInvetory"
xmlns:seed2="http://seed2.c3sl"
returnQName="seed2:setInventoryReturn"
xmlns:ns="http://www.w3.org/2001/XMLSchema"
returnType="ns:string">
<parameter qname="pns:Inventary" xmlns:pns="http://seed2.c3sl" type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
</operation>
<operation name="getAgentVersion" qname="seed2:getAgentVersion"
xmlns:seed2="http://seed2.c3sl"
returnQName="seed2:getAgentVersion"
xmlns:ns="http://www.w3.org/2001/XMLSchema"
returnType="ns:string">
</operation>
<operation name="verifyId" qname="seed2:verifyId"
xmlns:seed2="http://seed2.c3sl"
returnQName="seed2:verifyId"
xmlns:ns="http://www.w3.org/2001/XMLSchema"
returnType="ns:boolean">
<parameter qname="pns:INEP" xmlns:pns="http://seed2.c3sl" type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
</operation>
<operation name="setAvailability" qname="seed2:setAvailability"
xmlns:seed2="http://seed2.c3sl"
returnQName="seed2:setAvailability"
xmlns:ns="http://www.w3.org/2001/XMLSchema"
returnType="ns:string">
<parameter qname="pns:INEP" xmlns:pns="http://seed2.c3sl" type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
<parameter qname="pns:MacAddress" xmlns:pns="http://seed2.c3sl" type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
</operation>
<operation name="getUpdateLink" qname="seed2:getUpdateLink"
xmlns:seed2="http://seed2.c3sl"
returnQName="seed2:getUpdateLink"
xmlns:ns="http://www.w3.org/2001/XMLSchema"
returnType="ns:string">
</operation>
</service>
</deployment>
/*
* Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of server
*
* server is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/* Database libs */
import java.sql.*;
import org.postgresql.Driver;
/* File libs */
import java.io.*;
public class DBConnection {
/* Attributes */
Statement stmt = null;
public Connection myConnection;
/**
* Database constructor.
*
* @author Rubens Massayuki Suguimoto
* @return void
*/
public DBConnection() {
super();
}
/**
* Creates a new instance of data base connection.
*
* @author Rubens Massayuki Suguimoto
* @return boolean
*/
public boolean connect()
throws ClassNotFoundException, SQLException, Exception {
XmlUtil config = new XmlUtil("./seed2/conf.xml");
String dbTag = "db_config";
/* Get information from configuration file */
String host = config.getTextValue(config.getTag(dbTag), "host");
String port = config.getTextValue(config.getTag(dbTag), "port");
String schema = config.getTextValue(config.getTag(dbTag), "schema");
String user = config.getTextValue(config.getTag(dbTag), "user");
String passwd = config.getTextValue(config.getTag(dbTag), "passwd");
Driver.class.newInstance();
System.out.println("DB: Driver Initialized.");
/* Open connection to data base */
myConnection = DriverManager.getConnection("jdbc:postgresql://" + host +
":" + port + "/" + schema, user, passwd);
System.out.println("DB: Connected to Database.");
stmt = myConnection.createStatement();
return true;
}
/**
* Close connection with data base.
*
* @author Rubens Massayuki Suguimoto
* @return void
*/
public void close() throws SQLException {
stmt.close();
myConnection.close();
}
/**
* Execute query in data base.
*
* @author Rubens Massayuki Suguimoto
* @param pSql String
* @return ResultSet
*/
public ResultSet executeQuery(String pSql) throws SQLException {
System.out.println("DB: Query: " + pSql);
return stmt.executeQuery(pSql);
}
/**
* Execute update query in data base.
*
* @author Rubens Massayuki Suguimoto
* @param pSql String
* @return int
*/
public int executeUpdate(String pSql) throws SQLException {
System.out.println("DB: Update: " + pSql);
return stmt.executeUpdate(pSql);
}
}
/*
* Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of server
*
* server is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/* File libs */
import java.io.File;
public class FileUtil {
/**
* Get file size using file path.
*
* @author Rubens Massayuki Suguimoto
* @param filename String
* @return long
*/
public long getFileSize(String filename) {
File file = new File(filename);
if ((!file.exists()) || (!file.isFile())) {
System.out.println("File doesn\'t exist");
return -1;
}
/* Here we get the file size */
return file.length();
}
}
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of server
*
* server is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/* XML Parser libs */
import org.apache.xerces.parsers.*;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
/* File libs */
import java.io.IOException;
public class Seed2Doc {
/* Attributes */
private String docFile;
/**
* Seed2Doc service constructor.
*
* @author Rubens Massayuki Suguimoto
* @return void
*/
public Seed2Doc() {
XmlUtil docConf = new XmlUtil("./seed2/conf.xml");
String docTag = "doc_config";
/* Get information from configuration file */
docFile = docConf.getTextValue(docConf.getTag(docTag),"doc_path");
}
/**
* Return documents array.
*
* @author Rubens Massayuki Suguimoto
* @return Seed2Document array
*/
public Seed2Document[] getDocuments() {
int i;
System.out.println("Doc: Opening:" + docFile);
/* TODO - document array more flexible */
Seed2Document [] docs = new Seed2Document[10];
System.out.println("Doc: Parsing file.");
XmlUtil docXml = new XmlUtil(docFile);
System.out.println("Doc: Parse done.");
NodeList docElements = docXml.getTags("document");
for (i = 0; i < docElements.getLength(); i++) {
Element docElement = (Element)docElements.item(i);
docs[i] = getDocInfo(docElement);
}
return docs;
}
/**
* Get document element information.
*
* @author Rubens Massayuki Suguimoto
* @param docNode Element (dom element)
* @return Seed2Document item
*/
private Seed2Document getDocInfo(Element docNode) {
Seed2Document doc = new Seed2Document();
XmlUtil parse = new XmlUtil();
doc.Name = parse.getTextValue(docNode, "name");
doc.Size = parse.getTextValue(docNode, "size");
doc.Date = parse.getTextValue(docNode, "date");
doc.URL = parse.getTextValue(docNode, "url");
doc.Description = parse.getTextValue(docNode, "desc");
return doc;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment