Exemplo n.º 1
0
  /**
   * Returns a page definition constructed from the page definition DOM
   *
   * @param pPageDefinitionDOM The page definition DOM
   * @return A page definition constructed from the page definition DOM
   * @throws ExModule If the page definition DOM is invalid, for example required attributes are
   *     missing
   */
  public static PageDefinition createFromDOM(DOM pPageDefinitionDOM) throws ExModule {
    AttributeResolver<Attribute> lAttributeResolver = new AttributeResolver(ATTRIBUTE_DEFINITIONS);
    ChildElementResolver<ChildElement> lChildElementResolver =
        new ChildElementResolver<>(CHILD_ELEMENT_DEFINITIONS);

    Map<Attribute, String> lAttributes =
        lAttributeResolver.resolveAttributes(
            pPageDefinitionDOM, () -> new EnumMap<>(Attribute.class));
    Map<ChildElement, DOM> lChildElements =
        lChildElementResolver.resolveChildElements(
            pPageDefinitionDOM, () -> new EnumMap<>(ChildElement.class));

    // Must manually check for presence of the child element DOMs instead of mapping via optional,
    // as the createFromDOM
    // methods throw an exception, which means they can't be used in consumers
    Optional<DOM> lBodyDOM = Optional.ofNullable(lChildElements.get(ChildElement.BODY));
    Optional<DOM> lHeaderDOM = Optional.ofNullable(lChildElements.get(ChildElement.HEADER));
    Optional<DOM> lFooterDOM = Optional.ofNullable(lChildElements.get(ChildElement.FOOTER));

    Optional<Body> lBody =
        Optional.ofNullable(lBodyDOM.isPresent() ? Body.createFromDOM(lBodyDOM.get()) : null);
    Optional<Header> lHeader =
        Optional.ofNullable(lHeaderDOM.isPresent() ? Header.createFromDOM(lHeaderDOM.get()) : null);
    Optional<Footer> lFooter =
        Optional.ofNullable(lFooterDOM.isPresent() ? Footer.createFromDOM(lFooterDOM.get()) : null);

    return new PageDefinition(
        lAttributes.get(Attribute.NAME),
        lAttributes.get(Attribute.PAGE_WIDTH),
        lAttributes.get(Attribute.PAGE_HEIGHT),
        lAttributes.get(Attribute.MARGIN_LEFT),
        lAttributes.get(Attribute.MARGIN_RIGHT),
        lAttributes.get(Attribute.MARGIN_TOP),
        lAttributes.get(Attribute.MARGIN_BOTTOM),
        lBody,
        lHeader,
        lFooter);
  }
Exemplo n.º 2
0
  private void resolveGAs(RequestContext context) {

    attributeResolver.resolveGAs(context);
  }