org.jdom.Element.setText()方法的使用及代码示例

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

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

Element.setText介绍

[英]Sets the content of the element to be the text given. All existing text content and non-text context is removed. If this element should have both textual content and nested elements, use #setContent instead. Setting a null text value is equivalent to setting an empty string value.
[中]将元素的内容设置为给定的文本。将删除所有现有文本内容和非文本上下文。如果此元素同时包含文本内容和嵌套元素,请改用#setContent。设置空文本值等同于设置空字符串值。

代码示例

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

private Element mapZone(Zone zone) {
  Element zoneElement = new Element(ZONE_ELMT);
  zoneElement.addContent(new Element(ZONE_ID_ELMT).setText(Integer.toString(zone.getId())));
  String proximityListTest = StringUtils.join(zone.getProximityList().toArray(), ", ");
  zoneElement.addContent(new Element(ZONE_PROXIMITY_LIST_ELMT).setText(proximityListTest));
  return zoneElement;
}

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

private Element mapServer(Node node, boolean displayZones) {
    Element server = new Element(SERVER_ELMT);
    server.addContent(new Element(SERVER_ID_ELMT).setText(Integer.toString(node.getId())));
    server.addContent(new Element(HOST_ELMT).setText(node.getHost()));
    server.addContent(new Element(HTTP_PORT_ELMT).setText(Integer.toString(node.getHttpPort())));
    server.addContent(new Element(SOCKET_PORT_ELMT).setText(Integer.toString(node.getSocketPort())));
    server.addContent(new Element(ADMIN_PORT_ELMT).setText(Integer.toString(node.getAdminPort())));
    if(node.getRestPort() > 0) {
      server.addContent(new Element(REST_PORT_ELMT).setText(Integer.toString(node.getRestPort())));
    }
    String serverPartitionsText = StringUtils.join(node.getPartitionIds().toArray(), ", ");
    server.addContent(new Element(SERVER_PARTITIONS_ELMT).setText(serverPartitionsText));
    if(displayZones)
      server.addContent(new Element(ZONE_ID_ELMT).setText(Integer.toString(node.getZoneId())));
    return server;
  }
}

代码示例来源:origin: JetBrains/ideavim

/**
 * Set the text of an XML element, safely encode it if needed.
 */
@NotNull
public static Element setSafeXmlText(@NotNull Element element, @NotNull String text) {
 final Character first = firstCharacter(text);
 final Character last = lastCharacter(text);
 if (!StringHelper.isXmlCharacterData(text) ||
   first != null && Character.isWhitespace(first) ||
   last != null && Character.isWhitespace(last)) {
  element.setAttribute("encoding", "base64");
  final String encoded = new String(Base64.encodeBase64(text.getBytes()));
  element.setText(encoded);
 }
 else {
  element.setText(text);
 }
 return element;
}

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

public String writeCluster(Cluster cluster) {
  Document doc = new Document(new Element(CLUSTER_ELMT));
  doc.getRootElement().addContent(new Element(CLUSTER_NAME_ELMT).setText(cluster.getName()));
  boolean displayZones = cluster.getZones().size() > 1;
  if(displayZones) {
    for(Zone n: cluster.getZones())
      doc.getRootElement().addContent(mapZone(n));
  }
  for(Node n: cluster.getNodes())
    doc.getRootElement().addContent(mapServer(n, displayZones));
  XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
  return serializer.outputString(doc.getRootElement());
}

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

