/** Deserializes the object from XML */
  public DataReported parseReported(XMLStreamReader in) throws IOException, XMLStreamException {
    DataReported reported = new DataReported();

    ArrayList<DataField> fieldList = new ArrayList<DataField>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        reported.setFieldList(fieldList);

        return reported;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) {
        fieldList.add(parseField(in));
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "reported");

    return reported;
  }
Ejemplo n.º 2
0
  public void render(FacesContext context) throws FacesException {
    if (context.getResponseComplete()) return;

    Application app = context.getApplication();
    ViewHandler view = app.getViewHandler();

    beforePhase(context, PhaseId.RENDER_RESPONSE);

    try {
      if (log.isLoggable(Level.FINER)) log.finer(context.getViewRoot() + " before render view");

      view.renderView(context, context.getViewRoot());
    } catch (java.io.IOException e) {
      if (sendError(context, "renderView", e)) return;

      throw new FacesException(e);
    } catch (RuntimeException e) {
      if (sendError(context, "renderView", e)) return;

      throw e;
    } finally {
      afterPhase(context, PhaseId.RENDER_RESPONSE);

      logMessages(context);
    }
  }
Ejemplo n.º 3
0
 private void doPublish(
     String name,
     Object val,
     String src,
     String dpt,
     String textual,
     long updateTime,
     long lastChange) {
   JsonObject jso = new JsonObject();
   jso.add("ts", updateTime).add("lc", lastChange).add("knx_src_addr", src).add("knx_dpt", dpt);
   if (textual != null) jso.add("knx_textual", textual);
   if (val instanceof Integer) jso.add("val", ((Integer) val).intValue());
   else if (val instanceof Number) jso.add("val", ((Number) val).doubleValue());
   else jso.add("val", val.toString());
   String txtmsg = jso.toString();
   MqttMessage msg = new MqttMessage(jso.toString().getBytes(StandardCharsets.UTF_8));
   msg.setQos(0);
   msg.setRetained(true);
   try {
     String fullTopic = topicPrefix + "status/" + name;
     mqttc.publish(fullTopic, msg);
     L.finer("Published " + txtmsg + " to " + fullTopic);
   } catch (MqttException e) {
     L.log(Level.WARNING, "Error when publishing message " + txtmsg, e);
   }
 }
Ejemplo n.º 4
0
  @Override
  public boolean login(boolean isFail) {
    try {
      WebApp webApp = getWebApp();

      if (webApp == null) {
        if (log.isLoggable(Level.FINE)) log.finer("authentication failed, no web-app found");

        getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);

        return false;
      }

      // If the authenticator can find the user, return it.
      Login login = webApp.getLogin();

      if (login != null) {
        Principal user = login.login(this, getResponse(), isFail);

        return user != null;
        /*
        if (user == null)
          return false;

        setAttribute(AbstractLogin.LOGIN_NAME, user);

        return true;
        */
      } else if (isFail) {
        if (log.isLoggable(Level.FINE))
          log.finer("authentication failed, no login module found for " + webApp);

        getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);

        return false;
      } else {
        // if a non-failure, then missing login is fine

        return false;
      }
    } catch (IOException e) {
      log.log(Level.FINE, e.toString(), e);

      return false;
    }
  }
Ejemplo n.º 5
0
 public void xRequestFocus() {
   XToolkit.awtLock();
   try {
     if (focusLog.isLoggable(Level.FINER))
       focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
     XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Ejemplo n.º 6
0
  /** Bucle principal del thread. */
  public void run() {

    try {
      while (true) {
        mylogger.finer("Waiting for a message.");
        String pkt = myPP.receive();

        mylogger.finer("Received message: " + pkt);

        if (pkt == null) break;

        StringTokenizer st = new StringTokenizer(pkt);

        int nsec = Integer.parseInt(st.nextToken());

        if (st.hasMoreTokens()) {
          String disp = st.nextToken();
          mylogger.fine("Requesting Start to Peers (" + nsec + "," + disp + ")");
          NeReDa.peers.start(this, nsec, disp, null);
        } else {
          mylogger.fine("Requesting Stop to Peers (" + nsec + ")");
          NeReDa.peers.stop(this, nsec);
        }
      }
    } catch (Exception e) {
      mylogger.warning("Terminated DataAttendant: " + e.getMessage());
    }

    try {
      synchronized (sock) {
        sock.close();
        sock.notify();
      }

    } catch (Exception e) {
      mylogger.warning("Closing DataAttendant socket: " + e.getMessage());
    }

    mylogger.fine("Deregistering");
    NeReDa.peers.Del(this);
  }
  /** Deserializes the object from XML */
  public DataField parseField(XMLStreamReader in) throws IOException, XMLStreamException {
    String label = in.getAttributeValue(null, "label");
    String type = in.getAttributeValue(null, "type");
    String var = in.getAttributeValue(null, "var");

    DataField field = new DataField(type, var, label);

    ArrayList<DataValue> valueList = new ArrayList<DataValue>();
    ArrayList<DataOption> optionList = new ArrayList<DataOption>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        field.setValueList(valueList);
        field.setOptionList(optionList);

        return field;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "desc".equals(in.getLocalName())) {
        String desc = in.getElementText();

        field.setDesc(desc);

        skipToEnd(in, "desc");
      } else if (XMLStreamReader.START_ELEMENT == tag && "option".equals(in.getLocalName())) {
        optionList.add(parseOption(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "required".equals(in.getLocalName())) {
        field.setRequired(true);

        skipToEnd(in, "required");
      } else if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) {
        String value = in.getElementText();

        valueList.add(new DataValue(value));

        skipToEnd(in, "value");
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "field");

    return field;
  }
  /** Deserializes the object from XML */
  public Serializable fromXml(XmppStreamReader in) throws IOException, XMLStreamException {
    boolean isFinest = log.isLoggable(Level.FINEST);

    String type = in.getAttributeValue(null, "type");

    DataForm form = new DataForm(type);

    ArrayList<DataField> fieldList = new ArrayList<DataField>();
    ArrayList<DataItem> itemList = new ArrayList<DataItem>();
    ArrayList<DataInstructions> instructionsList = new ArrayList<DataInstructions>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        form.setFieldList(fieldList);
        form.setItemList(itemList);
        form.setInstructionsList(instructionsList);

        return form;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) {
        fieldList.add(parseField(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "item".equals(in.getLocalName())) {
        itemList.add(parseItem(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "reported".equals(in.getLocalName())) {
        form.setReported(parseReported(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "title".equals(in.getLocalName())) {
        String title = in.getElementText();

        form.setTitle(title);

        skipToEnd(in, "title");
      } else if (XMLStreamReader.START_ELEMENT == tag && "instructions".equals(in.getLocalName())) {
        String value = in.getElementText();

        instructionsList.add(new DataInstructions(value));

        skipToEnd(in, "instructions");
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    return null;
  }
Ejemplo n.º 9
0
 private void processSetGet(String namePart, MqttMessage msg, boolean set) {
   if (msg.isRetained()) {
     L.finer("Ignoring retained message " + msg + " to " + namePart);
     return;
   }
   // Now translate the topic into a group address
   GroupAddressInfo gai = GroupAddressManager.getGAInfoForName(namePart);
   if (gai == null) {
     L.warning(
         "Unable to translate name "
             + namePart
             + " into a group address, ignoring message "
             + msg);
     return;
   }
   L.fine("Name " + namePart + " translates to GA " + gai.address);
   String data = new String(msg.getPayload(), StandardCharsets.UTF_8);
   if (set) KNXConnector.doGroupWrite(gai.address, data, gai);
   else KNXConnector.doGroupRead(gai.address, data, gai);
 }
  /** Deserializes the object from XML */
  public DataOption parseOption(XMLStreamReader in) throws IOException, XMLStreamException {
    String label = in.getAttributeValue(null, "label");

    DataOption option = new DataOption(label);

    ArrayList<DataValue> valueList = new ArrayList<DataValue>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        option.setValueList(valueList);

        return option;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) {
        String value = in.getElementText();

        valueList.add(new DataValue(value));

        skipToEnd(in, "value");
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "option");

    return option;
  }
Ejemplo n.º 11
0
 public int run(PbTest[] tests, int timelimit, int memlimit) throws ServerException {
   allStdout = new ArrayList<String>();
   allStderr = new ArrayList<String>();
   int correct = 0;
   for (int i = 0; i < tests.length; ++i) {
     try {
       exec(runCmd, tests[i].in, timelimit, memlimit);
       allStdout.add(stdout);
       allStderr.add(stderr);
       if (!stderr.isEmpty()) {
         log.fine("NOK, stderr: " + stderr);
         continue;
       }
       if (!validator.ok(stdout, tests[i].out)) continue;
       log.fine("OK");
       ++correct;
     } catch (Exception e) {
       // Assume incorrect. Do NOT propagate anyhing from the exception to
       // the client, just put it in the log.
       log.finer("exc: " + UtilSrv.describe(e));
     }
   }
   return correct;
 }
Ejemplo n.º 12
0
  /**
   * Examines the contents of the string passed as a received message and checks it for problems. If
   * there is any reasons why the string may be considered erroneous then it is thrown out. Accepted
   * strings are broken into their constituent parts and stored in the back-end database and
   * outputted to the screen.
   *
   * <p>Checks against the contents of the received message are performed in the following order:
   *
   * <ul>
   *   <li>Is the string greater than 33 characters?
   *   <li>Does the string have '(', ')' or ' '?
   *   <li>Is the first token (from the start of the string to the first space) in the format (n)?
   *   <li>Is the token for the PSE name less than or equal to 8 characters?
   * </ul>
   *
   * If any of these checks fail then the string being processed is rejected and considered to be a
   * transmission error, error in configuration or link error.
   */
  public void formatMessage() {
    log.finer("Starting processing of message: " + incomingMessage);
    // Trim any whitespace from the string
    incomingMessage = incomingMessage.trim();
    if (incomingMessage.length() < 33) {
      // If the string is too short then throw it out
      return;
    }
    if (!incomingMessage.contains("(")
        && !incomingMessage.contains(")")
        && !incomingMessage.contains(" ")) {
      // If the string doesn't contain any brackets (parentheses) or spaces then throw it out
      return;
    }
    StringTokenizer stMsg = new StringTokenizer(incomingMessage);
    String token = "";
    String nextToken = "";
    String sSev = "5"; // Messages received should vary from 1-4. This is to spot problems
    token = stMsg.nextToken();
    if (token.length() != 3 && !token.startsWith("(") && !token.endsWith(")")) {
      // The first token should be the severity level of the message and be in the format (n).
      // If it's too long or not in the right format then throw the message out.
      return;
    } else {
      sSev = token.substring(1, 2);
    }
    // Second token should be the PSE name
    token = stMsg.nextToken();
    nextToken = stMsg.nextToken();
    String sPSENode = "";
    if (token.length() < 8) {
      // See if the next token is part of the PSE name.
      // If the total length of the two strings is 8 or less then they're part of the PSE name
      if ((token.length() + nextToken.length()) <= 8) {
        sPSENode = token + nextToken;
        nextToken = "";
      } else {
        sPSENode = token;
      }

    } else if (token.length() == 8) {
      sPSENode = token;
    } else {
      // The value for the token is too long to be a valid PSE name so throw it out.
      return;
    }
    // Try and get the date. If the nextToken is blank then we need to get the
    // date. If not then it holds the date
    if (nextToken.equals("")) {
      token = stMsg.nextToken(); // This will put the date into the token string
      nextToken = stMsg.nextToken(); // This will put the time into the next string
    } else {
      token = nextToken.toString(); // Move the date into the first string
      nextToken = stMsg.nextToken(); // Get the time and place into the second string
    }
    String sDate = "";
    String sDay = token.substring(0, 2);
    String sMonth = token.substring(3, 6);
    String sYear = token.substring(7, 11);
    String sHour = nextToken.substring(0, 2);
    String sMin = nextToken.substring(3, 5);
    if (sMonth.equals("JAN")) {
      sMonth = "01";
    }
    if (sMonth.equals("FEB")) {
      sMonth = "02";
    }
    if (sMonth.equals("MAR")) {
      sMonth = "03";
    }
    if (sMonth.equals("APR")) {
      sMonth = "04";
    }
    if (sMonth.equals("MAY")) {
      sMonth = "05";
    }
    if (sMonth.equals("JUN")) {
      sMonth = "06";
    }
    if (sMonth.equals("JUL")) {
      sMonth = "07";
    }
    if (sMonth.equals("AUG")) {
      sMonth = "08";
    }
    if (sMonth.equals("SEP")) {
      sMonth = "09";
    }
    if (sMonth.equals("OCT")) {
      sMonth = "10";
    }
    if (sMonth.equals("NOV")) {
      sMonth = "11";
    }
    if (sMonth.equals("DEC")) {
      sMonth = "12";
    }
    sDate = new String(sDay + "/" + sMonth + "/" + sYear + " " + sHour + ":" + sMin);
    sDay = null;
    sMonth = null;
    sYear = null;
    sHour = null;
    sMin = null;

    String sLinkID = "?";
    String sError = "";
    token = stMsg.nextToken();
    boolean hasChannel = false;
    String sChannel = "";
    if ((token.length() < 7) && token.contains("-")) {
      // We've got to pick out the link id on the PSE
      sLinkID = token.toString();
      // Skip the next token as it's only a hyphen
      token = stMsg.nextToken();
    }
    if (token.length() < 11 && token.contains("(") && token.contains(")")) {
      // If the code enters here then the token includes the channel number X25-nn(xx)
      sLinkID = token.substring(0, token.indexOf("("));
      sChannel = "on channel " + token.substring(token.indexOf("(") + 1, token.indexOf(")"));
      hasChannel = true;
      // Skip the next token as it's only a hyphen
      token = stMsg.nextToken();
    }
    if (token.equals("-")) {
      token = stMsg.nextToken();
      sError = sError + token + " ";
    } else {
      sError = sError + token + " ";
    }
    while (stMsg.hasMoreTokens()) {
      token = stMsg.nextToken();
      sError = sError + token + " ";
    }
    if (hasChannel) {
      sError = sError + sChannel;
    }
    sError = sError.trim();
    log.finer(sSev + ", " + sPSENode + ", " + sDate + ", " + sLinkID + ", " + sError);

    // Severity, PSE, Link, Message, Received, Unique ID
    formattedMessage[0] = sSev;
    formattedMessage[1] = sPSENode;
    formattedMessage[2] = sLinkID;
    formattedMessage[3] = sError;
    formattedMessage[4] = sDate;
    formattedMessage[5] = UUID.randomUUID().toString();

    log.entering("formatMessage", "UnformattedMessage.storeDataInDb(String)", formattedMessage);
    storeDataInDb(formattedMessage);
    log.entering(
        "formatMessage",
        "JNGui.Client.addAlarmData(String, String)",
        new Object[] {formattedMessage, originatingPort});
    parent.addAlarmData(formattedMessage);
  }
Ejemplo n.º 13
0
 public void handleClientMessage(XEvent xev) {
   if (eventLog.isLoggable(Level.FINER)) {
     XClientMessageEvent msg = xev.get_xclient();
     eventLog.finer(msg.toString());
   }
 }
Ejemplo n.º 14
0
 public void handleReparentNotifyEvent(XEvent xev) {
   if (eventLog.isLoggable(Level.FINER)) {
     XReparentEvent msg = xev.get_xreparent();
     eventLog.finer(msg.toString());
   }
 }
Ejemplo n.º 15
0
 public void setSizeHints(long flags, int x, int y, int width, int height) {
   if (insLog.isLoggable(Level.FINER))
     insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(flags));
   XToolkit.awtLock();
   try {
     XSizeHints hints = getHints();
     // Note: if PPosition is not set in flags this means that
     // we want to reset PPosition in hints.  This is necessary
     // for locationByPlatform functionality
     if ((flags & XlibWrapper.PPosition) != 0) {
       hints.set_x(x);
       hints.set_y(y);
     }
     if ((flags & XlibWrapper.PSize) != 0) {
       hints.set_width(width);
       hints.set_height(height);
     } else if ((hints.get_flags() & XlibWrapper.PSize) != 0) {
       flags |= XlibWrapper.PSize;
     }
     if ((flags & XlibWrapper.PMinSize) != 0) {
       hints.set_min_width(width);
       hints.set_min_height(height);
     } else if ((hints.get_flags() & XlibWrapper.PMinSize) != 0) {
       flags |= XlibWrapper.PMinSize;
       // Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
       // We don't need to reset minimum size if it's already set
     }
     if ((flags & XlibWrapper.PMaxSize) != 0) {
       if (maxBounds != null) {
         if (maxBounds.width != Integer.MAX_VALUE) {
           hints.set_max_width(maxBounds.width);
         } else {
           hints.set_max_width(XToolkit.getDefaultScreenWidth());
         }
         if (maxBounds.height != Integer.MAX_VALUE) {
           hints.set_max_height(maxBounds.height);
         } else {
           hints.set_max_height(XToolkit.getDefaultScreenHeight());
         }
       } else {
         hints.set_max_width(width);
         hints.set_max_height(height);
       }
     } else if ((hints.get_flags() & XlibWrapper.PMaxSize) != 0) {
       flags |= XlibWrapper.PMaxSize;
       if (maxBounds != null) {
         if (maxBounds.width != Integer.MAX_VALUE) {
           hints.set_max_width(maxBounds.width);
         } else {
           hints.set_max_width(XToolkit.getDefaultScreenWidth());
         }
         if (maxBounds.height != Integer.MAX_VALUE) {
           hints.set_max_height(maxBounds.height);
         } else {
           hints.set_max_height(XToolkit.getDefaultScreenHeight());
         }
       } else {
         // Leave intact
       }
     }
     flags |= XlibWrapper.PWinGravity;
     hints.set_flags(flags);
     hints.set_win_gravity((int) XlibWrapper.NorthWestGravity);
     if (insLog.isLoggable(Level.FINER))
       insLog.finer(
           "Setting hints, resulted flags "
               + XlibWrapper.hintsToString(flags)
               + ", values "
               + hints);
     XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), getWindow(), hints.pData);
   } finally {
     XToolkit.awtUnlock();
   }
 }
Ejemplo n.º 16
0
  public void execute(FacesContext context) throws FacesException {
    boolean isFiner = log.isLoggable(Level.FINER);

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.RESTORE_VIEW);

    try {
      if (isFiner) log.finer("JSF[] before restore view");

      restoreView(context);
    } finally {
      afterPhase(context, PhaseId.RESTORE_VIEW);
    }

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    UIViewRoot viewRoot = context.getViewRoot();

    beforePhase(context, PhaseId.APPLY_REQUEST_VALUES);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process decodes");

      viewRoot.processDecodes(context);
    } catch (RuntimeException e) {
      log.log(Level.WARNING, e.toString(), e);
    } finally {
      afterPhase(context, PhaseId.APPLY_REQUEST_VALUES);
    }

    //
    // Process Validations (processValidators)
    //

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.PROCESS_VALIDATIONS);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process validators");

      viewRoot.processValidators(context);
    } finally {
      afterPhase(context, PhaseId.PROCESS_VALIDATIONS);
    }

    //
    // Update Model Values (processUpdates)
    //

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.UPDATE_MODEL_VALUES);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process updates");

      viewRoot.processUpdates(context);
    } catch (RuntimeException e) {
      if (sendError(context, "processUpdates", e)) return;
    } finally {
      afterPhase(context, PhaseId.UPDATE_MODEL_VALUES);
    }

    //
    // Invoke Application (processApplication)
    //

    if (context.getResponseComplete() || context.getRenderResponse()) return;

    beforePhase(context, PhaseId.INVOKE_APPLICATION);

    try {
      if (isFiner) log.finer(context.getViewRoot() + " before process application");

      viewRoot.processApplication(context);
    } finally {
      afterPhase(context, PhaseId.INVOKE_APPLICATION);
    }
  }