Exemple #1
0
 protected String[] escapePaths(String srcPath, String dstPath) {
   srcPath = srcPath.trim();
   dstPath = dstPath.trim();
   String os = System.getProperty("os.name").toLowerCase();
   if (os != null && os.indexOf("windows") > -1) {
     srcPath = "\"" + srcPath + "\"";
     dstPath = "\"" + dstPath + "\"";
   } else {
     int lastidx = -1, curridx;
     StringBuffer buff = new StringBuffer(srcPath);
     while ((curridx = buff.indexOf(" ", lastidx)) > 0) {
       buff.insert(curridx, "\\");
       lastidx = curridx + 2;
     }
     srcPath = buff.toString();
     buff = new StringBuffer(dstPath);
     lastidx = -1;
     while ((curridx = buff.indexOf(" ", lastidx)) > 0) {
       buff.insert(curridx, "\\");
       lastidx = curridx + 2;
     }
     dstPath = buff.toString();
   }
   return new String[] {srcPath, dstPath};
 }
  private int printThreadGroup(OutputSink out, ThreadGroupReference tg, int iThread) {
    out.println("Group " + tg.name() + ":");
    List<ThreadReference> tlist = tg.threads();
    int maxId = 0;
    int maxName = 0;
    for (int i = 0; i < tlist.size(); i++) {
      ThreadReference thr = tlist.get(i);
      int len = Utils.description(thr).length();
      if (len > maxId) {
        maxId = len;
      }
      String name = thr.name();
      int iDot = name.lastIndexOf('.');
      if (iDot >= 0 && name.length() > iDot) {
        name = name.substring(iDot + 1);
      }
      if (name.length() > maxName) {
        maxName = name.length();
      }
    }
    String maxNumString = String.valueOf(iThread + tlist.size());
    int maxNumDigits = maxNumString.length();
    for (int i = 0; i < tlist.size(); i++) {
      ThreadReference thr = tlist.get(i);
      char buf[] = new char[80];
      for (int j = 0; j < 79; j++) {
        buf[j] = ' ';
      }
      buf[79] = '\0';
      StringBuffer sbOut = new StringBuffer();
      sbOut.append(buf);

      // Right-justify the thread number at start of output string
      String numString = String.valueOf(iThread + i + 1);
      sbOut.insert(maxNumDigits - numString.length(), numString);
      sbOut.insert(maxNumDigits, ".");

      int iBuf = maxNumDigits + 2;
      sbOut.insert(iBuf, Utils.description(thr));
      iBuf += maxId + 1;
      String name = thr.name();
      int iDot = name.lastIndexOf('.');
      if (iDot >= 0 && name.length() > iDot) {
        name = name.substring(iDot + 1);
      }
      sbOut.insert(iBuf, name);
      iBuf += maxName + 1;
      sbOut.insert(iBuf, Utils.getStatus(thr));
      sbOut.setLength(79);
      out.println(sbOut.toString());
    }
    for (ThreadGroupReference tg0 : tg.threadGroups()) {
      if (!tg.equals(tg0)) { // TODO ref mgt
        iThread += printThreadGroup(out, tg0, iThread + tlist.size());
      }
    }
    return tlist.size();
  }
Exemple #3
0
 public static void abcd(String str) {
   BigInteger sum = BigInteger.ZERO;
   StringBuffer n = new StringBuffer("");
   for (int i = 0; i < str.length(); i++) {
     BigInteger ab = BigInteger.valueOf(((int) str.charAt(i)) - 96);
     sum = sum.add(div.pow(str.length() - i - 1).multiply(ab));
   }
   String s = sum.toString();
   for (int i = 0; i < s.length(); i++) {
     if (i % 3 == 0 && i != 0) n.insert(0, ",");
     n.insert(0, s.charAt(s.length() - i - 1));
   }
   while (str.length() < 22) str = str + " ";
   System.out.println(str + "" + n);
 }
  void writeValue(PrintStream os, Hashtable writtenrefs) {
    // no [] around data; use hex digits when shorter

    int num = values.getCount(); // may be incomplete on readerror
    int[] vals = values.getData();
    // String hexdigits = new String ("0123456789ABCDEF");
    String hexdigits = new String("0123456789abcdef");

    int pre = (num < 3) ? num : 3; // preamble

    int i, val;
    for (i = 0; i < pre; i++) os.print(" " + vals[i]);

    for (i = pre; i < num; i++) {
      val = vals[i];
      if (val < 256) os.print(" " + val);
      else {
        // JDK versions prior to 1.0.1 lacked Integer.toHexString
        // os.print (" 0x" + Integer.toHexString (27));
        StringBuffer buf = new StringBuffer(16);
        do {
          buf.insert(0, hexdigits.charAt(val & 15));
          val >>>= 4;
        } while (val != 0);
        os.print(" 0x" + buf.toString());
      }
    }
  } // writeValue
