DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Attributes | Properties | Static Private Member Functions | List of all members
Deveel.Data.Util.Properties Class Reference
Inheritance diagram for Deveel.Data.Util.Properties:

Public Member Functions

 Properties ()
 Creates a new empty property list with no default values. More...
 
 Properties (Properties defaults)
 
Object SetProperty (String key, String value)
 
void Load (Stream inStream)
 /summary> param name="inStream"> More...
 
void Save (Stream output, String header)
 
void Store (Stream output, String header)
 
String GetProperty (String key)
 
String GetProperty (String key, String defaultValue)
 
void List (Stream output)
 
void List (StreamWriter output)
 

Protected Attributes

Properties defaults
 

Properties

ICollection PropertyNames [get]
 

Static Private Member Functions

static void FormatForOutput (String str, StringBuilder buffer, bool key)
 Formats a key or value for output in a properties file. More...
 

Detailed Description

Definition at line 24 of file Properties.cs.

Constructor & Destructor Documentation

Deveel.Data.Util.Properties.Properties ( )
inline

Creates a new empty property list with no default values.

summary> Create a new empty property list with the specified default values. /summary> param name="defaults">A Properties object containing the default values.

Definition at line 31 of file Properties.cs.

Deveel.Data.Util.Properties.Properties ( Properties  defaults)
inline

summary> Adds the given key/value pair to this properties. /summary> param name="key">The key for this property.

param name="value">The value for this property.

This calls the hashtable method put.

returns> Returns the old value for the given key

See also
GetProperty(string), GetProperty(string,string)

Definition at line 39 of file Properties.cs.

Member Function Documentation

static void Deveel.Data.Util.Properties.FormatForOutput ( String  str,
StringBuilder  buffer,
bool  key 
)
inlinestaticprivate

Formats a key or value for output in a properties file.

Parameters
strThe string to format.
bufferThe buffer to add it to.
keyTrue if all ' ' must be escaped for the key, false if only leading spaces must be escaped for the value

See Store for a description of the format.

Definition at line 420 of file Properties.cs.

420  {
421  if (key) {
422  buffer.Length = 0;
423  buffer.EnsureCapacity(str.Length);
424  } else
425  buffer.EnsureCapacity(buffer.Length + str.Length);
426  bool head = true;
427  int size = str.Length;
428  for (int i = 0; i < size; i++) {
429  char c = str[i];
430  switch (c) {
431  case '\n':
432  buffer.Append("\\n");
433  break;
434  case '\r':
435  buffer.Append("\\r");
436  break;
437  case '\t':
438  buffer.Append("\\t");
439  break;
440  case ' ':
441  buffer.Append(head ? "\\ " : " ");
442  break;
443  case '\\':
444  case '!':
445  case '#':
446  case '=':
447  case ':':
448  buffer.Append('\\').Append(c);
449  break;
450  default:
451  if (c < ' ' || c > '~') {
452  String hex = ((int)c).ToString("{0:x4}");
453  buffer.Append("\\u0000".Substring(0, 6 - hex.Length));
454  buffer.Append(hex);
455  } else
456  buffer.Append(c);
457  break;
458  }
459  if (c != ' ')
460  head = key;
461  }
462  }
A long string in the system.
String Deveel.Data.Util.Properties.GetProperty ( String  key)
inline

summary> Gets the property with the specified key in this property list. If the key is not found, the default property list is searched. If the property is not found in the default, the specified defaultValue is returned. /summary> param name="key">The key for this property.

param name="defaultValue">A default value.

returns> Returns the value for the given key.

Exceptions
InvalidCastExceptionIf this property contains any key or value that isn't a string.
See also
SetProperty

Definition at line 328 of file Properties.cs.

String Deveel.Data.Util.Properties.GetProperty ( String  key,
String  defaultValue 
)
inline

Definition at line 356 of file Properties.cs.

356  {
357  String prop = GetProperty(key);
358  if (prop == null)
359  prop = defaultValue;
360  return prop;
361  }
A long string in the system.
String GetProperty(String key)
Definition: Properties.cs:328
void Deveel.Data.Util.Properties.List ( Stream  output)
inline

Definition at line 390 of file Properties.cs.

