Example #1
0
 public static void postProperty() {
   String name = params.get("name");
   String value = params.get("value");
   Prop p = new Prop();
   p.name = name;
   p.value = value;
   p.save();
   renderText(p.id.toString());
 }
Example #2
0
  public static void removeProperty() {
    String id = params.get("id");
    Prop p = Prop.findById(Long.valueOf(id));
    List<Specification> specifications =
        Specification.em()
            .createQuery(
                "select r from Specification r join fetch r.properties s where s.id="
                    + Long.valueOf(id),
                Specification.class)
            .getResultList();

    for (Specification spec : specifications) {
      spec.properties.remove(p);
      spec.save();
    }
    if (p != null) p.delete();
    renderText(id);
  }
Example #3
0
  /**
   * Initializes the scanner.
   *
   * @param f input file
   * @param pr database properties
   * @param frag allow parsing of document fragment
   * @throws IOException I/O exception
   */
  XMLScanner(final IO f, final Prop pr, final boolean frag) throws IOException {
    input = new XMLInput(f);
    fragment = frag;

    try {
      for (int e = 0; e < ENTITIES.length; e += 2) {
        ents.add(token(ENTITIES[e]), token(ENTITIES[e + 1]));
      }
      dtd = pr.is(Prop.DTD);
      chop = pr.is(Prop.CHOP);

      String enc = null;
      // process document declaration...
      if (consume(DOCDECL)) {
        if (s()) {
          if (!version()) error(DECLSTART);
          boolean s = s();
          enc = encoding();
          if (enc != null) {
            if (!s) error(WSERROR);
            s = s();
          }
          if (sddecl() != null && !s) error(WSERROR);
          s();
          final int ch = nextChar();
          if (ch != '?' || nextChar() != '>') error(DECLWRONG);
        } else {
          prev(5);
        }
      }
      encoding = enc == null ? UTF8 : enc;

      if (!fragment) {
        final int n = consume();
        if (!s(n)) {
          if (n != '<') error(BEFOREROOT);
          prev(1);
        }
      }
    } catch (final IOException ex) {
      input.close();
      throw ex;
    }
  }
Example #4
0
  public static void impSpec(File file) {
    if (file != null) {
      List<Specification> specifications = new ArrayList<Specification>();
      Specification spec = null;
      Material material = null;
      try {
        FileInputStream fileInputStream = new FileInputStream(file);
        HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
        HSSFSheet worksheet = workbook.getSheetAt(0);
        HSSFRow row = null;
        HSSFCell cell = null;
        Map<Integer, String> headerMap = new HashMap<Integer, String>();
        Prop prop = null;
        if (worksheet.getLastRowNum() > 0) {
          row = worksheet.getRow(0);
          for (int i = 0; i < row.getLastCellNum(); i++) {
            headerMap.put(Integer.valueOf(i), row.getCell(i).getStringCellValue());
          }
        }
        for (int i = 1; i < worksheet.getLastRowNum(); i++) {
          row = worksheet.getRow(i);
          cell = row.getCell(0);
          String materialName = cell.getStringCellValue();

          cell = row.getCell(1);
          String specification = cell.getStringCellValue();

          cell = row.getCell(2);
          Double number = cell.getNumericCellValue();

          cell = row.getCell(3);
          String unit = cell.getStringCellValue();

          cell = row.getCell(4);
          String company = cell.getStringCellValue();

          cell = row.getCell(5);
          Date date = cell.getDateCellValue();

          cell = row.getCell(6);
          String description = cell.getStringCellValue();

          spec = new Specification();

          for (int x = 7; x < row.getLastCellNum(); x++) {
            cell = row.getCell(x);
            String value = "";
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            prop = new Prop();
            prop.name = headerMap.get(x);
            prop.value = value;
            prop.save();
            spec.properties.add(prop);
          }

          spec.name = specification;
          spec.specification = specification;
          if (number != null && !"".equals(number)) spec.amount = number;
          spec.unit = unit;
          spec.company = company;
          if (materialName != null && !"".equals(materialName)) {
            material = Material.find("name=?", materialName.trim()).first();
            spec.material = material;
          }
          spec.arrival_time = date;
          spec.description = description;
          spec.save();
          specifications.add(spec);
        }

        renderJSON(specifications);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }