All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openestate.io.filemaker.FilemakerLayoutDocument Maven / Gradle / Ivy

Go to download

OpenEstate-IO-Filemaker is a Java library to read and write XML formats of the real estate software FlatHunter Pro, which is based on the Filemaker database system.

There is a newer version: 1.4
Show newest version
/*
 * Copyright 2015 OpenEstate.org.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openestate.io.filemaker;

import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import org.openestate.io.core.XmlUtils;
import org.openestate.io.filemaker.xml.layout.FMPXMLLAYOUT;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * XML document from Filemaker with a
 * <FMPXMLLAYOUT> root element.
 *
 * @since 1.0
 * @author Andreas Rudolph
 */
public class FilemakerLayoutDocument extends FilemakerDocument
{
  //private final static Logger LOGGER = LoggerFactory.getLogger( FilemakerLayoutDocument.class );

  /**
   * Create from a {@link Document}.
   *
   * @param document
   * the document to create from
   */
  public FilemakerLayoutDocument( Document document )
  {
    super( document );
    if (!isReadable( document ))
      throw new IllegalArgumentException( "The provided document is invalid!" );
  }

  /**
   * Checks, if a {@link Document} is readable as a {@link FilemakerLayoutDocument}.
   *
   * @param doc
   * document to check
   *
   * @return
   * true, if the document is usable, otherwise false
   */
  public static boolean isReadable( Document doc )
  {
    Element root = XmlUtils.getRootElement( doc );
    return "FMPXMLLAYOUT".equals( root.getLocalName() );
  }

  /**
   * Creates an empty {@link FilemakerLayoutDocument}.
   *
   * @return
   * created document
   *
   * @throws ParserConfigurationException
   * if the parser is not properly configured
   *
   * @throws JAXBException
   * if a problem with JAXB occured
   */
  public static FilemakerLayoutDocument newDocument() throws ParserConfigurationException, JAXBException
  {
    return newDocument( FilemakerUtils.getFactoryForLayout().createFMPXMLLAYOUT() );
  }

  /**
   * Creates a {@link FilemakerLayoutDocument} from a {@link FMPXMLLAYOUT} object.
   *
   * @param xmlLayout
   * Java object, that represents the <FMPXMLLAYOUT> root element
   *
   * @return
   * created document
   *
   * @throws ParserConfigurationException
   * if the parser is not properly configured
   *
   * @throws JAXBException
   * if a problem with JAXB occured
   */
  public static FilemakerLayoutDocument newDocument( FMPXMLLAYOUT xmlLayout ) throws ParserConfigurationException, JAXBException
  {
    Document document = XmlUtils.newDocument();
    FilemakerUtils.createMarshaller( "UTF-8", true ).marshal( xmlLayout, document );
    return new FilemakerLayoutDocument( document );
  }

  /**
   * Creates a {@link FMPXMLLAYOUT} object from the contained {@link Document}.
   *
   * @return
   * created object, that represents the <FMPXMLLAYOUT> root element
   *
   * @throws JAXBException
   * if a problem with JAXB occured
   */
  @Override
  public FMPXMLLAYOUT toObject() throws JAXBException
  {
    return (FMPXMLLAYOUT) FilemakerUtils.createUnmarshaller().unmarshal( this.getDocument() );
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy