Automated merge with main-silver
authorffjre@netbeans.org
Sun, 09 Aug 2009 02:49:58 +0400
changeset 93390b133c9fb62
parent 932 d6fcec6024c6
parent 815 fae825a66188
child 934 052f7ff1a828
Automated merge with main-silver
     1.1 --- a/openide.util/src/org/openide/util/EditableProperties.java	Sat Aug 08 02:56:02 2009 +0400
     1.2 +++ b/openide.util/src/org/openide/util/EditableProperties.java	Sun Aug 09 02:49:58 2009 +0400
     1.3 @@ -216,6 +216,15 @@
     1.4      }
     1.5  
     1.6      @Override
     1.7 +    public String get(Object key) {
     1.8 +        if (!(key instanceof String)) {
     1.9 +            return null;
    1.10 +        }
    1.11 +        Item item = itemIndex.get((String) key);
    1.12 +        return item != null ? item.getValue() : null;
    1.13 +    }
    1.14 +
    1.15 +    @Override
    1.16      public String put(String key, String value) {
    1.17          Parameters.notNull("key", key);
    1.18          Parameters.notNull(key, value);
    1.19 @@ -518,7 +527,7 @@
    1.20          }
    1.21  
    1.22          public void setValue(List<String> value) {
    1.23 -            StringBuffer val = new StringBuffer();
    1.24 +            StringBuilder val = new StringBuilder();
    1.25              List<String> l = new ArrayList<String>();
    1.26              if (!value.isEmpty()) {
    1.27                  l.add(encode(key, true) + "=\\"); // NOI18N
    1.28 @@ -610,7 +619,7 @@
    1.29          private static String decode(String input) {
    1.30              char ch;
    1.31              int len = input.length();
    1.32 -            StringBuffer output = new StringBuffer(len);
    1.33 +            StringBuilder output = new StringBuilder(len);
    1.34              for (int x=0; x<len; x++) {
    1.35                  ch = input.charAt(x);
    1.36                  if (ch != '\\') {
    1.37 @@ -649,18 +658,19 @@
    1.38              return output.toString();
    1.39          }
    1.40  
    1.41 -        private static String encode(String input, boolean escapeSpace) {
    1.42 +        private static String encode(String input, boolean forKey) {
    1.43              int len = input.length();
    1.44 -            StringBuffer output = new StringBuffer(len*2);
    1.45 +            StringBuilder output = new StringBuilder(len*2);
    1.46  
    1.47              for(int x=0; x<len; x++) {
    1.48                  char ch = input.charAt(x);
    1.49                  switch(ch) {
    1.50                      case ' ':
    1.51 -                        if (x == 0 || escapeSpace)  {
    1.52 +                    case '#':
    1.53 +                        if (x == 0 || forKey)  {
    1.54                              output.append('\\');
    1.55                          }
    1.56 -                        output.append(' ');
    1.57 +                        output.append(ch);
    1.58                          break;
    1.59                      case '\\':
    1.60                          output.append("\\\\");
    1.61 @@ -677,6 +687,13 @@
    1.62                      case '\f':
    1.63                          output.append("\\f");
    1.64                          break;
    1.65 +                    case '=':
    1.66 +                    case ':':
    1.67 +                        if (forKey) {
    1.68 +                            output.append('\\');
    1.69 +                        }
    1.70 +                        output.append(ch);
    1.71 +                        break;
    1.72                      default:
    1.73                          if ((ch < 0x0020) || (ch > 0x007e)) {
    1.74                              output.append("\\u");
    1.75 @@ -696,7 +713,7 @@
    1.76          private static String decodeUnicode(String input) {
    1.77              char ch;
    1.78              int len = input.length();
    1.79 -            StringBuffer output = new StringBuffer(len);
    1.80 +            StringBuilder output = new StringBuilder(len);
    1.81              for (int x = 0; x < len; x++) {
    1.82                  ch = input.charAt(x);
    1.83                  if (ch != '\\') {
    1.84 @@ -733,7 +750,7 @@
    1.85  
    1.86          private static String encodeUnicode(String input) {
    1.87              int len = input.length();
    1.88 -            StringBuffer output = new StringBuffer(len * 2);
    1.89 +            StringBuilder output = new StringBuilder(len * 2);
    1.90              for (int x = 0; x < len; x++) {
    1.91                  char ch = input.charAt(x);
    1.92                  if ((ch < 0x0020) || (ch > 0x007e)) {
     2.1 --- a/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java	Sat Aug 08 02:56:02 2009 +0400
     2.2 +++ b/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java	Sun Aug 09 02:49:58 2009 +0400
     2.3 @@ -227,12 +227,12 @@
     2.4          String output = getAsString(ep);
     2.5          String expected = "a\\ a=a space a"+System.getProperty("line.separator")+
     2.6                  "b\\u4567=val\\u1234"+System.getProperty("line.separator")+
     2.7 -                "@!#$%^\\\\=!@#$%^&*(){}\\\\"+System.getProperty("line.separator")+
     2.8 +                "@!\\#$%^\\\\=!@#$%^&*(){}\\\\"+System.getProperty("line.separator")+
     2.9                  "d\\nd=d\\nnewline\\nd"+System.getProperty("line.separator")+
    2.10                  "umlaut=\\u00fc"+System.getProperty("line.separator")+
    2.11                  "_a\\ a=\\"+System.getProperty("line.separator")+"    a space a"+System.getProperty("line.separator")+
    2.12                  "_b\\u4567=\\"+System.getProperty("line.separator")+"    val\\u1234"+System.getProperty("line.separator")+
    2.13 -                "_@!#$%^\\\\=\\"+System.getProperty("line.separator")+"    !@#$%^&*\\\\\\"+System.getProperty("line.separator")+
    2.14 +                "_@!\\#$%^\\\\=\\"+System.getProperty("line.separator")+"    !@#$%^&*\\\\\\"+System.getProperty("line.separator")+
    2.15                      "    (){}\\\\"+System.getProperty("line.separator")+
    2.16                  "_d\\nd=\\"+System.getProperty("line.separator")+"    d\\nnew\\"+System.getProperty("line.separator")+
    2.17                      "    line\\nd\\"+System.getProperty("line.separator")+
    2.18 @@ -252,6 +252,22 @@
    2.19          assertEquals("d\nnewline\nd\nend", ep.getProperty("_d\nd"));
    2.20          assertEquals(umlaut+umlaut, ep.getProperty("_umlaut"));
    2.21      }
    2.22 +
    2.23 +    public void testMetaCharacters() throws Exception {
    2.24 +        testRoundTrip("foo=bar", "v1");
    2.25 +        testRoundTrip("foo:bar", "v2");
    2.26 +        testRoundTrip("#foobar", "v3");
    2.27 +        testRoundTrip(" foo bar ", "v4");
    2.28 +    }
    2.29 +    private void testRoundTrip(String key, String value) throws Exception {
    2.30 +        EditableProperties ep = new EditableProperties(false);
    2.31 +        ep.setProperty(key, value);
    2.32 +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    2.33 +        ep.store(baos);
    2.34 +        ep = new EditableProperties(false);
    2.35 +        ep.load(new ByteArrayInputStream(baos.toByteArray()));
    2.36 +        assertEquals(baos.toString(), Collections.singletonMap(key, value), ep);
    2.37 +    }
    2.38      
    2.39      // test that iterator implementation is OK
    2.40      public void testIterator() throws Exception {