/**
   * Perform the action of the plugin.
   *
   * @param document the current document.
   */
  public boolean perform(Document document) throws IOException {
    // Interact with the user to get the layer tag/

    Tag layerTag = getLayerTagFromUser(document);
    if (layerTag == null) return false; // User cancled.
    Tag endTag = new Tag(layerTag.getName(), false);
    // Get the output stream to hold the new document text.
    PrintWriter out = new PrintWriter(document.getOutput());
    // Create a lexical stream to tokenize the old document text.
    LexicalStream in = new LexicalStream(new SelectedHTMLReader(document.getInput(), out));
    for (; ; ) {
      // Get the next token of the document.
      Token token = in.next();
      if (token == null) break; //  Null means we've finished the document.
      else if (token instanceof Comment) {
        Comment comment = (Comment) token;
        if (comment.isSelectionStart()) {
          out.print(layerTag);
        } else if (comment.isSelectionEnd()) {
          out.print(comment);
          out.print(endTag);
          continue; // So comment isn't printed twice.
        }
      }
      out.print(token);
    }
    out.close();
    return true;
  }
 void load(DataInput dis) throws IOException {
   tags.clear();
   Tag tag;
   while ((tag = Tag.readNamedTag(dis)).getId() != Tag.TAG_End) {
     tags.put(tag.getName(), tag);
   }
 }
Example #3
0
 private void putTag(final String key, final Tag tag) {
   final String[] parts =
       (String[])
           Iterables.toArray(
               Splitter.on('.').split((CharSequence) this.createRelativeKey(key)),
               (Class) String.class);
   Map<String, Tag> parent = NBTStorage.this.root;
   for (int i = 0; i < parts.length - 1; ++i) {
     if (!parent.containsKey(parts[i]) || !(parent.get(parts[i]) instanceof CompoundTag)) {
       parent.put(parts[i], new CompoundTag(parts[i]));
     }
     parent = parent.get(parts[i]).getValue();
   }
   parent.put(tag.getName(), tag);
 }
Example #4
0
 private static boolean renameWorld(String worldname, String newname) {
   if (isLoaded(worldname)) return false;
   Tag t = getData(worldname);
   if (t == null) return false;
   t = t.findTagByName("Data");
   if (t == null || t.getType() != Type.TAG_Compound) return false;
   int i = 0;
   for (Tag tt : (Tag[]) t.getValue()) {
     if (tt.getName().equals("LevelName")) {
       t.removeTag(i);
       t.insertTag(new Tag(Type.TAG_String, "LevelName", newname), i);
       break;
     }
     i++;
   }
   return setData(worldname, t);
 }