Exemplo n.º 1
0
 private boolean hasSqlSignature(String s) {
   boolean bRetVal = false;
   try {
     bRetVal =
         Gadgets.matches(s, "(\\%27)|(\\')|(\\-\\-)|(\\%23)|(#)")
             || Gadgets.matches(s, "((\\%3D)|(=))[^\\n]*((\\%27)|(\\')|(\\-\\-)|(\\%3B)|(;))")
             || Gadgets.matches(s, "\\w*((\\%27)|(\\'))((\\%6F)|o|(\\%4F))((\\%72)|r|(\\%52))")
             || Gadgets.matches(s, "((\\%27)|(\\'))union");
   } catch (org.apache.oro.text.regex.MalformedPatternException ignore) {
     // never thrown
   }
   return bRetVal;
 } // hasSqlSignature
Exemplo n.º 2
0
  public boolean store(JDCConnection oConn) throws SQLException {

    if (isNull(DB.gu_degree)) {
      put(DB.gu_degree, Gadgets.generateUUID());
    }

    return super.store(oConn);
  }
Exemplo n.º 3
0
  public void putEntry(SyndEntryImpl oEntry) throws IllegalArgumentException {

    if (DebugFile.trace) DebugFile.writeln("FeedEntry.putEntry([SyndEntryImpl])");

    if (oEntry.getTitle() != null) put(DB.tl_entry, Gadgets.left(oEntry.getTitle(), 254));

    if (oEntry.getUri() != null) put(DB.uri_entry, oEntry.getUri());

    if (oEntry.getLink() != null) {

      put(DB.url_addr, Gadgets.left(oEntry.getLink(), MAX_URL_LENGTH));

      try {
        String[] aHost = Gadgets.split(new URL(oEntry.getLink()).getHost(), '.');
        if (aHost.length == 1) put(DB.url_domain, Gadgets.left(aHost[0], 100));
        else
          put(
              DB.url_domain,
              Gadgets.left(aHost[aHost.length - 2] + "." + aHost[aHost.length - 1], 100));
        if (getString(DB.url_domain, "").endsWith(".es")) put(DB.id_country, "es");
      } catch (Exception ignore) {
      }

      if (oEntry.getLink().startsWith("http://twitter.com/")) {
        String sUrlAuthor = null;
        if (oEntry.getLink().indexOf("/statuses/") > 0)
          sUrlAuthor = Gadgets.substrUpTo(oEntry.getLink(), 0, "/statuses/");
        else if (oEntry.getLink().indexOf("/status/") > 0)
          sUrlAuthor = Gadgets.substrUpTo(oEntry.getLink(), 0, "/status/");
        if (sUrlAuthor == null) sUrlAuthor = oEntry.getLink();
        else if (sUrlAuthor.length() == 0) sUrlAuthor = oEntry.getLink();
        put(DB.url_author, sUrlAuthor);
      } // Twitter
    } // getLink()

    if (oEntry.getDescription() != null)
      put(DB.de_entry, Gadgets.left(oEntry.getDescription().getValue(), 1000));
    if (oEntry.getPublishedDate() == null)
      if (oEntry.getUpdatedDate() != null) put(DB.dt_published, oEntry.getUpdatedDate());
      else put(DB.dt_published, new Date());
    else put(DB.dt_published, oEntry.getPublishedDate());
    if (oEntry.getUpdatedDate() != null) put(DB.dt_modified, oEntry.getUpdatedDate());
    put(DB.bin_entry, oEntry);
  } // putEntry
Exemplo n.º 4
0
  public static String createSynonym(
      JDCConnection oConn, String sGuMainTerm, String sTxTerm, String sTxTermPlural, String sDeTerm)
      throws SQLException {
    Term oMain = new Term();

    if (DebugFile.trace) {
      DebugFile.writeln(
          "Begin Thesauri.createSynonym([Connection],"
              + sGuMainTerm
              + ","
              + sTxTerm
              + ","
              + sTxTermPlural
              + ","
              + sDeTerm);
      DebugFile.incIdent();
    }

    oMain.load(oConn, new Object[] {sGuMainTerm});

    int iLevel = oMain.level();

    oMain.replace(DB.gu_term, Gadgets.generateUUID());
    oMain.replace(DB.gu_synonym, sGuMainTerm);
    oMain.replace(DB.id_term + String.valueOf(iLevel - 1), DBBind.nextVal(oConn, "seq_thesauri"));
    oMain.replace(DB.tx_term, sTxTerm);
    oMain.replace(DB.tx_term + "2", sTxTermPlural);
    oMain.replace(DB.de_term, sDeTerm);

    oMain.store(oConn);

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Thesauri.createSynonym() : " + oMain.getString(DB.gu_term));
    }

    return oMain.getString(DB.gu_term);
  }
