private void preCalculateElementsForProperty(Element tree) { elementsForProperty = new ArrayList<>(); Element element = tree != null ? tree.element( "attributes" ) : null; //put entity.attributes elements if ( element != null ) { for ( Element subelement : (List<Element>) element.elements() ) { if ( propertyName.equals( subelement.attributeValue( "name" ) ) ) { elementsForProperty.add( subelement ); } } } //add pre-* etc from entity and pure entity listener classes if ( tree != null ) { for ( Element subelement : (List<Element>) tree.elements() ) { if ( propertyName.equals( subelement.attributeValue( "method-name" ) ) ) { elementsForProperty.add( subelement ); } } } }
private List<Element> getIncrementActivityNodes(String packageName, List<Element> newActivityNodes, Collection<String> incActivities) { final List<Element> result = new ArrayList<>(); for (Element newActivityNode : newActivityNodes) { String activityClazzName = newActivityNode.attributeValue(XML_NODEATTR_NAME); if (activityClazzName.charAt(0) == '.') { activityClazzName = packageName + activityClazzName; } if (!incActivities.contains(activityClazzName)) { continue; } final String exportedVal = newActivityNode.attributeValue(XML_NODEATTR_EXPORTED, Utils.isNullOrNil(newActivityNode.elements(XML_NODENAME_INTENTFILTER)) ? "false" : "true"); if ("true".equalsIgnoreCase(exportedVal)) { announceWarningOrException( String.format("found a new exported activity %s" + ", tinker does not support increase exported activity.", activityClazzName) ); } final String processVal = newActivityNode.attributeValue(XML_NODEATTR_PROCESS); if (processVal != null && processVal.charAt(0) == ':') { announceWarningOrException( String.format("found a new activity %s which would be run in standalone process" + ", tinker does not support increase such kind of activities.", activityClazzName) ); } Logger.d("Found increment activity: " + activityClazzName); result.add(newActivityNode); } return result; }
/** * Extracts a list of features from an IQ packet. * * @param packet the packet * @return a list of features */ private static List<String> getFeaturesFrom(IQ packet) { List<String> discoFeatures = new ArrayList<>(); Element query = packet.getChildElement(); Iterator<Element> featuresIterator = query.elementIterator("feature"); if (featuresIterator != null) { while (featuresIterator.hasNext()) { Element featureElement = featuresIterator.next(); String discoFeature = featureElement.attributeValue("var"); discoFeatures.add(discoFeature); } } return discoFeatures; }
while (itemsItr.hasNext()) { item = itemsItr.next(); JID itemJid = new JID(item.attributeValue("jid")); String itemName = item.attributeValue("name"); String itemNode = item.attributeValue("node"); String itemAction = item.attributeValue("action"); answer.add(new DiscoItem(itemJid, itemName, itemNode, itemAction));
public HistoryRequest(Element userFragment) { Element history = userFragment.element("history"); if (history != null) { if (history.attribute("maxchars") != null) { this.maxChars = Integer.parseInt(history.attributeValue("maxchars")); } if (history.attribute("maxstanzas") != null) { this.maxStanzas = Integer.parseInt(history.attributeValue("maxstanzas")); } if (history.attribute("seconds") != null) { this.seconds = Integer.parseInt(history.attributeValue("seconds")); } if (history.attribute("since") != null) { try { // parse since String into Date this.since = xmppDateTime.parseString(history.attributeValue("since")); } catch(ParseException pe) { Log.error("Error parsing date from history management", pe); this.since = null; } } } }
List<String> discoIdentities = new ArrayList<>(); Element query = packet.getChildElement(); Iterator<Element> identitiesIterator = query.elementIterator("identity"); if (identitiesIterator != null) { while (identitiesIterator.hasNext()) { Element identityElement = identitiesIterator.next(); String cat = identityElement.attributeValue("category"); String type = identityElement.attributeValue("type"); String lang = identityElement.attributeValue("xml:lang"); String name = identityElement.attributeValue("name");
if (!isConfigured()) { Iterator<Message> history = roomHistory.getMessageHistory(); while (history.hasNext()) { joinRole.send(history.next()); try { Date delayedDate = xmppDateTime.parseString(delayInformation.attributeValue("stamp")); if (getSince() != null && delayedDate != null && delayedDate.before(getSince())) {
private static ConstructorResult buildConstructorResult( Element constructorResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) { AnnotationDescriptor constructorResultDescriptor = new AnnotationDescriptor( ConstructorResult.class ); final Class entityClass = resolveClassReference( constructorResultElement.attributeValue( "target-class" ), defaults, classLoaderAccess ); constructorResultDescriptor.setValue( "targetClass", entityClass ); List<ColumnResult> columnResultAnnotations = new ArrayList<>(); for ( Element columnResultElement : (List<Element>) constructorResultElement.elements( "column" ) ) { columnResultAnnotations.add( buildColumnResult( columnResultElement, defaults, classLoaderAccess ) ); } constructorResultDescriptor.setValue( "columns", columnResultAnnotations.toArray( new ColumnResult[ columnResultAnnotations.size() ] ) ); return AnnotationFactory.create( constructorResultDescriptor ); }
/** * Returns the value of the attribute of the given property name or <tt>null</tt> * if it doesn't exist. * * @param name the property name to lookup - ie, "foo.bar" * @param attribute the name of the attribute, ie "id" * @return the value of the attribute of the given property or <tt>null</tt> if * it doesn't exist. */ public String getAttribute(String name, String attribute) { if (name == null || attribute == null) { return null; } String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML hierarchy. Element element = document.getRootElement(); for (String child : propName) { element = element.element(child); if (element == null) { // This node doesn't match this part of the property name which // indicates this property doesn't exist so return empty array. break; } } if (element != null) { // Get its attribute values return element.attributeValue(attribute); } return null; }
private List<String> addEntityListenerClasses(Element element, String packageName, List<String> addedClasses) { List<String> localAddedClasses = new ArrayList<>(); Element listeners = element.element( "entity-listeners" ); if ( listeners != null ) { @SuppressWarnings( "unchecked" ) List<Element> elements = listeners.elements( "entity-listener" ); for (Element listener : elements) { String listenerClassName = buildSafeClassName( listener.attributeValue( "class" ), packageName ); if ( classOverriding.containsKey( listenerClassName ) ) { //maybe switch it to warn? if ( "entity-listener".equals( classOverriding.get( listenerClassName ).getName() ) ) { LOG.duplicateListener( listenerClassName ); continue; } throw new IllegalStateException("Duplicate XML entry for " + listenerClassName); } localAddedClasses.add( listenerClassName ); classOverriding.put( listenerClassName, listener ); } } LOG.debugf( "Adding XML overriding information for listeners: %s", localAddedClasses ); addedClasses.addAll( localAddedClasses ); return localAddedClasses; }
private static void overrideTab(Element tab, Element overrideTab) { if (overrideTab.attributeValue("name") != null) { tab.addAttribute("name", overrideTab.attributeValue("name")); if (overrideTab.attributeValue("url") != null) { tab.addAttribute("url", overrideTab.attributeValue("url")); if (overrideTab.attributeValue("description") != null) { tab.addAttribute("description", overrideTab.attributeValue("description")); if (overrideTab.attributeValue("plugin") != null) { tab.addAttribute("plugin", overrideTab.attributeValue("plugin")); if (overrideTab.attributeValue("order") != null) { tab.addAttribute("order", overrideTab.attributeValue("order")); for (Iterator i=overrideTab.elementIterator(); i.hasNext(); ) { Element sidebar = (Element)i.next(); String id = sidebar.attributeValue("id"); Element existingSidebar = getElemnetByID(id);
String node = iq.attributeValue("node"); while (identities.hasNext()) { identity = identities.next(); identity.setQName(new QName(identity.getName(), queryElement.getNamespace())); queryElement.add((Element)identity.clone()); boolean hasResultSetManagementFeature = false; while (features.hasNext()) { final String feature = features.next(); queryElement.addElement("feature").addAttribute("var", feature); if (feature.equals(NAMESPACE_DISCO_INFO)) {
final Element listElement = defaultPrivacyList.asElement(); final Set<Element> toRemove = new HashSet<>(); for ( final Element element : listElement.elements( "item" ) ) final JID jid = new JID( element.attributeValue( "value" ) ); if ( "jid".equals( element.attributeValue( "type" ) ) && "deny".equals( element.attributeValue( "action" ) ) && toUnblocks.contains( jid ) )
PrivacyItem(Element itemElement) { this.allow = "allow".equals(itemElement.attributeValue("action")); this.order = Integer.parseInt(itemElement.attributeValue("order")); String typeAttribute = itemElement.attributeValue("type"); if (typeAttribute != null) { this.type = Type.valueOf(typeAttribute); String value = itemElement.attributeValue("value"); if (type == Type.jid) { this.filterIQ = itemElement.element("iq") != null; this.filterMessage = itemElement.element("message") != null; this.filterPresence_in = itemElement.element("presence-in") != null; this.filterPresence_out = itemElement.element("presence-out") != null; if (!filterIQ && !filterMessage && !filterPresence_in && !filterPresence_out) {
return; //a primitive type most likely Element element = tree != null ? tree.element( "attributes" ) : null; for ( Element subelement : (List<Element>) element.elements() ) { String propertyName = subelement.attributeValue( "name" ); if ( !properties.contains( propertyName ) ) { LOG.propertyNotFound( StringHelper.qualify( className, propertyName ) );
private static void overrideEntry(Element entry, Element overrideEntry) { if (overrideEntry.attributeValue("name") != null) { entry.addAttribute("name", overrideEntry.attributeValue("name")); if (overrideEntry.attributeValue("url") != null) { entry.addAttribute("url", overrideEntry.attributeValue("url")); if (overrideEntry.attributeValue("description") != null) { entry.addAttribute("description", overrideEntry.attributeValue("description")); if (overrideEntry.attributeValue("plugin") != null) { entry.addAttribute("plugin", overrideEntry.attributeValue("plugin")); if (overrideEntry.attributeValue("order") != null) { entry.addAttribute("order", overrideEntry.attributeValue("order")); for (Iterator i=overrideEntry.elementIterator(); i.hasNext(); ) { Element sidebar = (Element)i.next(); String id = sidebar.attributeValue("id"); Element existingSidebar = getElemnetByID(id);
private static EntityResult buildEntityResult( Element entityResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) { final AnnotationDescriptor entityResultDescriptor = new AnnotationDescriptor( EntityResult.class ); final Class entityClass = resolveClassReference( entityResultElement.attributeValue( "entity-class" ), defaults, classLoaderAccess ); entityResultDescriptor.setValue( "entityClass", entityClass ); copyStringAttribute( entityResultDescriptor, entityResultElement, "discriminator-column", false ); // process the <field-result/> sub-elements List<FieldResult> fieldResultAnnotations = new ArrayList<>(); for ( Element fieldResult : (List<Element>) entityResultElement.elements( "field-result" ) ) { AnnotationDescriptor fieldResultDescriptor = new AnnotationDescriptor( FieldResult.class ); copyStringAttribute( fieldResultDescriptor, fieldResult, "name", true ); copyStringAttribute( fieldResultDescriptor, fieldResult, "column", true ); fieldResultAnnotations.add( AnnotationFactory.create( fieldResultDescriptor ) ); } entityResultDescriptor.setValue( "fields", fieldResultAnnotations.toArray( new FieldResult[fieldResultAnnotations.size()] ) ); return AnnotationFactory.create( entityResultDescriptor ); }
element = element.element(propName[i]); if (element == null) { break; value = element.attributeValue(attName);
private EntityListeners getEntityListeners(Element tree, XMLContext.Default defaults) { Element element = tree != null ? tree.element( "entity-listeners" ) : null; if ( element != null ) { List<Class> entityListenerClasses = new ArrayList<>(); for ( Element subelement : (List<Element>) element.elements( "entity-listener" ) ) { String className = subelement.attributeValue( "class" ); try { entityListenerClasses.add( classLoaderAccess.classForName( XMLContext.buildSafeClassName( className, defaults ) ) ); } catch ( ClassLoadingException e ) { throw new AnnotationException( "Unable to find " + element.getPath() + ".class: " + className, e ); } } AnnotationDescriptor ad = new AnnotationDescriptor( EntityListeners.class ); ad.setValue( "value", entityListenerClasses.toArray( new Class[entityListenerClasses.size()] ) ); return AnnotationFactory.create( ad ); } else if ( defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( EntityListeners.class ); } else { return null; } }
private static void overrideSidebar(Element sidebar, Element overrideSidebar) { // Override name. if (overrideSidebar.attributeValue("name") != null) { sidebar.addAttribute("name", overrideSidebar.attributeValue("name")); } if (overrideSidebar.attributeValue("plugin") != null) { sidebar.addAttribute("plugin", overrideSidebar.attributeValue("plugin")); } if (overrideSidebar.attributeValue("order") != null) { sidebar.addAttribute("order", overrideSidebar.attributeValue("order")); } // Override entries. for (Iterator i=overrideSidebar.elementIterator(); i.hasNext(); ) { Element entry = (Element)i.next(); String id = entry.attributeValue("id"); Element existingEntry = getElemnetByID(id); // Simple case, there is no existing sidebar with the same id. if (existingEntry == null) { sidebar.add(entry.createCopy()); } // More complex case -- an entry with the same id already exists. // In this case, we have to overrite only the difference between // the two elements. else { overrideEntry(existingEntry, entry); } } }