public static void addSerializer(Element parent, SerializerDefinition def) {
  parent.addContent(new Element(STORE_SERIALIZATION_TYPE_ELMT).setText(def.getName()));
  if(def.hasSchemaInfo()) {
    for(Map.Entry<Integer, String> entry: def.getAllSchemaInfoVersions().entrySet()) {
      Element schemaElmt = new Element(STORE_SERIALIZATION_META_ELMT);
      if(def.hasVersion())
        schemaElmt.setAttribute(STORE_VERSION_ATTR, Integer.toString(entry.getKey()));
      else
        schemaElmt.setAttribute(STORE_VERSION_ATTR, "none");
      schemaElmt.setText(entry.getValue());
      parent.addContent(schemaElmt);
    }
  }
  if(def.hasCompression()) {
    Compression compression = def.getCompression();
    Element compressionElmt = new Element(STORE_COMPRESSION_ELMT);
    Element type = new Element(STORE_COMPRESSION_TYPE_ELMT);
    type.setText(compression.getType());
    compressionElmt.addContent(type);
    String optionsText = compression.getOptions();
    if(optionsText != null) {
      Element options = new Element(STORE_COMPRESSION_OPTIONS_ELMT);
      options.setText(optionsText);
      compressionElmt.addContent(options);
    }
    parent.addContent(compressionElmt);
  }
}

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

/**
 * Given a storedefinition, constructs the xml string to be sent out in
 * response to a "schemata" fetch request
 * 
 * @param storeDefinition
 * @return serialized store definition
 */
public static String constructSerializerInfoXml(StoreDefinition storeDefinition) {
  Element store = new Element(StoreDefinitionsMapper.STORE_ELMT);
  store.addContent(new Element(StoreDefinitionsMapper.STORE_NAME_ELMT).setText(storeDefinition.getName()));
  Element keySerializer = new Element(StoreDefinitionsMapper.STORE_KEY_SERIALIZER_ELMT);
  StoreDefinitionsMapper.addSerializer(keySerializer, storeDefinition.getKeySerializer());
  store.addContent(keySerializer);
  Element valueSerializer = new Element(StoreDefinitionsMapper.STORE_VALUE_SERIALIZER_ELMT);
  StoreDefinitionsMapper.addSerializer(valueSerializer, storeDefinition.getValueSerializer());
  store.addContent(valueSerializer);
  XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
  return serializer.outputString(store);
}

代码示例来源:origin: kiegroup/optaplanner

schedulingPeriodIDElement.setText(nurseRoster.getCode());
solutionElement.addContent(schedulingPeriodIDElement);
competitorElement.setText("Geoffrey De Smet with OptaPlanner");
solutionElement.addContent(competitorElement);
softConstraintsPenaltyElement.setText(Integer.toString(nurseRoster.getScore().getSoftScore()));
solutionElement.addContent(softConstraintsPenaltyElement);
    dateElement.setText(shift.getShiftDate().getDate().format(DateTimeFormatter.ISO_DATE));
    assignmentElement.addContent(dateElement);
    employeeElement.setText(shiftAssignment.getEmployee().getCode());
    assignmentElement.addContent(employeeElement);
    shiftTypeElement.setText(shift.getShiftType().getCode());
    assignmentElement.addContent(shiftTypeElement);

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

