| Line | Hits | Source |
|---|---|---|
| 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; | |
| 36 | 2 | |
| 37 | 2 | public class JCard implements IVCard { |
| 38 | 2 | |
| 39 | 2 | private static transient Logger logger = Logger.getLogger(JCard.class.getName()); |
| 40 | ||
| 41 | ArrayList<Property> containedProperties; | |
| 42 | ||
| 43 | private Properties availableProperties; | |
| 44 | 2 | |
| 45 | 4 | public JCard() throws JCardException { |
| 46 | 2 | logger.info("New JCard created (in JCard ctor)"); |
| 47 | 2 | try { |
| 48 | 4 | availableProperties = new Properties(); |
| 49 | 2 | availableProperties.loadFromXML(new FileInputStream("jcard-properties.xml")); |
| 50 | 0 | |
| 51 | 2 | containedProperties = new ArrayList<Property>(); |
| 52 | 2 | } |
| 53 | 2 | catch(Exception e) { |
| 54 | 0 | throw new JCardException("Error reading properties file", e); |
| 55 | 0 | } |
| 56 | 2 | } |
| 57 | ||
| 58 | 0 | public Property addProperty(String propertyName) throws JCardException { |
| 59 | 2 | logger.info("Adding " + propertyName + " to JCard"); |
| 60 | try { | |
| 61 | // System.out.println(propertyName); | |
| 62 | // System.out.println(availableProperties.getProperty(propertyName)); | |
| 63 | 0 | // System.out.println(Class.forName(availableProperties.getProperty(propertyName))); |
| 64 | 2 | Property newProp = (Property) Class.forName(availableProperties.getProperty(propertyName)).newInstance(); |
| 65 | 0 | //newProp.setPropertyName(); |
| 66 | 0 | containedProperties.add(newProp); |
| 67 | 0 | return newProp; |
| 68 | 0 | } |
| 69 | 0 | catch(Exception e) { |
| 70 | 0 | throw new JCardException("Exception in creating property object", e); |
| 71 | } | |
| 72 | } | |
| 73 | ||
| 74 | 0 | public void write(String fileName) throws JCardException { |
| 75 | 0 | File file = new File(fileName); |
| 76 | 0 | write(file); |
| 77 | 0 | } |
| 78 | ||
| 79 | public void write(File file) throws JCardException { | |
| 80 | 0 | try { |
| 81 | 0 | FileWriter fWriter = new FileWriter(file); |
| 82 | 0 | write(fWriter); |
| 83 | 0 | } |
| 84 | 0 | catch(IOException e) { |
| 85 | 0 | throw new JCardException("Exception in creating Writer object", e); |
| 86 | 0 | } |
| 87 | 0 | } |
| 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 { | |
| 95 | 0 | |
| 96 | 0 | StringBuffer stringCard = new StringBuffer(); |
| 97 | 0 | stringCard.append("BEGIN:VCARD"); |
| 98 | 0 | stringCard.append(Property.CRLF); |
| 99 | 0 | stringCard.append("VERSION:2.1"); |
| 100 | 0 | stringCard.append(Property.CRLF); |
| 101 | 0 | |
| 102 | 0 | for(Property property : containedProperties) { |
| 103 | 0 | property.doValidate(); |
| 104 | 0 | stringCard.append(property.PROPERTY_NAME); |
| 105 | 0 | stringCard.append(property.toString()); |
| 106 | 0 | stringCard.append(Property.CRLF); |
| 107 | 0 | } |
| 108 | 0 | |
| 109 | 0 | stringCard.append("END:VCARD"); |
| 110 | 0 | |
| 111 | 0 | BufferedWriter buffWriter = new BufferedWriter(writer); |
| 112 | 0 | buffWriter.write(stringCard.toString()); |
| 113 | 0 | buffWriter.flush(); |
| 114 | 0 | buffWriter.close(); |
| 115 | 0 | } |
| 116 | 0 | catch(IOException e) { |
| 117 | 0 | throw new JCardException("Exception in writing file", e); |
| 118 | 0 | } |
| 119 | 0 | } |
| 120 | ||
| 121 | public void read(Reader reader) { | |
| 122 | // TODO Auto-generated method stub | |
| 123 | 0 | |
| 124 | 0 | } |
| 125 | ||
| 126 | public User newUser(JCard jcard) { | |
| 127 | 0 | // TODO Auto-generated method stub |
| 128 | 0 | return null; |
| 129 | } | |
| 130 | ||
| 131 | public JCard newJCard(User user) { | |
| 132 | 0 | // TODO Auto-generated method stub |
| 133 | 0 | return null; |
| 134 | } | |
| 135 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |