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

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

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

Element.<init>介绍

[英]This protected constructor is provided in order to support an Element subclass that wants full control over variable initialization. It intentionally leaves all instance variables null, allowing a lightweight subclass implementation. The subclass is responsible for ensuring all the get and set methods on Element behave as documented.

When implementing an Element subclass which doesn't require full control over variable initialization, be aware that simply calling super() (or letting the compiler add the implicit super() call) will not initialize the instance variables which will cause many of the methods to throw a NullPointerException. Therefore, the constructor for these subclasses should call one of the public constructors so variable initialization is handled automatically.
[中]提供此受保护的构造函数是为了支持希望完全控制变量初始化的元素子类。它有意将所有实例变量保留为null,从而允许轻量级子类实现。子类负责确保元素上的所有get和set方法都按照文档中的方式运行。
在实现不需要完全控制变量初始化的元素子类时,请注意,仅调用super()(或让编译器添加隐式super()调用)不会初始化实例变量,这将导致许多方法抛出NullPointerException。因此,这些子类的构造函数应该调用其中一个公共构造函数,以便自动处理变量初始化。

代码示例

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

public void saveData(@NotNull Element element) {
 if (isKeyRepeat != null) {
  final Element editor = new Element("editor");
  element.addContent(editor);
  final Element keyRepeat = new Element("key-repeat");
  keyRepeat.setAttribute("enabled", Boolean.toString(isKeyRepeat));
  editor.addContent(keyRepeat);
 }
}

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

private void saveData(@NotNull Element element, String key) {
 final HistoryBlock block = histories.get(key);
 if (block == null) {
  return;
 }
 final Element root = new Element("history-" + key);
 for (HistoryEntry entry : block.getEntries()) {
  final Element entryElement = new Element("entry");
  StringHelper.setSafeXmlText(entryElement, entry.getEntry());
  root.addContent(entryElement);
 }
 element.addContent(root);
}

代码示例来源:origin: org.geotools/gt-coverage

private Element createShortElement(final int value) {
  Element GeoKeyRecord = new Element(GeoTiffConstants.GEOTIFF_SHORT_TAG);
  GeoKeyRecord.setAttribute(GeoTiffConstants.VALUE_ATTRIBUTE, String
      .valueOf(value));
  return GeoKeyRecord;
}

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

public void saveData(@NotNull Element element) {
 final Element conflictsElement = new Element(SHORTCUT_CONFLICTS_ELEMENT);
 for (Map.Entry<KeyStroke, ShortcutOwner> entry : shortcutConflicts.entrySet()) {
  final ShortcutOwner owner = entry.getValue();
  if (owner != ShortcutOwner.UNDEFINED) {
   final Element conflictElement = new Element(SHORTCUT_CONFLICT_ELEMENT);
   conflictElement.setAttribute(OWNER_ATTRIBUTE, owner.getName());
   final Element textElement = new Element(TEXT_ELEMENT);
   StringHelper.setSafeXmlText(textElement, entry.getKey().toString());
   conflictElement.addContent(textElement);
   conflictsElement.addContent(conflictElement);
  }
 }
 element.addContent(conflictsElement);
}

代码示例来源: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: org.geotools/gt-coverage

private Element createAsciiElement(final String value) {
  Element param = new Element(GeoTiffConstants.GEOTIFF_ASCII_TAG);
  param.setAttribute(GeoTiffConstants.VALUE_ATTRIBUTE, String.valueOf(value));
  return param;
}

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

public void saveData(@NotNull final Element element) {
 logger.debug("saveData");
 final Element registersElement = new Element("registers");
 for (Character key : registers.keySet()) {
  final Register register = registers.get(key);
  final Element registerElement = new Element("register");
  registerElement.setAttribute("name", String.valueOf(key));
  registerElement.setAttribute("type", Integer.toString(register.getType().getValue()));
  final String text = register.getText();
  if (text != null) {
   final Element textElement = new Element("text");
   StringHelper.setSafeXmlText(textElement, text);
   registerElement.addContent(textElement);
  }
  else {
   final Element keys = new Element("keys");
   final List<KeyStroke> list = register.getKeys();
   for (KeyStroke stroke : list) {
    final Element k = new Element("key");
    k.setAttribute("char", Integer.toString(stroke.getKeyChar()));
    k.setAttribute("code", Integer.toString(stroke.getKeyCode()));
    k.setAttribute("mods", Integer.toString(stroke.getModifiers()));
    keys.addContent(k);
   }
   registerElement.addContent(keys);
  }
  registersElement.addContent(registerElement);
 }
 element.addContent(registersElement);
}

代码示例来源: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: org.geotools/gt-coverage

private Element createFieldElement(final TIFFTag tag) {
  Element field = new Element(GeoTiffConstants.GEOTIFF_FIELD_TAG);
  field.setAttribute(GeoTiffConstants.NUMBER_ATTRIBUTE, String.valueOf(tag
      .getNumber()));
  field.setAttribute(GeoTiffConstants.NAME_ATTRIBUTE, tag.getName());
  return field;
}

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