private Element viewToElement(StoreDefinition storeDefinition) {
  Element store = new Element(VIEW_ELMT);
  store.addContent(new Element(STORE_NAME_ELMT).setText(storeDefinition.getName()));
  store.addContent(new Element(VIEW_TARGET_ELMT).setText(storeDefinition.getViewTargetStoreName()));
  if(storeDefinition.getDescription() != null)
    store.addContent(new Element(STORE_DESCRIPTION_ELMT).setText(storeDefinition.getDescription()));
  if(storeDefinition.getOwners() != null && storeDefinition.getOwners().size() > 0) {
    String ownersText = StringUtils.join(storeDefinition.getOwners().toArray(), ", ");
    store.addContent(new Element(STORE_OWNERS_ELMT).setText(ownersText));
  store.addContent(new Element(VIEW_TRANS_ELMT).setText(storeDefinition.getValueTransformation()));
  store.addContent(new Element(STORE_ROUTING_TIER_ELMT).setText(storeDefinition.getRoutingPolicy()
                                         .toDisplay()));
  if(storeDefinition.hasPreferredReads())
    store.addContent(new Element(STORE_PREFERRED_READS_ELMT).setText(Integer.toString(storeDefinition.getPreferredReads())));
  store.addContent(new Element(STORE_REQUIRED_READS_ELMT).setText(Integer.toString(storeDefinition.getRequiredReads())));
  if(storeDefinition.hasPreferredWrites())
    store.addContent(new Element(STORE_PREFERRED_WRITES_ELMT).setText(Integer.toString(storeDefinition.getPreferredWrites())));
  store.addContent(new Element(STORE_REQUIRED_WRITES_ELMT).setText(Integer.toString(storeDefinition.getRequiredWrites())));
    store.addContent(new Element(STORE_ZONE_COUNT_READS).setText(Integer.toString(storeDefinition.getZoneCountReads())));
  if(storeDefinition.hasZoneCountWrites())
    store.addContent(new Element(STORE_ZONE_COUNT_WRITES).setText(Integer.toString(storeDefinition.getZoneCountWrites())));
    serializerFactory.setText(storeDefinition.getSerializerFactory());
    store.addContent(serializerFactory);

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

private Element storeToElement(StoreDefinition storeDefinition) {
  Element store = new Element(STORE_ELMT);
  store.addContent(new Element(STORE_NAME_ELMT).setText(storeDefinition.getName()));
  store.addContent(new Element(STORE_PERSISTENCE_ELMT).setText(storeDefinition.getType()));
  if(storeDefinition.getDescription() != null)
    store.addContent(new Element(STORE_DESCRIPTION_ELMT).setText(storeDefinition.getDescription()));
  if(storeDefinition.getOwners() != null && storeDefinition.getOwners().size() > 0) {
    String ownersText = StringUtils.join(storeDefinition.getOwners().toArray(), ", ");
    store.addContent(new Element(STORE_OWNERS_ELMT).setText(ownersText));
  store.addContent(new Element(STORE_ROUTING_STRATEGY).setText(storeDefinition.getRoutingStrategyType()));
  store.addContent(new Element(STORE_ROUTING_TIER_ELMT).setText(storeDefinition.getRoutingPolicy()
                                         .toDisplay()));
  store.addContent(new Element(STORE_REPLICATION_FACTOR_ELMT).setText(Integer.toString(storeDefinition.getReplicationFactor())));
  HashMap<Integer, Integer> zoneReplicationFactor = storeDefinition.getZoneReplicationFactor();
  if(zoneReplicationFactor != null) {
    Element zoneReplicationFactorNode = new Element(STORE_ZONE_REPLICATION_FACTOR_ELMT);
    for(Integer zone: zoneReplicationFactor.keySet()) {
      zoneReplicationFactorNode.addContent(new Element(STORE_REPLICATION_FACTOR_ELMT).setText(Integer.toString(zoneReplicationFactor.get(zone)))
                                              .setAttribute(STORE_ZONE_ID_ELMT,
                                                     Integer.toString(zone)));
    store.addContent(new Element(STORE_PREFERRED_READS_ELMT).setText(Integer.toString(storeDefinition.getPreferredReads())));
  store.addContent(new Element(STORE_REQUIRED_READS_ELMT).setText(Integer.toString(storeDefinition.getRequiredReads())));
  if(storeDefinition.hasPreferredWrites())
    store.addContent(new Element(STORE_PREFERRED_WRITES_ELMT).setText(Integer.toString(storeDefinition.getPreferredWrites())));
  store.addContent(new Element(STORE_REQUIRED_WRITES_ELMT).setText(Integer.toString(storeDefinition.getRequiredWrites())));
  if(storeDefinition.hasZoneCountReads())
    store.addContent(new Element(STORE_ZONE_COUNT_READS).setText(Integer.toString(storeDefinition.getZoneCountReads())));
  if(storeDefinition.hasZoneCountWrites())

代码示例来源:origin: banq/jdonframework

/**
 * Sets the value of the specified property. If the property doesn't
 * currently exist, it will be automatically created.
 * 
 * @param name
 *            the name of the property to set.
 * @param value
 *            the new value for the property.
 */
public void setProperty(String name, String value) {
  // Set cache correctly with prop name and value.
  propertyCache.put(name, value);
  String[] propName = parsePropertyName(name);
  // Search for this property by traversing down the XML heirarchy.
  Element element = doc.getRootElement();
  for (int i = 0; i < propName.length; i++) {
    // If we don't find this part of the property in the XML heirarchy
    // we add it as a new node
    if (element.getChild(propName[i]) == null) {
      element.addContent(new Element(propName[i]));
    }
    element = element.getChild(propName[i]);
  }
  // Set the value of the property in this node.
  element.setText(value);
}

代码示例来源:origin: apache/oozie

private void addChildElement(Element parent, Namespace ns, String childName, String childValue) {
  Element child = new Element(childName, ns);
  child.setText(childValue);
  parent.addContent(child);
}

代码示例来源:origin: org.entando.entando/entando-core-engine

private void addElement(String name, String text, Element parent) {
  Element element = new Element(name);
  element.setText(text);
  parent.addContent(element);
}

代码示例来源:origin: org.seasar.tuigwaa/tuigwaa-cms

public void addHref(String path) {
  Element from = new Element(DaslConstants.E_FROM, DNSP);
  rootElement.addContent(from);
  Element scope = new Element(DaslConstants.E_SCOPE, DNSP);
  from.addContent(scope);
  Element href = new Element("href", DNSP);
  scope.addContent(href);
  href.setText(path);
}

代码示例来源:origin: uk.org.mygrid.taverna.processors/taverna-stringconstant-processor

public Element elementForProcessor(Processor p) {
StringConstantProcessor scp = (StringConstantProcessor)p;
Element spec = new Element("stringconstant",XScufl.XScuflNS);
spec.setText(scp.getStringValue());
return spec;
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-api-module

/**
 * @param servletClass the servletClass to set
 */
public void setServletClass(String servletClass)
{
  Element e = child(WebXmlType.SERVLET_CLASS);
  e.setText(servletClass);
}

代码示例来源:origin: org.codehaus.cargo/cargo-core-api-module

/**
 * Set the parameter name.
 * @param paramName Name of the parameter
 */
public void setParamName(String paramName)
{
  child("param-name").setText(paramName);
}

代码示例来源:origin: edu.washington.cs.knowitall/nlp

@Override
  public Element toXmlElement() {
    Element e = super.toXmlElement();
    for (String term : terms) {
      e.addContent(new Element("term").setText(term));
    }
    return e;
  }
}

代码示例来源:origin: apache/oozie

/**
 * Update Sla tag element.
 *
 * @param elem the elem
 * @param tagName the tag name
 * @param value the value
 */
public void updateSlaTagElement(Element elem, String tagName, String value) {
  if (elem != null && elem.getChild(tagName, elem.getNamespace("sla")) != null) {
    elem.getChild(tagName, elem.getNamespace("sla")).setText(value);
  }
}

代码示例来源:origin: net.bpelunit/framework

public static Element createIfActivity(String conditionContent) {
  Element ifElement = createBPELElement(IF_ELEMENT);
  Element condition = createBPELElement(CONDITION_ELEMENT);
  condition.setAttribute("expressionLanguage",
      XpathLanguage.LANGUAGE_SPEZIFIKATION);
  condition.setText(conditionContent);
  ifElement.addContent(condition);
  return ifElement;
}

代码示例来源:origin: cytoscape/application

private Element createThemeContent(ThemeInfo obj) {
  Element Theme = new Element(PluginXml.THEME.getTag());
  
  Theme = createBasicContent(obj, Theme);
  Theme.addContent(new Element(PluginXml.THEME_VERSION.getTag()).setText(obj.getObjectVersion()));
  
  Element PluginList = new Element(PluginXml.PLUGIN_LIST.getTag());
  for (PluginInfo plugin: obj.getPlugins()) {
    PluginList.addContent(createPluginContent(plugin));
  }
  Theme.addContent(PluginList);
  
  return Theme;
}

相关文章