Ejemplo n.º 1
0
  /** @param aProperties the updated properties. */
  @SuppressWarnings("rawtypes")
  final void setProperties(final Dictionary aProperties) {
    final Map<String, String> newProps = new HashMap<String, String>();

    Enumeration keys = aProperties.keys();
    while (keys.hasMoreElements()) {
      final String key = (String) keys.nextElement();
      if (!KNOWN_KEYS.contains(key) && !IGNORED_KEYS.contains(key)) {
        LOG.log(Level.WARNING, "Unknown/unsupported profile key: " + key);
        continue;
      }

      final String value = aProperties.get(key).toString();
      newProps.put(key, value.trim());
    }

    // Verify whether all known keys are defined...
    final List<String> checkedKeys = new ArrayList<String>(KNOWN_KEYS);
    checkedKeys.removeAll(newProps.keySet());
    if (!checkedKeys.isEmpty()) {
      throw new IllegalArgumentException(
          "Profile settings not complete! Missing keys are: " + checkedKeys.toString());
    }

    this.properties.putAll(newProps);

    LOG.log(
        Level.INFO,
        "New device profile settings applied for {1} ({0}) ...", //
        new Object[] {getType(), getDescription()});
  }
Ejemplo n.º 2
0
 /**
  * @param props
  * @exception IllegalArgumentException
  */
 public synchronized void copyFrom(Dictionary props) throws IllegalArgumentException {
   Enumeration keys = props.keys();
   Enumeration values = props.elements();
   while (keys.hasMoreElements()) {
     put(keys.nextElement(), values.nextElement());
   }
 }
Ejemplo n.º 3
0
  public static void toJSON(ConfigurationAdmin admin, Writer osw, String filter) throws Exception {

    Configuration[] list = admin.listConfigurations(filter);
    Encoder encoder = codec.enc().to(osw);

    Protocol p = new Protocol();
    p.version = 1;
    p.date = new Date();
    p.size = list.length;
    encoder.put(p).append('\n');

    if (list != null)
      for (Configuration c : list) {
        Dictionary<String, Object> d = c.getProperties();
        Export export = new Export();
        export.values = new HashMap<String, Object>();
        export.factoryPid = c.getFactoryPid();
        export.pid = c.getPid();

        for (Enumeration<String> e = d.keys(); e.hasMoreElements(); ) {
          String k = e.nextElement();
          Object v = d.get(k);

          if (!(v instanceof String)) {

            if (export.types == null) export.types = new HashMap<String, Type>();

            Type type = new Type();

            Class<?> clazz = v.getClass();
            if (v instanceof Collection) {
              Collection<?> coll = (Collection<?>) v;
              clazz = String.class;
              if (coll.size() > 0) type.vectorOf = shortName(coll.iterator().next().getClass());
              else type.vectorOf = shortName(String.class);
            } else if (v.getClass().isArray()) {
              type.arrayOf = shortName(clazz.getComponentType());
            } else type.scalar = shortName(v.getClass());

            export.types.put(k, type);
          }
          export.values.put(k, v);
        }

        encoder.mark().put(export);
        // encoder.put(encoder.digest());
        encoder.append('\n');
      }
    osw.flush();
  }
      public String get(Object key) {
        if (!(key instanceof String)) return null;

        String sKey = (String) key;
        if (Constants.EXPORT_PACKAGE.equalsIgnoreCase(sKey)
            || Constants.PROVIDE_CAPABILITY.equalsIgnoreCase(sKey)) {
          String systemProvideHeader =
              getEquinoxContainer()
                  .getConfiguration()
                  .getConfiguration(
                      EquinoxConfiguration.PROP_SYSTEM_PROVIDE_HEADER,
                      EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_SYSTEM_EXTRA);
          boolean useSystemExtra =
              systemProvideHeader.equals(EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_SYSTEM_EXTRA);
          boolean useSystem =
              systemProvideHeader.equals(EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_SYSTEM)
                  || useSystemExtra;
          String systemProp =
              useSystem
                  ? (Constants.EXPORT_PACKAGE.equalsIgnoreCase(sKey)
                      ? Constants.FRAMEWORK_SYSTEMPACKAGES
                      : Constants.FRAMEWORK_SYSTEMCAPABILITIES)
                  : null;
          String systemExtraProp =
              useSystemExtra
                  ? (Constants.EXPORT_PACKAGE.equalsIgnoreCase(sKey)
                      ? Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA
                      : Constants.FRAMEWORK_SYSTEMCAPABILITIES_EXTRA)
                  : null;
          return getExtra(sKey, systemProp, systemExtraProp);
        }

        return headers.get(key);
      }
Ejemplo n.º 5
0
 /**
  * Compares the specified Object with this Dictionary for equality,
  *
  * @return true if the specified Object is equal to this Dictionary.
  */
 public synchronized boolean equals(Object o) {
   if (o == this) return true;
   if (!(o instanceof Dictionary)) return false;
   Dictionary dict = (Dictionary) o;
   int max = size();
   if (dict.size() != max) return false;
   Enumeration k = keys();
   Enumeration e = elements();
   for (int i = 0; i < max; i++) {
     Object key = k.nextElement();
     Object value = e.nextElement();
     if (!value.equals(dict.get(key))) {
       return false;
     }
   }
   return true;
 }
  private static synchronized String getSymbolicName(String path) {
    if (fCachedLocations == null) fCachedLocations = new HashMap();

    File file = new File(path);
    if (file.exists() && !fCachedLocations.containsKey(path)) {
      try {
        Dictionary dictionary = MinimalState.loadManifest(file);
        String value = (String) dictionary.get(Constants.BUNDLE_SYMBOLICNAME);
        if (value != null) {
          ManifestElement[] elements =
              ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, value);
          String id = elements.length > 0 ? elements[0].getValue() : null;
          if (id != null) fCachedLocations.put(path, elements[0].getValue());
        }
      } catch (IOException e) {
      } catch (BundleException e) {
      }
    }
    return (String) fCachedLocations.get(path);
  }
  /**
   * Get the names of all properties for this resource. This implementation reads all the properties
   * and then extracts their names.
   *
   * @return a MultiStatus of PropertyResponses (PropertyValue.value is always null,
   *     PropertyValue.status contains the status)
   * @exception com.ibm.webdav.WebDAVException
   */
  public MultiStatus getPropertyNames() throws WebDAVException {
    MultiStatus multiStatus = resource.getProperties(resource.getContext());
    Enumeration responses = multiStatus.getResponses();

    // we have the result, but all of the properties in our structure contain
    //    values.  We don't want to include values.  Just names.  The following
    //    code strips out the content of these elements.
    while (responses.hasMoreElements()) {
      PropertyResponse response = (PropertyResponse) responses.nextElement();
      Dictionary properties = response.getPropertiesByPropName();
      Enumeration keys = properties.keys();

      while (keys.hasMoreElements()) {
        PropertyName key = (PropertyName) keys.nextElement();
        Element value = (Element) response.getProperty(key).getValue();
        response.setProperty(
            key, new PropertyValue((Element) value.cloneNode(false), WebDAVStatus.SC_OK));
      }
    }

    return multiStatus;
  }
 /**
  * 训练时或者测试时使用,自动将类别信息加上 为语料库中所有文件计算特征值,并保存在本地文件(libsvm格式)
  *
  * <p>类别序号从1开始
  *
  * @param dicPath 词典目录
  * @param libPath 语料库目录,其下存放待分类类的语料。
  * @param resultFilePath 保存为libsvm格式的语料文档特征值文件
  */
 public void CalcFeaturesForAllFiles_Training(
     FeatureMaker FM, FeatureCounter FC, String dicPath, String libPath, String resultFilePath) {
   CategorizingDataManager CDM = new CategorizingDataManager(FC, dicPath, libPath, true);
   Dictionary dicEx = new Dictionary();
   String[] docs = CDM.getDocs();
   try {
     FileWriter fw = new FileWriter(resultFilePath);
     int docID = 0; // 文本ID在同一目录中递增
     //			fw.write(CDM.N+"\n");
     for (int i = 0; i < docs.length; i++) { // 对每一个类别
       for (String doc : CDM.getFilesPath(docs[i])) { // 对每一篇文档
         // 写入特征向量
         String temp = FeatureVectorOfDoc(FM, dicEx.readAll(doc), docID++, CDM);
         // System.out.println((i+1)+" "+temp+"\n");
         fw.write((i * 2 - 1) + " " + temp + "\n");
       }
     }
     fw.flush();
     fw.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
  public StopwordsEliminator(String filename)
      throws IOException, SAXException, ParserConfigurationException {
    Scanner scanner = new Scanner(new FileReader(filename));
    File newFile = new File("temporary2.dat");
    if (!newFile.exists()) newFile.createNewFile();

    BufferedWriter bw = new BufferedWriter(new FileWriter("temporary2.dat"));

    String sentence = new String();
    Dictionary SEDict = new Dictionary();
    while (scanner.hasNextLine()) {
      sentence = scanner.nextLine();
      String[] a = sentence.split(" ");
      for (int i = 0; i < a.length; i++) {
        if (SEDict.isStopword(a[i].trim().toLowerCase())) {
          sentence = sentence.replaceAll(" " + a[i] + " ", " ");
        }
      }
      bw.write(sentence);
    }
    bw.close();
    scanner.close();
  }
  public static Dictionary[] getPlatformProperties(String[] profiles, MinimalState state) {
    if (profiles == null || profiles.length == 0)
      return new Dictionary[] {getTargetEnvironment(state)};

    // add java profiles for those EE's that have a .profile file in the current system bundle
    ArrayList result = new ArrayList(profiles.length);
    for (int i = 0; i < profiles.length; i++) {
      IExecutionEnvironment environment =
          JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(profiles[i]);
      if (environment != null) {
        Properties profileProps = environment.getProfileProperties();
        if (profileProps != null) {
          Dictionary props = TargetPlatformHelper.getTargetEnvironment(state);
          String systemPackages = profileProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
          if (systemPackages != null) props.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages);
          String ee = profileProps.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
          if (ee != null) props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee);
          result.add(props);
        }
      }
    }
    if (result.size() > 0) return (Dictionary[]) result.toArray(new Dictionary[result.size()]);
    return new Dictionary[] {TargetPlatformHelper.getTargetEnvironment(state)};
  }
 public static Dictionary getTargetEnvironment() {
   Dictionary result = new Hashtable();
   result.put(ICoreConstants.OSGI_OS, TargetPlatform.getOS());
   result.put(ICoreConstants.OSGI_WS, TargetPlatform.getWS());
   result.put(ICoreConstants.OSGI_NL, TargetPlatform.getNL());
   result.put(ICoreConstants.OSGI_ARCH, TargetPlatform.getOSArch());
   result.put(ICoreConstants.OSGI_RESOLVE_OPTIONAL, "true"); // $NON-NLS-1$
   result.put(ICoreConstants.OSGI_RESOLVER_MODE, "development"); // $NON-NLS-1$
   return result;
 }
 private String getExtra(String header, String systemProp, String systemExtraProp) {
   String systemValue =
       systemProp != null
           ? getEquinoxContainer().getConfiguration().getConfiguration(systemProp)
           : null;
   String systemExtraValue =
       systemExtraProp != null
           ? getEquinoxContainer().getConfiguration().getConfiguration(systemExtraProp)
           : null;
   if (systemValue == null) systemValue = systemExtraValue;
   else if (systemExtraValue != null && systemExtraValue.trim().length() > 0)
     systemValue += ", " + systemExtraValue; // $NON-NLS-1$
   String result = headers.get(header);
   if (systemValue != null && systemValue.trim().length() > 0) {
     if (result != null) result += ", " + systemValue; // $NON-NLS-1$
     else result = systemValue;
   }
   return result;
 }
 /**
  * 词典初始化 由于IK Analyzer的词典采用Dictionary类的静态方法进行词典初始化 只有当Dictionary类被实际调用时,才会开始载入词典, 这将延长首次分词操作的时间
  * 该方法提供了一个在应用加载阶段就初始化字典的手段
  *
  * @return Dictionary
  */
 public static synchronized Dictionary initial(Configuration cfg) {
   if (singleton == null) {
     synchronized (Dictionary.class) {
       if (singleton == null) {
         singleton = new Dictionary();
         singleton.configuration = cfg;
         singleton.loadMainDict();
         singleton.loadSurnameDict();
         singleton.loadQuantifierDict();
         singleton.loadSuffixDict();
         singleton.loadPrepDict();
         singleton.loadStopWordDict();
         return singleton;
       }
     }
   }
   return singleton;
 }
