Java Code Examples for java.util.Dictionary#get()

The following examples show how to use java.util.Dictionary#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaxCulBinding.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("MaxCUL Reading config");
    if (config != null) {

        // handle timezone configuration
        // maxcul:timezone=Europe/London
        String timezoneString = (String) config.get("timezone");
        if (StringUtils.isNotBlank(timezoneString)) {
            this.tzStr = timezoneString;
        } else {
            this.tzStr = "Europe/London";
        }

        culHandlerLifecycle.config(config);
    }
}
 
Example 2
Source File: MailControlBinding.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        this.config = config;
        this.connectorBuilder = new ConnectorBuilder(config);
        connectorBuilder.createAndCheckMailConnector();

        // to override the default refresh interval one has to add a
        // parameter to openhab.cfg like
        // <bindingName>:refresh=<intervalInMs>
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        setProperlyConfigured(true);
    }
}
 
Example 3
Source File: TTSServiceGoogleTTS.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    if (properties != null) {
        String language = (String) properties.get(LANGUAGE_PROPERTY);
        if (!StringUtils.isBlank(language)) {
            logger.debug("Using TTS language from config: " + ttsLanguage);
            ttsLanguage = language;
        }

        String delimiters = (String) properties.get(SENTENCE_DELIMITERS_PROPERTY);
        if (!StringUtils.isBlank(delimiters)) {
            logger.debug("Using custom sentence delimiters from config: " + delimiters);
            textProcessor.setCustomSentenceDelimiters(delimiters);
        }

        String configTranslateUrl = (String) properties.get(TRANSLATE_URL_PROPERTY);
        if (!StringUtils.isBlank(configTranslateUrl)) {
            logger.debug("Using custom translate URL from config: " + configTranslateUrl);
            translateUrl = configTranslateUrl;
        }
    }
}
 
Example 4
Source File: ImageView.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Loads the image from the URL <code>getImageURL</code>. This should
 * only be invoked from <code>refreshImage</code>.
 */
private void loadImage() {
    URL src = getImageURL();
    Image newImage = null;
    if (src != null) {
        Dictionary cache = (Dictionary)getDocument().
                                getProperty(IMAGE_CACHE_PROPERTY);
        if (cache != null) {
            newImage = (Image)cache.get(src);
        }
        else {
            newImage = Toolkit.getDefaultToolkit().createImage(src);
            if (newImage != null && getLoadsSynchronously()) {
                // Force the image to be loaded by using an ImageIcon.
                ImageIcon ii = new ImageIcon();
                ii.setImage(newImage);
            }
        }
    }
    image = newImage;
}
 
Example 5
Source File: RestApiUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
public static Boolean checkETagSkipList(String path, String httpMethod) {
    //Check if the accessing URI is ETag skipped
    try {
        Dictionary<org.wso2.uri.template.URITemplate, List<String>> eTagSkipListToMethodsMap = RestApiUtil.getETagSkipListToMethodsMap();
        Enumeration<org.wso2.uri.template.URITemplate> uriTemplateSet = eTagSkipListToMethodsMap.keys();

        while (uriTemplateSet.hasMoreElements()) {
            org.wso2.uri.template.URITemplate uriTemplate = uriTemplateSet.nextElement();
            if (uriTemplate.matches(path, new HashMap<String, String>())) {
                List<String> ETagDisableHttpVerbs = eTagSkipListToMethodsMap.get(uriTemplate);
                return ETagDisableHttpVerbs.contains(httpMethod);
            }
        }
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Unable to resolve ETag skip list in api-manager.xml", e, log);
    }
    return false;
}
 
Example 6
Source File: RepositoryCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public int cmdList(Dictionary<String,?> opts, Reader in, PrintWriter out,
    Session session) {
  final String [] selection = (String[]) opts.get("repository");
  final SortedSet<RepositoryInfo> repos = getRepoSelection(selection);
  final boolean verbose = (opts.get("-l") != null);

  if (repos.isEmpty()) {
    if (selection != null) {
      out.println("No matching repository.");
    } else {
      out.println("No repositories found.");
    }
    return 1;
  } else {
    printRepos(out, repos, null, verbose);
    return 0;
  }
}
 
