AbstractSettings.java 2.36 KB
Newer Older
Alexander Ivanov's avatar
Alexander Ivanov committed
1 2
/**
 * Copyright (c) 2013, Redsolution LTD. All rights reserved.
3
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
4 5
 * This file is part of Xabber project; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License, Version 3.
6
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
7 8 9 10
 * Xabber 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.
11
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * You should have received a copy of the GNU General Public License,
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */
package com.xabber.xmpp.archive;

import java.io.IOException;

import org.xmlpull.v1.XmlSerializer;

import com.xabber.xmpp.Instance;
import com.xabber.xmpp.SerializerUtils;

/**
 * Settings item inside the {@link Pref}.
26
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
27 28 29 30
 * @author alexander.ivanov
 */
public abstract class AbstractSettings implements Instance {

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    public static final String EXPIRE_ATTRIBUTE = "expire";
    public static final String OTR_ATTRIBUTE = "otr";
    public static final String SAVE_ATTRIBUTE = "save";

    private Integer expire;
    private OtrMode otr;
    private SaveMode save;

    @Override
    public boolean isValid() {
        return true;
    }

    abstract String getElementName();

    @Override
    public void serialize(XmlSerializer serializer) throws IOException {
        serializer.startTag(null, getElementName());
        serializeAttributes(serializer);
        serializer.endTag(null, getElementName());
    }

    void serializeAttributes(XmlSerializer serializer) throws IOException {
        if (expire != null)
            SerializerUtils.setIntegerAttribute(serializer, EXPIRE_ATTRIBUTE,
                    expire);
        if (otr != null)
            SerializerUtils.setTextAttribute(serializer, OTR_ATTRIBUTE,
                    otr.toString());
        if (save != null)
            SerializerUtils.setTextAttribute(serializer, SAVE_ATTRIBUTE,
                    save.toString());
    }

    public Integer getExpire() {
        return expire;
    }

    public void setExpire(Integer expire) {
        this.expire = expire;
    }

    public OtrMode getOtr() {
        return otr;
    }

    public void setOtr(OtrMode otr) {
        this.otr = otr;
    }

    public SaveMode getSave() {
        return save;
    }

    public void setSave(SaveMode save) {
        this.save = save;
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
88 89

}