<p>
Read attributes from stream. Start the XML element
must be read out.
</p>
@param pReader reader.
@param pAddParam additional params
@return attributes map
@throws Exception - an exception
184180
@Override
  public final Map<String, String> readAttributes(final Reader pReader,
    final Map<String, Object> pAddParam) throws Exception {
    Map<String, String> attributesMap = new HashMap<String, String>();
    StringBuffer sb = new StringBuffer();
    int chi;
    while ((chi = pReader.read()) != -1) {
      char ch = (char) chi;
      if (ch == '>') {
        break;
      }
      switch (ch) {
        case '\\':
          sb.append("\\");
          break;
        case '"':
          sb.append("\"");
          break;
        case '\n':
          sb.append("\n");
          break;
        case '\r':
          sb.append("\r");
          break;
        case '\t':
          sb.append("\t");
          break;
        default:
          sb.append(ch);
          break;
      }
      evalAttributes(sb, attributesMap);
    }
    return attributesMap;
  }
461183
@Override
  public final <T> void fill(final Map<String, Object> pAddParam,
    final T pEntity, final IRequestData pReq) throws Exception {
    boolean isDbgSh = this.logger.getDbgSh(this.getClass())
      && this.logger.getDbgFl() < 7010 && this.logger.getDbgCl() > 7015;
    if (isDbgSh) {
      this.logger.debug(null, FillEntityFromReq.class,
        "Default charset = " + Charset.defaultCharset());
    }
    @SuppressWarnings("unchecked")
    IFillerObjectFields<T> filler = (IFillerObjectFields<T>)
      this.fillersFieldsFactory.lazyGet(pAddParam, pEntity.getClass());
    for (String fieldName : filler.getFieldsNames()) {
      try {
        String valStr = pReq.getParameter(pEntity.getClass().getSimpleName()
          + "." + fieldName); // standard
        if (valStr != null) { // e.g. Boolean checkbox or none-editable
          String convName = this.fieldConverterNamesHolder.getFor(pEntity
           .getClass(), fieldName);
          if (isDbgSh) {
            this.logger.debug(null, FillEntityFromReq.class,
              "Try fill field/inClass/converterName/value: " + fieldName + "/"
                + pEntity.getClass().getCanonicalName() + "/" + convName
                  + "/" + valStr);
          }
          IConverterToFromString conv = this.convertersFieldsFatory
            .lazyGet(pAddParam, convName);
          Object fieldVal = conv.fromString(pAddParam,  valStr);
          if (fieldVal != null && isDbgSh) {
              this.logger.debug(null, FillEntityFromReq.class,
                "Converted fieldClass/toString: " + fieldVal.getClass()
                  .getCanonicalName() + "/" + fieldVal);
          }
          filler.fill(pAddParam, pEntity, fieldVal, fieldName);
        }
      } catch (Exception ex) {
        String msg = "Can't fill field/class: " + fieldName + "/"
          + pEntity.getClass().getCanonicalName();
        throw new ExceptionWithCode(ExceptionWithCode.SOMETHING_WRONG, msg, ex);
      }
    }
  }
240635
public AttributeDataset parse(String name, InputStream stream) throws IOException, ParseException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

        String line = reader.readLine();
        if (line == null) {
            throw new IOException("Empty data source.");
        }

        String[] tokens = line.split("\t", -1);
        int p = (tokens.length - 2) / 2;

        line = reader.readLine();
        if (line == null) {
            throw new IOException("Premature end of file.");
        }

        String[] samples = line.split("\t", -1);
        if (samples.length != tokens.length-1) {
            throw new IOException("Invalid sample description header.");
        }
        
        Attribute[] attributes = new Attribute[p];
        for (int i = 0; i < p; i++) {
            attributes[i] = new NumericAttribute(tokens[2*i+2], samples[2*i+1]);
        }
        
        line = reader.readLine();
        if (line == null) {
            throw new IOException("Premature end of file.");
        }

        int n = Integer.parseInt(line);
        if (n <= 0) {
            throw new IOException("Invalid number of rows: " + n);            
        }
        
        AttributeDataset data = new AttributeDataset(name, attributes);
        
        for (int i = 0; i < n; i++) {
            line = reader.readLine();
            if (line == null) {
                throw new IOException("Premature end of file.");
            }
            
            tokens = line.split("\t", -1);
            if (tokens.length != samples.length+1) {
                throw new IOException(String.format("Invalid number of elements of line %d: %d", i+4, tokens.length));
            }

            double[] x = new double[p];
            for (int j = 0; j < p; j++) {
                x[j] = Double.valueOf(tokens[2*j+2]);
            }

            AttributeDataset.Row datum = data.add(x);
            datum.name = tokens[1];
            datum.description = tokens[0];
        }
        
        reader.close();
        return data;
    }
184592
@Override
  public final void process(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    String retrieverName = pRequestData.getParameter("nmRet");
    ICsvDataRetriever ret = this.retrievers.get(retrieverName);
    if (ret == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "Can't find retriever " + retrieverName);
    }
    pRequestData.setAttribute("dataTree", ret.getSampleDataRow(pAddParam));
  }
1339946
protected final PrcInvoiceGfe<IInvoice> lazyGetPrcInvoiceGfe(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcInvoiceGfe<IInvoice> proc = (PrcInvoiceGfe<IInvoice>)
      this.processorsMap.get(PrcInvoiceGfe.class.getSimpleName());
    if (proc == null) {
      proc = new PrcInvoiceGfe<IInvoice>();
      @SuppressWarnings("unchecked")
      PrcEntityPbEditDelete<RS, IInvoice> procDlg =
    (PrcEntityPbEditDelete<RS, IInvoice>) this.fctBnEntitiesProcessors
  .lazyGet(pAddParam, PrcEntityPbEditDelete.class.getSimpleName());
      proc.setPrcEntityPbEditDelete(procDlg);
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcInvoiceGfe.class.getSimpleName(), proc);
    }
    return proc;
  }
473977
protected final PrcAbout<RS> lazyGetPrcAbout(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcAbout<RS> proc = (PrcAbout<RS>) this.processorsMap
      .get(PrcAbout.class.getSimpleName());
    if (proc == null) {
      proc = new PrcAbout<RS>();
      proc.setSrvOrm(getSrvOrm());
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcAbout.class.getSimpleName(), proc);
    }
    return proc;
  }
256964
@Override
  public final void process(final Map<String, Object> pAddParam,
    final IRequestData pRequestData) throws Exception {
    String itemType = pRequestData.getParameter("itemType");
    if (InvItem.class.getSimpleName().equals(itemType)) {
      makeIt(pAddParam, pRequestData, InvItem.class);
    } else if (ServiceToSale.class.getSimpleName().equals(itemType)) {
      makeIt(pAddParam, pRequestData, ServiceToSale.class);
    } else {
      throw new Exception("NYI: " + itemType);
    }
  }
1084007
protected final PrcBankStatementLineSave<RS> lazyGetPrcBankStatementLineSave(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcBankStatementLineSave<RS> proc = (PrcBankStatementLineSave<RS>)
      this.processorsMap.get(PrcBankStatementLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcBankStatementLineSave<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvI18n(getSrvI18n());
      proc.setSrvAccEntry(getSrvAccEntry());
      proc.setPrcPurchaseInvoiceSave(lazyGetPrcPurchaseInvoiceSave(pAddParam));
      proc.setPrcSalesInvoiceSave(lazyGetPrcSalesInvoiceSave(pAddParam));
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcBankStatementLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }
1251042
private void readInstance(StreamTokenizer tokenizer, AttributeDataset data, Attribute[] attributes) throws IOException, ParseException {
        double[] x = responseIndex >= 0 ? new double[attributes.length - 1] : new double[attributes.length];
        double y = Double.NaN;
        
        // Get values for all attributes.
        for (int i = 0, k = 0; i < attributes.length; i++) {
            // Get next token
            if (i > 0) {
                getNextToken(tokenizer);
            }

            if (i == responseIndex) {
                if (tokenizer.ttype == '?') {
                    y = Double.NaN;
                } else {
                    y = attributes[i].valueOf(tokenizer.sval);
                }
            } else {
                if (tokenizer.ttype == '?') {
                    x[k++] = Double.NaN;
                } else {
                    x[k++] = attributes[i].valueOf(tokenizer.sval);
                }
            }
        }

        if (Double.isNaN(y)) data.add(x); else data.add(x, y);
    }
808596
public final synchronized void retrieveAccSettings(
    final Map<String, Object> pAddParam) throws Exception {
    this.accSettings = new AccSettings();
    this.accSettings.setItsId(1L);
    this.accSettings = getSrvOrm().retrieveEntity(pAddParam, this.accSettings);
    if (this.accSettings == null) {
      throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE,
        "There is no accounting settings!!!");
    }
    DrawMaterialSourcesLine dmsl = new DrawMaterialSourcesLine();
    dmsl.setItsOwner(this.accSettings);
    List<DrawMaterialSourcesLine> drawMaterialSources = getSrvOrm()
      .retrieveListForField(pAddParam, dmsl, "itsOwner");
    this.accSettings.setDrawMaterialSources(drawMaterialSources);
    CogsItemSourcesLine cisl = new CogsItemSourcesLine();
    cisl.setItsOwner(this.accSettings);
    List<CogsItemSourcesLine> cogsItemSources = getSrvOrm()
      .retrieveListForField(pAddParam, cisl, "itsOwner");
    this.accSettings.setCogsItemSources(cogsItemSources);
    AccEntriesSourcesLine aesl = new AccEntriesSourcesLine();
    aesl.setItsOwner(this.accSettings);
    List<AccEntriesSourcesLine> accEntriesSources = getSrvOrm()
      .retrieveListForField(pAddParam, aesl, "itsOwner");
    this.accSettings.setAccEntriesSources(accEntriesSources);
  }
520406
protected final PrBur<RS> lazyGetPrBur(
    final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrBur.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrBur<RS> proc = (PrBur<RS>)
      this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrBur<RS>();
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvDb(getSrvDatabase());
      proc.setLog(getLogger());
      proc.setProcFac(this);
      proc.setBuySr(getBuySr());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnPublicTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }
969938
@Override
  public final AItemSpecifics<T, ID> process(
    final Map<String, Object> pReqVars,
      final AItemSpecifics<T, ID> pEntity,
        final IRequestData pRequestData) throws Exception {
    String fileToUploadName = (String) pRequestData
      .getAttribute("fileToUploadName");
    OutputStream outs = null;
    InputStream ins = null;
    try {
      String filePath;
      if (pEntity.getStringValue1() == null) { //in base language:
        String ft = String.valueOf(new Date().getTime());
        filePath = this.webAppPath + File.separator
          + this.uploadDirectory + File.separator
            + ft + fileToUploadName;
        pEntity.setStringValue2(filePath);
        pEntity.setStringValue1(this.uploadDirectory
              + "/" + ft + fileToUploadName);
      } else { //I18N files:
        String fileLang = pRequestData.getParameter("fileLang");
        if (pEntity.getStringValue3() == null
          || !pEntity.getStringValue3().contains(fileLang)) {
          throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
            "notset_language");
        }
        int idhHtml = pEntity.getStringValue1().indexOf(".html");
        String urlWithoutHtml = pEntity.getStringValue1().substring(0, idhHtml);
        filePath = this.webAppPath + File.separator
          + urlWithoutHtml + "_" + fileLang + ".html";
      }
      ins = (InputStream) pRequestData.getAttribute("fileToUploadInputStream");
      outs = new BufferedOutputStream(new FileOutputStream(filePath));
      byte[] data = new byte[1024];
      int count;
      while ((count = ins.read(data)) != -1) {
        outs.write(data, 0, count);
      }
      outs.flush();
    } finally {
      if (ins != null) {
        ins.close();
      }
      if (outs != null) {
        outs.close();
      }
    }
    getSrvOrm().updateEntity(pReqVars, pEntity);
    return pEntity;
  }
254403
protected final PrcAdditionCostLineDelete<RS>
    lazyGetPrcAdditionCostLineDelete(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcAdditionCostLineDelete<RS> proc = (PrcAdditionCostLineDelete<RS>)
      this.processorsMap.get(PrcAdditionCostLineDelete.class.getSimpleName());
    if (proc == null) {
      proc = new PrcAdditionCostLineDelete<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvDatabase(getSrvDatabase());
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcAdditionCostLineDelete.class.getSimpleName(), proc);
    }
    return proc;
  }
587222
protected final PrcPageWithSubaccTypes<RS>
    createPutPrcPageWithSubaccTypes(
      final Map<String, Object> pAddParam) throws Exception {
    PrcPageWithSubaccTypes<RS> proc = new PrcPageWithSubaccTypes<RS>();
    PrcEntitiesPage procDlg = (PrcEntitiesPage) this.fctBnProcessors
      .lazyGet(pAddParam, PrcEntitiesPage.class.getSimpleName());
    proc.setPrcAccEntitiesPage(procDlg);
    proc.setSrvTypeCode(getSrvTypeCode());
    //assigning fully initialized object:
    this.processorsMap
      .put(PrcPageWithSubaccTypes.class.getSimpleName(), proc);
    return proc;
  }
591708
@Override
  public ParseResult parse(Reader reader, AttributeSource parent)
      throws IOException {
    ParseResult res = new ParseResult();

    // get MtasUpdateRequestProcessorResult
    StringBuilder sb = new StringBuilder();
    char[] buf = new char[128];
    int cnt;
    while ((cnt = reader.read(buf)) > 0) {
      sb.append(buf, 0, cnt);
    }
    Iterator<MtasUpdateRequestProcessorResultItem> iterator;

    try (
        MtasUpdateRequestProcessorResultReader result = new MtasUpdateRequestProcessorResultReader(
            sb.toString());) {
      iterator = result.getIterator();
      if (iterator != null && iterator.hasNext()) {
        res.str = result.getStoredStringValue();
        res.bin = result.getStoredBinValue();
      } else {
        res.str = null;
        res.bin = null;
        result.close();
        return res;
      }
      parent.clearAttributes();
      while (iterator.hasNext()) {
        MtasUpdateRequestProcessorResultItem item = iterator.next();
        if (item.tokenTerm != null) {
          CharTermAttribute catt = parent.addAttribute(CharTermAttribute.class);
          catt.append(item.tokenTerm);
        }
        if (item.tokenFlags != null) {
          FlagsAttribute flags = parent.addAttribute(FlagsAttribute.class);
          flags.setFlags(item.tokenFlags);
        }
        if (item.tokenPosIncr != null) {
          PositionIncrementAttribute patt = parent
              .addAttribute(PositionIncrementAttribute.class);
          patt.setPositionIncrement(item.tokenPosIncr);
        }
        if (item.tokenPayload != null) {
          PayloadAttribute p = parent.addAttribute(PayloadAttribute.class);
          p.setPayload(new BytesRef(item.tokenPayload));
        }
        if (item.tokenOffsetStart != null && item.tokenOffsetEnd != null) {
          OffsetAttribute offset = parent.addAttribute(OffsetAttribute.class);
          offset.setOffset(item.tokenOffsetStart, item.tokenOffsetEnd);
        }
        // capture state and add to result
        State state = parent.captureState();
        res.states.add(state.clone());
        // reset for reuse
        parent.clearAttributes();
      }
    } catch (IOException e) {
      // ignore
      log.debug(e);
    }
    return res;
  }
953647
@Override
  public final boolean readUntilStart(final Reader pReader,
    final String pElement) throws Exception {
    StringBuffer sb = new StringBuffer();
    int chi;
    boolean isLtOccured = false;
    while ((chi = pReader.read()) != -1) {
      char ch = (char) chi;
      if (isLtOccured) {
        if (ch ==  '>' || ch == '\n' || ch == '\\' || ch == '"' || ch == '\r'
          || ch == '\t') {
          isLtOccured = false;
          sb.delete(0, sb.length());
          continue;
        }
        sb.append(ch);
        String readedStr = sb.toString();
        if (readedStr.length() > pElement.length()) {
          isLtOccured = false;
          sb.delete(0, sb.length());
          continue;
        }
        if (pElement.equals(readedStr)) {
          return true;
        }
      } else if (ch == '<') {
        isLtOccured = true;
      }
    }
    return false;
  }
1143717
public static XMLStreamException invalidAttributeValue(final XMLStreamReader reader, final int index) {
        return new XMLStreamException("Invalid value '" + reader.getAttributeValue(index) + "' for attribute '"
                + reader.getAttributeName(index) + "'", reader.getLocation());
    }