Example 7
Source File: LogConfigCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public int cmdOut(Dictionary<String, ?> opts, Reader in, PrintWriter out, Session session)
{

  // Get log configuration service
  final LogConfig configuration =
    LogCommands.logConfigTracker.getService();
  if (configuration == null) {
    out.println("Unable to get a LogConfigService");
    return 1;
  }

  if (!configuration.isDefaultConfig()) {
    out.println("  This command is no persistent. (No valid configuration has been received)");
  }

  boolean optionFound = false;
  // System.out logging on/off
  if (opts.get("-on") != null) {
    optionFound = true;
    configuration.setOut(true);
  } else if (opts.get("-off") != null) {
    optionFound = true;
    configuration.setOut(false);
  }
  // Show current config
  if (!optionFound) {
    final boolean isOn = configuration.getOut();
    out.println("  Logging to standard out is " + (isOn ? "on" : "off") + ".");
  }
  return 0;
}
 
Example 8
Source File: OCD.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates an OCD with attribute definitions from an existing dictionary.
 *
 * @param id
 *          unique ID of the definition.
 * @param name
 *          human-readable name of the definition. If set to <tt>null</tt>,
 *          use <i>id</i> as name.
 * @param desc
 *          human-readable description of the definition
 * @param props
 *          set of key value pairs used for attribute definitions. all entries
 *          in <i>props</i> will be set as REQUIRED attributes.
 * @throws IllegalArgumentException
 *           if <i>id</i> is <null> or empty
 *
 */
public OCD(String id, String name, String desc, Dictionary<String, ?> props)
{
  this(id, name, desc, (URL) null);

  // System.out.println("OCD " + id + ", props=" + props);
  for (final Enumeration<String> e = props.keys(); e.hasMoreElements();) {
    final String key = e.nextElement();
    if ("service.pid".equals(key.toLowerCase())) {
      continue;
    }
    if ("service.factorypid".equals(key.toLowerCase())) {
      continue;
    }
    final Object val = props.get(key);

    int card = 0;
    final int type = AD.getType(val);

    if (val instanceof Vector) {
      card = Integer.MIN_VALUE;
    } else if (val.getClass().isArray()) {
      card = Integer.MAX_VALUE;
    }

    final AD ad =
      new AD(key, type, card, key, card == 0
        ? new String[] { AD.toString(val) }
        : null);

    // System.out.println(" add " + ad);
    add(ad, REQUIRED);
  }

}
 
Example 9
Source File: BasicSliderUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected int getHeightOfTallestLabel() {
    Dictionary dictionary = slider.getLabelTable();
    int tallest = 0;
    if ( dictionary != null ) {
        Enumeration keys = dictionary.keys();
        while ( keys.hasMoreElements() ) {
            JComponent label = (JComponent) dictionary.get(keys.nextElement());
            tallest = Math.max( label.getPreferredSize().height, tallest );
        }
    }
    return tallest;
}
 
Example 10
Source File: MeasuredValueBridgeListeners.java    From zigbee4java with Apache License 2.0 5 votes vote down vote up
/**
 * Called by the framework when a report has been received. This method calls all the listeners
 * <i>changedMeasuredValue</i> methods.
 */
public void receivedReport(final String endPointId, final short clusterId,
                           final Dictionary<Attribute, Object> reports) {
    if (reports.get(bridged) == null) {
        return;
    }
    synchronized (listeners) {
        for (MeasuredValueListener listener : listeners) {
            listener.changedMeasuredValue(new MeasuredValueEventImpl(cluster, (Integer) reports.get(bridged)));
        }
    }
}
 
