org.dom4j.Element.addAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(15.6k)|赞(0)|评价(0)|浏览(453)

本文整理了Java中org.dom4j.Element.addAttribute()方法的一些代码示例,展示了Element.addAttribute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.addAttribute()方法的具体详情如下:
包路径:org.dom4j.Element
类名称:Element
方法名:addAttribute

Element.addAttribute介绍

[英]Adds the attribute value of the given local name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.
[中]添加给定本地名称的属性值。如果给定名称的属性已存在,则将替换该属性。具有空值的属性将被静默忽略。如果属性的值为null,则此方法调用将删除具有给定名称的所有属性。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

public static Element addProperty(
    Element parent,
    String name,
    String type,
    boolean insertable,
    boolean updateable,
    boolean key) {
  final Element propMapping;
  if ( key ) {
    propMapping = parent.addElement( "key-property" );
  }
  else {
    propMapping = parent.addElement( "property" );
    propMapping.addAttribute( "insert", Boolean.toString( insertable ) );
    propMapping.addAttribute( "update", Boolean.toString( updateable ) );
  }
  propMapping.addAttribute( "name", name );
  if ( type != null ) {
    propMapping.addAttribute( "type", type );
  }
  return propMapping;
}

代码示例来源:origin: hibernate/hibernate-orm

public static Element addNativelyGeneratedId(
      Element parent, String name, String type,
      boolean useRevisionEntityWithNativeId) {
    final Element idMapping = parent.addElement( "id" );
    idMapping.addAttribute( "name", name ).addAttribute( "type", type );

    final Element generatorMapping = idMapping.addElement( "generator" );
    if ( useRevisionEntityWithNativeId ) {
      generatorMapping.addAttribute( "class", "native" );
    }
    else {
      generatorMapping.addAttribute( "class", "org.hibernate.envers.enhanced.OrderedSequenceGenerator" );
      generatorMapping.addElement( "param" ).addAttribute( "name", "sequence_name" ).setText(
          "REVISION_GENERATOR"
      );
      generatorMapping.addElement( "param" )
          .addAttribute( "name", "table_name" )
          .setText( "REVISION_GENERATOR" );
      generatorMapping.addElement( "param" ).addAttribute( "name", "initial_value" ).setText( "1" );
      generatorMapping.addElement( "param" ).addAttribute( "name", "increment_size" ).setText( "1" );
    }
//        generatorMapping.addAttribute("class", "sequence");
//        generatorMapping.addElement("param").addAttribute("name", "sequence").setText("custom");

    return idMapping;
  }

代码示例来源:origin: igniterealtime/Openfire

Element existingAppName = (Element)generatedModel.selectSingleNode(
    "//adminconsole/global/appname");
