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

org.opencms.xml.containerpage.CmsXmlGroupContainerHandler Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (C) Alkacon Software (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.xml.containerpage;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.xml.CmsXmlContentDefinition;
import org.opencms.xml.content.CmsDefaultXmlContentHandler;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.logging.Log;

/**
 * The XML content handler class for group containers.
 */
public class CmsXmlGroupContainerHandler extends CmsDefaultXmlContentHandler {

    /** The log instance for this class. */
    protected static final Log LOG = CmsLog.getLog(CmsXmlGroupContainerHandler.class);

    /**
     * Default constructor.

* */ public CmsXmlGroupContainerHandler() { super(); } /** * Helper method to load and prepare the elements of a group container.

* * @param cms the current CMS context * @param resource the group container resource * * @return the elements which have been read from the group container * * @throws CmsException if something goes wrong */ protected static List loadGroupContainerElements(CmsObject cms, CmsResource resource) throws CmsException { CmsXmlGroupContainer xmlGroupContainer = CmsXmlGroupContainerFactory.unmarshal(cms, resource); CmsGroupContainerBean groupContainer = xmlGroupContainer.getGroupContainer(cms); List elemBeans = groupContainer.getElements(); List result = new ArrayList(); for (CmsContainerElementBean elementBean : elemBeans) { if (!elementBean.isInMemoryOnly()) { elementBean.initResource(cms); result.add(elementBean); } } return result; } /** * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#getCSSHeadIncludes(org.opencms.file.CmsObject, org.opencms.file.CmsResource) */ @Override public Set getCSSHeadIncludes(CmsObject cms, CmsResource resource) throws CmsException { Set result = new LinkedHashSet(); List containerElements = loadGroupContainerElements(cms, resource); for (CmsContainerElementBean elementBean : containerElements) { if (elementBean.isGroupContainer(cms) || elementBean.isInheritedContainer(cms)) { throw new CmsException( Messages.get().container( Messages.ERR_ELEMENT_GROUP_REFERENCES_ANOTHER_GROUP_2, resource.getRootPath(), elementBean.getResource().getRootPath())); } CmsResource elementResource = elementBean.getResource(); Set elementIncludes = CmsXmlContentDefinition.getContentHandlerForResource( cms, elementResource).getCSSHeadIncludes(cms, elementResource); result.addAll(elementIncludes); } return result; } /** * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#getJSHeadIncludes(org.opencms.file.CmsObject, org.opencms.file.CmsResource) */ @Override public Set getJSHeadIncludes(CmsObject cms, CmsResource resource) throws CmsException { Set result = new LinkedHashSet(); List containerElements = loadGroupContainerElements(cms, resource); for (CmsContainerElementBean elementBean : containerElements) { if (elementBean.isGroupContainer(cms) || elementBean.isInheritedContainer(cms)) { throw new CmsException( Messages.get().container( Messages.ERR_ELEMENT_GROUP_REFERENCES_ANOTHER_GROUP_2, resource.getRootPath(), elementBean.getResource().getRootPath())); } CmsResource elementResource = elementBean.getResource(); Set elementIncludes = CmsXmlContentDefinition.getContentHandlerForResource( cms, elementResource).getJSHeadIncludes(cms, elementResource); result.addAll(elementIncludes); } return result; } /** * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#hasModifiableFormatters() */ @Override public boolean hasModifiableFormatters() { return false; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy