1
2
3
4
5 package gboat2.base.core.web.md;
6
7 import gboat2.base.bridge.debug.DefaultDebugHook;
8 import gboat2.base.core.util.JsonVelocityUtil;
9 import gboat2.base.core.web.MetadataException;
10
11 import java.net.URL;
12
13 import net.sf.json.JSONObject;
14
15 import org.osgi.framework.Bundle;
16
17
18
19
20
21
22
23
24
25
26 public class ExtendMetadataHandler extends MetadataHandler {
27
28
29
30
31 @Override
32 public JSONObject parseMetadata(JSONObject object, URL url, Bundle bundle, MetadataHandlerChain chain) {
33 if (object != null && object.containsKey("extends")) {
34 String parentPath = object.getString("extends");
35 URL parentUrl = DefaultDebugHook.getInstance().findResource(bundle, parentPath.startsWith("/")?parentPath:"/"+parentPath);
36 if (parentUrl == null) {
37 throw new MetadataException("can't find parent metadata file : " + parentPath);
38 } else {
39 JSONObject parentObject = MetadataSupport.parseMetadata(parentUrl, bundle, chain.clone(chain));
40 if (parentObject != null) {
41 object = JsonVelocityUtil.merge(parentObject, object);
42 }
43 }
44 }
45 return chain.doHandler(object, url, bundle);
46 }
47
48 }