@Override
public Element getState() {
 LOG.debug("Saving state");
 final Element element = new Element("ideavim");
 // Save whether the plugin is enabled or not
 final Element state = new Element("state");
 state.setAttribute("version", Integer.toString(STATE_VERSION));
 state.setAttribute("enabled", Boolean.toString(enabled));
 element.addContent(state);
 mark.saveData(element);
 register.saveData(element);
 search.saveData(element);
 history.saveData(element);
 key.saveData(element);
 editor.saveData(element);
 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: rome/rome

protected Element createRootElement(Feed feed) {
  Element root = new Element("feed",getFeedNamespace());
  root.addNamespaceDeclaration(getFeedNamespace());
  //Attribute version = new Attribute("version", getVersion());
  //root.setAttribute(version);
  if (feed.getXmlBase() != null) {
    root.setAttribute("base", feed.getXmlBase(), Namespace.XML_NAMESPACE);
  }
  generateModuleNamespaceDefs(root);
  return root;
}

代码示例来源:origin: hsz/idea-gitignore

/**
 * Creates {@link Element} with a list of the {@link UserTemplate} items.
 *
 * @param userTemplates templates
 * @return {@link Element} instance with user templates
 */
public static Element createTemplatesElement(@NotNull List<UserTemplate> userTemplates) {
  Element templates = new Element(KEY.USER_TEMPLATES.toString());
  for (UserTemplate userTemplate : userTemplates) {
    Element templateElement = new Element(KEY.USER_TEMPLATES_TEMPLATE.toString());
    templateElement.setAttribute(KEY.USER_TEMPLATES_NAME.toString(), userTemplate.getName());
    templateElement.addContent(userTemplate.getContent());
    templates.addContent(templateElement);
  }
  return templates;
}

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

public void saveData(@NotNull Element element) {
 logger.debug("saveData");
 Element search = new Element("search");
 if (lastSearch != null) {
  search.addContent(createElementWithText("last-search", lastSearch));
 }
 if (lastOffset != null) {
  search.addContent(createElementWithText("last-offset", lastOffset));
 }
 if (lastPattern != null) {
  search.addContent(createElementWithText("last-pattern", lastPattern));
 }
 if (lastReplace != null) {
  search.addContent(createElementWithText("last-replace", lastReplace));
 }
 if (lastSubstitute != null) {
  search.addContent(createElementWithText("last-substitute", lastSubstitute));
 }
 Element text = new Element("last-dir");
 text.addContent(Integer.toString(lastDir));
 search.addContent(text);
 text = new Element("show-last");
 text.addContent(Boolean.toString(showSearchHighlight));
 if (logger.isDebugEnabled()) logger.debug("text=" + text);
 search.addContent(text);
 element.addContent(search);
}

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

protected Element createRootElement(Channel channel) {
  Element root = new Element("rss",getFeedNamespace());
  Attribute version = new Attribute("version", getVersion());
  root.setAttribute(version);
  root.addNamespaceDeclaration(getContentNamespace());
  generateModuleNamespaceDefs(root);
  return root;
}

代码示例来源: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: rome/rome

protected Element createRootElement(Feed feed) {
  Element root = new Element("feed",getFeedNamespace());
  root.addNamespaceDeclaration(getFeedNamespace());
  Attribute version = new Attribute("version", getVersion());
  root.setAttribute(version);
  generateModuleNamespaceDefs(root);
  return root;
}

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

public void saveData(@NotNull Element element) {
 Element marksElem = new Element("globalmarks");
 for (Mark mark : globalMarks.values()) {
  if (!mark.isClear()) {
   Element markElem = new Element("mark");
   markElem.setAttribute("key", Character.toString(mark.getKey()));
   markElem.setAttribute("line", Integer.toString(mark.getLogicalLine()));
   markElem.setAttribute("column", Integer.toString(mark.getCol()));
   marksElem.addContent(markElem);
   if (logger.isDebugEnabled()) {
    logger.debug("saved mark = " + mark);
 element.addContent(marksElem);
 Element fileMarksElem = new Element("filemarks");
   Element fileMarkElem = new Element("file");
    if (!mark.isClear() && !Character.isUpperCase(mark.getKey()) &&
      SAVE_FILE_MARKS.indexOf(mark.getKey()) >= 0) {
     Element markElem = new Element("mark");
     fileMarkElem.addContent(markElem);
 Element jumpsElem = new Element("jumps");
 for (Jump jump : jumps) {
  if (!jump.isClear()) {
   Element jumpElem = new Element("jump");

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

public String writeStoreList(List<StoreDefinition> stores) {
  Element root = new Element(STORES_ELMT);
  for(StoreDefinition def: stores) {
    if(def.isView())
      root.addContent(viewToElement(def));
    else
      root.addContent(storeToElement(def));
  }
  XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
  return serializer.outputString(root);
}

相关文章

微信公众号

最新文章

更多