Ejemplo n.º 1
0
 void load(DataInput dis) throws IOException {
   tags.clear();
   Tag tag;
   while ((tag = Tag.readNamedTag(dis)).getId() != Tag.TAG_End) {
     tags.put(tag.getName(), tag);
   }
 }
Ejemplo n.º 2
0
  /**
   * 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;
  }
Ejemplo n.º 3
0
 @Override
 public Object getRaw(final String key) {
   final Tag tag = this.findLastTag(key);
   if (tag == null) {
     return null;
   }
   return tag.getValue();
 }
Ejemplo n.º 4
0
 public void print(String prefix, PrintStream out) {
   super.print(prefix, out);
   out.println(prefix + "{");
   String orgPrefix = prefix;
   prefix += "   ";
   for (Tag tag : tags.values()) {
     tag.print(prefix, out);
   }
   out.println(orgPrefix + "}");
 }
Ejemplo n.º 5
0
  @SuppressWarnings("unchecked")
  void load(DataInput dis) throws IOException {
    type = dis.readByte();
    int size = dis.readInt();

    list = new ArrayList<T>();
    for (int i = 0; i < size; i++) {
      Tag tag = Tag.newTag(type, null);
      tag.load(dis);
      list.add((T) tag);
    }
  }
Ejemplo n.º 6
0
 private void updateNextTag() {
   // ensures that nextTag is up to date
   while (nextTag != null) {
     if (nextTag.begin >= index) return;
     nextTag = nextTag.findNextTag();
   }
 }
Ejemplo n.º 7
0
  public void print(String prefix, PrintStream out) {
    super.print(prefix, out);

    out.println(prefix + "{");
    String orgPrefix = prefix;
    prefix += "   ";
    for (int i = 0; i < list.size(); i++) list.get(i).print(prefix, out);
    out.println(orgPrefix + "}");
  }
Ejemplo n.º 8
0
 public static boolean setData(String worldname, Tag data) {
   File datafile = getDataFile(worldname);
   try {
     OutputStream s = new FileOutputStream(datafile);
     data.writeTo(s);
     s.close();
     return true;
   } catch (IOException e) {
     e.printStackTrace();
     return false;
   }
 }
Ejemplo n.º 9
0
 public static Tag getData(String worldname) {
   File f = getDataFile(worldname);
   if (!f.exists()) return null;
   try {
     FileInputStream fis = new FileInputStream(f);
     Tag t = Tag.readFrom(fis);
     fis.close();
     return t;
   } catch (Exception ex) {
     return null;
   }
 }
Ejemplo n.º 10
0
 public static WorldInfo getInfo(String worldname) {
   WorldInfo info = null;
   try {
     Tag t = getData(worldname);
     if (t != null) {
       info = new WorldInfo();
       info.name = t.findTagByName("LevelName").getValue().toString();
       info.seed = (Long) t.findTagByName("RandomSeed").getValue();
       info.size = (Long) t.findTagByName("SizeOnDisk").getValue();
       info.time = (Long) t.findTagByName("Time").getValue();
       info.raining = ((Byte) t.findTagByName("raining").getValue()) != 0;
       info.thundering = ((Byte) t.findTagByName("thundering").getValue()) != 0;
       if (info.size == 0) info.size = getWorldSize(worldname);
     }
   } catch (Exception ex) {
   }
   World w = getWorld(worldname);
   if (w != null) {
     if (info == null) {
       info = new WorldInfo();
       info.size = getWorldSize(worldname);
     }
     info.name = w.getName();
     info.seed = w.getSeed();
     info.time = w.getFullTime();
     info.raining = w.hasStorm();
     info.thundering = w.isThundering();
   }
   return info;
 }
Ejemplo n.º 11
0
  void insertButton(Document document, PrintWriter out) {
    String fileName = "netnow3.gif";
    String imgURLString =
        "http://home.netscape.com/comprod/products/navigator/version_3.0/images/" + fileName;

    writeImageToDisk(document, imgURLString, fileName);

    try {
      // Write the HTML for the button
      Tag anchor = new Tag("A");
      anchor.addAttribute("HREF", "http://www.netscape.com");
      Tag anchorEnd = new Tag("A", false);
      Tag img = new Tag("IMG");
      URL imgURL = new URL(document.getWorkDirectoryURL(), fileName);
      img.addAttribute("SRC", imgURL.toString());
      out.print(anchor);
      out.print(img);
      out.print(anchorEnd);
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
Ejemplo n.º 12
0
 private void writeTag(final Tag tag, final int depth, final int end) throws IOException {
   // sets index to last position written, guaranteed < end
   // assert index==tag.begin
   // assert index < end
   nextTag = tag.findNextTag();
   final int tagEnd = (tag.end < end) ? tag.end : end;
   // assert index < tagEnd
   if (tag.getTagType() == StartTagType.COMMENT
       || tag.getTagType() == StartTagType.CDATA_SECTION
       || tag.getTagType().isServerTag()) {
     writeTextPreserveIndentation(tagEnd, depth);
   } else if (tidyTags) {
     final String tidyTag = tag.tidy();
     if ((tag instanceof StartTag) && ((StartTag) tag).getAttributes() != null)
       writer.write(tidyTag);
     else writeSpecifiedTextInline(tidyTag, depth);
     index = tagEnd;
   } else {
     writeTextInline(
         tagEnd, depth,
         true); // Write tag keeping linefeeds. This will add an indent to any attribute values
     // containing linefeeds, but the normal situation where line breaks are between
     // attributes will look nice.
   }
   if (end <= tag.end || !(tag instanceof StartTag)) return;
   if ((tag.name == HTMLElementName.SCRIPT && !indentScriptElements)
       || tag.getTagType().isServerTag()) {
     // NOTE SERVER ELEMENTS CONTAINING NON-INLINE TAGS WILL NOT FORMAT PROPERLY. NEED TO
     // INVESTIGATE INCLUDING SUCH SERVER ELEMENTS IN DOCUMENT HIERARCHY.
     // this is a script or server start tag, we may need to write the whole element:
     final Element element = tag.getElement();
     final EndTag endTag = element.getEndTag();
     if (endTag == null) return;
     final int contentEnd = (end < endTag.begin) ? end : endTag.begin;
     boolean singleLineContent = true;
     if (index != contentEnd) {
       // elementContainsMarkup should be made into a TagType property one day.
       // for the time being assume all server element content is code, although this is not true
       // for some Mason elements.
       final boolean elementContainsMarkup = false;
       if (elementContainsMarkup) {
         singleLineContent = writeTextInline(contentEnd, depth + 1, false);
       } else {
         singleLineContent = writeTextPreserveIndentation(contentEnd, depth);
       }
     }
     if (endTag.begin >= end) return;
     if (!singleLineContent) {
       writeEssentialNewLine(); // some server or client side scripting languages might need the
       // final new line
       writeIndent(depth);
     }
     // assert index==endTag.begin
     writeTag(endTag, depth, end);
   }
 }
Ejemplo n.º 13
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);
 }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
0
 public void put(String name, Tag tag) {
   tags.put(name, tag.setName(name));
 }
Ejemplo n.º 16
0
 public String toString() {
   return "" + list.size() + " entries of type " + Tag.getTagName(type);
 }
 public boolean tagMatch(Tag tag) {
   return TAG.equals(tag);
 }
Ejemplo n.º 18
0
  public void printTo(SootClass cl, PrintWriter out) {
    // add jimple line number tags
    setJimpleLnNum(1);

    // Print class name + modifiers
    {
      StringTokenizer st = new StringTokenizer(Modifier.toString(cl.getModifiers()));
      while (st.hasMoreTokens()) {
        String tok = (String) st.nextToken();
        if (cl.isInterface() && tok.equals("abstract")) continue;
        out.print(tok + " ");
      }

      String classPrefix = "";

      if (!cl.isInterface()) {
        classPrefix = classPrefix + " class";
        classPrefix = classPrefix.trim();
      }

      out.print(classPrefix + " " + Scene.v().quotedNameOf(cl.getName()) + "");
    }

    // Print extension
    {
      if (cl.hasSuperclass())
        out.print(" extends " + Scene.v().quotedNameOf(cl.getSuperclass().getName()) + "");
    }

    // Print interfaces
    {
      Iterator interfaceIt = cl.getInterfaces().iterator();

      if (interfaceIt.hasNext()) {
        out.print(" implements ");

        out.print("" + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + "");

        while (interfaceIt.hasNext()) {
          out.print(",");
          out.print(" " + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + "");
        }
      }
    }

    out.println();
    incJimpleLnNum();
    /*        if (!addJimpleLn()) {
        Iterator clTagsIt = cl.getTags().iterator();
        while (clTagsIt.hasNext()) {
            final Tag t = (Tag)clTagsIt.next();
            out.println(t);
        }
    }*/
    out.println("{");
    incJimpleLnNum();
    if (Options.v().print_tags_in_output()) {
      Iterator cTagIterator = cl.getTags().iterator();
      while (cTagIterator.hasNext()) {
        Tag t = (Tag) cTagIterator.next();
        out.print("/*");
        out.print(t.toString());
        out.println("*/");
      }
    }

    // Print fields
    {
      Iterator fieldIt = cl.getFields().iterator();

      if (fieldIt.hasNext()) {
        while (fieldIt.hasNext()) {
          SootField f = (SootField) fieldIt.next();

          if (f.isPhantom()) continue;

          if (Options.v().print_tags_in_output()) {
            Iterator fTagIterator = f.getTags().iterator();
            while (fTagIterator.hasNext()) {
              Tag t = (Tag) fTagIterator.next();
              out.print("/*");
              out.print(t.toString());
              out.println("*/");
            }
          }
          out.println("    " + f.getDeclaration() + ";");
          if (addJimpleLn()) {
            setJimpleLnNum(addJimpleLnTags(getJimpleLnNum(), f));
          }

          // incJimpleLnNum();
        }
      }
    }

    // Print methods
    {
      Iterator methodIt = cl.methodIterator();

      if (methodIt.hasNext()) {
        if (cl.getMethodCount() != 0) {
          out.println();
          incJimpleLnNum();
        }

        while (methodIt.hasNext()) {
          SootMethod method = (SootMethod) methodIt.next();

          if (method.isPhantom()) continue;

          if (!Modifier.isAbstract(method.getModifiers())
              && !Modifier.isNative(method.getModifiers())) {
            if (!method.hasActiveBody())
              throw new RuntimeException("method " + method.getName() + " has no active body!");
            else if (Options.v().print_tags_in_output()) {
              Iterator mTagIterator = method.getTags().iterator();
              while (mTagIterator.hasNext()) {
                Tag t = (Tag) mTagIterator.next();
                out.print("/*");
                out.print(t.toString());
                out.println("*/");
              }
            }
            printTo(method.getActiveBody(), out);

            if (methodIt.hasNext()) {
              out.println();
              incJimpleLnNum();
            }
          } else {

            if (Options.v().print_tags_in_output()) {
              Iterator mTagIterator = method.getTags().iterator();
              while (mTagIterator.hasNext()) {
                Tag t = (Tag) mTagIterator.next();
                out.print("/*");
                out.print(t.toString());
                out.println("*/");
              }
            }

            out.print("    ");
            out.print(method.getDeclaration());
            out.println(";");
            incJimpleLnNum();
            if (methodIt.hasNext()) {
              out.println();
              incJimpleLnNum();
            }
          }
        }
      }
    }
    out.println("}");
    incJimpleLnNum();
  }
Ejemplo n.º 19
0
  /** Prints the given <code>JimpleBody</code> to the specified <code>PrintWriter</code>. */
  private void printStatementsInBody(
      Body body, java.io.PrintWriter out, LabeledUnitPrinter up, UnitGraph unitGraph) {
    Chain units = body.getUnits();
    Iterator unitIt = units.iterator();
    Unit currentStmt = null, previousStmt;

    while (unitIt.hasNext()) {

      previousStmt = currentStmt;
      currentStmt = (Unit) unitIt.next();

      // Print appropriate header.
      {
        // Put an empty line if the previous node was a branch node, the current node is a join node
        //   or the previous statement does not have body statement as a successor, or if
        //   body statement has a label on it

        if (currentStmt != units.getFirst()) {
          if (unitGraph.getSuccsOf(previousStmt).size() != 1
              || unitGraph.getPredsOf(currentStmt).size() != 1
              || up.labels().containsKey(currentStmt)) {
            up.newline();
          } else {
            // Or if the previous node does not have body statement as a successor.

            List succs = unitGraph.getSuccsOf(previousStmt);

            if (succs.get(0) != currentStmt) {
              up.newline();
            }
          }
        }

        if (up.labels().containsKey(currentStmt)) {
          up.unitRef(currentStmt, true);
          up.literal(":");
          up.newline();
        }

        if (up.references().containsKey(currentStmt)) {
          up.unitRef(currentStmt, false);
        }
      }

      up.startUnit(currentStmt);
      currentStmt.toString(up);
      up.endUnit(currentStmt);

      up.literal(";");
      up.newline();

      // only print them if not generating attributes files
      // because they mess up line number
      // if (!addJimpleLn()) {
      if (Options.v().print_tags_in_output()) {
        Iterator tagIterator = currentStmt.getTags().iterator();
        while (tagIterator.hasNext()) {
          Tag t = (Tag) tagIterator.next();
          up.noIndent();
          up.literal("/*");
          up.literal(t.toString());
          up.literal("*/");
          up.newline();
        }
        /*Iterator udIt = currentStmt.getUseAndDefBoxes().iterator();
        while (udIt.hasNext()) {
            ValueBox temp = (ValueBox)udIt.next();
            Iterator vbtags = temp.getTags().iterator();
            while (vbtags.hasNext()) {
                Tag t = (Tag) vbtags.next();
                up.noIndent();
                up.literal("VB Tag: "+t.toString());
                up.newline();
            }
        }*/
      }
    }

    out.print(up.toString());
    if (addJimpleLn()) {
      setJimpleLnNum(up.getPositionTagger().getEndLn());
    }

    // Print out exceptions
    {
      Iterator trapIt = body.getTraps().iterator();

      if (trapIt.hasNext()) {
        out.println();
        incJimpleLnNum();
      }

      while (trapIt.hasNext()) {
        Trap trap = (Trap) trapIt.next();

        out.println(
            "        catch "
                + Scene.v().quotedNameOf(trap.getException().getName())
                + " from "
                + up.labels().get(trap.getBeginUnit())
                + " to "
                + up.labels().get(trap.getEndUnit())
                + " with "
                + up.labels().get(trap.getHandlerUnit())
                + ";");

        incJimpleLnNum();
      }
    }
  }
Ejemplo n.º 20
0
 void write(DataOutput dos) throws IOException {
   for (Tag tag : tags.values()) {
     Tag.writeNamedTag(tag, dos);
   }
   dos.writeByte(Tag.TAG_End);
 }