existingAppName.setText(appName.getText());
if (appName.attributeValue("plugin") != null) {
  existingAppName.addAttribute("plugin", appName.attributeValue("plugin"));
Element existingLogoImage = (Element)generatedModel.selectSingleNode(
    "//adminconsole/global/logo-image");
existingLogoImage.setText(appLogoImage.getText());
if (appLogoImage.attributeValue("plugin") != null) {
  existingLogoImage.addAttribute("plugin", appLogoImage.attributeValue("plugin"));
Element existingLoginImage = (Element)generatedModel.selectSingleNode(
    "//adminconsole/global/login-image");
existingLoginImage.setText(appLoginImage.getText());
if (appLoginImage.attributeValue("plugin") != null) {
  existingLoginImage.addAttribute("plugin", appLoginImage.attributeValue("plugin"));
  existingVersion.setText(appVersion.getText());
  if (appVersion.attributeValue("plugin") != null) {
    existingVersion.addAttribute("plugin", appVersion.attributeValue("plugin"));
        "//item[@url]");
    if (firstItem != null) {
      tab.addAttribute("url", firstItem.attributeValue("url"));

代码示例来源:origin: hibernate/hibernate-orm

private void mapEnumerationType(Element parent, Type type, Properties parameters) {
  if ( parameters.getProperty( EnumType.ENUM ) != null ) {
    parent.addElement( "param" )
        .addAttribute( "name", EnumType.ENUM )
        .setText( parameters.getProperty( EnumType.ENUM ) );
  }
  else {
    parent.addElement( "param" )
        .addAttribute( "name", EnumType.ENUM )
        .setText( type.getReturnedClass().getName() );
  }
  if ( parameters.getProperty( EnumType.NAMED ) != null ) {
    parent.addElement( "param" )
        .addAttribute( "name", EnumType.NAMED )
        .setText( parameters.getProperty( EnumType.NAMED ) );
  }
  else {
    parent.addElement( "param" )
        .addAttribute( "name", EnumType.NAMED )
        .setText( "" + !( (EnumType) ( (CustomType) type ).getUserType() ).isOrdinal() );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

String joinTableValueColumnName,
  String joinTableValueColumnType) {
final Element set = classMapping.addElement( "set" );
set.addAttribute( "name", propertyName );
set.addAttribute( "table", joinTableName );
set.addAttribute( "schema", joinTableSchema );
set.addAttribute( "catalog", joinTableCatalog );
set.addAttribute( "cascade", "persist, delete" );
set.addAttribute( "fetch", "join" );
set.addAttribute( "lazy", "false" );
final Element key = set.addElement( "key" );
key.addAttribute( "column", joinTablePrimaryKeyColumnName );
final Element element = set.addElement( "element" );
element.addAttribute( "type", joinTableValueColumnType );
final Element column = element.addElement( "column" );
column.addAttribute( "name", joinTableValueColumnName );

代码示例来源:origin: igniterealtime/Openfire

appName.addAttribute( "plugin", canonicalName );
if ( imageEl != null )
  imageEl.setText( "plugins/" + canonicalName + "/" + imageEl.getText() );
  imageEl.addAttribute( "plugin", canonicalName ); // Set the plugin name so that the proper i18n String can be loaded.
  imageEl.setText( "plugins/" + canonicalName + "/" + imageEl.getText() );
  imageEl.addAttribute( "plugin", canonicalName ); // Set the plugin name so that the proper i18n String can be loaded.
      element.addAttribute( "plugin", canonicalName );

代码示例来源:origin: spotbugs/spotbugs

/**
 * Add BugCode elements.
 *
 * @param bugCodeSet
 *            all bug codes (abbrevs) referenced in the BugCollection
 */
private void addBugCodes(Set<String> bugCodeSet) {
  Element root = document.getRootElement();
  for (String bugCode : bugCodeSet) {
    Element element = root.addElement("BugCode");
    element.addAttribute("abbrev", bugCode);
    Element description = element.addElement("Description");
    description.setText(I18N.instance().getBugTypeDescription(bugCode));
  }
}

代码示例来源:origin: hibernate/hibernate-orm

public static Element createJoin(
    Element parent,
    String tableName,
    String schema,
    String catalog) {
  final Element joinMapping = parent.addElement( "join" );
  joinMapping.addAttribute( "table", tableName );
  if ( !StringTools.isEmpty( schema ) ) {
    joinMapping.addAttribute( "schema", schema );
  }
  if ( !StringTools.isEmpty( catalog ) ) {
    joinMapping.addAttribute( "catalog", catalog );
  }
  return joinMapping;
}

代码示例来源:origin: igniterealtime/Openfire

added.setText(child.getText());
        added.addAttribute(attr.getQName(), attr.getValue());
delayInformation.addAttribute("stamp", XMPPDateTimeFormat.format(sentDate));
if (room.canAnyoneDiscoverJID()) {
  delayInformation.addAttribute("from", senderJID);
  delayInformation.addAttribute("from", room.getRole().getRoleAddress().toString());

代码示例来源:origin: igniterealtime/Openfire

element.addElement(propName[i]);
  element.addElement(eleName);
element.element(eleName).addAttribute(attName, value);
  element.addElement(lastName);
element.element(lastName).setText(value);

代码示例来源:origin: gocd/gocd

void populateXml(Element materials, Modifications modifications, XmlWriterContext writerContext) {
  Element materialElement = materials.addElement("material");
  materialElement.addAttribute("materialUri", writerContext.getBaseUrl() + "/api/materials/" + material.getId() + ".xml");
  for (Map.Entry<String, Object> criterion : material.getAttributesForXml().entrySet()) {
    if (criterion.getValue() != null) {
      materialElement.addAttribute(criterion.getKey(), criterion.getValue().toString());
    }
  }
  Element modificationsTag = materialElement.addElement("modifications");
  populateXmlForModifications(modifications, writerContext, modificationsTag);
}

代码示例来源:origin: igniterealtime/Openfire

lastActivity.addAttribute("seconds", String.valueOf(lastActivityTime));
return reply;
      lastActivity.addAttribute("seconds", String.valueOf(lastActivityTime));
      String lastStatus = presenceManager.getLastPresenceStatus(user);
      if (lastStatus != null && lastStatus.length() > 0) {
        lastActivity.setText(lastStatus);
      lastActivity.addAttribute("seconds", "0");

代码示例来源:origin: igniterealtime/Openfire

@Override
public void execute(SessionData sessionData, Element command) {
  Element note = command.addElement("note");
  Map<String, List<String>> data = sessionData.getData();
  // Gets the username
  String username;
  try {
    username = get(data, "username", 0);
  }
  catch (NullPointerException npe) {
    note.addAttribute("type", "error");
    note.setText("Username required parameter.");
    return;
  }
  // Loads the vCard
  Element vCard = VCardManager.getInstance().getVCard(username);
  if (vCard == null) {
    note.addAttribute("type", "error");
    note.setText("VCard not found.");
    return;
  }
  // Fire event.
  VCardEventDispatcher.dispatchVCardDeleted(username, vCard);
  // Answer that the operation was successful
  note.addAttribute("type", "info");
  note.setText("Operation finished successfully");
}

代码示例来源:origin: hibernate/hibernate-orm

String customWrite,
  boolean quoted) {
final Element columnMapping = parent.addElement( "column" );
columnMapping.addAttribute( "name", quoted ? "`" + name + "`" : name );
if ( length != null ) {
  columnMapping.addAttribute( "length", length.toString() );
  columnMapping.addAttribute( "scale", Integer.toString( scale ) );
  columnMapping.addAttribute( "precision", Integer.toString( precision ) );
  columnMapping.addAttribute( "sql-type", sqlType );
  columnMapping.addAttribute( "read", customRead );
  columnMapping.addAttribute( "write", customWrite );

代码示例来源:origin: igniterealtime/Openfire

@Override
public void execute(SessionData sessionData, Element command) {
  Element note = command.addElement("note");
  Map<String, List<String>> data = sessionData.getData();
  // Get the username
  String username;
  try {
    username = get(data, "username", 0);
  }
  catch (NullPointerException npe) {
    note.addAttribute("type", "error");
    note.setText("Username required parameter.");
    return;
  }
  // Sends the event
  User user;
  try {
    // Loads the new user            
    user = UserManager.getUserProvider().loadUser(username);
    // Fire event.
    Map<String, Object> params = Collections.emptyMap();
    UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_created, params);
  } catch (UserNotFoundException e) {
    note.addAttribute("type", "error");
    note.setText("User not found.");
  }
  // Answer that the operation was successful
  note.addAttribute("type", "info");
  note.setText("Operation finished successfully");
}

代码示例来源:origin: igniterealtime/Openfire

private Element addAffiliationToResult(String affiliation, Element parent, JID jid) {
    Element result = parent.addElement("item", "http://jabber.org/protocol/muc#admin");
    result.addAttribute("affiliation", affiliation);
    result.addAttribute("jid", jid.toString());
    try {
      List<MUCRole> roles = room.getOccupantsByBareJID(jid);
      MUCRole role = roles.get(0);
      result.addAttribute("role", role.getRole().toString());
      result.addAttribute("nick", role.getNickname());
    }
    catch (UserNotFoundException e) {
      // the JID is note currently an occupant
    }
    return result;
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void execute(SessionData sessionData, Element command) {
  Element note = command.addElement("note");
  Map<String, List<String>> data = sessionData.getData();
  // Get the group name
  String groupname;
  try {
    groupname = get(data, "groupName", 0);
  }
  catch (NullPointerException npe) {
    note.addAttribute("type", "error");
    note.setText("Group name required parameter.");
    return;
  }
  // Sends the event
  Group group;
  try {
    group = GroupManager.getInstance().getGroup(groupname, true);
    // Fire event.
    Map<String, Object> params = Collections.emptyMap();
    GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_deleting, params);
  } catch (GroupNotFoundException e) {
    note.addAttribute("type", "error");
    note.setText("Group not found.");
  }
  // Answer that the operation was successful
  note.addAttribute("type", "info");
  note.setText("Operation finished successfully");
}

代码示例来源:origin: hibernate/hibernate-orm

@SuppressWarnings({"unchecked"})
boolean addManyToOne(
    Element parent,
    PropertyAuditingData propertyAuditingData,
    Value value,
    SimpleMapperBuilder mapper) {
  final Type type = value.getType();
  // A null mapper occurs when adding to composite-id element
  final Element manyToOneElement = parent.addElement( mapper != null ? "many-to-one" : "key-many-to-one" );
  manyToOneElement.addAttribute( "name", propertyAuditingData.getName() );
  manyToOneElement.addAttribute( "class", type.getName() );
  // HHH-11107
  // Use FK hbm magic value 'none' to skip making foreign key constraints between the Envers
  // schema and the base table schema when a @ManyToOne is present in an identifier.
  if ( mapper == null ) {
    manyToOneElement.addAttribute( "foreign-key", "none" );
  }
  MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() );
  return true;
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void execute(SessionData sessionData, Element command) {
  Element note = command.addElement("note");
  Map<String, List<String>> data = sessionData.getData();
  // Get the group name
  String groupname;
  try {
    groupname = get(data, "groupName", 0);
  }
  catch (NullPointerException npe) {
    note.addAttribute("type", "error");
    note.setText("Group name required parameter.");
    return;
  }
  // Sends the event
  Group group;
  try {
    group = GroupManager.getInstance().getGroup(groupname, true);
    // Fire event.
    Map<String, Object> params = Collections.emptyMap();
    GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_created, params);
  } catch (GroupNotFoundException e) {
    note.addAttribute("type", "error");
    note.setText("Group not found.");
  }
  // Answer that the operation was successful
  note.addAttribute("type", "info");
  note.setText("Operation finished successfully");
}

代码示例来源:origin: spotbugs/spotbugs

public void toElement(BugInstance bugInstance) {
  String className = bugInstance.getPrimaryClass().getClassName();
  Element element = (Element) root.selectSingleNode(FILE_ELEMENT_NAME + "[@classname='" + className + "']");
  if (element == null) {
    element = root.addElement(FILE_ELEMENT_NAME);
    element.addAttribute("classname", className);
  }
  element = element.addElement(ELEMENT_NAME);
  element.addAttribute("type", bugInstance.getType());
  switch (bugInstance.getPriority()) {
  case Priorities.EXP_PRIORITY:
    element.addAttribute("priority", "Experimental");
    break;
  case Priorities.LOW_PRIORITY:
    element.addAttribute("priority", "Low");
    break;
  case Priorities.NORMAL_PRIORITY:
    element.addAttribute("priority", "Normal");
    break;
  case Priorities.HIGH_PRIORITY:
    element.addAttribute("priority", "High");
    break;
  default:
    assert false;
  }
  element.addAttribute("message", xmlEscape(bugInstance.getMessage()));
  SourceLineAnnotation line = bugInstance.getPrimarySourceLineAnnotation();
  element.addAttribute("line", Integer.toString(line.getStartLine()));
}

相关文章

微信公众号

最新文章

更多

Element类方法