Exemple #5
0
  /*
   *  Replaces a template string throughout the entire file
   */
  public boolean replaceValue(String templateString, String newValue) {
    boolean retVal = false;
    if (templateString != null
        && templateString.length() > 0
        && newValue != null
        && newValue.length() > 0) {

      StringBuffer workTemplateString = new StringBuffer(templateString);

      if (!templateString.startsWith("[[") && !templateString.endsWith("]]")) {
        workTemplateString.insert(0, "[[");
        workTemplateString.append("]]");
      }

      boolean done = false;
      while (!done) {
        if (m_css.indexOf(workTemplateString.toString()) >= 0) {
          m_css.replace(
              m_css.indexOf(workTemplateString.toString()),
              m_css.indexOf(workTemplateString.toString()) + workTemplateString.length(),
              newValue);
          retVal = true;
        } else {
          done = true;
        }
      }
    }
    return retVal;
  }
Exemple #6
0
 public static void num(String str) {
   BigInteger a = new BigInteger(str);
   StringBuffer sb = new StringBuffer("");
   StringBuffer n = new StringBuffer("");
   while (!(a.divide(div).equals(zero))) {
     sb.insert(0, (char) (a.mod(div).intValue() + 96));
     a = a.divide(div);
   }
   sb.insert(0, (char) (a.intValue() + 96));
   for (int i = 0; i < str.length(); i++) {
     if (i % 3 == 0 && i != 0) n.insert(0, ",");
     n.insert(0, str.charAt(str.length() - i - 1));
   }
   while (sb.length() < 22) sb.append(" ");
   System.out.println(sb + "" + n);
 }
  public static void LCS(String str, String str2) {
    int len = str.length();
    int len2 = str2.length();
    int[][] storage = new int[len + 1][len2 + 1];
    for (int i = 0; i <= len; i++) {
      for (int j = 0; j <= len2; j++) {
        if (i == 0 || j == 0) {
          storage[i][j] = 0;
        } else if (str.charAt(i - 1) == str2.charAt(j - 1)) {
          storage[i][j] = 1 + storage[i - 1][j - 1];
        } else {
          storage[i][j] = Math.max(storage[i - 1][j], storage[i][j - 1]);
        }
      }
    }

    int i = len;
    int j = len2;
    StringBuffer sb = new StringBuffer();
    while (storage[i][j] > 0) {
      if (str.charAt(i - 1) == str2.charAt(j - 1)) {
        sb.insert(0, str.charAt(i - 1));
        i--;
        j--;
      } else if (storage[i - 1][j] > storage[i][j - 1]) {
        i--;
      } else {
        j--;
      }
    }
    System.out.println(sb.toString());
  }
Exemple #8
0
 public static void main(String[] args) throws Exception {
   PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("decoder_bench.cmd")));
   writer.println("stepsize 2ns");
   writer.println("vector a a[5] a[4] a[3] a[2] a[1] a[0]");
   writer.println(
       "vector y y[63] y[62] y[61] y[60] y[59] y[58] y[57] y[56] y[55] y[54] y[53] y[52] y[51] y[50] y[49] y[48] y[47] y[46] y[45] y[44] y[43] y[42] y[41] y[40] y[39] y[38] y[37] y[36] y[35] y[34] y[33] y[32] y[31] y[30] y[29] y[28] y[27] y[26] y[25] y[24] y[23] y[22] y[21] y[20] y[19] y[18] y[17] y[16] y[15] y[14] y[13] y[12] y[11] y[10] y[9] y[8] y[7] y[6] y[5] y[4] y[3] y[2] y[1] y[0]");
   writer.println();
   final int aSize = 6;
   final int ySize = 64;
   StringBuffer a;
   StringBuffer y;
   int tally;
   int phN;
   char ph1;
   for (int i = 0; i < ySize; i++) {
     a = new StringBuffer();
     y = new StringBuffer();
     tally = i;
     for (int j = 0; j < aSize; j++) {
       if (tally % 2 == 0) {
         a.insert(0, 'l');
       } else {
         a.insert(0, 'h');
       }
       tally = (tally - (tally % 2)) / 2;
     }
     for (int j = 0; j < ySize - 1; j++) {
       y.append(0);
     }
     phN = (int) Math.floor(2 * Math.random());
     if (phN == 1) {
       ph1 = 'h';
       y.insert(63 - i, 1);
     } else {
       ph1 = 'l';
       y.insert(63 - i, 0);
     }
     writer.println("print iteration " + i + " ph1 set to " + ph1);
     writer.println("set a " + a);
     writer.println(ph1 + " ph1");
     writer.println("s 50");
     writer.println("assert y " + y);
     writer.println();
   }
   writer.close();
 }
Exemple #9
0
 /**
  * This method inserts a selector into the CSS file.
  *
  * @param newValue
  * @return
  */
 public boolean insertSelector(String newValue) {
   boolean retVal = false;
   // always insert at the end.
   int beginPos = m_css.indexOf("</style>");
   m_css.insert(beginPos, newValue + "\n");
   retVal = true;
   return retVal;
 }
Exemple #10
0
  /**
   * Append XML content into root element
   *
   * @param hrefValue href of the topicref
   * @param parentResult XML content to insert into
   * @param tmpContent XML content to insert
   */
  private void insertAfter(String hrefValue, StringBuffer parentResult, CharSequence tmpContent) {
    int insertpoint = parentResult.lastIndexOf("</");
    final int end = parentResult.indexOf(">", insertpoint);

    if (insertpoint == -1 || end == -1) {
      logger.error(MessageUtils.getInstance().getMessage("DOTJ033E", hrefValue).toString());
    } else {
      if (ELEMENT_NAME_DITA.equals(parentResult.substring(insertpoint, end).trim())) {
        insertpoint = parentResult.lastIndexOf("</", insertpoint - 1);
      }
      parentResult.insert(insertpoint, tmpContent);
    }
  }
  private static void offsetAndLimitOracleQuery(
      StringBuffer query, List<Serializable> params, int offset, int limit) {
    // prepare the LIMIT clause
    if (limit > 0 || offset > 0) {
      query.insert(0, "SELECT /*+ FIRST_ROWS(n) */ rec.*, ROWNUM rnum  FROM (");
      query.append(") ");
    }

    if (limit > 0) {
      query.append("rec WHERE rownum<=? ");
      if (offset > 0) {
        params.add(Integer.valueOf(limit + offset));
      } else {
        params.add(Integer.valueOf(limit));
      }
    }

    if (offset > 0) {
      query.insert(0, "SELECT * FROM (");
      query.append(") WHERE rnum>?");
      params.add(Integer.valueOf(offset));
    }
  }
Exemple #12
0
 /**
  * Converts a dir string to a linked dir string
  *
  * @param dir the directory string (e.g. /usr/local/httpd)
  * @param browserLink web-path to Browser.jsp
  */
 public static String dir2linkdir(String dir, String browserLink, int sortMode) {
   File f = new File(dir);
   StringBuffer buf = new StringBuffer();
   while (f.getParentFile() != null) {
     if (f.canRead()) {
       String encPath = URLEncoder.encode(f.getAbsolutePath());
       buf.insert(
           0,
           "<a href=\""
               + browserLink
               + "?sort="
               + sortMode
               + "&amp;dir="
               + encPath
               + "\">"
               + conv2Html(f.getName())
               + File.separator
               + "</a>");
     } else buf.insert(0, conv2Html(f.getName()) + File.separator);
     f = f.getParentFile();
   }
   if (f.canRead()) {
     String encPath = URLEncoder.encode(f.getAbsolutePath());
     buf.insert(
         0,
         "<a href=\""
             + browserLink
             + "?sort="
             + sortMode
             + "&amp;dir="
             + encPath
             + "\">"
             + conv2Html(f.getAbsolutePath())
             + "</a>");
   } else buf.insert(0, f.getAbsolutePath());
   return buf.toString();
 }
 String toBinary(int n) {
   if (n == 0) {
     return ("0");
   }
   StringBuffer binary = new StringBuffer();
   while (n > 0) {
     int rem = n % 2;
     binary = new StringBuffer(rem + binary.toString());
     n = n / 2;
   }
   while (binary.length() < 8) {
     binary.insert(0, "0");
   }
   return binary.toString();
 }
Exemple #14
0
  /**
   * This method inserts a blank character between to consecutive newline characters if encoutered.
   * Also appends a blank character at the beginning of the text, if the first character is a
   * newline character and at the end of the text, if the last character is also a newline. This is
   * useful when trying to layout the paragraphs. Thanks to Teodor Danciu for this this method (c)
   * 2003 Teodor Danciu
   */
  public static String treatNewLineChars(String source) {
    String result = source;

    if (source != null && source.length() > 0) {
      StringBuffer sbuffer = new StringBuffer(source);

      // insert a blank character between every two consecutives
      // newline characters
      int offset = source.length() - 1;
      int pos = source.lastIndexOf("\n\n", offset);
      while (pos >= 0 && offset > 0) {
        sbuffer = sbuffer.insert(pos + 1, " ");
        offset = pos - 1;
        pos = source.lastIndexOf("\n\n", offset);
      }

      // append a blank character at the and of the text
      // if the last character is a newline character
      if (sbuffer.charAt(sbuffer.length() - 1) == '\n') {
        sbuffer.append(' ');
      }

      // append a blank character at the begining of the text
      // if the first character is a newline character
      if (sbuffer.charAt(0) == '\n') {
        sbuffer.insert(0, ' ');
      }

      result = sbuffer.toString();
    }

    // remove this if you want to treat the tab characters in a special way
    result = replaceTabWithBlank(result);

    return result;
  }
  boolean addToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.insert(x, ch);

      if (vectorLines.size() < y) {
        vectorLines.addElement(currentLine);
      } else {
        // setLine
        vectorLines.setElementAt(currentLine, y);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in addToLine()");
      return false;
    }
  }