Example 11
Source File: ConfigAdminHttpConduitConfigurer.java    From cxf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void updated(String pid, @SuppressWarnings("rawtypes") Dictionary properties)
    throws ConfigurationException {
    if (pid == null) {
        return;
    }
    deleted(pid);

    String url = (String)properties.get("url");
    String name = (String)properties.get("name");
    Matcher matcher = url == null ? null : Pattern.compile(url).matcher("");
    String p = (String)properties.get("order");
    int order = 50;
    if (p != null) {
        order = Integer.parseInt(p);
    }

    PidInfo info = new PidInfo(properties, matcher, order);

    props.put(pid, info);
    if (url != null) {
        props.put(url, info);
    }
    if (name != null) {
        props.put(name, info);
    }
    addToSortedInfos(info);
}
 
Example 12
Source File: KFLegacyMetaTypeParser.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Overwrite default values in MTP using a set of dictionaries.
 * 
 * @param mtp
 *          MetaTypeProvider containing instances of <tt>AD</tt>
 * @param propList
 *          List of Dictionary
 */
public static void setDefaultValues(MetaTypeProvider mtp,
    List<Dictionary<String, Object>> propList) {

  for (final Dictionary<String, Object> dictionary : propList) {
    final Dictionary<?, ?> props = dictionary;
    String pid = (String) props.get(SERVICE_PID);
    if (pid == null) {
      pid = (String) props.get("factory.pid");
    }

    ObjectClassDefinition ocd = null;
    try {
      ocd = mtp.getObjectClassDefinition(pid, null);
    } catch (final Exception ignored) {
    }

    if (ocd == null) {
      throw new IllegalArgumentException("No definition for pid '" + pid
          + "'");
    } else {
      final AttributeDefinition[] ads = ocd
          .getAttributeDefinitions(ObjectClassDefinition.ALL);

      for (int i = 0; ads != null && i < ads.length; i++) {
        final Object val = props.get(ads[i].getID());

        if (!(ads[i] instanceof AD)) {
          throw new IllegalArgumentException(
              "AttributeDefinitions must be instances of AD, otherwise default values cannot be set");
        }

        final AD ad = (AD) ads[i];

        if (val instanceof Vector) {
          ad.setDefaultValue(toStringArray((Vector<?>) val));
        } else if (val.getClass().isArray()) {
          ad.setDefaultValue(toStringArray((Object[]) val));
        } else {
          ad.setDefaultValue(new String[] { val.toString() });
        }
      }
    }
  }
}
 
Example 13
Source File: OrientDBAppender.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
private String getValue(Dictionary<String, Object> config, String key, String defaultValue) {
    String value = (String)config.get(key);
    return (value != null) ? value :  defaultValue;
}
 
Example 14
Source File: BasicSliderUI.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void paintLabels( Graphics g ) {
    Rectangle labelBounds = labelRect;

    Dictionary dictionary = slider.getLabelTable();
    if ( dictionary != null ) {
        Enumeration keys = dictionary.keys();
        int minValue = slider.getMinimum();
        int maxValue = slider.getMaximum();
        boolean enabled = slider.isEnabled();
        while ( keys.hasMoreElements() ) {
            Integer key = (Integer)keys.nextElement();
            int value = key.intValue();
            if (value >= minValue && value <= maxValue) {
                JComponent label = (JComponent) dictionary.get(key);
                label.setEnabled(enabled);

                if (label instanceof JLabel) {
                    Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon();

                    if (icon instanceof ImageIcon) {
                        // Register Slider as an image observer. It allows to catch notifications about
                        // image changes (e.g. gif animation)
                        Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider);
                    }
                }

                if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
                    g.translate( 0, labelBounds.y );
                    paintHorizontalLabel( g, value, label );
                    g.translate( 0, -labelBounds.y );
                }
                else {
                    int offset = 0;
                    if (!BasicGraphicsUtils.isLeftToRight(slider)) {
                        offset = labelBounds.width -
                            label.getPreferredSize().width;
                    }
                    g.translate( labelBounds.x + offset, 0 );
                    paintVerticalLabel( g, value, label );
                    g.translate( -labelBounds.x - offset, 0 );
                }
            }
        }
    }

}
 
