/** * Returns true iff all the files listed in this tracker's dependency list exist and are at the * same version as when they were recorded. * * @return a boolean */ boolean isUpToDate(Properties properties) { Iterator e; // fixes bug 962 { if (mProperties.size() != properties.size()) { mLogger.debug( /* (non-Javadoc) * @i18n.test * @org-mes="my size " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage( DependencyTracker.class.getName(), "051018-181", new Object[] {new Integer(mProperties.size())})); mLogger.debug( /* (non-Javadoc) * @i18n.test * @org-mes="new size " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage( DependencyTracker.class.getName(), "051018-189", new Object[] {new Integer(properties.size())})); return false; } for (e = mProperties.keySet().iterator(); e.hasNext(); ) { String key = (String) e.next(); String val0 = mProperties.getProperty(key); String val1 = properties.getProperty(key); // val0 can't be null; properties don't allow that if (val1 == null || !val0.equals(val1)) { mLogger.debug( /* (non-Javadoc) * @i18n.test * @org-mes="Missing or changed property: " + p[0] */ org.openlaszlo.i18n.LaszloMessages.getMessage( DependencyTracker.class.getName(), "051018-207", new Object[] {val0})); return false; } } } for (e = mDependencies.iterator(); e.hasNext(); ) { FileInfo saved = (FileInfo) e.next(); FileInfo current = new FileInfo(saved.mPathname); if (!saved.isUpToDate(current)) { mLogger.debug(saved.mPathname + " has changed"); mLogger.debug("was " + saved.mLastMod); mLogger.debug(" is " + current.mLastMod); return false; } } return true; }
/** 读取配置文件中的全局参数的配置,存到缓存中 */ private static void initProperties() { try { logger.debug("加载属性配置文件开始!"); String propUrl = getSysPath() + "config.properties"; logger.debug("系统全局参数的路径是:" + propUrl); FileInputStream fis = new FileInputStream(propUrl); // 属性文件流 Properties prop = new Properties(); // 属性集合对象 prop.load(fis); // 将属性文件流装载到Properties对象中 logger.debug("属性的长度:" + prop.size()); Map<String, String> paramMap = new HashMap<String, String>(); Iterator<Object> it = prop.keySet().iterator(); while (it.hasNext()) { String key = (String) (it.next()); String value = prop.getProperty(key); logger.debug(key + "=" + value); // global.ip=192.168.0.242的格式 // map.put(key, prop.getProperty(key)); paramMap.put(key, value); } logger.debug("加载属性配置文件结束!"); setConfigMap(paramMap); } catch (FileNotFoundException e) { logger.error("文件未找到!"); e.printStackTrace(); } catch (IOException e) { logger.error("读取文件的时候异常!"); e.printStackTrace(); } catch (Exception e) { logger.error("其它异常!"); e.printStackTrace(); } }
public String getHeaderField(int index) throws IOException { LOG.TRACE("getHeaderField: " + index); processRequest(); if (index >= resHeaders.size()) { return null; } return resHeaders.getValueAt(index); }
/** * Method to obtain the custom UI media types. * * @param configSystemRegistry a configuration system registry instance. * @return a String of custom UI media types, in the format name:type,name:type,... * @throws RegistryException if the operation failed. */ public static String getCustomUIMediaTypeMappings(Registry configSystemRegistry) throws RegistryException { RegistryContext registryContext = configSystemRegistry.getRegistryContext(); if (getCustomUIMediaTypeMappings(registryContext) != null) { return getCustomUIMediaTypeMappings(registryContext); } Resource resource; String mediaTypeString = null; String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR + RESOURCE_MIME_TYPE_INDEX; // TODO: Adding the media types should ideally be done by the handler associated with the // media type if (!configSystemRegistry.resourceExists(resourcePath)) { getResourceMediaTypeMappings(configSystemRegistry); } if (!configSystemRegistry.resourceExists( resourcePath + RegistryConstants.PATH_SEPARATOR + CUSTOM_UI_MIME_TYPE_INDEX)) { resource = configSystemRegistry.newResource(); resource.setProperty("profiles", "application/vnd.wso2-profiles+xml"); // resource.setProperty("service", "application/vnd.wso2-service+xml"); resource.setDescription( "This resource contains the media Types associated with " + "custom user interfaces on the Registry. Add, Edit or Delete properties to " + "Manage Media Types."); configSystemRegistry.put( resourcePath + RegistryConstants.PATH_SEPARATOR + CUSTOM_UI_MIME_TYPE_INDEX, resource); } else { resource = configSystemRegistry.get( resourcePath + RegistryConstants.PATH_SEPARATOR + CUSTOM_UI_MIME_TYPE_INDEX); } Properties properties = resource.getProperties(); if (properties.size() > 0) { Set<Object> keySet = properties.keySet(); for (Object key : keySet) { if (key instanceof String) { String ext = (String) key; if (RegistryUtils.isHiddenProperty(ext)) { continue; } String value = resource.getProperty(ext); String mediaTypeMapping = ext + ":" + value; if (mediaTypeString == null) { mediaTypeString = mediaTypeMapping; } else { mediaTypeString = mediaTypeString + "," + mediaTypeMapping; } } } } registryContext.setCustomUIMediaTypes(mediaTypeString); return mediaTypeString; }
@Test public void testEmptyState() throws IOException { final File fcontent = File.createTempFile("foo2", "bar"); final Properties loadProperties = new Properties(); final InputStream in = new FileInputStream(fcontent); loadProperties.load(in); assertEquals(0, loadProperties.size()); }
@Override public boolean execute(MOB mob, List<String> commands, int metaFlags) throws java.io.IOException { final Properties helpFile = CMLib.help().getHelpFile(); if (helpFile.size() == 0) { if (mob != null) mob.tell(L("No help is available.")); return false; } doTopics(mob, helpFile, "HELP", "PLAYER TOPICS"); return false; }
public void reportUnusedPropertyNames(IProgressMonitor pm) { // Don't use endReporting() for long running operation. pm.beginTask("", fProperties.size()); // $NON-NLS-1$ boolean hasUnused = false; pm.setTaskName(NLSSearchMessages.NLSSearchResultRequestor_searching); FileEntry groupElement = new FileEntry(fPropertiesFile, NLSSearchMessages.NLSSearchResultCollector_unusedKeys); for (Enumeration<?> enumeration = fProperties.propertyNames(); enumeration.hasMoreElements(); ) { String propertyName = (String) enumeration.nextElement(); if (!fUsedPropertyNames.contains(propertyName)) { addMatch(groupElement, propertyName); hasUnused = true; } pm.worked(1); } if (hasUnused) fResult.addFileEntryGroup(groupElement); pm.done(); }
/** * This method is used to get the String that contain key value pair from the propertise. * * @param String * @return String. */ public String list(String propfile) { Properties properties = (Properties) cachedPropertyFiles.get(propfile); if (properties == null) return ""; synchronized (properties) { StringBuffer buf = new StringBuffer(properties.size() * 50); for (Enumeration e = properties.keys(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String val = (String) properties.get(key); if (val.length() > 40) { val = val.substring(0, 37) + "..."; } buf.append(key); buf.append('='); buf.append(val); buf.append('\n'); } return buf.toString(); } }
public void testProperties() throws Exception { Properties props = new Properties(); String propsString = (String) blocks.get("PROPERTIES"); ByteArrayInputStream input = new ByteArrayInputStream(propsString.trim().getBytes(encoding)); props.load(input); String[] pageKeys = page.getPropertyKeys(); assertEquals( file.getName() + " : Unexpected number of page properties [" + join(pageKeys) + "]", props.size(), pageKeys.length); for (int i = 0; i < pageKeys.length; i++) { String pageKey = pageKeys[i]; String blockValue = props.getProperty(pageKey); String pageValue = page.getProperty(pageKey); assertEquals( file.getName() + ": " + pageKey, blockValue == null ? null : blockValue.trim(), pageValue == null ? null : pageValue.trim()); } }
public String getHeaderFieldKey(int index) throws IOException { LOG.TRACE("getHeaderFieldKey: " + index); processRequest(); if (index >= resHeaders.size()) return null; return ((String) (resHeaders.getKeyAt(index))); }
/** * Method to obtain the resource media types. * * @param configSystemRegistry a configuration system registry instance. * @return a String of resource media types, in the format extension:type,extension:type,... * @throws RegistryException if the operation failed. */ public static String getResourceMediaTypeMappings(Registry configSystemRegistry) throws RegistryException { RegistryContext registryContext = configSystemRegistry.getRegistryContext(); if (getResourceMediaTypeMappings(registryContext) != null) { return getResourceMediaTypeMappings(registryContext); } Resource resource; String mediaTypeString = null; String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR + RESOURCE_MIME_TYPE_INDEX; if (!configSystemRegistry.resourceExists(resourcePath)) { resource = configSystemRegistry.newCollection(); } else { resource = configSystemRegistry.get(resourcePath); Properties properties = resource.getProperties(); if (properties.size() > 0) { Set<Object> keySet = properties.keySet(); for (Object key : keySet) { if (key instanceof String) { String ext = (String) key; if (RegistryUtils.isHiddenProperty(ext)) { continue; } String value = resource.getProperty(ext); String mediaTypeMapping = ext + ":" + value; if (mediaTypeString == null) { mediaTypeString = mediaTypeMapping; } else { mediaTypeString = mediaTypeString + "," + mediaTypeMapping; } } } } registryContext.setResourceMediaTypes(mediaTypeString); return mediaTypeString; } BufferedReader reader; try { File mimeFile = getMediaTypesFile(); reader = new BufferedReader(new InputStreamReader(new FileInputStream(mimeFile))); } catch (Exception e) { String msg = "Failed to read the the media type definitions file. Only a limited " + "set of media type definitions will be populated. "; log.error(msg, e); mediaTypeString = "txt:text/plain,jpg:image/jpeg,gif:image/gif"; registryContext.setResourceMediaTypes(mediaTypeString); return mediaTypeString; } try { while (reader.ready()) { String mediaTypeData = reader.readLine().trim(); if (mediaTypeData.startsWith("#")) { // ignore the comments continue; } if (mediaTypeData.length() == 0) { // ignore the blank lines continue; } // mime.type file delimits media types:extensions by tabs. if there is no // extension associated with a media type, there are no tabs in the line. so we // don't need such lines. if (mediaTypeData.indexOf('\t') > 0) { String[] parts = mediaTypeData.split("\t+"); if (parts.length == 2 && parts[0].length() > 0 && parts[1].length() > 0) { // there can multiple extensions associated with a single media type. in // that case, extensions are delimited by a space. String[] extensions = parts[1].trim().split(" "); for (String extension : extensions) { if (extension.length() > 0) { String mediaTypeMapping = extension + ":" + parts[0]; resource.setProperty(extension, parts[0]); if (mediaTypeString == null) { mediaTypeString = mediaTypeMapping; } else { mediaTypeString = mediaTypeString + "," + mediaTypeMapping; } } } } } } resource.setDescription( "This collection contains the media Types available for " + "resources on the Registry. Add, Edit or Delete properties to Manage Media " + "Types."); Resource collection = configSystemRegistry.newCollection(); collection.setDescription( "This collection lists the media types available on the " + "Registry Server. Before changing an existing media type, please make sure " + "to alter existing resources/collections and related configuration details."); configSystemRegistry.put(MIME_TYPE_COLLECTION, collection); configSystemRegistry.put(resourcePath, resource); } catch (IOException e) { String msg = "Could not read the media type mappings file from the location: "; throw new RegistryException(msg, e); } finally { try { reader.close(); } catch (IOException ignore) { } } registryContext.setResourceMediaTypes(mediaTypeString); return mediaTypeString; }
/** * Setup the Protocol instance acording to the configuration string The following properties are * being read by the UDP protocol param mcast_addr - the multicast address to use default is * 224.0.0.200 param mcast_port - (int) the port that the multicast is sent on default is 7500 * param ip_mcast - (boolean) flag whether to use IP multicast - default is true param ip_ttl - * Set the default time-to-live for multicast packets sent out on this socket. default is 32 * * @return true if no other properties are left. false if the properties still have data in them, * ie , properties are left over and not handled by the protocol stack */ public boolean setProperties(Properties props) { String str, tmp; tmp = System.getProperty("UDP.bind_addr"); if (tmp != null) { str = tmp; } else { str = props.getProperty("bind_addr"); } if (str != null) { try { bind_addr = InetAddress.getByName(str); } catch (UnknownHostException unknown) { Trace.fatal("UDP.setProperties()", "(bind_addr): host " + str + " not known"); return false; } props.remove("bind_addr"); } str = props.getProperty("bind_port"); if (str != null) { bind_port = new Integer(str).intValue(); props.remove("bind_port"); } str = props.getProperty("start_port"); if (str != null) { bind_port = new Integer(str).intValue(); props.remove("start_port"); } str = props.getProperty("port_range"); if (str != null) { port_range = new Integer(str).intValue(); props.remove("port_range"); } str = props.getProperty("mcast_addr"); if (str != null) { mcast_addr_name = new String(str); props.remove("mcast_addr"); } str = props.getProperty("mcast_port"); if (str != null) { mcast_port = new Integer(str).intValue(); props.remove("mcast_port"); } str = props.getProperty("ip_mcast"); if (str != null) { ip_mcast = new Boolean(str).booleanValue(); props.remove("ip_mcast"); } str = props.getProperty("ip_ttl"); if (str != null) { ip_ttl = new Integer(str).intValue(); props.remove("ip_ttl"); } str = props.getProperty("mcast_send_buf_size"); if (str != null) { mcast_send_buf_size = Integer.parseInt(str); props.remove("mcast_send_buf_size"); } str = props.getProperty("mcast_recv_buf_size"); if (str != null) { mcast_recv_buf_size = Integer.parseInt(str); props.remove("mcast_recv_buf_size"); } str = props.getProperty("ucast_send_buf_size"); if (str != null) { ucast_send_buf_size = Integer.parseInt(str); props.remove("ucast_send_buf_size"); } str = props.getProperty("ucast_recv_buf_size"); if (str != null) { ucast_recv_buf_size = Integer.parseInt(str); props.remove("ucast_recv_buf_size"); } str = props.getProperty("loopback"); if (str != null) { loopback = new Boolean(str).booleanValue(); props.remove("loopback"); } // this is deprecated, just left for compatibility (use use_incoming_packet_handler) str = props.getProperty("use_packet_handler"); if (str != null) { use_incoming_packet_handler = new Boolean(str).booleanValue(); props.remove("use_packet_handler"); Trace.warn( "UDP.setProperties()", "'use_packet_handler' is deprecated; use 'use_incoming_packet_handler' instead"); } str = props.getProperty("use_incoming_packet_handler"); if (str != null) { use_incoming_packet_handler = new Boolean(str).booleanValue(); props.remove("use_incoming_packet_handler"); } str = props.getProperty("use_outgoing_packet_handler"); if (str != null) { use_outgoing_packet_handler = new Boolean(str).booleanValue(); props.remove("use_outgoing_packet_handler"); } str = props.getProperty("max_bundle_size"); if (str != null) { int bundle_size = Integer.parseInt(str); if (bundle_size > max_bundle_size) { Trace.error( "UDP.setProperties()", "max_bundle_size (" + bundle_size + ") is greater than largest UDP fragmentation size (" + max_bundle_size + ")"); return false; } if (bundle_size <= 0) { Trace.error("UDP.setProperties()", "max_bundle_size (" + bundle_size + ") is <= 0"); return false; } max_bundle_size = bundle_size; props.remove("max_bundle_size"); } str = props.getProperty("max_bundle_timeout"); if (str != null) { max_bundle_timeout = Long.parseLong(str); if (max_bundle_timeout <= 0) { Trace.error( "UDP.setProperties()", "max_bundle_timeout of " + max_bundle_timeout + " is invalid"); return false; } props.remove("max_bundle_timeout"); } str = props.getProperty("enable_bundling"); if (str != null) { enable_bundling = new Boolean(str).booleanValue(); props.remove("enable_bundling"); } if (props.size() > 0) { System.err.println("UDP.setProperties(): the following properties are not recognized:"); props.list(System.out); return false; } if (enable_bundling) { if (use_outgoing_packet_handler == false) { Trace.warn( "UDP.setProperties()", "enable_bundling is true; setting use_outgoing_packet_handler=true"); } use_outgoing_packet_handler = true; } return true; }
/* * @see org.eclipse.jdt.core.search.SearchRequestor#beginReporting() */ @Override public void beginReporting() { loadProperties(); fUsedPropertyNames = new HashSet<String>(fProperties.size()); }