001/*
002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021package org.nuxeo.ecm.platform.scanimporter.service;
022
023import java.io.Serializable;
024import java.text.SimpleDateFormat;
025
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XObject;
028
029/**
030 * XMap descriptor for meta-data mapping
031 *
032 * @author Thierry Delprat
033 */
034@XObject("fieldMapping")
035public class ScanFileFieldMapping implements Serializable {
036
037    private static final long serialVersionUID = 1L;
038
039    public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.sss'Z'");
040
041    @XNode("@sourceXPath")
042    protected String sourceXPath;
043
044    @XNode("@sourceAttribute")
045    protected String sourceAttribute = "TEXT";
046
047    @XNode("@targetXPath")
048    protected String targetXPath;
049
050    @XNode("@targetType")
051    protected String targetType = "String";
052
053    @XNode("@dateFormat")
054    protected String dateFormatStr;
055
056    protected SimpleDateFormat dateFormat;
057
058    public SimpleDateFormat getDateFormat() {
059        if (dateFormat == null) {
060            if (dateFormatStr != null) {
061                dateFormat = new SimpleDateFormat(dateFormatStr);
062            } else {
063                dateFormat = DEFAULT_DATE_FORMAT;
064            }
065        }
066        return dateFormat;
067    }
068
069    public String getSourceXPath() {
070        return sourceXPath;
071    }
072
073    public String getSourceAttribute() {
074        return sourceAttribute;
075    }
076
077    public String getTargetXPath() {
078        return targetXPath;
079    }
080
081    public String getTargetType() {
082        return targetType;
083    }
084
085}