Пример #1
0
 // User defined finders/Buscadores definidos por el usuario
 public static FilterBySubfamily findBy() throws javax.ejb.ObjectNotFoundException {
   if (XavaPreferences.getInstance().isJPAPersistence()) {
     javax.persistence.Query query =
         org.openxava.jpa.XPersistence.getManager().createQuery("from FilterBySubfamily as o");
     try {
       return (FilterBySubfamily) query.getSingleResult();
     } catch (Exception ex) {
       // In this way in order to work with Java pre 5
       if (ex.getClass().getName().equals("javax.persistence.NoResultException")) {
         throw new javax.ejb.ObjectNotFoundException(
             XavaResources.getString("object_not_found", "FilterBySubfamily"));
       } else {
         ex.printStackTrace();
         throw new RuntimeException(ex.getMessage());
       }
     }
   } else {
     org.hibernate.Query query =
         org.openxava.hibernate.XHibernate.getSession().createQuery("from FilterBySubfamily as o");
     FilterBySubfamily r = (FilterBySubfamily) query.uniqueResult();
     if (r == null) {
       throw new javax.ejb.ObjectNotFoundException(
           XavaResources.getString("object_not_found", "FilterBySubfamily"));
     }
     return r;
   }
 }
    private Object getValueWithoutWebEditorsFormat(int row, int column) {
      Object r = original.getValueAt(row, column);

      if (r instanceof Boolean) {
        if (((Boolean) r).booleanValue()) return XavaResources.getString(locale, "yes");
        return XavaResources.getString(locale, "no");
      }
      if (withValidValues) {
        MetaProperty p = getMetaProperty(column);
        if (p.hasValidValues()) {
          return p.getValidValueLabel(locale, original.getValueAt(row, column));
        }
      }

      if (r instanceof java.util.Date) {
        MetaProperty p =
            getMetaProperty(column); // In order to use the type declared by the developer
        // and not the one returned by JDBC or the JPA engine
        if (java.sql.Time.class.isAssignableFrom(p.getType())) {
          return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(r);
        }
        if (java.sql.Timestamp.class.isAssignableFrom(p.getType())) {
          DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
          return dateFormat.format(r);
        }
        return DateFormat.getDateInstance(DateFormat.SHORT, locale).format(r);
      }

      if (r instanceof BigDecimal) {
        return formatBigDecimal(r, locale);
      }

      return r;
    }
Пример #3
0
 // User defined finders/Buscadores definidos por el usuario
 public static Size findById(int id) throws javax.ejb.ObjectNotFoundException {
   if (XavaPreferences.getInstance().isJPAPersistence()) {
     javax.persistence.Query query =
         org.openxava.jpa.XPersistence.getManager()
             .createQuery("from Size as o where o.id = :arg0");
     query.setParameter("arg0", new Integer(id));
     try {
       return (Size) query.getSingleResult();
     } catch (Exception ex) {
       // In this way in order to work with Java pre 5
       if (ex.getClass().getName().equals("javax.persistence.NoResultException")) {
         throw new javax.ejb.ObjectNotFoundException(
             XavaResources.getString("object_not_found", "Size"));
       } else {
         ex.printStackTrace();
         throw new RuntimeException(ex.getMessage());
       }
     }
   } else {
     org.hibernate.Query query =
         org.openxava.hibernate.XHibernate.getSession()
             .createQuery("from Size as o where o.id = :arg0");
     query.setParameter("arg0", new Integer(id));
     Size r = (Size) query.uniqueResult();
     if (r == null) {
       throw new javax.ejb.ObjectNotFoundException(
           XavaResources.getString("object_not_found", "Size"));
     }
     return r;
   }
 }
 private void generateNoRowsPage(HttpServletResponse response) throws Exception {
   response.setContentType("text/html");
   response.getWriter().println("<html><head><title>");
   response.getWriter().println(XavaResources.getString("no_rows_report_message_title"));
   response
       .getWriter()
       .println(
           "</title></head><body style='font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;'>");
   response.getWriter().println("<h1 style='font-size:22px;'>");
   response.getWriter().println(XavaResources.getString("no_rows_report_message_title"));
   response.getWriter().println("</h1>");
   response.getWriter().println("<p style='font-size:16px;'>");
   response.getWriter().println(XavaResources.getString("no_rows_report_message_detail"));
   response.getWriter().println("</p></body></html>");
 }
  private int[] getSelectedRows(int[] selectedRowsNumber, Map[] selectedRowsKeys, Tab tab) {
    if (selectedRowsKeys == null || selectedRowsKeys.length == 0) return new int[0];
    // selectedRowsNumber is the most performant so we use it when possible
    else if (selectedRowsNumber.length == selectedRowsKeys.length) return selectedRowsNumber;
    else {
      // find the rows from the selectedKeys

      // This has a poor performance, but it covers the case when the selected
      // rows are not loaded for the tab, something that can occurs if the user
      // select rows and afterwards reorder the list.
      try {
        int[] s = new int[selectedRowsKeys.length];
        List selectedKeys = Arrays.asList(selectedRowsKeys);
        int end = tab.getTableModel().getTotalSize();
        int x = 0;
        for (int i = 0; i < end; i++) {
          Map key = (Map) tab.getTableModel().getObjectAt(i);
          if (selectedKeys.contains(key)) {
            s[x] = i;
            x++;
          }
        }
        return s;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("fails_selected"), ex);
        throw new XavaException("fails_selected");
      }
    }
  }
Пример #6
0
 public void setOfficeManager(org.openxava.test.model.IClerk newClerk) throws RemoteException {
   if (newClerk != null && !(newClerk instanceof org.openxava.test.model.Clerk)) {
     throw new IllegalArgumentException(XavaResources.getString("ejb_to_pojo_illegal"));
   }
   this.officeManager = newClerk;
   this.officeManager_number = newClerk == null ? null : new Integer(newClerk.getNumber());
 }
Пример #7
0
  public String getRangeDescription() {
    try {
      org.openxava.test.calculators.RangeDescriptionCalculator rangeDescriptionCalculator =
          (org.openxava.test.calculators.RangeDescriptionCalculator)
              getMetaModel()
                  .getMetaProperty("rangeDescription")
                  .getMetaCalculator()
                  .createCalculator();

      rangeDescriptionCalculator.setSubfamilyNumberFrom(getSubfamily().getNumber());

      rangeDescriptionCalculator.setSubfamilyNumberTo(getSubfamilyTo().getNumber());
      return (String) rangeDescriptionCalculator.calculate();
    } catch (NullPointerException ex) {
      // Usually for multilevel property access with null references
      return null;
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new RuntimeException(
          XavaResources.getString(
              "generator.calculate_value_error",
              "RangeDescription",
              "FilterBySubfamily",
              ex.getLocalizedMessage()));
    }
  }
Пример #8
0
 public void setMainWarehouse(org.openxava.test.model.IWarehouse newWarehouse)
     throws RemoteException {
   if (newWarehouse != null && !(newWarehouse instanceof org.openxava.test.model.Warehouse)) {
     throw new IllegalArgumentException(XavaResources.getString("ejb_to_pojo_illegal"));
   }
   this.mainWarehouse = newWarehouse;
   this.mainWarehouse_number = newWarehouse == null ? null : new Integer(newWarehouse.getNumber());
 }
Пример #9
0
 public String toString() {
   try {
     return getMetaModel().toString(this);
   } catch (XavaException ex) {
     System.err.println(XavaResources.getString("toString_warning", "Size"));
     return super.toString();
   }
 }
Пример #10
0
 public int getReceptionist() {
   try {
     return ((Integer) getReceptionistConverter().toJava(get_Receptionist())).intValue();
   } catch (org.openxava.converters.ConversionException ex) {
     ex.printStackTrace();
     throw new RuntimeException(
         XavaResources.getString("generator.conversion_error", "Receptionist", "Office", "int"));
   }
 }
Пример #11
0
 public void setZoneNumber(int newZoneNumber) {
   try {
     set_ZoneNumber((java.lang.Integer) getZoneNumberConverter().toDB(new Integer(newZoneNumber)));
   } catch (org.openxava.converters.ConversionException ex) {
     ex.printStackTrace();
     throw new RuntimeException(
         XavaResources.getString("generator.conversion_error", "ZoneNumber", "Office", "int"));
   }
 }
Пример #12
0
 public String getName() {
   try {
     return (String) getNameConverter().toJava(get_Name());
   } catch (org.openxava.converters.ConversionException ex) {
     ex.printStackTrace();
     throw new RuntimeException(
         XavaResources.getString("generator.conversion_error", "Name", "Size", "String"));
   }
 }
Пример #13
0
 public void setName(String newName) {
   try {
     set_Name((java.lang.String) getNameConverter().toDB(newName));
   } catch (org.openxava.converters.ConversionException ex) {
     ex.printStackTrace();
     throw new RuntimeException(
         XavaResources.getString("generator.conversion_error", "Name", "Size", "String"));
   }
 }
Пример #14
0
  private void loadDatabaseMetadata() {
    if (!databaseMetadataLoaded) {
      String componentName = "UNKNOWN";
      Connection con = null;
      try {
        componentName = getMetaComponent().getName();

        con = DataSourceConnectionProvider.getByComponent(componentName).getConnection();
        DatabaseMetaData metaData = con.getMetaData();
        supportsSchemasInDataManipulation = metaData.supportsSchemasInDataManipulation();
        Collection timeDateFunctions =
            Strings.toCollection(metaData.getTimeDateFunctions().toUpperCase());

        //
        // another solution instead of the use of 'if' would be to use a xml with
        //	the information of the functions from each BBDD
        if ("DB2 UDB for AS/400".equals(metaData.getDatabaseProductName())
            || "Oracle".equals(metaData.getDatabaseProductName())
            || "PostgresSQL".equals(metaData.getDatabaseProductName())) {
          supportsTranslateFunction = true;
        }
        if ("Oracle".equals(metaData.getDatabaseProductName())
            || "PostgreSQL".equals(metaData.getDatabaseProductName())) {
          supportsYearFunction = supportsMonthFunction = false;
        } else {
          supportsYearFunction = timeDateFunctions.contains("YEAR");
          supportsMonthFunction = timeDateFunctions.contains("MONTH");
        }
        databaseMetadataLoaded = true;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("load_database_metadata_warning"));
      } finally {
        try {
          if (con != null) {
            con.close();
          }
        } catch (SQLException e) {
          log.warn(XavaResources.getString("close_connection_warning"));
        }
      }
    }
  }
Пример #15
0
 private org.openxava.converters.IConverter getNameConverter() {
   if (nameConverter == null) {
     try {
       nameConverter =
           (org.openxava.converters.IConverter) getMetaModel().getMapping().getConverter("name");
     } catch (Exception ex) {
       ex.printStackTrace();
       throw new RuntimeException(
           XavaResources.getString("generator.create_converter_error", "name"));
     }
   }
   return nameConverter;
 }
Пример #16
0
 private boolean hasSome3LevelProperty(String sentence) throws XavaException {
   if (sentence == null) return false;
   int i = sentence.indexOf("${");
   int f = 0;
   while (i >= 0) {
     f = sentence.indexOf("}", i + 2);
     if (f < 0) break;
     String property = sentence.substring(i + 2, f);
     StringTokenizer st = new StringTokenizer(property, ".");
     if (st.countTokens() > 3) {
       log.warn(XavaResources.getString("property_3_level_in_ejb2_finder", property, getName()));
       return true;
     }
     if (st.countTokens() == 3) {
       if (!getMetaModel().getMetaProperty(property).isKey()) {
         log.warn(XavaResources.getString("property_3_level_in_ejb2_finder", property, getName()));
         return true;
       }
     }
     i = sentence.indexOf("${", i + 1);
   }
   return false;
 }
 private void associateKey(Map key) {
   try {
     associateEntity(key);
     added++;
   } catch (Exception ex) {
     addValidationMessage(ex);
     failed++;
     log.error(
         XavaResources.getString(
             "add_collection_element_error",
             getCollectionElementView().getModelName(),
             getCollectionElementView().getParent().getModelName()),
         ex);
   }
 }
Пример #18
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String[] uri = request.getRequestURI().split("/");
    if (uri.length < 4) {
      response.getWriter().print(XavaResources.getString(request, "module_name_missing"));
      return;
    }
    String url = "/naviox/index.jsp?application=" + uri[1] + "&module=" + uri[3];
    RequestDispatcher dispatcher = request.getRequestDispatcher(url);

    Style.setPotalInstance(
        NaviOXStyle
            .getInstance()); // We manage style in NaviOX as in the portal case, to override the
                             // style defined in xava.properties and by device
    dispatcher.forward(request, response);
  }
  public static void setCurrent(HttpServletRequest request) {
    Object rundata = request.getAttribute("rundata");
    String portalUser = (String) request.getSession().getAttribute("xava.portal.user");
    String webUser = (String) request.getSession().getAttribute("xava.user");
    String user = portalUser == null ? webUser : portalUser;
    if (Is.emptyString(user) && rundata != null) {
      PropertiesManager pmRundata = new PropertiesManager(rundata);
      try {
        Object jetspeedUser = pmRundata.executeGet("user");
        PropertiesManager pmUser = new PropertiesManager(jetspeedUser);
        user = (String) pmUser.executeGet("userName");
      } catch (Exception ex) {
        log.warn(XavaResources.getString("warning_get_user"), ex);
        user = null;
      }
    }
    municipioUsuario.set(user);
    request.getSession().setAttribute("xava.user", user);

    municipioUsuarioInfo.set(request.getSession().getAttribute("xava.portal.userinfo"));
  }