Example 15
Source File: BasicSliderUI.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void paintLabels( Graphics g ) {
    Rectangle labelBounds = labelRect;

    Dictionary dictionary = slider.getLabelTable();
    if ( dictionary != null ) {
        Enumeration keys = dictionary.keys();
        int minValue = slider.getMinimum();
        int maxValue = slider.getMaximum();
        boolean enabled = slider.isEnabled();
        while ( keys.hasMoreElements() ) {
            Integer key = (Integer)keys.nextElement();
            int value = key.intValue();
            if (value >= minValue && value <= maxValue) {
                JComponent label = (JComponent) dictionary.get(key);
                label.setEnabled(enabled);

                if (label instanceof JLabel) {
                    Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon();

                    if (icon instanceof ImageIcon) {
                        // Register Slider as an image observer. It allows to catch notifications about
                        // image changes (e.g. gif animation)
                        Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider);
                    }
                }

                if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
                    g.translate( 0, labelBounds.y );
                    paintHorizontalLabel( g, value, label );
                    g.translate( 0, -labelBounds.y );
                }
                else {
                    int offset = 0;
                    if (!BasicGraphicsUtils.isLeftToRight(slider)) {
                        offset = labelBounds.width -
                            label.getPreferredSize().width;
                    }
                    g.translate( labelBounds.x + offset, 0 );
                    paintVerticalLabel( g, value, label );
                    g.translate( -labelBounds.x - offset, 0 );
                }
            }
        }
    }

}
 
Example 16
Source File: Loader.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Overwrite default values in MTP using a set of dictionaries.
 *
 * @param mtp
 *          MetaTypeProvider containing instances of <tt>AD</tt>
 * @param propList
 *          List of Dictionary
 */
public static void setDefaultValues(MetaTypeProvider mtp,
                                    List<Dictionary<String, Object>> propList)
{

  for (final Dictionary<String, Object> dictionary : propList) {
 final Dictionary<?, ?> props = dictionary;
 String pid = (String) props.get(SERVICE_PID);
 if (pid == null) {
  pid = (String) props.get("factory.pid");
 }

 ObjectClassDefinition ocd = null;
 try {
  ocd = mtp.getObjectClassDefinition(pid, null);
 } catch (final Exception ignored) {
 }

 if (ocd == null) {
  throw new IllegalArgumentException("No definition for pid '" + pid
                                     + "'");
 } else {
  final AttributeDefinition[] ads =
    ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);

  for (int i = 0; ads != null && i < ads.length; i++) {
    final Object val = props.get(ads[i].getID());

    if (!(ads[i] instanceof AD)) {
      throw new IllegalArgumentException(
                                         "AttributeDefinitions must be instances of AD, otherwise default values cannot be set");
    }

    final AD ad = (AD) ads[i];

    if (val instanceof Vector) {
      ad.setDefaultValue(toStringArray((Vector<?>) val));
    } else if (val.getClass().isArray()) {
      ad.setDefaultValue(toStringArray((Object[]) val));
    } else {
      ad.setDefaultValue(new String[] { val.toString() });
    }
  }
 }
}
}
 
Example 17
Source File: ScrCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public int cmdShow(final Dictionary<String, ?> opts,
                   final Reader in,
                   final PrintWriter out,
                   final Session session)
{
  final ScrService scr = scrService;
  int failed = 0;
  if (scr == null) {
    out.println("SCR commands are currently inactive");
    return 1;
  }
  Comparator<Component> order;
  if (opts.get("-b") != null) {
    order = new OrderBundle();
  } else if (opts.get("-n") != null) {
    order = new OrderName();
  } else {
    order = new OrderId();
  }
  final TreeSet<Component> comps = new TreeSet<Component>(order);
  final String[] cids = (String[]) opts.get("component");
  if (cids != null) {
    for (final String cid : cids) {
      final Component[] components = getComponents(scr, cid, out);
      if (components != null) {
        for (final Component component : components) {
          comps.add(component);
        }
      } else {
        failed++;
      }
    }
  } else {
    final Component[] cs = scr.getComponents();
    if (cs != null) {
      for (final Component element : cs) {
        comps.add(element);
      }
    }
  }
  final int format = opts.get("-f") != null ? FORMAT_FULL : FORMAT_DYNAMIC;
  final boolean reverse = opts.get("-r") != null;
  showInfo(comps, format, reverse, out);

  return failed > 0 ? 1 : 0;
}
 