390  {
391  StreamWriter writer = new StreamWriter(output);
392  List(writer);
393  }
void List(Stream output)
Definition: Properties.cs:390
void Deveel.Data.Util.Properties.List ( StreamWriter  output)
inline

Definition at line 395 of file Properties.cs.

395  {
396  output.WriteLine("-- listing properties --");
397 
398  foreach (var entry in this) {
399  output.Write((String)entry.Key + "=");
400 
401  String s = (String)entry.Value;
402  if (s != null && s.Length > 40)
403  output.WriteLine(s.Substring(0, 37) + "...");
404  else
405  output.WriteLine(s);
406  }
407  output.Flush();
408  }
A long string in the system.
void Deveel.Data.Util.Properties.Load ( Stream  inStream)
inline

/summary> param name="inStream">

Reads a property list from an input stream. The stream should have the following format:

An empty line or a line starting with # or ! is ignored. An backslash (</code>) at the end of the line makes the line continueing on the next line (but make sure there is no whitespace after the backslash). Otherwise, each line describes a key/value pair.

The chars up to the first whitespace, = or : are the key. You can include this caracters in the key, if you precede them with a backslash (</code>). The key is followed by optional whitespaces, optionally one = or :, and optionally some more whitespaces. The rest of the line is the resource belonging to the key.

Escape sequences ,
, , \, ", \', !, #, \
(a space), and unicode characters with the \uxxxx notation are detected, and converted to the corresponding single character.

# This is a comment
key     = value
k\:5      \ a string starting with space and ending with newline
# This is a multiline specification; note that the value contains # no white space. weekdays: Sunday,Monday,Tuesday,Wednesday,\ Thursday,Friday,Saturday # The safest way to include a space at the end of a value: label = Name:\u0020
 @param inStream the input stream
 @throws IOException if an error occurred when reading the input
 @throws NullPointerException if in is null

summary> Calls Store and ignores the IOException that may be thrown. /summary> param name="output">The stream to write to.

param name="header">A description of the property list.

Exceptions
InvalidCastExceptionIf this property contains any key or value that are not strings.

Definition at line 100 of file Properties.cs.

void Deveel.Data.Util.Properties.Save ( Stream  output,
String  header 
)
inline

summary> Writes the key/value pairs to the given output stream, in a format suitable for Load. /summary> param name="output">The output stream.

param name="header">The header written in the first line, may be null.

If header is not null, this method writes a comment containing the header as first line to the stream. The next line (or first line if header is null) contains a comment with the current date. Afterwards the key/value pairs are written to the stream in the following format.

Each line has the form key = value. Newlines, Returns and tabs are written as
,,
resp. The characters \, !, #, = and : are preceeded by a backslash. Spaces are preceded with a backslash, if and only if they are at the beginning of the key. Characters that are not in the ascii range 33 to 127 are written in the </c>uxxxx Form.

Following the listing, the output stream is flushed but left open.

Exceptions
InvalidCastExceptionIf this property contains any key or value that isn't a string.
IOExceptionIf writing to the stream fails.
ArgumentNullExceptionIf output is null.

Definition at line 255 of file Properties.cs.

Object Deveel.Data.Util.Properties.SetProperty ( String  key,
String  value 
)
inline

Definition at line 56 of file Properties.cs.

56  {
57  return this[key] = value;
58  }
void Deveel.Data.Util.Properties.Store ( Stream  output,
String  header 
)
inline

summary> Gets the property with the specified key in this property list. If the key is not found, the default property list is searched. If the property is not found in the default, null is returned. /summary> param name="key">The key for this property.

returns> Returns the value for the given key, or null if not found.

Exceptions
InvalidCastExceptionIf this property contains any key or value that isn't a string.
See also
GetProperty(string,string), SetProperty

Definition at line 296 of file Properties.cs.

Member Data Documentation

Properties Deveel.Data.Util.Properties.defaults
protected

Definition at line 26 of file Properties.cs.

Property Documentation

ICollection Deveel.Data.Util.Properties.PropertyNames
get

summary> Prints the key/value pairs to the given print stream. /summary> param name="output">The print stream, where the key/value pairs are written to.

This is mainly useful for debugging purposes.

Exceptions
InvalidCastExceptionIf this property contains a key or a value that isn't a string.

Definition at line 363 of file Properties.cs.


The documentation for this class was generated from the following file: