You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/01/13 08:31:56 UTC
svn commit: r1778514 - in /felix/trunk/webconsole-plugins/metatype: pom.xml
src/main/java/org/apache/felix/webconsole/plugins/metatype/internal/MetatypeInventoryPrinter.java
Author: cziegeler
Date: Fri Jan 13 08:31:56 2017
New Revision: 1778514
URL: http://svn.apache.org/viewvc?rev=1778514&view=rev
Log:
Remove dependency to org.json
Modified:
felix/trunk/webconsole-plugins/metatype/pom.xml
felix/trunk/webconsole-plugins/metatype/src/main/java/org/apache/felix/webconsole/plugins/metatype/internal/MetatypeInventoryPrinter.java
Modified: felix/trunk/webconsole-plugins/metatype/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/metatype/pom.xml?rev=1778514&r1=1778513&r2=1778514&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/metatype/pom.xml (original)
+++ felix/trunk/webconsole-plugins/metatype/pom.xml Fri Jan 13 08:31:56 2017
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.felix</groupId>
<artifactId>felix-parent</artifactId>
- <version>2.1</version>
+ <version>4</version>
<relativePath>../../../pom/pom.xml</relativePath>
</parent>
@@ -44,18 +44,9 @@
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
-
- <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.4</version>
+ <version>3.2.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
@@ -65,12 +56,22 @@
<Bundle-Activator>
org.apache.felix.webconsole.plugins.metatype.internal.Activator
</Bundle-Activator>
+ <Import-Package>
+ !org.osgi.service.metatype,*
+ </Import-Package>
<DynamicImport-Package>
org.osgi.service.metatype; version="[1.1,2)"
</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <excludePackageNames>org.apache.felix.webconsole.plugins.metatype.internal</excludePackageNames>
+ </configuration>
+ </plugin>
</plugins>
</build>
@@ -93,11 +94,5 @@
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>20070829</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
</project>
Modified: felix/trunk/webconsole-plugins/metatype/src/main/java/org/apache/felix/webconsole/plugins/metatype/internal/MetatypeInventoryPrinter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/metatype/src/main/java/org/apache/felix/webconsole/plugins/metatype/internal/MetatypeInventoryPrinter.java?rev=1778514&r1=1778513&r2=1778514&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/metatype/src/main/java/org/apache/felix/webconsole/plugins/metatype/internal/MetatypeInventoryPrinter.java (original)
+++ felix/trunk/webconsole-plugins/metatype/src/main/java/org/apache/felix/webconsole/plugins/metatype/internal/MetatypeInventoryPrinter.java Fri Jan 13 08:31:56 2017
@@ -23,8 +23,6 @@ import java.util.Hashtable;
import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.InventoryPrinter;
-import org.json.JSONException;
-import org.json.JSONWriter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
@@ -51,15 +49,15 @@ class MetatypeInventoryPrinter implement
this.metatype = metatype;
this.registration = bundleContext.registerService(InventoryPrinter.SERVICE, this,
- new Hashtable<String, Object>()
+ new Hashtable<String, Object>()
+ {
{
- {
- put(InventoryPrinter.NAME, "metatype");
- put(InventoryPrinter.TITLE, "Metatype Service");
- put(InventoryPrinter.FORMAT, new String[]
+ put(InventoryPrinter.NAME, "metatype");
+ put(InventoryPrinter.TITLE, "Metatype Service");
+ put(InventoryPrinter.FORMAT, new String[]
{ Format.TEXT.toString(), Format.JSON.toString() });
- }
- });
+ }
+ });
}
void unregister()
@@ -165,21 +163,16 @@ class MetatypeInventoryPrinter implement
{
switch (defaultValue.length)
{
- case 0: // ignore
- break;
+ case 0: // ignore
+ break;
- case 1:
- pw.keyValue("default", defaultValue[0]);
- break;
-
- default:
- pw.list("default");
- for (String value : defaultValue)
- {
- pw.entry(value);
- }
- pw.endList();
- break;
+ case 1:
+ pw.keyValue("default", defaultValue[0]);
+ break;
+
+ default:
+ pw.list("default", defaultValue);
+ break;
}
}
}
@@ -202,32 +195,32 @@ class MetatypeInventoryPrinter implement
{
switch (type)
{
- case AttributeDefinition.BIGDECIMAL:
- return "BigDecimal";
- case AttributeDefinition.BIGINTEGER:
- return "BigInteger";
- case AttributeDefinition.BOOLEAN:
- return "Boolean";
- case AttributeDefinition.BYTE:
- return "Byte";
- case AttributeDefinition.CHARACTER:
- return "Character";
- case AttributeDefinition.DOUBLE:
- return "Double";
- case AttributeDefinition.FLOAT:
- return "Float";
- case AttributeDefinition.INTEGER:
- return "Integer";
- case AttributeDefinition.LONG:
- return "Long";
- case AttributeDefinition.SHORT:
- return "Short";
- case AttributeDefinition.STRING:
- return "String";
- case 12 /* PASSWORD */:
- return "Password";
- default:
- return String.valueOf(type);
+ case AttributeDefinition.BIGDECIMAL:
+ return "BigDecimal";
+ case AttributeDefinition.BIGINTEGER:
+ return "BigInteger";
+ case AttributeDefinition.BOOLEAN:
+ return "Boolean";
+ case AttributeDefinition.BYTE:
+ return "Byte";
+ case AttributeDefinition.CHARACTER:
+ return "Character";
+ case AttributeDefinition.DOUBLE:
+ return "Double";
+ case AttributeDefinition.FLOAT:
+ return "Float";
+ case AttributeDefinition.INTEGER:
+ return "Integer";
+ case AttributeDefinition.LONG:
+ return "Long";
+ case AttributeDefinition.SHORT:
+ return "Short";
+ case AttributeDefinition.STRING:
+ return "String";
+ case 12 /* PASSWORD */:
+ return "Password";
+ default:
+ return String.valueOf(type);
}
}
@@ -257,13 +250,9 @@ class MetatypeInventoryPrinter implement
void endGroup();
- void list(String name);
-
- void entry(String value);
+ void list(String name, String[] values);
- void endList();
-
- void keyValue(String key, Object value);
+ void keyValue(String key, String value);
}
@@ -274,14 +263,11 @@ class MetatypeInventoryPrinter implement
private String indent;
- private boolean inList;
-
TextPrinter(final PrintWriter pw)
{
this.pw = pw;
this.indent = "";
- this.inList = false;
}
public void start()
@@ -306,31 +292,23 @@ class MetatypeInventoryPrinter implement
}
}
- public void list(String name)
+ public void list(String name, String[] values)
{
this.pw.printf("%s%s: [", indent, name);
- }
-
- public void entry(String value)
- {
- if (this.inList)
- {
- this.pw.print(", ");
- }
- else
+ boolean first = true;
+ for (String val : values)
{
- this.inList = true;
+ if (first) {
+ first = false;
+ } else {
+ this.pw.print(", ");
+ }
+ this.pw.print(val);
}
- this.pw.print(value);
- }
-
- public void endList()
- {
- this.inList = false;
this.pw.println("]");
}
- public void keyValue(String key, Object value)
+ public void keyValue(String key, String value)
{
this.pw.printf("%s%s: %s%n", indent, key, value);
}
@@ -338,108 +316,123 @@ class MetatypeInventoryPrinter implement
private static class JsonPrinter implements Printer
{
+ private boolean needsComma;
- private final JSONWriter pw;
+ private final PrintWriter pw;
JsonPrinter(final PrintWriter pw)
{
- this.pw = new JSONWriter(pw);
+ this.pw = pw;
}
public void start()
{
- try
- {
- this.pw.object();
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
- }
+ this.pw.print('{');
}
public void end()
{
- try
- {
- this.pw.endObject();
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
- }
+ this.pw.print('}');
}
- public void group(String name)
- {
- try
- {
- this.pw.key(name).object();
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
+ private void key(String name) {
+ if (needsComma) {
+ this.pw.print(',');
}
+ this.pw.print('"');
+ this.pw.print(name);
+ this.pw.print("\" : ");
}
- public void endGroup()
+ public void group(String name)
{
- try
- {
- this.pw.endObject();
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
- }
+ this.key(name);
+ this.pw.print('{');
+ this.needsComma = false;
}
- public void list(String name)
+ public void endGroup()
{
- try
- {
- this.pw.key(name).array();
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
- }
+ this.pw.print('}');
+ this.needsComma = true;
}
- public void entry(String value)
+ public void list(String name, String[] values)
{
- try
- {
- this.pw.value(value);
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
+ this.key(name);
+ this.pw.print('[');
+ boolean first = true;
+ for (String val : values) {
+ if (first) {
+ first = false;
+ } else {
+ this.pw.print(',');
+ }
+ value(val);
}
+ this.pw.print(']');
+ this.needsComma = true;
}
- public void endList()
+ private void value(String value)
{
- try
- {
- this.pw.endArray();
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
+ if (value == null) {
+ this.pw.print("null");
+ } else {
+ this.pw.print('"');
+ // escape the value
+ final int len = value.length();
+ for(int i=0;i<len;i++){
+ final char c = value.charAt(i);
+ switch(c){
+ case '"':
+ this.pw.print("\\\"");
+ break;
+ case '\\':
+ this.pw.print("\\\\");
+ break;
+ case '\b':
+ this.pw.print("\\b");
+ break;
+ case '\f':
+ this.pw.print("\\f");
+ break;
+ case '\n':
+ this.pw.print("\\n");
+ break;
+ case '\r':
+ this.pw.print("\\r");
+ break;
+ case '\t':
+ this.pw.print("\\t");
+ break;
+ case '/':
+ this.pw.print("\\/");
+ break;
+ default:
+ if ((c>='\u0000' && c<='\u001F') || (c>='\u007F' && c<='\u009F') || (c>='\u2000' && c<='\u20FF'))
+ {
+ final String hex=Integer.toHexString(c);
+ this.pw.print("\\u");
+ for(int k=0;k<4-hex.length();k++){
+ this.pw.print('0');
+ }
+ this.pw.print(hex.toUpperCase());
+ }
+ else{
+ this.pw.print(c);
+ }
+ }
+ }
+ this.pw.print('"');
}
}
- public void keyValue(String key, Object value)
+ public void keyValue(String key, String value)
{
- try
- {
- this.pw.key(key).value(value);
- }
- catch (JSONException ignore)
- {
- throw new RuntimeException(ignore);
- }
+ key(key);
+ value(value);
+ this.needsComma = true;
}
}
}