001/*
002 * Copyright 2007-2018 The jdeb developers.
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
017package org.vafer.jdeb.debian;
018
019import java.io.IOException;
020import java.io.InputStream;
021import java.text.ParseException;
022
023/**
024 * Binary package control file.
025 *
026 * @see <a href="http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles">Debian Policy Manual - Binary package control files</a>
027 */
028public final class BinaryPackageControlFile extends ControlFile {
029
030    private static final ControlField[] FIELDS = {
031            new ControlField("Package", true),
032            new ControlField("Source"),
033            new ControlField("Version", true),
034            new ControlField("Section", true),
035            new ControlField("Priority", true),
036            new ControlField("Architecture", true),
037            new ControlField("Essential"),
038            new ControlField("Depends"),
039            new ControlField("Pre-Depends"),
040            new ControlField("Recommends"),
041            new ControlField("Suggests"),
042            new ControlField("Breaks"),
043            new ControlField("Enhances"),
044            new ControlField("Conflicts"),
045            new ControlField("Provides"),
046            new ControlField("Replaces"),
047            new ControlField("Installed-Size"),
048            new ControlField("Maintainer", true),
049            new ControlField("Description", true, ControlField.Type.MULTILINE),
050            new ControlField("Homepage"),
051            new ControlField("Multi-Arch")
052    };
053
054    public BinaryPackageControlFile() {
055        set("Architecture", "all");
056        set("Priority", "optional");
057    }
058
059    public BinaryPackageControlFile(String input) throws IOException, ParseException {
060        parse(input);
061    }
062
063    public BinaryPackageControlFile(InputStream input) throws IOException, ParseException {
064        parse(input);
065    }
066
067    public void set(final String field, final String value) {
068        super.set(field, value);
069    }
070
071    protected ControlField[] getFields() {
072        return FIELDS;
073    }
074
075    /**
076     * Returns the short description of the package. The short description
077     * consists in the first line of the Description field.
078     *
079     * @return
080     */
081    public String getShortDescription() {
082        if (get("Description") == null) {
083            return null;
084        }
085
086        return get("Description").split("\n")[0];
087    }
088
089    protected char getUserDefinedFieldLetter() {
090        return 'B';
091    }
092}