Example 18
Source File: LogConfigCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public int cmdFile(final Dictionary<String, ?> opts,
                   final Reader in,
                   final PrintWriter out,
                   final Session session)
{

  // Get log configuration service
  final LogConfig configuration =
    LogCommands.logConfigTracker.getService();
  if (configuration == null) {
    out.println("Unable to get a LogConfigService");
    return 1;
  }

  if (configuration.getDir() == null) {
    out.println(" This command is disabled; "
                + "writable filesystem not available.");
    return 1;
  }

  boolean optionFound = false;
  // File logging on/off
  if (opts.get("-on") != null) {
    optionFound = true;
    configuration.setFile(true);
  } else if (opts.get("-off") != null) {
    optionFound = true;
    configuration.setFile(false);
  }
  // Flush
  if (opts.get("-flush") != null) {
    optionFound = true;
    configuration.setFlush(true);
  } else if (opts.get("-noflush") != null) {
    optionFound = true;
    configuration.setFlush(false);
  }
  // Log size
  String value = (String) opts.get("-size");
  if (value != null) {
    optionFound = true;
    try {
      configuration.setFileSize(Integer.parseInt(value));
    } catch (final NumberFormatException nfe1) {
      out.println("Cannot set log size (" + nfe1 + ").");
    }
  }
  // Log generations
  value = (String) opts.get("-gen");
  if (value != null) {
    optionFound = true;
    try {
      configuration.setMaxGen(Integer.parseInt(value));
    } catch (final NumberFormatException nfe2) {
      out.println("Cannot set generation count (" + nfe2 + ").");
    }
  }

  if (optionFound) {
    // Create persistent CM-config
    configuration.commit();
  } else {
    // Show current config
    final boolean isOn = configuration.getFile();
    out.println("  file logging is " + (isOn ? "on" : "off") + ".");
    out.println("  file size:    " + configuration.getFileSize());
    out.println("  generations:  " + configuration.getMaxGen());
    out.println("  flush:        " + configuration.getFlush());
    out.println("  log location: " + configuration.getDir());
  }
  return 0;
}
 
Example 19
Source File: PulseaudioBinding.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    if (config != null) {
        Enumeration keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();

            // the config-key enumeration contains additional keys that we
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }

            Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
            if (!matcher.matches()) {
                logger.debug("given pulseaudio-config-key '" + key
                        + "' does not follow the expected pattern '<serverId>.<host|port>'");
                continue;
            }

            matcher.reset();
            matcher.find();

            String serverId = matcher.group(1);

            PulseaudioServerConfig serverConfig = serverConfigCache.get(serverId);
            if (serverConfig == null) {
                serverConfig = new PulseaudioServerConfig();
                serverConfigCache.put(serverId, serverConfig);
            }

            String configKey = matcher.group(2);
            String value = (String) config.get(key);

            if ("host".equals(configKey)) {
                serverConfig.host = value;
            } else if ("port".equals(configKey)) {
                serverConfig.port = Integer.valueOf(value);
            } else {
                throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
            }
        }
        connectAllPulseaudioServers();
    }
}
 
Example 20
Source File: CsvMarshaller.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
@Activate
public void activate(ComponentContext componentContext) {
    Dictionary<String, Object> config = componentContext.getProperties();
    separator = (config.get("separator") != null) ? (String) config.get("separator") : ",";
}