Esempio n. 1
0
 public static void main(String[] args) {
   System.err.println("Checking FSL path in " + args[0]);
   StringBuffer bf = new StringBuffer();
   try {
     FileReader fr = new FileReader(args[0]);
     int c;
     do {
       c = fr.read();
       bf.append((char) c);
     } while (c != -1);
     FSLNSResolver nsr = new FSLNSResolver();
     nsr.addPrefixBinding("a", "http://a#");
     nsr.addPrefixBinding("b", "http://b#");
     nsr.addPrefixBinding("c", "http://c#");
     nsr.addPrefixBinding("d", "http://d#");
     nsr.addPrefixBinding("e", "http://e#");
     nsr.addPrefixBinding("f", "http://f#");
     nsr.addPrefixBinding("n", "http://n#");
     nsr.addPrefixBinding("dc", "http://dc#");
     nsr.addPrefixBinding("xsd", "http://xsd#");
     nsr.addPrefixBinding("rdf", "http://rdf#");
     nsr.addPrefixBinding("foaf", "http://foaf#");
     nsr.addPrefixBinding("r", "http://r#");
     nsr.addPrefixBinding("", "http://DD#"); // default NS
     System.out.println(
         "serialization:  "
             + FSLPath.pathFactory(bf.substring(0, bf.length() - 1), nsr, FSLPath.NODE_STEP)
                 .serialize()
             + "\n");
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Esempio n. 2
0
  public DeviceResponse sendCommand(DeviceCommand command) {
    if (socket == null || socket.isClosed()) {
      try {
        socket = new Socket(device.getInetAddress(), device.getPort());
      } catch (IOException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
      }
    }

    try {
      BufferedReader deviceInput =
          new BufferedReader(new InputStreamReader(socket.getInputStream()));
      BufferedWriter deviceOutput =
          new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

      String commandString = command.getCommandString();
      deviceOutput.write(commandString + "\n");
      deviceOutput.flush();

      StringBuffer fullResponse = new StringBuffer();
      String partialResponse;
      while (!(partialResponse = deviceInput.readLine().trim()).equals("")) {
        fullResponse.append(partialResponse);
        fullResponse.append("\n");
      }

      int contentLength = 0;
      if (fullResponse.indexOf("Content-Length:") != -1) {
        String cls = "Content-Length:";
        int si = fullResponse.indexOf(cls);
        int ei = fullResponse.indexOf("\n", si + cls.length());
        contentLength = Integer.parseInt(fullResponse.substring(si + cls.length(), ei).trim());
      }

      StringBuffer content = null;
      if (contentLength > 0) {
        content = new StringBuffer(contentLength);
        char buffer[] = new char[1024];
        int read, totalRead = 0;
        do {
          read = deviceInput.read(buffer);
          totalRead += read;
          content.append(buffer, 0, read);
        } while (read != -1 && totalRead < contentLength);
      }

      return new DeviceResponse(
          fullResponse.toString(), content == null ? null : content.toString());
    } catch (IOException e) {
      logger.log(Level.SEVERE, e.getMessage(), e);
      throw new RuntimeException(e.getMessage(), e);
    }
  }
Esempio n. 3
0
  /*
   * Returns the CSS for the selector name passed in.  Allows you to return one
   * selector from the entire file.
   */
  public String getSelector(String selectorName) {
    String retVal = "";
    if (selectorName != null) {
      if (m_css.indexOf(selectorName) >= 0) {
        int beginPos = m_css.indexOf(selectorName);
        int endPos = m_css.indexOf("}", beginPos);

        retVal = m_css.substring(beginPos, endPos + 1);
      }
    }
    return retVal;
  }
Esempio n. 4
0
  /**
   * Append XML content into root element
   *
   * @param hrefValue href of the topicref
   * @param parentResult XML content to insert into
   * @param tmpContent XML content to insert
   */
  private void insertAfter(String hrefValue, StringBuffer parentResult, CharSequence tmpContent) {
    int insertpoint = parentResult.lastIndexOf("</");
    final int end = parentResult.indexOf(">", insertpoint);

    if (insertpoint == -1 || end == -1) {
      logger.error(MessageUtils.getInstance().getMessage("DOTJ033E", hrefValue).toString());
    } else {
      if (ELEMENT_NAME_DITA.equals(parentResult.substring(insertpoint, end).trim())) {
        insertpoint = parentResult.lastIndexOf("</", insertpoint - 1);
      }
      parentResult.insert(insertpoint, tmpContent);
    }
  }
Esempio n. 5
0
  /**
   * Removes a CSS item from the CSS file.
   *
   * @param selectorName Name of selector.
   * @param name Name of item to remove.
   */
  public void removeValueFromSelector(String selectorName, String name) {
    if (selectorName != null && name != null) {
      if (m_css.indexOf(selectorName) >= 0) {
        boolean done = false;
        int pos = 0;
        while (!done) {
          int beginPos = m_css.indexOf(selectorName, pos);

          if (beginPos >= 0) {
            int endPos = m_css.indexOf("{", beginPos);

            if (endPos >= 0) {
              String workSelectorName = m_css.substring(beginPos, endPos).trim();

              if (workSelectorName.equals(selectorName)) {

                // ArrayList lines = readLines(m_css.substring(endPos, m_css.indexOf("}")));
                // String work = m_css.substring(endPos, m_css.indexOf("}"));
                // int removeStartPos = m_css.substring(endPos, m_css.indexOf("}")).indexOf(name);
                int removeStartPos = m_css.indexOf(name, endPos);
                int removeEndPos = m_css.indexOf(";", removeStartPos);

                if (removeStartPos < removeEndPos) {
                  // logger.info("REMOVING:::::::" + m_css.substring(removeStartPos,
                  // removeEndPos+1));
                  m_css.replace(removeStartPos, removeEndPos + 1, " ");
                }
                done = true;
              }

              pos = endPos;
              if (pos >= m_css.length()) {
                done = true;
              }
            } else {
              done = true;
            }
          } else {
            done = true;
          }
        }
      } else {
        logger.error("Error processing CSS removeValueFromSelector: " + selectorName);
      }
    }
  }
Esempio n. 6
0
  /**
   * This method inserts a value into the selector. It allows you to insert new CSS into the
   * template.
   *
   * @param selectorName Name of CSS selector.
   * @param name Name of CSS item.
   * @param value Value of CSS item.
   */
  public void insertValueIntoSelector(String selectorName, String name, String value) {
    if (selectorName != null && name != null && value != null) {
      if (m_css.indexOf(selectorName) >= 0) {
        boolean done = false;
        int pos = 0;
        while (!done) {
          int beginPos = m_css.indexOf(selectorName, pos);

          if (beginPos >= 0) {
            int endPos = m_css.indexOf("{", beginPos);

            if (endPos >= 0) {
              String workSelectorName = m_css.substring(beginPos, endPos).trim();

              if (workSelectorName.equals(selectorName)) {
                int workEndPos = m_css.indexOf("}", endPos);
                m_css.insert(workEndPos - 1, "\n" + name + ":" + value + ";\n");
                done = true;
              }

              pos = endPos;
              if (pos >= m_css.length()) {
                done = true;
              }
            } else {
              done = true;
            }
          } else {
            done = true;
          }
        }
      } else {
        logger.error(
            "Error processing CSS in insertValueIntoSelector: selectorName:" + selectorName);
      }
    }
  }
Esempio n. 7
0
  public static final HTTPStream createHTTPStream(
      String address,
      boolean isPost,
      byte[] postData,
      String headers,
      int timeOutMs,
      int[] statusCode,
      StringBuffer responseHeaders,
      int numRedirectsToFollow) {
    // timeout parameter of zero for HttpUrlConnection is a blocking connect (negative value for
    // juce::URL)
    if (timeOutMs < 0) timeOutMs = 0;
    else if (timeOutMs == 0) timeOutMs = 30000;

    // headers - if not empty, this string is appended onto the headers that are used for the
    // request. It must therefore be a valid set of HTML header directives, separated by newlines.
    // So convert headers string to an array, with an element for each line
    String headerLines[] = headers.split("\\n");

    for (; ; ) {
      try {
        HttpURLConnection connection = (HttpURLConnection) (new URL(address).openConnection());

        if (connection != null) {
          try {
            connection.setInstanceFollowRedirects(false);
            connection.setConnectTimeout(timeOutMs);
            connection.setReadTimeout(timeOutMs);

            // Set request headers
            for (int i = 0; i < headerLines.length; ++i) {
              int pos = headerLines[i].indexOf(":");

              if (pos > 0 && pos < headerLines[i].length()) {
                String field = headerLines[i].substring(0, pos);
                String value = headerLines[i].substring(pos + 1);

                if (value.length() > 0) connection.setRequestProperty(field, value);
              }
            }

            if (isPost) {
              connection.setRequestMethod("POST");
              connection.setDoOutput(true);

              if (postData != null) {
                OutputStream out = connection.getOutputStream();
                out.write(postData);
                out.flush();
              }
            }

            HTTPStream httpStream = new HTTPStream(connection, statusCode, responseHeaders);

            // Process redirect & continue as necessary
            int status = statusCode[0];

            if (--numRedirectsToFollow >= 0
                && (status == 301 || status == 302 || status == 303 || status == 307)) {
              // Assumes only one occurrence of "Location"
              int pos1 = responseHeaders.indexOf("Location:") + 10;
              int pos2 = responseHeaders.indexOf("\n", pos1);

              if (pos2 > pos1) {
                String newLocation = responseHeaders.substring(pos1, pos2);
                // Handle newLocation whether it's absolute or relative
                URL baseUrl = new URL(address);
                URL newUrl = new URL(baseUrl, newLocation);
                String transformedNewLocation = newUrl.toString();

                if (transformedNewLocation != address) {
                  address = transformedNewLocation;
                  // Clear responseHeaders before next iteration
                  responseHeaders.delete(0, responseHeaders.length());
                  continue;
                }
              }
            }

            return httpStream;
          } catch (Throwable e) {
            connection.disconnect();
          }
        }
      } catch (Throwable e) {
      }

      return null;
    }
  }
Esempio n. 8
0
  /** Find out the type of the current word */
  private int processWord(StringBuffer curWord, int wordContext) throws SchemaParseException {
    String word = curWord.toString();
    int len = word.length();

    if (len > 0) {
      //	We have some word to play with
      switch (wordContext) {
        case WORD_CHECK:
          if (word.startsWith("--")) { // NOI18N
            if (len > 2) word = curWord.substring(2);
            else word = ""; // NOI18N

            this.handler.startElement(word, word, Common.COMMENT);
            wordContext = WORD_COMMENT;
          } else if (word.equals("ELEMENT")) // NOI18N
          wordContext = WORD_ELEMENT1;
          else if (word.equals("ATTLIST")) // NOI18N
          wordContext = WORD_ATTLIST1;
          else if (word.equals("ENTITY")) // NOI18N
          wordContext = WORD_ENTITY1;
          else {
            // System.err.println("Error: found an unknown '<!' sequence (" + word + ")");	// NOI18N
            throw new SchemaParseException(
                "Error: found an unknown '<!' sequence (" + word + ")"); // NOI18N
          }
          break;
        case WORD_COMMENT:
          this.handler.element(word, word, 0);
          break;
        case WORD_ELEMENT1:
          this.handler.startElement(word, word, Common.ELEMENT);
          wordContext = WORD_ELEMENT;
          break;
        case WORD_ATTLIST1:
          this.handler.startElement(word, word, Common.ATTLIST);
          wordContext = WORD_ATTLIST;
          break;
        case WORD_ENTITY1:
          wordContext = WORD_ENTITY;
          break;
        case WORD_ENTITY:
          break;
        case WORD_ELEMENT:
        case WORD_ATTLIST:
          // Find out the instance value (*, ? or +)
          int instance = this.getInstanceValue(word.charAt(len - 1));
          //	Get rid of the extra character
          if (instance != Common.TYPE_1) word = curWord.substring(0, len - 1);

          try {
            this.handler.element(word, word, instance);
          } catch (MissingEndOfEltException e) {
            if (wordContext == WORD_ATTLIST) {
              //
              //  The TreeBuilder is done with the previous
              //  attribute and would expect an end of ATTLIST
              //  declaration.
              //  We might have several attributes declared on the
              //  same ATTLIST declaration.
              //  Let's continue assuming so, the TreeBuilder
              //  checks the attribute semantic and will throw
              // if this is not the case.
              //
              this.handler.startElement(e.propName, e.propName, Common.ATTLIST);
              this.handler.element(word, word, instance);
            }
          }

          break;
        default:
      }
      curWord.delete(0, len);
    }
    return wordContext;
  }