Ejemplo n.º 14
0
 public void action(String word, Scanner input) {
   if (word.equalsIgnoreCase("/switch") || word.equalsIgnoreCase("/s")) {
     try {
       super.chooseBank();
     } catch (FileNotFoundException e) {
       // Handle the exception
     }
   } else if (word.equalsIgnoreCase("/quit") || word.equalsIgnoreCase("/q")) {
     quit();
   } else if (word.equalsIgnoreCase("/bank")) {
     getBank();
     define(input);
   } else if (word.equalsIgnoreCase("/add")) {
     addDef(file);
   } else if (word.equalsIgnoreCase("/help") || word.equalsIgnoreCase("/?")) {
     getHelp();
     System.out.println("\n");
     System.out.println("Enter a help function to be defined: ");
     helpDefine(input.nextLine(), input);
     define(input);
     // Update Comment
   }
 }
 public Object getAttribute(String attributeName) {
   Dictionary<String, Object> attributes = proxyContext.getContextAttributes(httpContext);
   return attributes.get(attributeName);
 }
 public Enumeration<String> elements() {
   return headers.elements();
 }
 public int size() {
   return headers.size();
 }
 public String remove(Object key) {
   return headers.remove(key);
 }
 public String put(String key, String value) {
   return headers.put(key, value);
 }
 public Enumeration<String> keys() {
   return headers.keys();
 }
 public static Dictionary getTargetEnvironment(MinimalState state) {
   Dictionary result = getTargetEnvironment();
   result.put(ICoreConstants.OSGI_SYSTEM_BUNDLE, state.getSystemBundle());
   return result;
 }
 public Enumeration<String> getAttributeNames() {
   Dictionary<String, Object> attributes = proxyContext.getContextAttributes(httpContext);
   return attributes.keys();
 }
 public void setAttribute(String attributeName, Object attributeValue) {
   Dictionary<String, Object> attributes = proxyContext.getContextAttributes(httpContext);
   attributes.put(attributeName, attributeValue);
 }
 public boolean isEmpty() {
   return headers.isEmpty();
 }
 public void removeAttribute(String attributeName) {
   Dictionary<String, Object> attributes = proxyContext.getContextAttributes(httpContext);
   attributes.remove(attributeName);
 }