Exemple #16
0
  /**
   * This method inserts a value into the selector. It allows you to insert new CSS into the
   * template.
   *
   * @param selectorName Name of CSS selector.
   * @param name Name of CSS item.
   * @param value Value of CSS item.
   */
  public void insertValueIntoSelector(String selectorName, String name, String value) {
    if (selectorName != null && name != null && value != null) {
      if (m_css.indexOf(selectorName) >= 0) {
        boolean done = false;
        int pos = 0;
        while (!done) {
          int beginPos = m_css.indexOf(selectorName, pos);

          if (beginPos >= 0) {
            int endPos = m_css.indexOf("{", beginPos);

            if (endPos >= 0) {
              String workSelectorName = m_css.substring(beginPos, endPos).trim();

              if (workSelectorName.equals(selectorName)) {
                int workEndPos = m_css.indexOf("}", endPos);
                m_css.insert(workEndPos - 1, "\n" + name + ":" + value + ";\n");
                done = true;
              }

              pos = endPos;
              if (pos >= m_css.length()) {
                done = true;
              }
            } else {
              done = true;
            }
          } else {
            done = true;
          }
        }
      } else {
        logger.error(
            "Error processing CSS in insertValueIntoSelector: selectorName:" + selectorName);
      }
    }
  }
  /**
   * Run from the command-line, with a list of URLs as argument.
   *
   * <p><B>NOTE:</B><br>
   * This code will run with all the documents in memory - if you want to unload each from memory
   * after use, add code to store the corpus in a DataStore.
   */
  public static void main(String args[]) throws GateException, IOException {
    // initialise the GATE library
    Out.prln("Initialising GATE...");
    Gate.init();
    Out.prln("...GATE initialised");

    // initialise ANNIE (this may take several minutes)
    StandAloneAnnie annie = new StandAloneAnnie();
    annie.initAnnie();

    // create a GATE corpus and add a document for each command-line
    // argument
    Corpus corpus = Factory.newCorpus("StandAloneAnnie corpus");
    for (int i = 0; i < args.length; i++) {
      URL u = new URL(args[i]);
      FeatureMap params = Factory.newFeatureMap();
      params.put("sourceUrl", u);
      params.put("preserveOriginalContent", new Boolean(true));
      params.put("collectRepositioningInfo", new Boolean(true));
      Out.prln("Creating doc for " + u);
      Document doc = (Document) Factory.createResource("gate.corpora.DocumentImpl", params);
      corpus.add(doc);
    } // for each of args

    // tell the pipeline about the corpus and run it
    annie.setCorpus(corpus);
    annie.execute();

    // for each document, get an XML document with the
    // person and location names added
    Iterator iter = corpus.iterator();
    int count = 0;
    String startTagPart_1 = "<span GateID=\"";
    String startTagPart_2 = "\" title=\"";
    String startTagPart_3 = "\" style=\"background:Red;\">";
    String endTag = "</span>";

    while (iter.hasNext()) {
      Document doc = (Document) iter.next();
      AnnotationSet defaultAnnotSet = doc.getAnnotations();
      Set annotTypesRequired = new HashSet();
      annotTypesRequired.add("Person");
      annotTypesRequired.add("Location");
      Set<Annotation> peopleAndPlaces =
          new HashSet<Annotation>(defaultAnnotSet.get(annotTypesRequired));

      FeatureMap features = doc.getFeatures();
      String originalContent =
          (String) features.get(GateConstants.ORIGINAL_DOCUMENT_CONTENT_FEATURE_NAME);
      RepositioningInfo info =
          (RepositioningInfo) features.get(GateConstants.DOCUMENT_REPOSITIONING_INFO_FEATURE_NAME);

      ++count;
      File file = new File("StANNIE_" + count + ".HTML");
      Out.prln("File name: '" + file.getAbsolutePath() + "'");
      if (originalContent != null && info != null) {
        Out.prln("OrigContent and reposInfo existing. Generate file...");

        Iterator it = peopleAndPlaces.iterator();
        Annotation currAnnot;
        SortedAnnotationList sortedAnnotations = new SortedAnnotationList();

        while (it.hasNext()) {
          currAnnot = (Annotation) it.next();
          sortedAnnotations.addSortedExclusive(currAnnot);
        } // while

        StringBuffer editableContent = new StringBuffer(originalContent);
        long insertPositionEnd;
        long insertPositionStart;
        // insert anotation tags backward
        Out.prln("Unsorted annotations count: " + peopleAndPlaces.size());
        Out.prln("Sorted annotations count: " + sortedAnnotations.size());
        for (int i = sortedAnnotations.size() - 1; i >= 0; --i) {
          currAnnot = (Annotation) sortedAnnotations.get(i);
          insertPositionStart = currAnnot.getStartNode().getOffset().longValue();
          insertPositionStart = info.getOriginalPos(insertPositionStart);
          insertPositionEnd = currAnnot.getEndNode().getOffset().longValue();
          insertPositionEnd = info.getOriginalPos(insertPositionEnd, true);
          if (insertPositionEnd != -1 && insertPositionStart != -1) {
            editableContent.insert((int) insertPositionEnd, endTag);
            editableContent.insert((int) insertPositionStart, startTagPart_3);
            editableContent.insert((int) insertPositionStart, currAnnot.getType());
            editableContent.insert((int) insertPositionStart, startTagPart_2);
            editableContent.insert((int) insertPositionStart, currAnnot.getId().toString());
            editableContent.insert((int) insertPositionStart, startTagPart_1);
          } // if
        } // for

        FileWriter writer = new FileWriter(file);
        writer.write(editableContent.toString());
        writer.close();
      } // if - should generate
      else if (originalContent != null) {
        Out.prln("OrigContent existing. Generate file...");

        Iterator it = peopleAndPlaces.iterator();
        Annotation currAnnot;
        SortedAnnotationList sortedAnnotations = new SortedAnnotationList();

        while (it.hasNext()) {
          currAnnot = (Annotation) it.next();
          sortedAnnotations.addSortedExclusive(currAnnot);
        } // while

        StringBuffer editableContent = new StringBuffer(originalContent);
        long insertPositionEnd;
        long insertPositionStart;
        // insert anotation tags backward
        Out.prln("Unsorted annotations count: " + peopleAndPlaces.size());
        Out.prln("Sorted annotations count: " + sortedAnnotations.size());
        for (int i = sortedAnnotations.size() - 1; i >= 0; --i) {
          currAnnot = (Annotation) sortedAnnotations.get(i);
          insertPositionStart = currAnnot.getStartNode().getOffset().longValue();
          insertPositionEnd = currAnnot.getEndNode().getOffset().longValue();
          if (insertPositionEnd != -1 && insertPositionStart != -1) {
            editableContent.insert((int) insertPositionEnd, endTag);
            editableContent.insert((int) insertPositionStart, startTagPart_3);
            editableContent.insert((int) insertPositionStart, currAnnot.getType());
            editableContent.insert((int) insertPositionStart, startTagPart_2);
            editableContent.insert((int) insertPositionStart, currAnnot.getId().toString());
            editableContent.insert((int) insertPositionStart, startTagPart_1);
          } // if
        } // for

        FileWriter writer = new FileWriter(file);
        writer.write(editableContent.toString());
        writer.close();
      } else {
        Out.prln("Content : " + originalContent);
        Out.prln("Repositioning: " + info);
      }

      String xmlDocument = doc.toXml(peopleAndPlaces, false);
      String fileName = new String("StANNIE_toXML_" + count + ".HTML");
      FileWriter writer = new FileWriter(fileName);
      writer.write(xmlDocument);
      writer.close();
    } // for each doc
  } // main
  @Nullable
  static String filterBadPlugins(
      List<? extends IdeaPluginDescriptor> result, final Map<String, String> disabledPluginNames) {
    final Map<PluginId, IdeaPluginDescriptor> idToDescriptorMap =
        new HashMap<PluginId, IdeaPluginDescriptor>();
    final StringBuffer message = new StringBuffer();
    boolean pluginsWithoutIdFound = false;
    for (Iterator<? extends IdeaPluginDescriptor> it = result.iterator(); it.hasNext(); ) {
      final IdeaPluginDescriptor descriptor = it.next();
      final PluginId id = descriptor.getPluginId();
      if (id == null) {
        pluginsWithoutIdFound = true;
      }
      if (idToDescriptorMap.containsKey(id)) {
        message.append("<br>");
        message.append(IdeBundle.message("message.duplicate.plugin.id"));
        message.append(id);
        it.remove();
      } else if (descriptor.isEnabled()) {
        idToDescriptorMap.put(id, descriptor);
      }
    }
    addModulesAsDependents(idToDescriptorMap);
    final List<String> disabledPluginIds = new ArrayList<String>();
    final LinkedHashSet<String> faultyDescriptors = new LinkedHashSet<String>();
    for (final Iterator<? extends IdeaPluginDescriptor> it = result.iterator(); it.hasNext(); ) {
      final IdeaPluginDescriptor pluginDescriptor = it.next();
      checkDependants(
          pluginDescriptor,
          new Function<PluginId, IdeaPluginDescriptor>() {
            @Override
            public IdeaPluginDescriptor fun(final PluginId pluginId) {
              return idToDescriptorMap.get(pluginId);
            }
          },
          new Condition<PluginId>() {
            @Override
            public boolean value(final PluginId pluginId) {
              if (!idToDescriptorMap.containsKey(pluginId)) {
                pluginDescriptor.setEnabled(false);
                if (!pluginId.getIdString().startsWith(MODULE_DEPENDENCY_PREFIX)) {
                  faultyDescriptors.add(pluginId.getIdString());
                  disabledPluginIds.add(pluginDescriptor.getPluginId().getIdString());
                  message.append("<br>");
                  final String name = pluginDescriptor.getName();
                  final IdeaPluginDescriptor descriptor = idToDescriptorMap.get(pluginId);
                  String pluginName;
                  if (descriptor == null) {
                    pluginName = pluginId.getIdString();
                    if (disabledPluginNames.containsKey(pluginName)) {
                      pluginName = disabledPluginNames.get(pluginName);
                    }
                  } else {
                    pluginName = descriptor.getName();
                  }

                  message.append(
                      getDisabledPlugins().contains(pluginId.getIdString())
                          ? IdeBundle.message("error.required.plugin.disabled", name, pluginName)
                          : IdeBundle.message(
                              "error.required.plugin.not.installed", name, pluginName));
                }
                it.remove();
                return false;
              }
              return true;
            }
          });
    }
    if (!disabledPluginIds.isEmpty()) {
      myPlugins2Disable = disabledPluginIds;
      myPlugins2Enable = faultyDescriptors;
      message.append("<br>");
      message.append("<br>").append("<a href=\"" + DISABLE + "\">Disable ");
      if (disabledPluginIds.size() == 1) {
        final PluginId pluginId2Disable = PluginId.getId(disabledPluginIds.iterator().next());
        message.append(
            idToDescriptorMap.containsKey(pluginId2Disable)
                ? idToDescriptorMap.get(pluginId2Disable).getName()
                : pluginId2Disable.getIdString());
      } else {
        message.append("not loaded plugins");
      }
      message.append("</a>");
      boolean possibleToEnable = true;
      for (String descriptor : faultyDescriptors) {
        if (disabledPluginNames.get(descriptor) == null) {
          possibleToEnable = false;
          break;
        }
      }
      if (possibleToEnable) {
        message
            .append("<br>")
            .append("<a href=\"" + ENABLE + "\">Enable ")
            .append(
                faultyDescriptors.size() == 1
                    ? disabledPluginNames.get(faultyDescriptors.iterator().next())
                    : " all necessary plugins")
            .append("</a>");
      }
      message.append("<br>").append("<a href=\"" + EDIT + "\">Open plugin manager</a>");
    }
    if (pluginsWithoutIdFound) {
      message.append("<br>");
      message.append(IdeBundle.message("error.plugins.without.id.found"));
    }
    if (message.length() > 0) {
      message.insert(0, IdeBundle.message("error.problems.found.loading.plugins"));
      return message.toString();
    }
    return null;
  }
  /**
   * agINFRA Social visualization components aux. tool
   *
   * @param args
   * @throws FileNotFoundException
   */
  public static void main(String[] args) throws FileNotFoundException {

    System.out.println("Hello");

    // PARAMS
    if (args.length != 5) {
      System.out.println(
          "Proper Arguments are: [Dataset files full path] [URL store] [URI graph base] [Destination directory] [commit to 4store]");
      System.out.println(
          "Example: java -jar xxxxx.jar /home/carlos/Desktop/agINFRA-workflow/workflow/loms/bioe/ http://localhost:81 http://laclo.laflor /home/carlos/Desktop/agINFRA-workflow/workflow/loms/bioerdf/ false");
      System.exit(0);
    }

    String dspath = args[0];
    String urlStore = args[1];
    String uriGraph = args[2];
    String destination = args[3];
    String commit4store_arg = args[4];

    /*String dspath = "/home/carlos/workspace/WebAPI/ds/";
    String urlStore = "http://4store.ipb.ac.rs:81";
    String uriGraph = "http://aginfra.eu";
    String localCouchdbProxy = "localhost";
    String commit4store_arg = "no";*/

    boolean commit4store = false;
    if (commit4store_arg.equals("commit")) commit4store = true;

    String output = "0"; // valor de retorno
    String status = "ERROR";
    String errorDescription = "";
    String tmpMetadataFile = "";
    // check if type is valid
    boolean bContinuar = true;
    // StorageService service;
    ArrayList<KeyValue> keyValues = new ArrayList<KeyValue>();
    HashMap fileDatasetMap = new HashMap();

    /*
    //Fetch and download IPB metadata sets.
    //CouchDB via PHP local proxy
    //http://agro.ipb.ac.rs/agcouchdb/_design/datasets/_view/list?limit=10
    //http://localhost/ag_couch_proxy/proxy-IPB-datasets.php
    try{
    	System.out.println("Connecting IPB CouchDB...");

    	String url = "http://"+localCouchdbProxy+"/ag_couch_proxy/proxy-IPB-datasets.php?dspath="+dspath;
    	WebResource webResource = Client.create().resource(url);
    	//System.out.println(url);
    	ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON,MediaType.TEXT_HTML,MediaType.WILDCARD).get(ClientResponse.class);
    	if (response.getStatus() != 200) {
    	   throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    	}


    	//String response_str = response.getEntity(String.class);	//I don't know why this does not work when running in shell
    	String response_str = getStringFromInputStream(response.getEntityInputStream());
    	//System.out.println(response_str);	//debug

    	System.out.println("Finished IPB call");



    	System.out.println("Reading Dataset Map...");

    	//READ CSV
    	//create BufferedReader to read csv file
              StringTokenizer st = null;
              int lineNumber = 0, tokenNumber = 0;

              //read comma separated file line by line
              Scanner scanner = new Scanner(response_str);
              while (scanner.hasNextLine())
              {
                      lineNumber++;
                      String strLine = scanner.nextLine();

                      //break comma separated line using ","
                      st = new StringTokenizer(strLine, ",");

                      String datasetFile = "";
                      String datasetName = "";

                      while(st.hasMoreTokens())
                      {
                              //display csv values
                              tokenNumber++;
                              //System.out.println("Line # " + lineNumber +", Token # " + tokenNumber + ", Token : "+ st.nextToken());
                              if(tokenNumber == 1)
                              	datasetFile = st.nextToken();
                              if(tokenNumber == 2)
                              	datasetName = st.nextToken();
                      }

                      fileDatasetMap.put(datasetFile,datasetName);

                      //reset token number
                      tokenNumber = 0;

              }

              System.out.println("Finished Map reading");

    } catch (Exception e) {
    	e.printStackTrace();
    }
    */

    /*
    //foreach dataset.tar.gz **
    //Iterate
    File root = new File("ds/");
    Collection files = FileUtils.listFiles(root, null, false);

    //mini db processed files
    ArrayList processed = new ArrayList();
          try {
          	BufferedReader br = new BufferedReader(new FileReader("processed.txt"));
              String line;
          	while((line = br.readLine()) != null) {
          		processed.add(line);
    	}
    } catch (IOException e) {
    	e.printStackTrace();
    }

    System.out.println("Iterating all downloaded datasets tgz files...");
    int dsCount = 0;

    for (Iterator iterator = files.iterator(); iterator.hasNext();) {
    	File dsFile = (File) iterator.next();
    	String inputDataset = dsFile.getAbsolutePath();

    	dsCount = dsCount + 1;
    	System.out.println("  Processing "+dsCount+":"+inputDataset);	//debug

    	//po5i: mini db processed files
    	if(processed.contains(inputDataset)){
    		System.out.println("    >>Already processed... skipping... ");
    		continue;
    	}
    	else
    	{
    		processed.add(inputDataset);
    		try {
    			FileWriter fileWritter = new FileWriter("processed.txt",true);
    			BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
       	        bufferWritter.write(inputDataset+"\n");
       	        bufferWritter.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}

    	//Set the GraphID
    	String graphID = (String) fileDatasetMap.get(dsFile.getName());
    	System.out.println("    Graph:: "+graphID);



    	//Uncompress the dataset and iterate throughout the files
    	try {
    		FileInputStream fin = new FileInputStream(inputDataset);
    		BufferedInputStream in = new BufferedInputStream(fin);
    		FileOutputStream out = new FileOutputStream("ds/archive.tar");
    		GzipCompressorInputStream gzIn;
    		gzIn = new GzipCompressorInputStream(in);
    		final byte[] buffer = new byte[1024];
    		int n = 0;
    		while (-1 != (n = gzIn.read(buffer))) {
    		    out.write(buffer, 0, n);
    		}
    		out.close();
    		gzIn.close();

    		//read the tar
    		File input = new File("ds/archive.tar"); //getFile("ds/archive.tar");
            InputStream is = new FileInputStream(input);
            ArchiveInputStream in1 = new ArchiveStreamFactory().createArchiveInputStream("tar", is);
            TarArchiveEntry entry = (TarArchiveEntry)in1.getNextEntry();

            while (entry != null) {// create a file with the same name as the tarEntry
                File destPath = new File("ds/extract/" + entry.getName());
                if (entry.isDirectory()) {
                    destPath.mkdirs();
                } else {
                    destPath.createNewFile();
                    OutputStream out1 = new FileOutputStream(destPath);
                    IOUtils.copy(in1, out1);
                    out1.close();
                }
                entry = (TarArchiveEntry)in1.getNextEntry();
            }

            in1.close();
    	} catch (Exception e) {
    		e.printStackTrace();
    	}*/

    // Iterate on extracted files
    try {
      File root1 = new File(dspath);
      Collection files1 = FileUtils.listFiles(root1, null, true);
      // new File(dspath+"../rdf").mkdir();

      for (Iterator iterator1 = files1.iterator(); iterator1.hasNext(); ) {
        File lomFile = (File) iterator1.next();
        String inputFile = lomFile.getAbsolutePath();

        // System.out.println("      Processing:"+inputFile);	//debug

        if (bContinuar) {
          // save metadata stream in a local file
          tmpMetadataFile = inputFile;
          String valid = "1";
          // valid = XMLValidator.validate(tmpMetadataFile,
          //		StorageService.getXSDFile(storageType));
          boolean hasSource = false;
          if (tmpMetadataFile.length() > 0) {
            // TODO: metadata validation
            // valid = "1";
            if (valid.equalsIgnoreCase("1")) {
              // generate id for the new material

              // output = graphID;
              // save metatada in rdf
              // obtain key-value pairs
              try {
                LOMParser.parseToKeyValue(tmpMetadataFile);
                if (!LOMParser.keyValues.isEmpty()) {
                  keyValues = LOMParser.keyValues;
                }
              } catch (MalformedURLException e1) {
                e1.printStackTrace();
              } catch (IOException e1) {
                e1.printStackTrace();
              }

              if (!keyValues.isEmpty()) {

                int canSave = 1;

                if (canSave > 0) {

                  // 4store
                  // save to rdf this triple (slow)
                  // HandleGraph graph = new HandleGraph(urlStore,uriGraph);
                  // result = graph.AppendTriple(graphID, keyValues);

                  // 4store
                  // prepare RDF file (better)
                  try {
                    // HELP: http://www.roseindia.net/tutorials/rdf/generateRDF.shtml

                    Model model = ModelFactory.createDefaultModel();

                    for (KeyValue kv : keyValues) {
                      String s = uriGraph + "/" + lomFile.getName();
                      // String p = URLEncoder.encode(kv.getKey(),"UTF-8");
                      String p = kv.getKey().replaceAll("[^\\w\\s\\.]", "_");
                      String v = kv.getValue();

                      // obtener el autor del CDATA en variable v
                      if (v.contains("CDATA")) {
                        v = v.replace("<![CDATA[", "");
                        v = v.replace("]]>", "");

                        VCardEngine vcardEngine = new VCardEngine();
                        VCard vcard = vcardEngine.parse(v);
                        if (vcard.hasFN()) v = vcard.getFN().getFormattedName();
                        else if (vcard.hasN()) v = vcard.getN().getFamilyName();
                        else {
                          // format string it can be parsed.

                          StringBuffer sb;
                          sb = new StringBuffer(v);
                          sb.insert(v.indexOf("VERSION:"), "\n");
                          v = sb.toString();

                          sb = new StringBuffer(v);
                          sb.insert(v.indexOf(" FN:") + 1, "\n");
                          v = sb.toString();

                          sb = new StringBuffer(v);
                          sb.insert(v.indexOf(" N:") + 1, "\n");
                          v = sb.toString();

                          sb = new StringBuffer(v);
                          sb.insert(v.indexOf("ORG:"), "\n");
                          v = sb.toString();

                          sb = new StringBuffer(v);
                          sb.insert(v.indexOf("EMAIL:"), "\n");
                          v = sb.toString();

                          sb = new StringBuffer(v);
                          sb.insert(v.indexOf("END:"), "\n");
                          v = sb.toString();

                          vcard = vcardEngine.parse(v);
                          if (vcard.hasFN()) v = vcard.getFN().getFormattedName();
                          else if (vcard.hasN()) v = vcard.getN().getFamilyName();
                          else {
                            System.out.println(" ~ ~ Problem with:::" + v);
                            System.out.println(" ~ ~ When Processing:" + inputFile); // debug
                          }

                          // System.out.println(" ~ author is: "+v);
                        }
                      }

                      // System.out.println("p: "+p+"\t\t\t v: "+v);

                      Property lom_prop = model.createProperty("http://ltsc.ieee.org/xsd/LOM#" + p);
                      Resource node = model.createResource(s).addProperty(lom_prop, v);
                    }

                    FileOutputStream fop = null;
                    File rdfFile =
                        new File(destination + lomFile.getName().replace(".xml", ".rdf"));
                    fop = new FileOutputStream(rdfFile);

                    // model.write(System.out);
                    model.write(fop);

                    // 4store
                    if (commit4store) {
                      HandleGraph graph = new HandleGraph(urlStore, uriGraph);
                      int result = graph.AppendGraph(rdfFile.getAbsolutePath()); // returns 0-1
                    }

                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                  // break;	//debug

                }
                output = "1";
              } else {
                output = "0";
                errorDescription = "Could not handle metadata to key-value";
              }

            } else {
              errorDescription = "XML Validation:" + valid;
            }
          } else {
            errorDescription = "Could not handle metadata file";
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    /*//break;	//debug

    			//Borrar todo lo de ds/extract/, rdf y el archive.tar para liberar espacio
    			try {
    				FileUtils.deleteDirectory(new File("ds/extract/"));
    				FileUtils.deleteDirectory(new File("ds/rdf/"));
    				FileUtils.deleteQuietly(new File("ds/archive.tar"));

    			} catch (IOException e) {
    				e.printStackTrace();
    			}

    		}
    */

    // prepare response
    if (output.contentEquals("0")) status = "ERROR: " + errorDescription;
    else status = "OK";

    System.out.println(status);
  }