org.eclipse.birt.report.model.api.validators.MasterPageSizeValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.eclipse.birt.runtime Show documentation
Show all versions of org.eclipse.birt.runtime Show documentation
A component of the BIRT runtime
/*******************************************************************************
* Copyright (c) 2004 Actuate Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Actuate Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.birt.report.model.api.validators;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.SemanticError;
import org.eclipse.birt.report.model.api.util.Point;
import org.eclipse.birt.report.model.api.util.Rectangle;
import org.eclipse.birt.report.model.core.DesignElement;
import org.eclipse.birt.report.model.core.Module;
import org.eclipse.birt.report.model.elements.MasterPage;
import org.eclipse.birt.report.model.validators.AbstractElementValidator;
/**
* Validates the page size is invalid.
*
* Rule
The rule is that
*
* - the
MasterPage.HEIGHT_PROP
and
* MasterPage.WIDTH_PROP
must be larger than or equals zero.
* - the margin space shouldn't occupy all page space.
*
*
* Applicability
This validator is only applied to
* MasterPage
.
*/
public class MasterPageSizeValidator extends AbstractElementValidator
{
private static MasterPageSizeValidator instance = new MasterPageSizeValidator( );
/**
* Returns the singleton validator instance.
*
* @return the validator instance
*/
public static MasterPageSizeValidator getInstance( )
{
return instance;
}
/**
* Validates whether the page size is invalid.
*
* @param module
* the module
* @param element
* the master page to validate
*
* @return error list, each of which is the instance of
* SemanticException
.
*/
public List validate( Module module,
DesignElement element )
{
if ( !( element instanceof MasterPage ) )
return Collections.emptyList( );
return doValidate( module, (MasterPage) element );
}
private List doValidate( Module module,
MasterPage toValidate )
{
List list = new ArrayList( );
// Validate the size. Must be positive in both dimensions.
Point size = toValidate.getSize( module );
if ( size.x <= 0 || size.y <= 0 )
{
list.add( new SemanticError( toValidate,
SemanticError.DESIGN_EXCEPTION_INVALID_PAGE_SIZE ) );
}
else
{
// Check margins. Must start on the page and not be of negative
// size.
Rectangle margins = toValidate.getContentArea( module );
if ( margins.x >= size.x || margins.y >= size.y
|| margins.height <= 0 || margins.width <= 0 )
{
list.add( new SemanticError( toValidate,
SemanticError.DESIGN_EXCEPTION_INVALID_PAGE_MARGINS ) );
}
}
return list;
}
}