View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.composer.layout;
23  
24  import static org.opencastproject.util.Jsons.obj;
25  import static org.opencastproject.util.Jsons.p;
26  
27  import org.opencastproject.util.JsonObj;
28  import org.opencastproject.util.Jsons;
29  
30  public final class Serializer {
31    private Serializer() {
32    }
33  
34    public static Jsons.Obj json(Dimension a) {
35      return obj(p("w", a.getWidth()),
36                 p("h", a.getHeight()));
37    }
38  
39    public static Dimension dimension(JsonObj json) {
40      return new Dimension(json.get(Integer.class, "w"), json.get(Integer.class, "h"));
41    }
42  
43    public static Jsons.Obj json(Anchor a) {
44      return obj(p("left", a.getLeft()),
45                 p("top", a.getTop()));
46    }
47  
48    public static Anchor anchor(JsonObj json) {
49      return new Anchor(json.get(Double.class, "left"), json.get(Double.class, "top"));
50    }
51  
52    public static Jsons.Obj json(Offset a) {
53      return obj(p("x", a.getX()),
54                 p("y", a.getY()));
55    }
56  
57    public static Offset offset(JsonObj json) {
58      return new Offset(json.get(Integer.class, "x"), json.get(Integer.class, "y"));
59    }
60  
61    public static Jsons.Obj json(AnchorOffset a) {
62      return obj(p("offset", json(a.getOffset())),
63                 p("reference", json(a.getReferenceAnchor())),
64                 p("referring", json(a.getReferringAnchor())));
65    }
66  
67    public static AnchorOffset anchorOffset(JsonObj json) {
68      return new AnchorOffset(anchor(json.getObj("reference")),
69                              anchor(json.getObj("referring")),
70                              offset(json.getObj("offset")));
71    }
72  
73    public static Jsons.Obj json(TwoShapeLayout a) {
74      return obj(p("canvas", json(a.getCanvas())),
75                 p("upper", json(a.getUpper())),
76                 p("lower", json(a.getLower())));
77    }
78  
79    public static TwoShapeLayout twoShapeLayout(JsonObj json) {
80      return new TwoShapeLayout(dimension(json.getObj("canvas")),
81                                layout(json.getObj("upper")),
82                                layout(json.getObj("lower")));
83    }
84  
85    public static Jsons.Obj json(Layout a) {
86      return obj(p("dimension", json(a.getDimension())),
87                 p("offset", json(a.getOffset())));
88    }
89  
90    public static Layout layout(JsonObj json) {
91      return new Layout(dimension(json.getObj("dimension")),
92                        offset(json.getObj("offset")));
93    }
94  
95    public static Jsons.Obj json(HorizontalCoverageLayoutSpec a) {
96      return obj(p("anchorOffset", json(a.getAnchorOffset())),
97                 p("horizontalCoverage", a.getHorizontalCoverage()));
98    }
99  
100   public static HorizontalCoverageLayoutSpec horizontalCoverageLayoutSpec(JsonObj json) {
101     return new HorizontalCoverageLayoutSpec(anchorOffset(json.getObj("anchorOffset")),
102                                             json.get(Double.class, "horizontalCoverage"));
103   }
104 
105   public static Jsons.Obj json(AbsolutePositionLayoutSpec a) {
106     return obj(p("anchorOffset", json(a.getAnchorOffset())));
107   }
108 
109   public static AbsolutePositionLayoutSpec absolutePositionLayoutSpec(JsonObj json) {
110     return new AbsolutePositionLayoutSpec(anchorOffset(json.obj("anchorOffset")));
111   }
112 }