All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bedework.caldav.server.IscheduleMessage Maven / Gradle / Ivy

There is a newer version: 5.0.7
Show newest version
/* ********************************************************************
    Licensed to Jasig under one or more contributor license
    agreements. See the NOTICE file distributed with this work
    for additional information regarding copyright ownership.
    Jasig licenses this file to you under the Apache License,
    Version 2.0 (the "License"); you may not use this file
    except in compliance with the License. You may obtain a
    copy of the License at:

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on
    an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied. See the License for the
    specific language governing permissions and limitations
    under the License.
*/
package org.bedework.caldav.server;

import org.bedework.util.misc.ToString;

import org.apache.james.jdkim.api.Headers;
import org.apache.james.jdkim.api.SignatureRecord;
import org.apache.james.jdkim.tagvalue.SignatureRecordImpl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author douglm
 *
 */
public class IscheduleMessage implements Headers, Serializable {
  private Map> headers = new HashMap>();
  private List fields = new ArrayList();

  /** value of the Originator header */
  protected String originator;

  /** values of Recipient headers */
  protected Set recipients = new TreeSet();

  protected String iScheduleVersion;
  protected String iScheduleMessageId;

  protected SignatureRecordImpl dkimSignature;

  /** Constructor
   */
  public IscheduleMessage() {
  }

  /** Add a field
   *
   * @param nameLc
   */
  public void addField(final String nameLc) {
    fields.add(nameLc);
  }

  /** Update the headers
   *
   * @param name
   * @param val
   */
  public void addHeader(final String name, final String val) {
    String nameLc = name.toLowerCase();
    List vals = headers.get(nameLc);
    if (vals == null) {
      vals = new ArrayList();
        headers.put(nameLc, vals);
    }

    if (!fields.contains(nameLc)) {
      addField(nameLc);
    }

    vals.add(val);
  }

  /** Get the originator
   *
   *  @return String     originator
   */
  public String getOriginator() {
    return originator;
  }

  /** Get the recipients
   *
   *  @return Set of String     recipients
   */
  public Set getRecipients() {
    return recipients;
  }

  /** Get the iScheduleVersion
   *
   *  @return String     iScheduleVersion
   */
  public String getIScheduleVersion() {
    return iScheduleVersion;
  }

  /** Get the iScheduleMessageId
   *
   *  @return String     iScheduleMessageId
   */
  public String getIScheduleMessageId() {
    return iScheduleMessageId;
  }

  /** Get the dkim signature
   *
   *  @return SignatureRecord
   */
  public SignatureRecord getDkimSignature() {
    return dkimSignature;
  }

  @Override
  public List getFields() {
    return fields;
  }

  @Override
  public List getFields(final String val) {
    /* The rest of the package assumes each 'field' is a header record with name
     * and CR LF terminator.
     *
     * For Ischedule - we concatenate all the headers to produce a single value.
     */
    List l = headers.get(val.toLowerCase());
    if ((l == null) || (l.size() == 0)) {
      return l;
    }

    StringBuilder sb = new StringBuilder();
    String delim = "";

    for (String s: l) {
      sb.append(delim);
      delim = ",";
      sb.append(s);
    }

    List namedL = new ArrayList();

    namedL.add(val + ":" + sb.toString());

    return namedL;
  }

  /**
   * @param val
   * @return header values without the name: part
   */
  public List getFieldVals(final String val) {
    return headers.get(val.toLowerCase());
  }

  @Override
  public String toString() {
    ToString ts = new ToString(this);

    ts.append("originator", getOriginator());

    return ts.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy