Changeset 7738


Ignore:
Timestamp:
Aug 14, 2019, 9:16:18 AM (2 years ago)
Author:
Nicklas Nordborg
Message:

Merge 3.15.1 to the trunk.

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/build.xml

    r7732 r7738  
    8484  <property name="javac.encoding" value="UTF-8"
    8585    description="Default value for the 'encoding' attribute when compiling java code" />
    86   <property name="javadoc.arg" value="-Xdoclint:all,-missing"
     86  <property name="javadoc.arg" value="-Xdoclint:all,-missing --no-module-directories"
    8787    description="Extra arguments sent to Javadoc generation" />
    8888  <property name="src" location="src" description="Location of source files" />
  • trunk/src/clients/web/net/sf/basedb/clients/web/Base.java

    r7703 r7738  
    17581758    query.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
    17591759
    1760     Expression parameter = filter.getValue() == null ? null : Expressions.parameter("context", filter.getValueAsObject());
     1760    Expression parameter = filter.getValue() == null ? null : Expressions.parameter("context", filter.getValueAsObject(), filter.getValueType());
    17611761    Restriction r = filter.getOperator().getRestriction(Hql.property(property), parameter);
    17621762    query.restrict(r);
  • trunk/src/clients/web/net/sf/basedb/clients/web/util/HTML.java

    r7243 r7738  
    2323package net.sf.basedb.clients.web.util;
    2424
     25import java.io.UnsupportedEncodingException;
     26import java.net.URLEncoder;
    2527import java.util.regex.*;
    2628
     
    338340
    339341  /**
    340     Encode URL-unsafe characters in a string. Replaces
    341     % with %25, + with %2B, space with +, # with %23 and &amp; with %26.
     342    Encode URL-unsafe characters in a string.
     343    See {@link URLEncoder} for more information.
    342344    @param in The string to encode
    343345    @return The encoded string, or an empty string if NULL was passed
     
    346348  {
    347349    if (in == null) return "";
    348     in = PERCENT.matcher(in).replaceAll("%25");
    349     in = PLUS.matcher(in).replaceAll("%2B");
    350     in = SPACE.matcher(in).replaceAll("+");
    351     in = HASH.matcher(in).replaceAll("%23");
    352     in = AMPERSAND.matcher(in).replaceAll("%26");
     350    try
     351    {
     352      in = URLEncoder.encode(in, "UTF-8");
     353    }
     354    catch (UnsupportedEncodingException ex)
     355    {}
    353356    return in;
    354357  }
  • trunk/src/core/net/sf/basedb/core/AnnotationType.java

    r7615 r7738  
    12331233    if (!isEnumeration()) return null;
    12341234    ParameterValueData<?> pv = getData().getEnumerationValues();
    1235     return pv == null ? null : Collections.unmodifiableList(Values.getItemValues(getDbControl(), pv.getValues()));
     1235    if (pv == null) return null;
     1236   
     1237    List<T> values = Values.getItemValues(getDbControl(), pv.getValues());
     1238    if (values.size() > 1) values.sort(null);
     1239    return Collections.unmodifiableList(values);
    12361240  }
    12371241 
  • trunk/src/core/net/sf/basedb/core/Job.java

    r7605 r7738  
    18511851  {
    18521852    DbControl dc = getDbControl();
    1853     Message m = Message.getNewSystemMessage(dc, getOwner(), "SYSTEM", null, this);
     1853    Message m = Message.getNewSystemMessage(dc, getData().getOwner(), "SYSTEM", null, getData());
    18541854    m.setDescription(getStatusMessage());
    18551855    String jobName = net.sf.basedb.util.Values.trim(getName(), Message.MAX_NAME_LENGTH - 20);
  • trunk/src/core/net/sf/basedb/core/Keyring.java

    r7703 r7738  
    297297      // Schedule another reload as configured in base.config
    298298      Application.getCoreTimer().schedule(new ReloadTask(),
    299         601000L*Application.permissionTimeout());
     299        60000L*Application.permissionTimeout());
    300300    }
    301301    catch (BaseException ex)
     
    799799  synchronized boolean setRoleInactive(int roleId, boolean inactive)
    800800  {
     801    if (getReload()) reload();
    801802    // Ignore roles that the user is not a member of
    802     if (!roles.contains(roleId)) return false;
     803    if (roles == null || !roles.contains(roleId)) return false;
    803804   
    804805    if (inactiveRoles == null) inactiveRoles = new HashSet<Integer>();
  • trunk/src/core/net/sf/basedb/core/Message.java

    r7452 r7738  
    2323package net.sf.basedb.core;
    2424
     25import net.sf.basedb.core.data.JobData;
    2526import net.sf.basedb.core.data.MessageData;
    2627import net.sf.basedb.core.data.UserData;
     
    7374    Message m = dc.newItem(Message.class);
    7475    m.setName("New message");
    75     m.setTo(to);
     76    m.setTo(to == null ? null : to.getData());
    7677    m.setFrom(fromName);
    77     m.setSender(fromUser);
     78    m.setSender(fromUser == null ? null : fromUser.getData());
    7879    m.getData().setTimeSent(new Date());
    79     m.setJob(job);
     80    m.setJob(job == null ? null : job.getData());
    8081    return m;
    8182  }
     
    9495    @throws BaseException If there is an error
    9596  */
    96   static Message getNewSystemMessage(DbControl dc, User to, String fromName, User fromUser, Job job)
     97  static Message getNewSystemMessage(DbControl dc, UserData to, String fromName, UserData fromUser, JobData job)
    9798  {
    9899    Message m = dc.newItem(Message.class);
     
    325326    @throws InvalidDataException If the user is null
    326327  */
    327   private void setTo(User to)
     328  private void setTo(UserData to)
    328329    throws InvalidDataException
    329330  {
    330331    if (to == null) throw new InvalidUseOfNullException("to");
    331     getData().setTo(to.getData());
    332     sendAsEmail = EmailUtil.isEnabled(to);
     332    getData().setTo(to);
     333    sendAsEmail = EmailUtil.isEnabled() && to.getSendMessagesAsEmail() && EmailUtil.isValidEmail(to.getEmail());
    333334  }
    334335 
     
    385386  }
    386387 
    387   private void setSender(User sender)
     388  private void setSender(UserData sender)
    388389  {
    389390    getData().setFromId(sender == null ? 0 : sender.getId());
     
    402403    return getDbControl().getItem(Job.class, getData().getJob());
    403404  }
    404   private void setJob(Job job)
     405  private void setJob(JobData job)
    405406    throws PermissionDeniedException
    406407  {
    407     if (job != null) job.checkPermission(Permission.READ);
    408     getData().setJob(job == null ? null : job.getData());
     408    getData().setJob(job == null ? null : job);
    409409  }
    410410 
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r7716 r7738  
    396396    li.userId = 0;
    397397    li.userLogin = null;
     398    li.userName = null;
    398399    li.authenticationMethod = AuthenticationMethod.INTERNAL;
    399400    loginInfo = li;
     
    11071108    li.userId = userData.getId();
    11081109    li.userLogin = userData.getLogin();
     1110    li.userName = userData.getName();
    11091111    li.authenticationMethod = authenticationMethod;
    11101112    li.sessionSettings = Collections.synchronizedMap(new HashMap<String,Object>());
     
    11891191    updateLastAccess();
    11901192    return loginInfo == null ? 0 : loginInfo.userId;
     1193  }
     1194 
     1195  /**
     1196    Get the login name of the currently logged in user.
     1197    Returns null if no user is logged in.
     1198    @see User#getLogin()
     1199    @since 3.15.1
     1200  */
     1201  public String getLoggedInUserLogin()
     1202  {
     1203    updateLastAccess();
     1204    return loginInfo == null ? null : loginInfo.userLogin;
     1205  }
     1206 
     1207  /**
     1208    Get the name of the currently logged in user.
     1209    Returns null if no user is logged in.
     1210    @see User#getName()
     1211    @since 3.15.1
     1212  */
     1213  public String getLoggedInUserName()
     1214  {
     1215    updateLastAccess();
     1216    return loginInfo == null ? null : loginInfo.userName;
    11911217  }
    11921218 
     
    13181344    return loginInfo == null ? 0 : loginInfo.activeProjectId;
    13191345  }
     1346 
     1347  /**
     1348    Get the name of the active project, or null if no project is active.
     1349    @see #setActiveProject(Project)
     1350    @since 3.15.1
     1351  */
     1352  public String getActiveProjectName()
     1353  {
     1354    updateLastAccess();
     1355    return loginInfo == null ? null : loginInfo.activeProjectName;
     1356  }
    13201357
    13211358  /**
     
    13421379        loginInfo.keyring.setActiveProject(null);
    13431380        loginInfo.activeProjectId = 0;
     1381        loginInfo.activeProjectName = null;
    13441382        loginInfo.projectKeyId = 0;
    13451383        loginInfo.itemKeyId = 0;
     
    13501388        loginInfo.keyring.setActiveProject(project.getData());
    13511389        loginInfo.activeProjectId = project.getId();
     1390        loginInfo.activeProjectName = project.getName();
    13521391        if (project.hasPermission(Permission.USE))
    13531392        {
     
    26902729    */
    26912730    private String userLogin;
     2731
     2732    /**
     2733      The name property of the logged in user.
     2734    */
     2735    private String userName;
    26922736   
    26932737    /**
     
    27102754
    27112755    /**
     2756      The name of the the active project.
     2757    */
     2758    private String activeProjectName;
     2759
     2760    /**
    27122761      The id of the {@link ProjectKeyData} object that new items should
    27132762      be shared to.
     
    27502799      this.userId = parent.userId;
    27512800      this.userLogin = parent.userLogin;
     2801      this.userName = parent.userName;
    27522802      this.deviceId = parent.deviceId;
    27532803      this.activeProjectId = parent.activeProjectId;
     2804      this.activeProjectName = parent.activeProjectName;
    27542805      this.projectKeyId = parent.projectKeyId;
    27552806      this.keyring = parent.keyring;
  • trunk/src/core/net/sf/basedb/util/excel/XlsxToCsvUtil.java

    r7714 r7738  
    1515
    1616import org.apache.poi.poifs.filesystem.FileMagic;
     17import org.apache.poi.ss.formula.eval.NotImplementedException;
     18import org.apache.poi.ss.formula.eval.NotImplementedFunctionException;
    1719import org.apache.poi.ss.usermodel.Cell;
    1820import org.apache.poi.ss.usermodel.CellType;
    1921import org.apache.poi.ss.usermodel.DataFormatter;
    2022import org.apache.poi.ss.usermodel.DateUtil;
     23import org.apache.poi.ss.usermodel.FormulaError;
    2124import org.apache.poi.ss.usermodel.FormulaEvaluator;
    2225import org.apache.poi.ss.usermodel.Row;
     
    482485      String value = null;
    483486      CellType cellType = cell.getCellType();
     487      CellTypeWithInfo info = null;
    484488      if (cellType == CellType.FORMULA && evaluateFormulas)
    485489      {
    486         cellType = cell.getCachedFormulaResultType();
     490        info = evaluateFormula(cell);
     491        cellType = info.cellType;
    487492      }
    488493      if (cellType == CellType.NUMERIC)
     
    520525        value = dataFormat.formatCellValue(cell, formulaEval);
    521526      }
     527      if (info != null && info.info != null) value += info.info;
    522528      return value;
    523529    }
     
    536542      if (cellType == CellType.FORMULA && evaluateFormulas)
    537543      {
    538         cellType = cell.getCachedFormulaResultType();
     544        cellType = evaluateFormula(cell).cellType;
    539545      }
    540546      if (cellType == CellType.NUMERIC)
     
    564570      if (cellType == CellType.FORMULA && evaluateFormulas)
    565571      {
    566         cellType = cell.getCachedFormulaResultType();
     572        cellType = evaluateFormula(cell).cellType;
    567573      }
    568574      if (cellType == CellType.NUMERIC)
     
    576582      }
    577583      return value;
     584    }
     585   
     586    private CellTypeWithInfo evaluateFormula(Cell cell)
     587    {
     588      CellTypeWithInfo ct = new CellTypeWithInfo();
     589      try
     590      {
     591        ct.cellType = formulaEval.evaluateFormulaCell(cell);
     592      }
     593      catch (NotImplementedException ex)
     594      {
     595        cell.setCellType(CellType.ERROR);
     596        cell.setCellErrorValue(FormulaError.NAME.getCode());
     597        ct.cellType = CellType.ERROR;
     598        if (ex.getCause() instanceof NotImplementedFunctionException)
     599        {
     600          NotImplementedFunctionException nof = (NotImplementedFunctionException)ex.getCause();
     601          ct.info = nof.getFunctionName();
     602        }
     603      }
     604      catch (RuntimeException ex)
     605      {
     606        cell.setCellType(CellType.ERROR);
     607        cell.setCellErrorValue(FormulaError.VALUE.getCode());
     608        ct.cellType = CellType.ERROR;
     609      }
     610      return ct;
    578611    }
    579612   
     
    726759  }
    727760 
     761  // Used to return some error information if formula evaluation fails
     762  static class CellTypeWithInfo
     763  {
     764    CellType cellType;
     765    String info;
     766  }
     767 
    728768}
  • trunk/src/core/net/sf/basedb/util/parser/FlatFileParser.java

    r7676 r7738  
    268268 
    269269  /**
     270    If white space should be trimmed from data values or not.
     271    Default is false.
     272    @since 3.15.1
     273  */
     274  private boolean trimWhiteSpace;
     275 
     276  /**
    270277    The regular expression for matching the data footer line.
    271278  */
     
    512519    this.trimQuotes = trimQuotes;
    513520  }
     521 
     522  /**
     523    Set a flag indicating if white-space should be trimmed from
     524    start and end of data values. The default setting is false.
     525    @param trimWhiteSpace TRUE to remove white-space, FALSE to keep them
     526    @since 3.15.1
     527   */
     528  public void setTrimWhiteSpace(boolean trimWhiteSpace)
     529  {
     530    this.trimWhiteSpace = trimWhiteSpace;
     531  }
    514532
    515533  /**
     
    651669  {
    652670    return excelSheetName;
     671  }
     672 
     673  /**
     674    If the input stream that is being parsed is an Excel
     675    document, this method returns information about it.
     676    @return An XlsxToCsvUtil object or null if the stream is not an Excel document
     677    @since 3.15.1
     678  */
     679  public XlsxToCsvUtil getCurrentExcelWorkbook()
     680  {
     681    return excelWorkbook;
     682  }
     683 
     684  /**
     685    If the input stream that is being parsed is an Excel
     686    document, this method returns information about the current
     687    worksheet.
     688    @return An XlsxToCsvUtil.SheetInfo object or null if the stream is not an Excel document
     689    @since 3.15.1
     690  */
     691  public XlsxToCsvUtil.SheetInfo getCurrentSheet()
     692  {
     693    return excelSheet;
    653694  }
    654695 
     
    924965            lines.add(new Line(parsedLines, line, LineType.DATA));
    925966            parsedDataLines = 1;
    926             nextData = new Data(parsedLines, parsedDataLines, line, columns, emptyIsNull, nullIsNull);
     967            nextData = new Data(parsedLines, parsedDataLines, line, columns, emptyIsNull, nullIsNull, trimWhiteSpace);
    927968          }
    928969        }
     
    14491490              if (excelSheet != null)
    14501491              {
    1451                 nextData = new ExcelData(excelSheet, excelParsedLinesOffset, parsedLines, parsedDataLines, line, columns, emptyIsNull, nullIsNull);
     1492                nextData = new ExcelData(excelSheet, excelParsedLinesOffset, parsedLines, parsedDataLines, line, columns, emptyIsNull, nullIsNull, trimWhiteSpace);
    14521493              }
    14531494              else
    14541495              {
    1455                 nextData = new Data(parsedLines, parsedDataLines, line, columns, emptyIsNull, nullIsNull);
     1496                nextData = new Data(parsedLines, parsedDataLines, line, columns, emptyIsNull, nullIsNull, trimWhiteSpace);
    14561497              }
    14571498            }
     
    18741915    private final boolean emptyIsNull;
    18751916    private final boolean nullIsNull;
     1917    private final boolean trimWhiteSpace;
    18761918
    18771919    /**
    18781920      Create a new data object.
    18791921    */
    1880     private Data(int lineNo, int dataLineNo, String line, String[] columns, boolean emptyIsNull, boolean nullIsNull)
     1922    private Data(int lineNo, int dataLineNo, String line, String[] columns, boolean emptyIsNull, boolean nullIsNull, boolean trimWhiteSpace)
    18811923    {
    18821924      this.lineNo = lineNo;
     
    18861928      this.emptyIsNull = emptyIsNull;
    18871929      this.nullIsNull = nullIsNull;
     1930      this.trimWhiteSpace = trimWhiteSpace;
    18881931    }
    18891932   
     
    19582001    public String getString(int index)
    19592002    {
    1960       String value = result[index];
    1961       return emptyIsNull && value.length() == 0 ||
    1962         nullIsNull && "NULL".equalsIgnoreCase(value) ? null : value;
     2003      return fixString(result[index]);
     2004    }
     2005   
     2006    /**
     2007      Fix the value string according to options
     2008      for 'emptyIsNull', 'nullIsNull', etc.
     2009      @since 3.15.1
     2010    */
     2011    protected String fixString(String value)
     2012    {
     2013      // TODO - In Java 11 we can use String.strip() which also handles other white-space than "space"
     2014      if (value != null && trimWhiteSpace) value = value.trim();     
     2015     
     2016      return value == null ||
     2017        emptyIsNull && value.length() == 0 ||
     2018        nullIsNull && "NULL".equalsIgnoreCase(value)
     2019        ? null : value;
    19632020    }
    19642021   
     
    19792036    public Integer getInt(int index, NumberFormat parser, boolean nullIfException)
    19802037    {
    1981       return (Integer)Type.INT.parseString(get(index), parser, nullIfException);
     2038      return (Integer)Type.INT.parseString(getString(index), parser, nullIfException);
    19822039    }
    19832040
     
    19902047    public Long getLong(int index, NumberFormat parser, boolean nullIfException)
    19912048    {
    1992       return (Long)Type.LONG.parseString(get(index), parser, nullIfException);
     2049      return (Long)Type.LONG.parseString(getString(index), parser, nullIfException);
    19932050    }
    19942051   
     
    20092066    public Float getFloat(int index, NumberFormat parser, boolean nullIfException)
    20102067    {
    2011       return (Float)Type.FLOAT.parseString(get(index), parser, nullIfException);
     2068      return (Float)Type.FLOAT.parseString(getString(index), parser, nullIfException);
    20122069    }
    20132070
     
    20202077    public Double getDouble(int index, NumberFormat parser, boolean nullIfException)
    20212078    {
    2022       return (Double)Type.DOUBLE.parseString(get(index), parser, nullIfException);
     2079      return (Double)Type.DOUBLE.parseString(getString(index), parser, nullIfException);
    20232080    }
    20242081
     
    20312088    public Date getDate(int index, Formatter<Date> parser, boolean nullIfException)
    20322089    {
    2033       return (Date)Type.DATE.parseString(get(index), parser, nullIfException);
     2090      return (Date)Type.DATE.parseString(getString(index), parser, nullIfException);
    20342091    }
    20352092  }
     
    20512108      Create a new data object.
    20522109    */
    2053     ExcelData(SheetInfo sheet, int lineOffset, int lineNo, int dataLineNo, String line, String[] columns, boolean emptyIsNull, boolean nullIsNull)
    2054     {
    2055       super(lineNo, dataLineNo, line, columns, emptyIsNull, nullIsNull);
     2110    ExcelData(SheetInfo sheet, int lineOffset, int lineNo, int dataLineNo, String line, String[] columns, boolean emptyIsNull, boolean nullIsNull, boolean trimWhiteSpace)
     2111    {
     2112      super(lineNo, dataLineNo, line, columns, emptyIsNull, nullIsNull, trimWhiteSpace);
    20562113      this.sheet = sheet;
    20572114      this.rowOffset = sheet.getFirstRow()-1-lineOffset;
     
    20632120    {
    20642121      Cell c = sheet.getCell(lineNo()+rowOffset, index+colOffset);
    2065       return sheet.getCellValueAsString(c);
     2122      return fixString(sheet.getCellValueAsString(c));
    20662123    }
    20672124   
  • trunk/www/filemanager/files/download_file.jsp

    r6308 r7738  
    3131  import="net.sf.basedb.core.Permission"
    3232  import="net.sf.basedb.core.File"
     33  import="net.sf.basedb.core.Path"
    3334  import="net.sf.basedb.core.Location"
    3435  import="net.sf.basedb.core.User"
     
    6162{
    6263  File file = File.getById(dc, itemId);
    63   String path = file.getPath().toString();
     64  Path path = file.getPath();
    6465  String title = "Download " + path;
    6566 
     
    7071  }
    7172 
    72   String downloadUrl = root + "filemanager/files/download/-"+ID+"-"+HTML.urlEncode(path);
     73  String downloadUrl = root + "filemanager/files/download/-"+ID+"-"+path.toURLString("UTF-8");
    7374  %>
    7475  <base:page type="popup" title="<%=title%>">
     
    8586      <tr>
    8687        <th>File</th>
    87         <td><a href="<%=downloadUrl%>"><%=HTML.encodeTags(path)%></a></td>
     88        <td><a href="<%=downloadUrl%>"><%=HTML.encodeTags(path.toString())%></a></td>
    8889      </tr>
    8990      <tr>
  • trunk/www/filemanager/index.jsp

    r6457 r7738  
    6666  {
    6767    // Display the list page after updating the current context from the request parameters
    68     Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     68    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext, true);
    6969    forward = "select_file.jsp?mode=selectone";
    7070  }
     
    7272  {
    7373    // Display the list page after updating the current context from the request parameters
    74     Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     74    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext, true);
    7575    forward = "select_file.jsp?mode=selectmultiple";
    7676  }
     
    7878  {
    7979    // Display the list page after updating the current context from the request parameters
    80     Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     80    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext, true);
    8181    forward = "save_as.jsp";
    8282  }
  • trunk/www/login.jsp

    r7605 r7738  
    214214    if (errorMessage != null)
    215215    {
    216       response.sendRedirect(root+"main.jsp?ID="+ID+"&again=1&login="+HTML.urlEncode(login)+"&loginForm="+HTML.encodeTags(loginForm)+"&error="+HTML.urlEncode(errorMessage));
     216      response.sendRedirect(root+"main.jsp?ID="+ID+"&again=1&login="+HTML.urlEncode(login)+"&loginForm="+HTML.urlEncode(loginForm)+"&error="+HTML.urlEncode(errorMessage));
    217217    }
    218218    else
     
    233233    if (errorMessage != null)
    234234    {
    235       response.sendRedirect(root+"main.jsp?ID="+ID+"&login="+HTML.urlEncode(login)+"&loginForm="+HTML.encodeTags(loginForm)+"&error="+HTML.urlEncode(errorMessage));
     235      response.sendRedirect(root+"main.jsp?ID="+ID+"&login="+HTML.urlEncode(login)+"&loginForm="+HTML.urlEncode(loginForm)+"&error="+HTML.urlEncode(errorMessage));
    236236    }
    237237    else
Note: See TracChangeset for help on using the changeset viewer.