[Castore-commits] PpsElement.java NONE 1.1
Céline BENOIT
cbenoit at adullact1.hosting.cri74.org
Mer 22 Mar 15:11:38 CET 2006
Update of /cvsroot/castore/castore-core/src/java/fr/emn/castor/documents/metier/textes/retro/pointtopointschema
In directory adullact1:/tmp/cvs-serv7547/src/java/fr/emn/castor/documents/metier/textes/retro/pointtopointschema
Added Files:
PpsElement.java
Log Message:
déplacement du fichier
--- NEW FILE: PpsElement.java ---
/*
* $Id: PpsElement.java,v 1.1 2006/03/22 14:11:36 cbenoit Exp $
*
* Plateforme CASTORE
* CeCILL Copyright (C) 2005-2006 by EMN
* Made by Stéphane Bouchet, Xerox
* Web site = http://www.emn.fr/castore
* Contact = Cédric Dumas, e-mail = Cedric.Dumas at emn.fr
*
* Version 1.0 (1er mars 2005)
*
* Ce logiciel est un programme informatique servant à créer une plateforme
* open-source de bibliothèque numérique XML pour Conserver, Valoriser et
* Diffuser le patrimoine documentaire de votre institut.
*
* Ce logiciel est régi par la licence CeCILL soumise au droit français et
* respectant les principes de diffusion des logiciels libres. Vous pouvez
* utiliser, modifier et/ou redistribuer ce programme sous les conditions de la
* licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA sur le site
* "http://www.cecill.info". En contrepartie de l'accessibilité au code source
* et des droits de copie, de modification et de redistribution accordés par
* cette licence, il n'est offert aux utilisateurs qu'une garantie limitée. Pour
* les mêmes raisons, seule une responsabilité restreinte pèse sur l'auteur du
* programme, le titulaire des droits patrimoniaux et les concédants successifs.
* A cet égard l'attention de l'utilisateur est attirée sur les risques associés
* au chargement, à l'utilisation, à la modification et/ou au développement et à
* la reproduction du logiciel par l'utilisateur étant donné sa spécificité de
* logiciel libre, qui peut le rendre complexe à manipuler et qui le réserve
* donc à des développeurs et des professionnels avertis possédant des
* connaissances informatiques approfondies. Les utilisateurs sont donc invités
* à charger et tester l'adéquation du logiciel à leurs besoins dans des
* conditions permettant d'assurer la sécurité de leurs systèmes et ou de leurs
* données et, plus généralement, à l'utiliser et l'exploiter dans les mêmes
* conditions de sécurité. Le fait que vous puissiez accéder à cet en-tête
* signifie que vous avez pris connaissance de la licence CeCILL, et que vous en
* avez accepté les termes.
*
*/
package fr.emn.castor.documents.metier.textes.retro.pointtopointschema;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Element;
/**
* @author rdelambe TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
*/
public class PpsElement {
/** le logger.*/
private static Log logger = LogFactory.getLog(PpsElement.class);
/**
* Class members (attributes)
*/
protected String name;
/**
*/
protected boolean mixedContent;
/**
*/
protected boolean textOnlyContent;
/**
*/
protected boolean allowedEmptyContent;
/**
*/
protected boolean mandatoryEmptyContent;
/**
*/
protected Map<String, PpsElement> allowedChildren = new TreeMap<String, PpsElement>();
/**
*/
protected Map<String, PpsElement> allowedFirstChildren = new TreeMap<String, PpsElement>();
/**
*/
protected Map<String, PpsElement> allowedLastChildren = new TreeMap<String, PpsElement>();
/**
*/
protected Map<String, Map<String, PpsElement>> allowedFollowingSiblingsOfChild = new TreeMap<String, Map<String, PpsElement>>();
/**
*/
protected PointToPointSchema pps;
public PpsElement(PointToPointSchema container_pps) {
pps = container_pps;
}
/**
* Load the DOM Element in an instance of the PpsElement java class
*
* @param element
*/
public void load(Element element) {
// Load simple PpsElement attributes
if (element.getAttribute(ATTR_NAME) != null)
this.name = element.getAttributeValue(ATTR_NAME);
if (element.getAttribute(ATTR_MIXED_CONTENT) != null)
this.mixedContent = element
.getAttributeValue(ATTR_MIXED_CONTENT)
.equalsIgnoreCase(TRUE);
if (element.getAttribute(ATTR_TEXT_ONLY_CONTENT) != null)
this.textOnlyContent = element.getAttributeValue(
ATTR_TEXT_ONLY_CONTENT).equalsIgnoreCase(TRUE);
if (element.getAttribute(ATTR_ALLOWED_EMPY_CONTENT) != null)
this.allowedEmptyContent = element.getAttributeValue(
ATTR_ALLOWED_EMPY_CONTENT).equalsIgnoreCase(TRUE);
if (element.getAttribute(ATTR_MANDATORY_EMPY_CONTENT) != null)
this.mandatoryEmptyContent = element.getAttributeValue(
ATTR_MANDATORY_EMPY_CONTENT).equalsIgnoreCase(TRUE);
// Load complex attributes
// populate allowed children list
// Get the "AllowedChilds" node
Element theAllowedChildrenNode = (Element) element.getChild(
ALLOWED_CHILDREN, PointToPointSchema.NAMESPACE);
// there is only one such node (if it exists), get its "Element"
// children
if (theAllowedChildrenNode != null) {
List theAllowedChildrenElements = theAllowedChildrenNode
.getChildren();
allowedChildren = populateAllowedAttributes(theAllowedChildrenElements);
}
// populate allowed first children list
// Get the "AllowedFirstChilds" node
Element theAllowedFirstChildren = (Element) element.getChild(
ALLOWED_FIRST_CHILDREN, PointToPointSchema.NAMESPACE);
// there is only one such node (if it exists), get its "Element"
// children
if (theAllowedFirstChildren != null) {
List theAllowedFirstChildrenElements = theAllowedFirstChildren
.getChildren();
allowedFirstChildren = populateAllowedAttributes(theAllowedFirstChildrenElements);
}
// populate allowed last children list
// Get the "AllowedLastChilds" node
Element theAllowedLastChildren = (Element) element.getChild(
ALLOWED_LAST_CHILDREN, PointToPointSchema.NAMESPACE);
// there is only one such node (if it exists), get its "Element"
// children
if (theAllowedLastChildren != null) {
List theAllowedLastChildrenElements = theAllowedLastChildren
.getChildren();
allowedLastChildren = populateAllowedAttributes(theAllowedLastChildrenElements);
}
// populate allowedFollowingSiblingsOfChild
allowedFollowingSiblingsOfChild = populateAllowedFollowingSiblingsOfChild(element);
}
/**
* Populate the "complex" attributes (lists) with the information contained
* in the node
*
* @param attributeList
* the attribute list to be populated
* @param children
* the Node list to read the information from
*/
private Map<String, PpsElement> populateAllowedAttributes(List children) {
// initialize vector
Map<String, PpsElement> attributeMap = new TreeMap<String, PpsElement>();
for (int i = 0; i < children.size(); i++) {
// each child is an entry in allowedChildren
Element refElement = (Element) children.get(i);
String refElementName = PointToPointSchema.getName(refElement);
PpsElement toBeAdded = pps.getElement(refElementName);
attributeMap.put(refElementName, toBeAdded);
}
return attributeMap;
}
/**
* Populate this last and complex attribute
*
* @param element
*/
private TreeMap<String, Map<String, PpsElement>> populateAllowedFollowingSiblingsOfChild(
Element element) {
TreeMap<String, Map<String, PpsElement>> allowedFollowingSiblingsOfChildMap = new TreeMap<String, Map<String, PpsElement>>();
List allowedFollowingSiblingsOfChildList = element.getChildren(
ALLOWED_FOLLOWING_SIBLINGS_OF_CHILD,
PointToPointSchema.NAMESPACE);
// These nodes (if they exists) are <AllowedFollowingSiblingOfChild>,
if (allowedFollowingSiblingsOfChildList == null
|| allowedFollowingSiblingsOfChildList.size() == 0)
return null;
// loop on these <AllowedFollowingSiblingOfChild> nodes
for (int i = 0; i < allowedFollowingSiblingsOfChildList.size(); i++) {
// each of them has a unique <Child> element as well as a unique
// <AllowedFollowingSibling> element: get them
Element ithElement = (Element) allowedFollowingSiblingsOfChildList
.get(i);
// Child = Text or Element
Element child = (Element) ithElement.getChild(
CHILD, PointToPointSchema.NAMESPACE).getChildren().get(0);
String childName = PointToPointSchema.getName(child);
Element allowedFollowingSiblings = ithElement.getChild(
ALLOWED_FOLLOWING_SIBLING, PointToPointSchema.NAMESPACE);
// the <AllowedFollowingSibling> node has one or many <Element>
// nodes: get them
List elementList = allowedFollowingSiblings.getChildren();
// create a vector which will be associated to child.name key in the
// result Map
Map<String, PpsElement> ppsElementMap = new TreeMap<String, PpsElement>();
for (int j = 0; j < elementList.size(); j++) {
Element allowedFollowingSibling = (Element) elementList
.get(j);
String allowedFollowingSiblingName = PointToPointSchema
.getName(allowedFollowingSibling);
ppsElementMap.put(allowedFollowingSiblingName, pps
.getElement(allowedFollowingSiblingName));
}
// put (child.name, childMapValues) into the result map
allowedFollowingSiblingsOfChildMap.put(childName, ppsElementMap);
}
return allowedFollowingSiblingsOfChildMap;
}
/**
*
* @param elementName
* @return true if element is an allowed child, false otherwise
*/
public boolean isAllowedChild(String elementName) {
if (allowedChildren == null) {
return false;
} else {
return allowedChildren.containsKey(elementName);
}
}
/**
*
* @param elementName
* @return true if element is an allowed first child, false otherwise
*/
public boolean isAllowedFirstChild(String elementName) {
if (allowedFirstChildren == null) {
return false;
} else {
return allowedFirstChildren.containsKey(elementName);
}
}
/**
*
* @param elementName
* @return true if element is an allowed last child, false otherwise
*/
public boolean isAllowedLastChild(String elementName) {
if (allowedLastChildren == null) {
return false;
} else {
return allowedLastChildren.containsKey(elementName);
}
}
/**
*
* @param childName
* @param elementName
* @return true if element named "elementName" is an allowed first sibling
* of child named "childName", false otherwise
*/
public boolean isAllowedFollowingSiblingOfChild(
String childName, String elementName) {
if (allowedFollowingSiblingsOfChild == null) {
return false;
} else {
Map ppsElementMap = (Map) allowedFollowingSiblingsOfChild
.get(childName);
if (ppsElementMap != null) {
return ppsElementMap.containsKey(elementName);
} else {
return false;
}
}
}
/**
*
* @param childName
* @return the vector of the allowed following siblings of child
*/
public Collection getAllowedFollowingSiblingsOfChild(String childName) {
return ((Map) allowedFollowingSiblingsOfChild.get(childName))
.values();
}
public void displayAllowedFollowingSiblingsOfChild() {
if (allowedFollowingSiblingsOfChild != null
&& allowedFollowingSiblingsOfChild.size() > 0) {
logger.debug("@allowedFollowingSiblingsOfChild: ");
Set KeySet = allowedFollowingSiblingsOfChild.keySet();
for (Iterator iter = KeySet.iterator(); iter.hasNext();) {
String childName = (String) iter.next();
String keyVals = "(";
Collection keyMappedValues = getAllowedFollowingSiblingsOfChild(childName);
for (Iterator iter2 = keyMappedValues.iterator(); iter2
.hasNext();) {
PpsElement element = (PpsElement) iter2.next();
keyVals += (String) element.name;
keyVals += ";";
}
keyVals += ")";
logger.debug("child key = " + childName
+ " -> AFS mapped values = " + keyVals);
}
logger.debug("end of @allowedFollowingSiblingsOfChild");
}
}
/**
* getter method for "name" attribute
* @return the name
*/
public String getName() {
return name;
}
/**
* getter method for "allowedChildren" attribute
* @return
*/
public Collection getAllowedChildren() {
return allowedChildren.values();
}
/**
* getter method for "allowedFirstChildren" attribute
* @return
*/
public Collection getAllowedFirstChildren() {
return allowedFirstChildren.values();
}
/**
* getter method for "allowedLastChildren" attribute
* @return
*/
public Collection getAllowedLastChildren() {
return allowedLastChildren.values();
}
/**
*
* @return true if "allowedEmptyContent" or "mandatoryEmptyContent" is true,
* false otherwise
*/
public boolean getCanEmptyContent() {
return (allowedEmptyContent || mandatoryEmptyContent);
}
/**
*
* @return true if element is a paragraph, ie if it can contain text
*/
public boolean isParagraph() {
return (mixedContent || textOnlyContent);
}
/**
* Display elements
*
*/
public void display() {
logger.debug("Element");
logger.debug(" @name = " + this.name);
logger.debug(" @mixedContent = " + this.mixedContent);
logger.debug(" @textOnlyContent = " + this.textOnlyContent);
logger.debug(" @allowedEmptyContent = " + this.allowedEmptyContent);
logger.debug(" @mandatoryEmptyContent = "
+ this.mandatoryEmptyContent);
if (allowedChildren != null && allowedChildren.size() > 0) {
logger.debug("@allowedChildren: ");
Set allowedChildrenSet = allowedChildren.entrySet();
for (Iterator iter = allowedChildrenSet.iterator(); iter
.hasNext();) {
PpsElement element = (PpsElement) iter.next();
logger.debug(" " + element.name);
}
logger.debug("end of @allowedChildren");
}
if (allowedFirstChildren != null && allowedFirstChildren.size() > 0) {
logger.debug("@allowedFirstChildren: ");
Set allowedFirstChildrenSet = allowedFirstChildren.entrySet();
for (Iterator iter = allowedFirstChildrenSet.iterator(); iter
.hasNext();) {
PpsElement element = (PpsElement) iter.next();
logger.debug(" " + element.name);
}
logger.debug("end of @allowedFirstChildren");
}
if (allowedLastChildren != null && allowedLastChildren.size() > 0) {
logger.debug("@allowedLastChildren: ");
Set allowedFirstChildrenSet = allowedLastChildren.entrySet();
for (Iterator iter = allowedFirstChildrenSet.iterator(); iter
.hasNext();) {
PpsElement element = (PpsElement) iter.next();
logger.debug(" " + element.name);
}
logger.debug("end of @allowedLastChildren");
}
if (allowedFollowingSiblingsOfChild != null
&& allowedFollowingSiblingsOfChild.size() > 0) {
displayAllowedFollowingSiblingsOfChild();
}
logger.debug("end of Element");
}
/**
* Class constants
*/
// Attribute names
private static final String ATTR_NAME = "name";
private static final String ATTR_MIXED_CONTENT = "mixedContent";
private static final String ATTR_TEXT_ONLY_CONTENT = "textOnlyContent";
private static final String ATTR_ALLOWED_EMPY_CONTENT = "allowedEmptyContent";
private static final String ATTR_MANDATORY_EMPY_CONTENT = "mandatoryEmptyContent";
/**
* XML Tags
*/
private static final String ALLOWED_CHILDREN = "AllowedChilds";
private static final String ALLOWED_FIRST_CHILDREN = "AllowedFirstChilds";
private static final String ALLOWED_LAST_CHILDREN = "AllowedLastChilds";
private static final String ALLOWED_FOLLOWING_SIBLINGS_OF_CHILD = "AllowedFollowingSiblingOfChild";
private static final String ALLOWED_FOLLOWING_SIBLING = "AllowedFollowingSibling";
private static final String CHILD = "Child";
/**
* Boolean values
*
*/
private static final String TRUE = "true";
}
Plus d'informations sur la liste de diffusion Castore-commits