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

com.tigervnc.rfb.Configuration Maven / Gradle / Ivy

The newest version!
/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
 * Copyright 2004-2005 Cendio AB.
 * Copyright 2012 Brian P. Hinz
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This software 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 * USA.
 */

//
// Configuration - class for dealing with configuration parameters.
//

package com.tigervnc.rfb;

import java.io.FileInputStream;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class Configuration {

  static LogWriter vlog = new LogWriter("Configuration");

  public enum ConfigurationObject { ConfGlobal, ConfServer, ConfViewer };

  // -=- The Global/server/viewer Configuration objects
  private static Configuration global_ = null;
  private static Configuration server_ = null;
  private static Configuration viewer_ = null;

  public static Configuration global() {
    if (global_ == null)
      global_ = new Configuration("Global");
    return global_;
  }

  public static Configuration server() {
    if (server_ == null)
      server_ = new Configuration("Server");
    return server_;
  }

  public static Configuration viewer() {
    if (viewer_ == null)
      viewer_ = new Configuration("Viewer");
    return viewer_;
  }

  // Enable server/viewer specific parameters
  public static void enableServerParams() { global().appendConfiguration(server()); }
  public static void enableViewerParams() { global().appendConfiguration(viewer()); }

  // Append configuration object to this instance.
  // NOTE: conf instance can be only one configuration object
  public void appendConfiguration(Configuration conf) {
    conf._next = _next; _next = conf;
  }

  // -=- Configuration implementation
  public Configuration(String name_, Configuration attachToGroup) {
    name = name_; head = null; _next = null;
    if (attachToGroup != null) {
      _next = attachToGroup._next;
      attachToGroup._next = this;
    }
  }

  public Configuration(String name_) {
    this(name_, null);
  }

  // - Return the buffer containing the Configuration's name
  final public String getName() { return name; }

  // - Assignment operator.  For every Parameter in this Configuration's
  //   group, get()s the corresponding source parameter and copies its
  //   content.
  public Configuration assign(Configuration src) {
    VoidParameter current = head;
    while (current != null) {
      VoidParameter srcParam = ((Configuration)src).get(current.getName());
      if (srcParam != null) {
        current.immutable = false;
        String value = srcParam.getValueStr();
        vlog.debug("operator=("+current.getName()+", "+value+")");
        current.setParam(value);
      }
      current = current._next;
    }
    if (_next != null)
      _next = src;
    return this;
  }

  // - Set named parameter to value
  public boolean set(String n, String v, boolean immutable) {
    return set(n, n.length(), v, immutable);
  }

  public boolean set(String n, String v) {
    return set(n, n.length(), v, false);
  }

  // - Set parameter to value (separated by "=")
  public boolean set(String name, int len,
                     String val, boolean immutable)
  {
    VoidParameter current = head;
    while (current != null) {
      if (current.getName().length() == len &&
          current.getName().equalsIgnoreCase(name.substring(0, len)))
      {
        boolean b = current.setParam(val);
        current.setHasBeenSet();
        if (b && immutable)
  	  current.setImmutable();
        return b;
      }
      current = current._next;
    }
    return (_next != null) ? _next.set(name, len, val, immutable) : false;
  }

  // - Set named parameter to value, with name truncated at len
  boolean set(String config, boolean immutable) {
    boolean hyphen = false;
    if (config.charAt(0) == '-') {
      hyphen = true;
      config = config.substring(1);
      if (config.charAt(0) == '-') config = config.substring(1); // allow gnu-style --




© 2015 - 2024 Weber Informatics LLC | Privacy Policy