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