View Javadoc
1   /*
2   * Copyright 2012-2025 Christophe Friederich
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   * http://www.apache.org/licenses/LICENSE-2.0
9   *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16  package org.devacfr.maven.skins.reflow.context;
17  
18  import static java.util.Objects.requireNonNull;
19  
20  import javax.annotation.Nonnull;
21  import org.devacfr.maven.skins.reflow.ISkinConfig;
22  import org.devacfr.maven.skins.reflow.SkinConfigTool;
23  import org.devacfr.maven.skins.reflow.model.Toc;
24  import org.devacfr.maven.skins.reflow.model.TocSidebar;
25  
26  /**
27   * The context associate to page of frame page.
28   *
29   * @author Christophe Friederich
30   * @since 2.0
31   */
32  public class FrameContext extends Context<FrameContext> {
33  
34    /** */
35    private final String documentParent;
36  
37    /** */
38    private final Toc<?> toc;
39  
40    /**
41     * @param config
42     *          a config (can not be {@code null}).
43     * @param documentParent
44     *          name of parent.
45     */
46    public FrameContext(final @Nonnull ISkinConfig config, @Nonnull final String documentParent) {
47      super(config, ContextType.frame);
48      final String type = config.getPropertyValue(Toc.COMPONENT, String.class, "sidebar");
49      // enforce sidebar
50      if ("top".equals(type) || "sidebar".equals(type)) {
51        toc = new TocSidebar(config);
52      } else {
53        toc = new Toc<Toc<?>>(config, "", "") {};
54      }
55  
56      this.documentParent = requireNonNull(documentParent);
57  
58      this.addChildren(this.toc);
59    }
60  
61    /**
62     * @return Returns a {@link String} representing the name of parent page.
63     */
64    public String getDocumentParent() {
65      return documentParent;
66    }
67  
68    /**
69     * @return Returns a {@link String} representing the slugged name(pageId) of parent page.
70     */
71    public String getSlugDocumentParent() {
72      return SkinConfigTool.slugFilename(documentParent);
73    }
74  
75    /**
76     * @return returns the {@link Toc}.
77     */
78    public Toc<?> getToc() {
79      return toc;
80    }
81  }