Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
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.
/*
* 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.acacia.shared;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.SimpleEventBus;
/**
* Serializable entity implementation.
*/
public class CmsEntity implements HasValueChangeHandlers, Serializable {
/**
* Handles child entity changes.
*/
protected class EntityChangeHandler implements ValueChangeHandler {
/**
* @see com.google.gwt.event.logical.shared.ValueChangeHandler#onValueChange(com.google.gwt.event.logical.shared.ValueChangeEvent)
*/
public void onValueChange(ValueChangeEvent event) {
fireChange();
}
}
/** The serial version id. */
private static final long serialVersionUID = -6933931178070025267L;
/** The entity attribute values. */
private Map> m_entityAttributes;
/** The entity id. */
private String m_id;
/** The simple attribute values. */
private Map> m_simpleAttributes;
/** The type name. */
private String m_typeName;
/** The event bus. */
private transient SimpleEventBus m_eventBus;
/** The child entites change handler. */
private transient EntityChangeHandler m_childChangeHandler = new EntityChangeHandler();
/** The handler registrations. */
private transient Map m_changeHandlerRegistry;
/**
* Constructor.
*
* @param id the entity id/URI
* @param typeName the entity type name
*/
public CmsEntity(String id, String typeName) {
this();
m_id = id;
m_typeName = typeName;
}
/**
* Constructor. For serialization only.
*/
protected CmsEntity() {
m_simpleAttributes = new HashMap>();
m_entityAttributes = new HashMap>();
m_changeHandlerRegistry = new HashMap();
}
/**
* Returns the value of a simple attribute for the given path or null, if the value does not exist.
*
* @param entity the entity to get the value from
* @param pathElements the path elements
*
* @return the value
*/
public static String getValueForPath(CmsEntity entity, String[] pathElements) {
String result = null;
if ((pathElements != null) && (pathElements.length >= 1)) {
String attributeName = pathElements[0];
int index = CmsContentDefinition.extractIndex(attributeName);
if (index > 0) {
index--;
}
attributeName = entity.getTypeName() + "/" + CmsContentDefinition.removeIndex(attributeName);
CmsEntityAttribute attribute = entity.getAttribute(attributeName);
if (!((attribute == null) || (attribute.isComplexValue() && (pathElements.length == 1)))) {
if (attribute.isSimpleValue()) {
if ((pathElements.length == 1) && (attribute.getValueCount() > 0)) {
List values = attribute.getSimpleValues();
result = values.get(index);
}
} else if (attribute.getValueCount() > (index)) {
String[] childPathElements = new String[pathElements.length - 1];
for (int i = 1; i < pathElements.length; i++) {
childPathElements[i - 1] = pathElements[i];
}
List values = attribute.getComplexValues();
result = getValueForPath(values.get(index), childPathElements);
}
}
}
return result;
}
/**
* Gets the list of values reachable from the given base object with the given path.
*
* @param baseObject the base object (a CmsEntity or a string)
* @param pathComponents the path components
* @return the list of values for the given path (either of type String or CmsEntity)
*/
public static List