Skip to content

Package: LayoutJaxbMarshallable

LayoutJaxbMarshallable

nameinstructionbranchcomplexitylinemethod
LayoutJaxbMarshallable(Layout)
M: 79 C: 0
0%
M: 22 C: 0
0%
M: 12 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
marshal(Layout)
M: 36 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
marshal(OutputStream)
M: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.core.impl.io;
28:
29: import javax.annotation.Nonnull;
30: import javax.inject.Inject;
31: import java.io.IOException;
32: import java.io.OutputStream;
33: import jakarta.xml.bind.JAXBException;
34: import jakarta.xml.bind.Marshaller;
35: import org.springframework.beans.factory.annotation.Configurable;
36: import it.tidalwave.role.io.Marshallable;
37: import it.tidalwave.dci.annotation.DciRole;
38: import it.tidalwave.northernwind.frontend.ui.Layout;
39: import it.tidalwave.northernwind.core.impl.io.jaxb.ComponentJaxb;
40: import it.tidalwave.northernwind.core.impl.io.jaxb.ObjectFactory;
41: import lombok.extern.slf4j.Slf4j;
42:
43: /***********************************************************************************************************************
44: *
45: * @author Fabrizio Giudici
46: *
47: **********************************************************************************************************************/
48: @DciRole(datumType = Layout.class) @Configurable @Slf4j
49: public class LayoutJaxbMarshallable implements Marshallable
50: {
51: @Nonnull
52: private final Layout ownerLayout;
53:
54: @Inject
55: private ObjectFactory objectFactory;
56:
57: @Inject
58: private Marshaller marshaller;
59:
60: /*******************************************************************************************************************
61: *
62: *
63: *
64: ******************************************************************************************************************/
65: public LayoutJaxbMarshallable (@Nonnull final Layout ownerLayout)
66:• {
67: this.ownerLayout = ownerLayout;
68:• }
69:
70: /*******************************************************************************************************************
71: *
72: * {@inheritDoc}
73: *
74: ******************************************************************************************************************/
75: @Override
76: public void marshal (@Nonnull final OutputStream os)
77: throws IOException
78: {
79: try
80: {
81: final var componentsJaxb = objectFactory.createComponentsJaxb();
82: componentsJaxb.setVersion("1.0");
83: componentsJaxb.setComponent(marshal(ownerLayout));
84: marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // FIXME: set in Spring
85: marshaller.marshal(objectFactory.createComponents(componentsJaxb), os);
86: }
87: catch (JAXBException e)
88: {
89: throw new IOException("", e);
90: }
91: }
92:
93: /*******************************************************************************************************************
94: *
95: *
96: ******************************************************************************************************************/
97: @Nonnull
98: private ComponentJaxb marshal (@Nonnull final Layout layout)
99: {
100: final var componentJaxb = objectFactory.createComponentJaxb();
101: componentJaxb.setId(layout.getId().stringValue());
102: componentJaxb.setType(layout.getTypeUri());
103:
104:• for (final var child : layout.findChildren().results())
105: {
106: componentJaxb.getComponent().add(marshal(child));
107: }
108:
109: return componentJaxb;
110: }
111: }