List of usage examples for org.apache.commons.lang ArrayUtils isEmpty
public static boolean isEmpty(boolean[] array)
Checks if an array of primitive booleans is empty or null
.
From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsPropertyVisitor.java
private void addSubElementsAsChildProperties(XSModelGroup modelGroup, boolean modelGroupBelongsToContentObjectType) { //Expected that all elements are defined in xs:sequence or xs:all if (modelGroup != null && (XSModelGroup.Compositor.SEQUENCE == modelGroup.getCompositor() || XSModelGroup.Compositor.ALL == modelGroup.getCompositor())) { XSParticle[] subElements = modelGroup.getChildren(); if (!ArrayUtils.isEmpty(subElements)) { for (XSParticle subElement : subElements) { if (modelGroupBelongsToContentObjectType) { //We are processing child elements of built in complex type contentObjectType //In this case element owner must be ignored if ("owner".equals(subElement.getTerm().asElementDecl().getName())) { continue; }/* w w w .j a v a 2 s . c o m*/ } //Elements representing content types extend a base complex type //thus they contain all particles from that complex type along with their own //Process XSParticles that exist in the same Schema document with the parent complexType if (subElement.getSourceDocument() != null && modelGroup.getSourceDocument() != null && subElement.getSourceDocument().getSystemId() .equalsIgnoreCase(modelGroup.getSourceDocument().getSystemId())) { //It may be the case that particle is itself a model group. //In that case process its children if (subElement.getTerm() != null && subElement.getTerm().isModelGroup() && !ArrayUtils.isEmpty(subElement.getTerm().asModelGroup().getChildren())) { XSParticle[] particleChildren = subElement.getTerm().asModelGroup().getChildren(); for (XSParticle anotherSubElement : particleChildren) { addChildProperty(anotherSubElement); } } else { addChildProperty(subElement); } } } } } else { logger.warn( "Unable to process sub properties for definition '{}' because sub elements are not defined inside an xs:sequence or an xs:all element", name); } }
From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsPropertyVisitor.java
private void setBasicProperties(XSComponent component) throws Exception { if (propertyRepresentsTheSimpleContentOfAComplexProperty) { //Special case. This property represents the simple content of a complex type //In this case, its name is fixed name = CmsConstants.NAME_OF_PROPERTY_REPRESENTING_SIMPLE_CONTENT; } else if (component instanceof XSDeclaration) { name = ((XSDeclaration) component).getName(); } else if (component instanceof XSAttributeUse) { name = ((XSAttributeUse) component).getDecl().getName(); }/* w w w .j av a2s .c om*/ //Validate name if (!XMLChar.isValidNCName(name)) { throw new Exception("Invalid XML Name " + name + ". Check XML Namespaces recommendation [4] (http://www.w3.org/TR/REC-xml-names)"); } logger.debug("Setting basic properties for definition '{}'", name); // Retrieve annotation to build display name and description if (component.getAnnotation() != null) { annotation(component.getAnnotation()); } else if (component instanceof XSAttributeUse && ((XSAttributeUse) component).getDecl().getAnnotation() != null) { annotation(((XSAttributeUse) component).getDecl().getAnnotation()); } if (isDefinitionSimple()) { getDefaultValue(component); getValueRange(component); } //Attributes defined by repository if (CollectionUtils.isNotEmpty(component.getForeignAttributes())) { //Process attributes specified in the context of the types and not in the context of CmsDefinitionItem.contentObjectPropertyAttGroup if (ValueType.Complex == valueType || ValueType.ContentType == valueType) { //Retrieve value from schema String labelElementPathFromSchema = component.getForeignAttribute( CmsDefinitionItem.labelElementPath.getNamespaceURI(), CmsDefinitionItem.labelElementPath.getLocalPart()); if (StringUtils.isNotBlank(labelElementPathFromSchema)) { labelElementPath = labelElementPathFromSchema; } } if (MapUtils.isNotEmpty(builtInAttributes)) { for (Entry<ItemQName, XSAttributeUse> builtInAttribute : builtInAttributes.entrySet()) { ItemQName attribute = builtInAttribute.getKey(); XSAttributeDecl attributeDefinition = builtInAttribute.getValue().getDecl(); String defaultValue = (attributeDefinition.getDefaultValue() != null) ? attributeDefinition.getDefaultValue().value : null; //Retrieve value from schema String attributeValueFromSchema = component.getForeignAttribute(attribute.getNamespaceURI(), attribute.getLocalPart()); //Value to be set finally String valueToBeSet = (attributeValueFromSchema == null) ? defaultValue : attributeValueFromSchema; //BuiltIn attributes must be known a priori in order to map to ContentObjectPropertyDefinition if (valueToBeSet != null) { if (attribute.equals(CmsDefinitionItem.obsolete)) { if (ValueType.ContentType == valueType) { //Complex Type cannot be obsolete. Issue a warning if any such value has been set //Regardless if actual value is false if (attributeValueFromSchema != null) attributeIsNotAcceptedInContentType(CmsDefinitionItem.obsolete); } else obsolete = Boolean.valueOf(valueToBeSet); } else if (attribute.equals(CmsDefinitionItem.restrictReadToRoles)) restrictReadToRoles = valueToBeSet; else if (attribute.equals(CmsDefinitionItem.restrictWriteToRoles)) restrictWriteToRoles = valueToBeSet; else if (attribute.equals(CmsDefinitionItem.order)) order = Integer.parseInt(valueToBeSet); else { //Attributes corresponds only to Simple ContentObject Property if (isDefinitionSimple()) { //Not used for now. Needs further modeling // if (CmsDefinitionItem.repositoryObjectRestriction.getJcrName().equals(attributeJcrName)) // ((SimpleCmsPropertyDefinition)definition).setRepositoryObjectRestriction(valueToBeSet); if (ValueType.String == valueType) { //Look for string specific attributes if (attribute.equals(CmsDefinitionItem.stringFormat)) { stringFormat = StringFormat.valueOf(valueToBeSet); } else if (attribute.equals(CmsDefinitionItem.passwordEncryptorClassName)) { passwordEncryptorClassName = valueToBeSet; } } else if (ValueType.Binary == valueType) { if (attribute.equals(CmsDefinitionItem.unmanagedBinaryChannel)) { binaryChannelIsUnmanaged = true; } } else if (ValueType.TopicReference == valueType) { if (attribute.equals(CmsDefinitionItem.acceptedTaxonomies)) { try { String[] acceptedTaxonomyNameArray = StringUtils.split(valueToBeSet, ","); // Trim values if (!ArrayUtils.isEmpty(acceptedTaxonomyNameArray)) { acceptedTaxonomies = new ArrayList<String>(); for (String acceptedTaxonomyName : acceptedTaxonomyNameArray) { String trimmedValue = StringUtils .trimToNull(acceptedTaxonomyName); if (trimmedValue != null) acceptedTaxonomies.add(trimmedValue); } } } catch (Exception e) { logger.warn("While splitting accepted taxonomies {} in element {}", valueToBeSet, name); logger.warn("", e); acceptedTaxonomies = null; } } } else if (ValueType.ObjectReference == valueType) { //Expecting a comma delimited string if (attribute.equals(CmsDefinitionItem.acceptedContentTypes)) { try { String[] acceptedObjectTypeArray = StringUtils.split(valueToBeSet, ","); // Trim values if (!ArrayUtils.isEmpty(acceptedObjectTypeArray)) { acceptedObjectTypes = new HashSet<String>(); for (String acceptedObjectType : acceptedObjectTypeArray) { String trimmedValue = StringUtils .trimToNull(acceptedObjectType); if (trimmedValue != null) acceptedObjectTypes.add(trimmedValue); } } } catch (Exception e) { logger.warn("While splitting accepted object types {} in element {}", valueToBeSet, name); logger.warn("", e); acceptedObjectTypes = null; } } } } } } } } } }
From source file:org.betaconceptframework.astroboa.engine.jcr.query.CmsScoreNode.java
private Object getValueForProperty(Node node, String property) throws RepositoryException { String propertyPath = PropertyPath.getJcrPropertyPath(property); if (node.hasProperty(propertyPath)) { Property jcrProperty = node.getProperty(propertyPath); if (!jcrProperty.getDefinition().isMultiple()) { Value value = node.getProperty(propertyPath).getValue(); return JcrValueUtils.getObjectValue(value); } else {/*www . j a v a 2 s . c o m*/ Value[] values = node.getProperty(propertyPath).getValues(); if (ArrayUtils.isEmpty(values)) { return null; } else { // Get the last value to compare with return JcrValueUtils.getObjectValue(values[values.length - 1]); } } } else { if (logger.isDebugEnabled()) { logger.debug("Node {} does not have property {}", node.getPath(), propertyPath); } } return null; }
From source file:org.betaconceptframework.astroboa.engine.jcr.query.CmsScoreNodeIteratorUsingCmsNodes.java
public CmsScoreNodeIteratorUsingCmsNodes(CmsScoreNode[] rows, int offset, int limit) { if (ArrayUtils.isEmpty(rows)) reset();/*w ww. j av a 2s. c o m*/ else { this.rows = (CmsScoreNode[]) ArrayUtils.addAll(rows, null); this.limit = limit; this.offset = offset; position = -1; skip(offset); } }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.JcrNodeUtils.java
private static void addMultiValueProperty(SaveMode saveMode, Node node, ItemQName property, Value[] values, ValueFactory valueFactory, ValueType valueType) throws RepositoryException { if (!ArrayUtils.isEmpty(values)) { //It may be the case that property contains a single value and not a single value array. //In this case JCR throws an exception. Thus we remove value first and then we add the array of values if (node.hasProperty(property.getJcrName()) && node.getProperty(property.getJcrName()).getDefinition() != null && !node.getProperty(property.getJcrName()).getDefinition().isMultiple()) { if (values != null) { if (values.length > 1) { throw new CmsException("Cannot save more than one values " + generateStringOutput(values) + " to single value property " + node.getProperty(property.getJcrName()).getPath() + ".Probably this property used to be single valued and its definition change to multivalue " + " and now user tries to save more than one values. To correct this propblem " + " you should run a script which modifies existing property values from single value to a value Array"); } else if (values.length == 1) { addSimpleProperty(saveMode, node, property, JcrValueUtils.getObjectValue(values[0]), valueFactory, valueType); }// w w w . jav a2 s .c o m } else { node.setProperty(property.getJcrName(), JcrValueUtils.getJcrNull()); } } else { node.setProperty(property.getJcrName(), values); } } else if (saveMode == SaveMode.UPDATE) { if (node.hasProperty(property.getJcrName()) && node.getProperty(property.getJcrName()).getDefinition() != null && !node.getProperty(property.getJcrName()).getDefinition().isMultiple()) { removeProperty(node, property, false); } else { removeProperty(node, property, true); } } }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.JcrNodeUtils.java
private static String generateStringOutput(Value[] values) { StringBuilder sb = new StringBuilder(); try {//from w ww . j a v a 2s . co m if (!ArrayUtils.isEmpty(values)) { for (Value value : values) { if (value != null) { switch (value.getType()) { case PropertyType.BOOLEAN: sb.append(value.getBoolean()); break; case PropertyType.DATE: sb.append(DateUtils.format(value.getDate())); break; case PropertyType.DOUBLE: sb.append(value.getDouble()); break; case PropertyType.LONG: sb.append(value.getLong()); break; case PropertyType.NAME: case PropertyType.PATH: case PropertyType.REFERENCE: case PropertyType.STRING: sb.append(value.getString()); break; default: break; } } else { sb.append("NULL"); } sb.append(" "); } } } catch (Exception e) { logger.warn("While trying to log value array", e); } return sb.toString(); }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.JcrValueUtils.java
public static void replaceValue(Node node, ItemQName property, Value newValue, Value oldValue, Boolean isPropertyMultivalued) throws RepositoryException { //Node does not have property if (!node.hasProperty(property.getJcrName())) { //New Value is null. Do nothing if (newValue == null) return; //Determine if property is multiple, if this info is not provided if (isPropertyMultivalued == null) { isPropertyMultivalued = propertyIsMultiValued(node, property); }/*from w ww .java2s .com*/ if (isPropertyMultivalued) node.setProperty(property.getJcrName(), new Value[] { newValue }); else node.setProperty(property.getJcrName(), newValue); } else { //Node has property Property jcrProperty = node.getProperty(property.getJcrName()); if (isPropertyMultivalued == null) //Determine by property isPropertyMultivalued = jcrProperty.getDefinition().isMultiple(); if (!isPropertyMultivalued) { if (oldValue == null || (oldValue != null && oldValue.equals(jcrProperty.getValue()))) { //Set newValue only if no old value is provided OR //oldValue is provided and it really exists there jcrProperty.setValue(newValue); } } else { Value[] values = jcrProperty.getValues(); //Remove oldValue if (oldValue != null) { int index = ArrayUtils.indexOf(values, oldValue); if (index == ArrayUtils.INDEX_NOT_FOUND) throw new ItemNotFoundException( "Value " + oldValue.getString() + " in property " + jcrProperty.getPath()); values = (Value[]) ArrayUtils.remove(values, index); } //Add new value if (newValue != null && !ArrayUtils.contains(values, newValue)) values = (Value[]) ArrayUtils.add(values, newValue); //If at the end values array is empty //remove property if (ArrayUtils.isEmpty(values)) { node.setProperty(property.getJcrName(), JcrValueUtils.getJcrNullForMultiValue()); } else { node.setProperty(property.getJcrName(), values); } } } }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.PopulateComplexCmsProperty.java
private void populateAspects() throws Exception { if (complexPropertyNode.isNodeType(CmsBuiltInItem.StructuredContentObject.getJcrName()) && complexProperty instanceof ComplexCmsRootProperty) { //Populate Aspects List<String> newAspects = ((ComplexCmsRootProperty) complexProperty).getAspects(); boolean newAspectsExist = CollectionUtils.isNotEmpty(newAspects); if (newAspectsExist) { for (String aspect : newAspects) { //Retrieve aspect definition ComplexCmsPropertyDefinition aspectDefinition = contentDefinitionDao .getAspectDefinition(aspect); if (aspectDefinition == null) throw new CmsException("Aspect " + aspect + " does not have a definition"); populateAccordingToChildPropertyDefinition(aspect, aspectDefinition); }/*from w w w. ja v a 2s . com*/ } // Check which aspects should be removed Value[] existingAspects = null; if (complexPropertyNode.hasProperty(CmsBuiltInItem.Aspects.getJcrName())) { existingAspects = complexPropertyNode.getProperty(CmsBuiltInItem.Aspects.getJcrName()).getValues(); } Map<String, Node> aspectNodesToBeRemoved = new HashMap<String, Node>(); if (!ArrayUtils.isEmpty(existingAspects)) { for (Value existingAspect : existingAspects) { //If aspect list is empty or it does not contain existing aspect, remove aspect node String existingAspectName = existingAspect.getString(); //Remove existing aspect only if it has been removed by the user if (!newAspects.contains(existingAspectName)) { if (((ComplexCmsPropertyImpl) complexProperty) .cmsPropertyHasBeenLoadedAndRemoved(existingAspectName)) { //Node may have already been removed if (complexPropertyNode.hasNode(existingAspectName)) { aspectNodesToBeRemoved.put(existingAspectName, complexPropertyNode.getNode(existingAspectName)); } } else { if (newAspectsExist) { logger.warn("Property " + existingAspectName + " is not included in the aspect list '" + newAspects + "' of the content object " + contentObjectNodeUUID + " but it has not removed properly from the content object. This is probably a bug, however property will not be removed from the repository."); } //Load Aspect again ((ComplexCmsRootPropertyImpl) complexProperty).loadAspectDefinition(existingAspectName); } } } } //Remove deleted aspects if (MapUtils.isNotEmpty(aspectNodesToBeRemoved)) { ComplexCmsPropertyNodeRemovalVisitor aspectNodeRemovalVisitor = prototypeFactory .newComplexCmsPropertyNodeRemovalVisitor(); aspectNodeRemovalVisitor.setParentNode(complexPropertyNode, complexPropertyNode); aspectNodeRemovalVisitor.setSession(session); for (Node aspectNodeToBeRemoved : aspectNodesToBeRemoved.values()) { //Find aspect definition String aspectName = aspectNodeToBeRemoved.getName(); ComplexCmsPropertyDefinition aspectDefinition = contentDefinitionDao .getAspectDefinition(aspectName); if (aspectDefinition == null) throw new CmsException("Unable to find definition for aspect " + aspectName + ". Aspect jcr node " + aspectNodeToBeRemoved.getPath() + " will not be removed from content object jcr node"); else { aspectNodeRemovalVisitor.loadChildNodesToBeDeleted(aspectName); aspectDefinition.accept(aspectNodeRemovalVisitor); aspectNodeToBeRemoved.remove(); } } } //Finally it may be the case that an aspect has been specified but finally //no jcr equivalent node exists. For example one provided an aspect but without //any value for at least one of its child properties. In that case repository //has chosen to delete any previous jcr node for this aspect, or not to create //a jcr node if the aspect was not there at first place. List<String> aspectsToBeRemoved = new ArrayList<String>(); for (String finalAspect : newAspects) { if (!complexPropertyNode.hasNode(finalAspect)) { aspectsToBeRemoved.add(finalAspect); } } if (aspectsToBeRemoved.size() > 0) { newAspects = (List<String>) CollectionUtils.disjunction(newAspects, aspectsToBeRemoved); //Also remove them from complex property for (String aspectToBeRemoved : aspectsToBeRemoved) { if (((ComplexCmsRootProperty) complexProperty).hasAspect(aspectToBeRemoved)) { ((ComplexCmsRootProperty) complexProperty).removeChildProperty(aspectToBeRemoved); } } } //Update aspects jcr property with new values JcrNodeUtils.addMultiValueProperty(complexPropertyNode, CmsBuiltInItem.Aspects, SaveMode.UPDATE, newAspects, ValueType.String, session.getValueFactory()); } }
From source file:org.betaconceptframework.astroboa.engine.model.lazy.local.LazyComplexCmsPropertyLoader.java
private void renderVersionNames(SimpleCmsProperty<?, ?, ?> simpleProperty, Node contentObjectNode, Session session) throws RepositoryException { VersionHistory versioningHistory = null; //Render is about an archived content object, therefore node uuid is under jcr:frozenUUID if (contentObjectNode.hasProperty(JcrBuiltInItem.JcrFrozenUUID.getJcrName())) versioningHistory = versionUtils.getVersionHistoryForNode(session, cmsRepositoryEntityUtils.getCmsIdentifier(contentObjectNode)); else/* ww w. j a v a 2s . c om*/ versioningHistory = session.getWorkspace().getVersionManager() .getVersionHistory(contentObjectNode.getPath()); if (versioningHistory != null) { VersionIterator versIter = versioningHistory.getAllVersions(); while (versIter.hasNext()) { Version currentVersion = versIter.nextVersion(); String versionName = currentVersion.getName(); if (!versionName.equals(JcrBuiltInItem.JcrRootVersion.getJcrName())) { //Version with no successors is the base version Version[] successors = currentVersion.getSuccessors(); //RenderHasVersion //Current version does not have successors if (ArrayUtils.isEmpty(successors)) { if (CmsReadOnlyItem.HasVersion.getJcrName().equals(simpleProperty.getName())) renderSimpleValue(simpleProperty, versionName, session, null, null); } //Render versionName if (CmsReadOnlyItem.Versions.getJcrName().equals(simpleProperty.getName())) { renderSimpleValue(simpleProperty, versionName, session, null, null); } } } } }
From source file:org.betaconceptframework.astroboa.model.impl.query.xpath.OrderByClauseHelper.java
public static Map<String, Order> extractOrderPropertiesFromQuery(String xpathSearchQuery) { Map<String, Order> orderProperties = new HashMap<String, Order>(); if (StringUtils.isNotBlank(xpathSearchQuery)) { //First delete OrderByClause xpathSearchQuery = xpathSearchQuery.replaceFirst(CmsConstants.ORDER_BY, ""); //Then separate each order by clause String[] orderTokens = StringUtils.split(xpathSearchQuery, CmsConstants.COMMA); if (!ArrayUtils.isEmpty(orderTokens)) { for (String orderToken : orderTokens) { Order order = null;/*ww w. j a v a 2 s. c o m*/ String property = null; //Look for ascending or descending if (orderToken.contains(Order.ascending.toString())) { order = Order.ascending; property = orderToken.replace(Order.ascending.toString(), "").trim(); } else if (orderToken.contains(Order.descending.toString())) { order = Order.descending; property = orderToken.replace(Order.descending.toString(), "").trim(); } orderProperties.put(property, order); } } } return orderProperties; }