Exemplo n.º 5
0
  /**
   * Create Root Term
   *
   * @param oConn Database Connection
   * @param sTxTerm Term Text Singular
   * @param sTxTerm Term Text Plural
   * @param sDeTerm Term Contextual Description
   * @param sIdLanguage Language
   * @param sIdScope Scope
   * @param iIdDomain Domain Numeric Identifier (from k_domains)
   * @param sGuWorkArea WorkArea GUID
   * @return GUID for new term
   * @throws SQLException
   */
  public static String createRootTerm(
      JDCConnection oConn,
      String sTxTerm,
      String sTxTermPlural,
      String sDeTerm,
      String sIdLanguage,
      String sIdScope,
      int iIdDomain,
      String sGuWorkArea)
      throws SQLException {
    PreparedStatement oStmt;
    String sGuRootTerm = Gadgets.generateUUID();
    int iNextVal;

    if (DebugFile.trace) {
      DebugFile.writeln(
          "Begin Thesauri.createRootTerm([Connection],"
              + sTxTerm
              + ","
              + sTxTermPlural
              + ","
              + sDeTerm
              + ","
              + sIdLanguage
              + ","
              + sIdScope
              + String.valueOf(iIdDomain)
              + ","
              + sGuWorkArea
              + ")");
      DebugFile.incIdent();
      DebugFile.writeln(
          "Connection.prepareStatement(INSERT INTO "
              + DB.k_thesauri_root
              + " ("
              + DB.gu_rootterm
              + ","
              + DB.tx_term
              + ","
              + DB.tx_term
              + "2,"
              + DB.id_domain
              + ","
              + DB.gu_workarea
              + ","
              + DB.id_scope
              + ") VALUES ('"
              + sGuRootTerm
              + "','"
              + sTxTerm
              + "',"
              + String.valueOf(iIdDomain)
              + ",'"
              + sGuWorkArea
              + "','"
              + sIdScope
              + "'))");
    }

    oStmt =
        oConn.prepareStatement(
            "INSERT INTO "
                + DB.k_thesauri_root
                + " ("
                + DB.gu_rootterm
                + ","
                + DB.tx_term
                + ","
                + DB.id_domain
                + ","
                + DB.gu_workarea
                + ","
                + DB.id_scope
                + ") VALUES (?,?,?,?,?)");
    oStmt.setString(1, sGuRootTerm);
    oStmt.setString(2, sTxTerm);
    oStmt.setInt(3, iIdDomain);
    oStmt.setString(4, sGuWorkArea);
    oStmt.setString(5, sIdScope);
    oStmt.executeUpdate();
    oStmt.close();

    iNextVal = DBBind.nextVal(oConn, "seq_thesauri");

    if (DebugFile.trace)
      DebugFile.writeln(
          "Connection.prepareStatement(INSERT INTO "
              + DB.k_thesauri
              + " ("
              + DB.gu_rootterm
              + ","
              + DB.gu_term
              + ","
              + DB.tx_term
              + ","
              + DB.tx_term
              + "2,"
              + DB.id_language
              + ","
              + DB.de_term
              + ","
              + DB.id_scope
              + ","
              + DB.id_domain
              + ","
              + DB.id_term
              + "0) VALUES ('"
              + sGuRootTerm
              + "','"
              + sGuRootTerm
              + "','"
              + sTxTerm
              + "','"
              + sIdLanguage
              + "','"
              + sDeTerm
              + "','"
              + sIdScope
              + "',"
              + String.valueOf(iIdDomain)
              + ","
              + String.valueOf(iNextVal)
              + "))");

    oStmt =
        oConn.prepareStatement(
            "INSERT INTO "
                + DB.k_thesauri
                + " ("
                + DB.gu_rootterm
                + ","
                + DB.gu_term
                + ","
                + DB.tx_term
                + ","
                + DB.tx_term
                + "2,"
                + DB.id_language
                + ","
                + DB.de_term
                + ","
                + DB.id_scope
                + ","
                + DB.id_domain
                + ","
                + DB.id_term
                + "0) VALUES (?,?,?,?,?,?,?,?,?)");
    oStmt.setString(1, sGuRootTerm);
    oStmt.setString(2, sGuRootTerm);
    oStmt.setString(3, sTxTerm);
    oStmt.setString(4, sTxTermPlural);
    oStmt.setString(5, sIdLanguage);
    if (sDeTerm == null) oStmt.setNull(6, Types.VARCHAR);
    else oStmt.setString(6, sDeTerm);
    oStmt.setString(7, sIdScope);
    oStmt.setInt(8, iIdDomain);
    oStmt.setInt(9, iNextVal);
    oStmt.executeUpdate();
    oStmt.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Thesauri.createRootTerm() : " + sGuRootTerm);
    }

    return sGuRootTerm;
  } // createRootTerm
Exemplo n.º 6
0
  /**
   * Create Term
   *
   * @param oConn Database Connection
   * @param sGuParent Parent Term
   * @param sTxTerm Term Text Singular
   * @param sTxTermPlural Term Text Plural
   * @param sDeTerm Term Contextual Description
   * @param sIdLanguage Language
   * @param sIdScope Scope
   * @param iIdDomain Domain Numeric Identifier (from k_domains)
   * @return GUID for new term
   * @throws SQLException
   */
  public static String createTerm(
      JDCConnection oConn,
      String sGuParent,
      String sTxTerm,
      String sTxTermPlural,
      String sDeTerm,
      String sIdLanguage,
      String sIdScope,
      int iIdDomain)
      throws SQLException {
    ResultSet oRSet;
    PreparedStatement oStmt;
    String sGuTerm = Gadgets.generateUUID();
    String sGuRootTerm;
    Object[] oTerm = new Object[10];
    int iTerm;
    int iNext;

    if (DebugFile.trace) {
      DebugFile.writeln(
          "Begin Thesauri.createTerm([Connection],"
              + sGuParent
              + ","
              + sTxTerm
              + ","
              + sTxTermPlural
              + ","
              + sDeTerm
              + ","
              + sIdLanguage
              + ","
              + sIdScope
              + String.valueOf(iIdDomain)
              + ")");
      DebugFile.incIdent();
      DebugFile.writeln(
          "Connection.prepareStatement(SELECT "
              + DB.gu_rootterm
              + ","
              + DB.id_term
              + "0,"
              + DB.id_term
              + "1,"
              + DB.id_term
              + "2,"
              + DB.id_term
              + "3,"
              + DB.id_term
              + "4,"
              + DB.id_term
              + "5,"
              + DB.id_term
              + "6,"
              + DB.id_term
              + "7,"
              + DB.id_term
              + "8,"
              + DB.id_term
              + "9 FROM "
              + DB.k_thesauri
              + " WHERE "
              + DB.gu_term
              + "='"
              + sGuParent
              + "'");
    }

    oStmt =
        oConn.prepareStatement(
            "SELECT "
                + DB.gu_rootterm
                + ","
                + DB.id_term
                + "0,"
                + DB.id_term
                + "1,"
                + DB.id_term
                + "2,"
                + DB.id_term
                + "3,"
                + DB.id_term
                + "4,"
                + DB.id_term
                + "5,"
                + DB.id_term
                + "6,"
                + DB.id_term
                + "7,"
                + DB.id_term
                + "8,"
                + DB.id_term
                + "9 FROM "
                + DB.k_thesauri
                + " WHERE "
                + DB.gu_term
                + "=?",
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    oStmt.setString(1, sGuParent);
    oRSet = oStmt.executeQuery();
    boolean bParentExists = oRSet.next();
    if (bParentExists) {
      sGuRootTerm = oRSet.getString(1);
      oTerm[0] = oRSet.getObject(2);
      oTerm[1] = oRSet.getObject(3);
      oTerm[2] = oRSet.getObject(4);
      oTerm[3] = oRSet.getObject(5);
      oTerm[4] = oRSet.getObject(6);
      oTerm[5] = oRSet.getObject(7);
      oTerm[6] = oRSet.getObject(8);
      oTerm[7] = oRSet.getObject(9);
      oTerm[8] = oRSet.getObject(10);
      oTerm[9] = oRSet.getObject(11);
    } else {
      sGuRootTerm = null;
    }
    oRSet.close();
    oStmt.close();

    if (!bParentExists) {
      if (DebugFile.trace) {
        DebugFile.writeln("Parent term \"" + sGuParent + "\" not found");
        DebugFile.decIdent();
      }
      throw new SQLException("Thesauri.createTerm() Parent term \"" + sGuParent + "\" not found");
    }

    if (DebugFile.trace)
      DebugFile.writeln(
          "Connection.prepareStatement(INSERT INTO "
              + DB.k_thesauri
              + " ("
              + DB.gu_rootterm
              + ","
              + DB.gu_term
              + ","
              + DB.tx_term
              + ","
              + DB.tx_term
              + "2,"
              + DB.id_language
              + ","
              + DB.de_term
              + ","
              + DB.id_scope
              + ","
              + DB.id_domain
              + ","
              + DB.id_term
              + "0,"
              + DB.id_term
              + "1,"
              + DB.id_term
              + "2,"
              + DB.id_term
              + "3,"
              + DB.id_term
              + "4,"
              + DB.id_term
              + "5,"
              + DB.id_term
              + "6,"
              + DB.id_term
              + "7,"
              + DB.id_term
              + "8,"
              + DB.id_term
              + "9) VALUES ('"
              + sGuRootTerm
              + "','"
              + sGuTerm
              + "','"
              + sTxTerm
              + "','"
              + sTxTermPlural
              + "','"
              + sIdLanguage
              + "','"
              + sDeTerm
              + "','"
              + sIdScope
              + "',"
              + String.valueOf(iIdDomain)
              + ",?,?,?,?,?,?,?,?,?,?))");

    oStmt =
        oConn.prepareStatement(
            "INSERT INTO "
                + DB.k_thesauri
                + " ("
                + DB.gu_rootterm
                + ","
                + DB.gu_term
                + ","
                + DB.tx_term
                + ","
                + DB.tx_term
                + "2,"
                + DB.id_language
                + ","
                + DB.de_term
                + ","
                + DB.id_scope
                + ","
                + DB.id_domain
                + ","
                + DB.id_term
                + "0,"
                + DB.id_term
                + "1,"
                + DB.id_term
                + "2,"
                + DB.id_term
                + "3,"
                + DB.id_term
                + "4,"
                + DB.id_term
                + "5,"
                + DB.id_term
                + "6,"
                + DB.id_term
                + "7,"
                + DB.id_term
                + "8,"
                + DB.id_term
                + "9) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    oStmt.setString(1, sGuRootTerm);
    oStmt.setString(2, sGuTerm);
    oStmt.setString(3, sTxTerm);
    oStmt.setString(4, sTxTermPlural);
    oStmt.setString(5, sIdLanguage);
    if (sDeTerm == null) oStmt.setNull(6, Types.VARCHAR);
    else oStmt.setString(6, sDeTerm);
    oStmt.setString(7, sIdScope);
    oStmt.setInt(8, iIdDomain);

    iTerm = 0;
    do {
      if (null == oTerm[iTerm]) break;

      if (DebugFile.trace)
        DebugFile.writeln(
            "PreparedStatement.setObject("
                + String.valueOf(iTerm + 9)
                + ", "
                + oTerm[iTerm]
                + ", java.sql.Types.INTEGER)");

      oStmt.setObject(iTerm + 9, oTerm[iTerm], java.sql.Types.INTEGER);
    } while (++iTerm <= 9);

    if (10 == iTerm)
      throw new SQLException("Thesauri maximum number of hierarchical levels exceeded");

    iNext = DBBind.nextVal(oConn, "seq_thesauri");

    if (DebugFile.trace)
      DebugFile.writeln(
          "PreparedStatement.setInt ("
              + String.valueOf(iTerm + 9)
              + ","
              + String.valueOf(iNext)
              + ")");

    oStmt.setInt(iTerm + 9, iNext);

    while (++iTerm <= 9) {
      if (DebugFile.trace)
        DebugFile.writeln(
            "PreparedStatement.setObject("
                + String.valueOf(iTerm + 9)
                + ", null, java.sql.Types.INTEGER)");

      oStmt.setObject(iTerm + 9, null, java.sql.Types.INTEGER);
    } // wend

    if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate();");

    oStmt.executeUpdate();
    oStmt.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Thesauri.createTerm() : " + sGuTerm);
    }

    return sGuTerm;
  } // createTerm