001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *    Mariana Cedica
016 */
017package org.nuxeo.ecm.platform.importer.properties;
018
019import java.io.File;
020import java.io.FileInputStream;
021import java.io.IOException;
022import java.io.Serializable;
023import java.util.Enumeration;
024import java.util.HashMap;
025import java.util.Map;
026import java.util.Properties;
027
028/**
029 * The properties are mapped by the collector using as key the path of the file/folder to import.
030 */
031public class IndividualMetadataCollector extends MetadataCollector {
032
033    @Override
034    public void addPropertyFile(File propertyFile) throws IOException {
035        String contextPath = propertyFile.getAbsolutePath();
036        addPropertyFile(propertyFile, contextPath);
037    }
038
039    public void addPropertyFile(File propertyFile, String contextPath) throws IOException {
040        Properties mdProperties = new Properties();
041        mdProperties.load(new FileInputStream(propertyFile));
042        Map<String, String> stringMap = new HashMap<String, String>();
043        Enumeration<?> names = mdProperties.propertyNames();
044        while (names.hasMoreElements()) {
045            String name = (String) names.nextElement();
046            stringMap.put(name, mdProperties.getProperty(name));
047        }
048        addPropertiesFromStrings(contextPath, stringMap);
049    }
050
051    public Map<String, Serializable> getProperties(File file) {
052        return getProperties(file.getPath());
053    }
054}