Пример #20
0
 public MetaTab cloneMetaTab() {
   try {
     MetaTab r = (MetaTab) clone();
     if (r.metaPropertiesHiddenCalculated != null) {
       r.metaPropertiesHiddenCalculated = new ArrayList(metaPropertiesHiddenCalculated);
     }
     if (r.metaPropertiesHidden != null) {
       r.metaPropertiesHidden = new ArrayList(metaPropertiesHidden);
     }
     if (r.propertiesNames != null) {
       r.propertiesNames = new ArrayList(propertiesNames);
     }
     if (r.metaProperties != null) {
       r.metaProperties = new ArrayList(metaProperties);
     }
     if (r.metaPropertiesCalculated != null) {
       r.metaPropertiesCalculated = new ArrayList(metaPropertiesCalculated);
     }
     if (r.tableColumns != null) {
       r.tableColumns = new ArrayList(tableColumns);
     }
     if (r.hiddenPropertiesNames != null) {
       r.hiddenPropertiesNames = new ArrayList(hiddenPropertiesNames);
     }
     if (r.propertiesNamesWithKeyAndHidden != null) {
       r.propertiesNamesWithKeyAndHidden = new ArrayList(propertiesNamesWithKeyAndHidden);
     }
     if (r.hiddenTableColumns != null) {
       r.hiddenTableColumns = new ArrayList(hiddenTableColumns);
     }
     if (r.metaPropertiesTab != null) {
       r.metaPropertiesTab = new HashMap(metaPropertiesTab);
     }
     return r;
   } catch (CloneNotSupportedException ex) {
     throw new RuntimeException(XavaResources.getString("clone_error", getClass()));
   }
 }
  public int doStartTag() throws JspException {
    try {
      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
      ModuleContext context = (ModuleContext) request.getSession().getAttribute("context");

      String viewObject = request.getParameter("viewObject");
      viewObject = (viewObject == null || viewObject.equals("")) ? "xava_view" : viewObject;
      View view = (View) context.get(request, viewObject);

      MetaReference metaReference = view.getMetaReference(reference).cloneMetaReference();
      metaReference.setName(reference);
      String prefix = request.getParameter("propertyPrefix");
      prefix = prefix == null ? "" : prefix;
      String application = request.getParameter("application");
      String module = request.getParameter("module");
      String referenceKey = Ids.decorate(application, module, prefix + reference);
      request.setAttribute(referenceKey, metaReference);
      String editorURL =
          "reference.jsp?referenceKey="
              + referenceKey
              + "&onlyEditor=true&frame=false&composite=false&descriptionsList=true";
      String editorPrefix = Module.isPortlet() ? "/WEB-INF/jsp/xava/" : "/xava/";
      try {
        pageContext.include(editorPrefix + editorURL);
      } catch (ServletException ex) {
        Throwable cause = ex.getRootCause() == null ? ex : ex.getRootCause();
        log.error(cause.getMessage(), cause);
        pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp");
      } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp");
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new JspException(XavaResources.getString("descriptionsList_tag_error", reference));
    }
    return SKIP_BODY;
  }
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      Locales.setCurrent(request);
      if (Users.getCurrent() == null) { // for a bug in websphere portal 5.1 with Domino LDAP
        Users.setCurrent((String) request.getSession().getAttribute("xava.user"));
      }
      request.getParameter("application"); // for a bug in websphere 5.1
      request.getParameter("module"); // for a bug in websphere 5.1
      Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab");
      int[] selectedRowsNumber =
          (int[]) request.getSession().getAttribute("xava_selectedRowsReportTab");
      Map[] selectedKeys = (Map[]) request.getSession().getAttribute("xava_selectedKeysReportTab");
      int[] selectedRows = getSelectedRows(selectedRowsNumber, selectedKeys, tab);
      request.getSession().removeAttribute("xava_selectedRowsReportTab");
      Integer columnCountLimit =
          (Integer) request.getSession().getAttribute("xava_columnCountLimitReportTab");
      request.getSession().removeAttribute("xava_columnCountLimitReportTab");

      setDefaultSchema(request);
      String user = (String) request.getSession().getAttribute("xava_user");
      request.getSession().removeAttribute("xava_user");
      Users.setCurrent(user);
      String uri = request.getRequestURI();
      if (uri.endsWith(".pdf")) {
        InputStream is;
        JRDataSource ds;
        Map parameters = new HashMap();
        synchronized (tab) {
          tab.setRequest(request);
          parameters.put("Title", tab.getTitle());
          parameters.put("Organization", getOrganization());
          parameters.put("Date", getCurrentDate());
          for (String totalProperty : tab.getTotalPropertiesNames()) {
            parameters.put(totalProperty + "__TOTAL__", getTotal(request, tab, totalProperty));
          }
          TableModel tableModel = getTableModel(request, tab, selectedRows, false, true, null);
          tableModel.getValueAt(0, 0);
          if (tableModel.getRowCount() == 0) {
            generateNoRowsPage(response);
            return;
          }
          is = getReport(request, response, tab, tableModel, columnCountLimit);
          ds = new JRTableModelDataSource(tableModel);
        }
        JasperPrint jprint = JasperFillManager.fillReport(is, parameters, ds);
        response.setContentType("application/pdf");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".pdf\"");
        JasperExportManager.exportReportToPdfStream(jprint, response.getOutputStream());
      } else if (uri.endsWith(".csv")) {
        String csvEncoding = XavaPreferences.getInstance().getCSVEncoding();
        if (!Is.emptyString(csvEncoding)) {
          response.setCharacterEncoding(csvEncoding);
        }
        response.setContentType("text/x-csv");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".csv\"");
        synchronized (tab) {
          tab.setRequest(request);
          response
              .getWriter()
              .print(
                  TableModels.toCSV(
                      getTableModel(request, tab, selectedRows, true, false, columnCountLimit)));
        }
      } else {
        throw new ServletException(
            XavaResources.getString("report_type_not_supported", "", ".pdf .csv"));
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new ServletException(XavaResources.getString("report_error"));
    } finally {
      request.getSession().removeAttribute("xava_reportTab");
    }
  }
Пример #23
0
 public void setDefaultCarrier(org.openxava.test.model.ICarrier newCarrier) {
   if (newCarrier != null && !(newCarrier instanceof org.openxava.test.model.Carrier)) {
     throw new IllegalArgumentException(XavaResources.getString("ejb_to_pojo_illegal"));
   }
   this.defaultCarrier = newCarrier;
 }
Пример #24
0
 public void setSubfamily(org.openxava.test.model.ISubfamily2 newSubfamily2) {
   if (newSubfamily2 != null && !(newSubfamily2 instanceof org.openxava.test.model.Subfamily2)) {
     throw new IllegalArgumentException(XavaResources.getString("ejb_to_pojo_illegal"));
   }
   this.subfamily = newSubfamily2;
 }