use of org.dom4j.Element in project Openfire by igniterealtime.
the class HandsetProvider method buildCompleteCommand.
private Object buildCompleteCommand(Element element) {
Element reasonElement = (Element) element.elements().get(0);
String reasonValue = reasonElement.getName().toUpperCase();
Reason reason = Reason.valueOf(reasonValue);
SayCompleteEvent complete = new SayCompleteEvent();
complete.setReason(reason);
return complete;
}
use of org.dom4j.Element in project hibernate-orm by hibernate.
the class CollectionMetadataGenerator method addWithMiddleTable.
@SuppressWarnings({ "unchecked" })
private void addWithMiddleTable() {
LOG.debugf("Adding audit mapping for property %s.%s: collection with a join table", referencingEntityName, propertyName);
// Generating the name of the middle table
String auditMiddleTableName;
String auditMiddleEntityName;
if (!StringTools.isEmpty(propertyAuditingData.getJoinTable().name())) {
auditMiddleTableName = propertyAuditingData.getJoinTable().name();
auditMiddleEntityName = propertyAuditingData.getJoinTable().name();
} else {
final String middleTableName = getMiddleTableName(propertyValue, referencingEntityName);
auditMiddleTableName = mainGenerator.getVerEntCfg().getAuditTableName(null, middleTableName);
auditMiddleEntityName = mainGenerator.getVerEntCfg().getAuditEntityName(middleTableName);
}
LOG.debugf("Using join table name: %s", auditMiddleTableName);
// Generating the XML mapping for the middle entity, only if the relation isn't inverse.
// If the relation is inverse, will be later checked by comparing middleEntityXml with null.
Element middleEntityXml;
if (!propertyValue.isInverse()) {
// Generating a unique middle entity name
auditMiddleEntityName = mainGenerator.getAuditEntityNameRegister().createUnique(auditMiddleEntityName);
// Registering the generated name
mainGenerator.getAuditEntityNameRegister().register(auditMiddleEntityName);
middleEntityXml = createMiddleEntityXml(auditMiddleTableName, auditMiddleEntityName, propertyValue.getWhere());
} else {
middleEntityXml = null;
}
// ******
// Generating the mapping for the referencing entity (it must be an entity).
// ******
// Getting the id-mapping data of the referencing entity (the entity that "owns" this collection).
final IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
// Only valid for an inverse relation; null otherwise.
String mappedBy;
// The referencing prefix is always for a related entity. So it has always the "_" at the end added.
String referencingPrefixRelated;
String referencedPrefix;
if (propertyValue.isInverse()) {
// If the relation is inverse, then referencedEntityName is not null.
mappedBy = getMappedBy(propertyValue.getCollectionTable(), mainGenerator.getMetadata().getEntityBinding(referencedEntityName));
referencingPrefixRelated = mappedBy + "_";
referencedPrefix = StringTools.getLastComponent(referencedEntityName);
} else {
mappedBy = null;
referencingPrefixRelated = StringTools.getLastComponent(referencingEntityName) + "_";
referencedPrefix = referencedEntityName == null ? "element" : propertyName;
}
// Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
final MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping, referencingPrefixRelated, referencingEntityName);
// Creating a query generator builder, to which additional id data will be added, in case this collection
// references some entities (either from the element or index). At the end, this will be used to build
// a query generator to read the raw data collection from the middle table.
final QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(mainGenerator.getGlobalCfg(), mainGenerator.getVerEntCfg(), mainGenerator.getAuditStrategy(), referencingIdData, auditMiddleEntityName, isRevisionTypeInId());
// Adding the XML mapping for the referencing entity, if the relation isn't inverse.
if (middleEntityXml != null) {
// Adding related-entity (in this case: the referencing's entity id) id mapping to the xml.
addRelatedToXmlMapping(middleEntityXml, referencingPrefixRelated, MetadataTools.getColumnNameIterator(propertyValue.getKey().getColumnIterator()), referencingIdMapping);
}
// ******
// Generating the element mapping.
// ******
final MiddleComponentData elementComponentData = addValueToMiddleTable(propertyValue.getElement(), middleEntityXml, queryGeneratorBuilder, referencedPrefix, propertyAuditingData.getJoinTable().inverseJoinColumns(), !isLobMapElementType());
// ******
// Generating the index mapping, if an index exists.
// ******
final MiddleComponentData indexComponentData = addIndex(middleEntityXml, queryGeneratorBuilder);
// ******
// Generating the property mapper.
// ******
// Building the query generator.
final RelationQueryGenerator queryGenerator = queryGeneratorBuilder.build(elementComponentData, indexComponentData);
// Creating common data
final CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(mainGenerator.getVerEntCfg(), auditMiddleEntityName, propertyAuditingData.getPropertyData(), referencingIdData, queryGenerator);
// Checking the type of the collection and adding an appropriate mapper.
addMapper(commonCollectionMapperData, elementComponentData, indexComponentData);
// ******
// Storing information about this relation.
// ******
storeMiddleEntityRelationInformation(mappedBy);
}
use of org.dom4j.Element in project hibernate-orm by hibernate.
the class CollectionMetadataGenerator method createMiddleEntityXml.
private Element createMiddleEntityXml(String auditMiddleTableName, String auditMiddleEntityName, String where) {
final String schema = mainGenerator.getSchema(propertyAuditingData.getJoinTable().schema(), propertyValue.getCollectionTable());
final String catalog = mainGenerator.getCatalog(propertyAuditingData.getJoinTable().catalog(), propertyValue.getCollectionTable());
final Element middleEntityXml = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(), new AuditTableData(auditMiddleEntityName, auditMiddleTableName, schema, catalog), null, null);
final Element middleEntityXmlId = middleEntityXml.addElement("composite-id");
// If there is a where clause on the relation, adding it to the middle entity.
if (where != null) {
middleEntityXml.addAttribute("where", where);
}
middleEntityXmlId.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
// Adding the revision number as a foreign key to the revision info entity to the composite id of the
// middle table.
mainGenerator.addRevisionInfoRelation(middleEntityXmlId);
// Adding the revision type property to the entity xml.
mainGenerator.addRevisionType(isRevisionTypeInId() ? middleEntityXmlId : middleEntityXml, middleEntityXml, isRevisionTypeInId());
// All other properties should also be part of the primary key of the middle entity.
return middleEntityXmlId;
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class SearchPlugin method isValidSearchRequest.
/**
* This method checks if the search request that was received is a valid JABBER:IQ:SEARCH request. In other words, it checks if the
* search request is spec compliant (XEP-0055). It does this by checking:
* <ul>
* <li>if the IQ stanza is of type 'set';</li>
* <li>if a child element identified by the jabber:iq:search namespace is supplied;</li>
* <li>if the stanza child element is has valid children itself.</li>
* </ul>
*
* @param iq
* The IQ object that should include a jabber:iq:search request.
* @return ''true'' if the supplied IQ stanza is a spec compliant search request, ''false'' otherwise.
*/
@SuppressWarnings("unchecked")
public static boolean isValidSearchRequest(IQ iq) {
if (iq == null) {
throw new IllegalArgumentException("Argument 'iq' cannot be null.");
}
if (iq.getType() != IQ.Type.set) {
return false;
}
final Element childElement = iq.getChildElement();
if (childElement == null) {
return false;
}
if (!childElement.getNamespaceURI().equals(NAMESPACE_JABBER_IQ_SEARCH)) {
return false;
}
if (!childElement.getName().equals("query")) {
return false;
}
final List<Element> fields = childElement.elements();
if (fields.size() == 0) {
return false;
}
for (Element element : fields) {
final String name = element.getName();
if (!validSearchRequestFields.contains(name)) {
return false;
}
if (name.equals("set") && !ResultSet.isValidRSMRequest(element)) {
return false;
}
}
return true;
}
use of org.dom4j.Element in project Openfire by igniterealtime.
the class SearchPlugin method replyNonDataFormResult.
/**
* Constructs a query that is returned as an IQ packet that contains the search results.
*
* @param users
* set of users that will be used to construct the search results
* @param packet
* the IQ packet sent by the client
* @return the iq packet that contains the search results
*/
private IQ replyNonDataFormResult(Collection<User> users, IQ packet) {
IQ replyPacket = IQ.createResultIQ(packet);
Element replyQuery = replyPacket.setChildElement("query", NAMESPACE_JABBER_IQ_SEARCH);
for (User user : users) {
Element item = replyQuery.addElement("item");
String username = JID.unescapeNode(user.getUsername());
item.addAttribute("jid", username + "@" + serverName);
// return to the client the same fields that were submitted
for (String field : reverseFieldLookup.keySet()) {
if ("Username".equals(field)) {
Element element = item.addElement(reverseFieldLookup.get(field));
element.addText(username);
}
if ("Name".equals(field)) {
Element element = item.addElement(reverseFieldLookup.get(field));
element.addText(user.isNameVisible() ? removeNull(user.getName()) : "");
}
if ("Email".equals(field)) {
Element element = item.addElement(reverseFieldLookup.get(field));
element.addText(user.isEmailVisible() ? removeNull(user.getEmail()) : "");
}
}
}
return replyPacket;
}
Aggregations