Coverage details for base.user.jcard.JCard

LineHitsSource
1 /*******************************************************************************
2  * InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20  
21 package base.user.jcard;
22  
23 import java.io.BufferedWriter;
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileWriter;
27 import java.io.IOException;
28 import java.io.Reader;
29 import java.io.Writer;
30 import java.util.ArrayList;
31 import java.util.Properties;
32  
33 import org.apache.log4j.Logger;
34  
35 import base.user.User;
362 
372public class JCard implements IVCard {
382    
392    private static transient Logger logger = Logger.getLogger(JCard.class.getName());
40     
41     ArrayList<Property> containedProperties;
42     
43     private Properties availableProperties;
442    
454    public JCard() throws JCardException {
462        logger.info("New JCard created (in JCard ctor)");
472        try {
484            availableProperties = new Properties();
492            availableProperties.loadFromXML(new FileInputStream("jcard-properties.xml"));
500        
512            containedProperties = new ArrayList<Property>();
522        }
532        catch(Exception e) {
540            throw new JCardException("Error reading properties file", e);
550        }
562    }
57     
580    public Property addProperty(String propertyName) throws JCardException {
592        logger.info("Adding " + propertyName + " to JCard");
60         try {
61 // System.out.println(propertyName);
62 // System.out.println(availableProperties.getProperty(propertyName));
630// System.out.println(Class.forName(availableProperties.getProperty(propertyName)));
642            Property newProp = (Property) Class.forName(availableProperties.getProperty(propertyName)).newInstance();
650            //newProp.setPropertyName();
660            containedProperties.add(newProp);
670            return newProp;
680        }
690        catch(Exception e) {
700            throw new JCardException("Exception in creating property object", e);
71         }
72     }
73     
740    public void write(String fileName) throws JCardException {
750        File file = new File(fileName);
760        write(file);
770    }
78     
79     public void write(File file) throws JCardException {
800        try {
810            FileWriter fWriter = new FileWriter(file);
820            write(fWriter);
830        }
840        catch(IOException e) {
850            throw new JCardException("Exception in creating Writer object", e);
860        }
870    }
88     
89  
90     /* (non-Javadoc)
91      * @see test.base.user.jcard.IVCard#write(java.io.Writer)
92      */
93     public void write(Writer writer) throws JCardException {
94         try {
950            
960            StringBuffer stringCard = new StringBuffer();
970            stringCard.append("BEGIN:VCARD");
980            stringCard.append(Property.CRLF);
990            stringCard.append("VERSION:2.1");
1000            stringCard.append(Property.CRLF);
1010            
1020            for(Property property : containedProperties) {
1030                property.doValidate();
1040                stringCard.append(property.PROPERTY_NAME);
1050                stringCard.append(property.toString());
1060                stringCard.append(Property.CRLF);
1070            }
1080            
1090            stringCard.append("END:VCARD");
1100            
1110            BufferedWriter buffWriter = new BufferedWriter(writer);
1120            buffWriter.write(stringCard.toString());
1130            buffWriter.flush();
1140            buffWriter.close();
1150        }
1160        catch(IOException e) {
1170            throw new JCardException("Exception in writing file", e);
1180        }
1190    }
120  
121     public void read(Reader reader) {
122         // TODO Auto-generated method stub
1230        
1240    }
125  
126     public User newUser(JCard jcard) {
1270        // TODO Auto-generated method stub
1280        return null;
129     }
130  
131     public JCard newJCard(User user) {
1320        // TODO Auto-generated method stub
1330        return null;
134     }
135 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.