Logo Search packages:      
Sourcecode: icedtea-web version File versions  Download package

void net::sourceforge::nanoxml::XMLElement::sanitizeInput ( InputStreamReader  isr,
PipedOutputStream  pout 
) [inline]

Reads an xml file and removes the comments, leaving only relevant xml code.

Parameters:
isr The reader of the InputStream containing the xml.
pout The PipedOutputStream that will be receiving the filtered xml file.

Definition at line 1250 of file XMLElement.java.

References parserLineNr, reader, sanitizeCharReadTooMuch, and skipSpecialTag().

                                                                             {
        try {
            PrintStream out = new PrintStream(pout);

            this.sanitizeCharReadTooMuch = '\0';
            this.reader = isr;
            this.parserLineNr = 0;
            int newline = 2;
            char prev = ' ';

            while(true) {
                char ch;
                if (this.sanitizeCharReadTooMuch != '\0') {
                    ch = this.sanitizeCharReadTooMuch;
                    this.sanitizeCharReadTooMuch = '\0';
                } else {

                    int i = this.reader.read();
                    if (i == -1) {
                        // no character in buffer, and nothing read
                        out.flush();
                        break;
                    } else if (i == 10) {
                        ch = '\n';
                    } else {
                        ch = (char) i;
                    }
                }

                char next;
                int i = this.reader.read();
                if (i == -1) {
                    // character in buffer and nothing read. write out
                    // what's in the buffer
                    out.print(ch);
                    out.flush();
                    if (JNLPRuntime.isDebug()) {
                        if (ch == 10) {
                            System.out.println();
                            System.out.print("line: " + newline + " ");
                            newline++;
                        } else {
                            System.out.print(ch);
                        }
                    }
                    break;
                } else if (i == 10) {
                    next = '\n';
                } else {
                    next = (char) i;
                }

                this.sanitizeCharReadTooMuch = next;

                // If the next char is a ? or !, then we've hit a special tag,
                // and should skip it.
                if (prev == '<' && (next == '!' || next == '?')) {
                    this.skipSpecialTag(0);
                    this.sanitizeCharReadTooMuch = '\0';
                }
                // Otherwise we haven't hit a comment, and we should write ch.
                else {
                    out.print(ch);
                    if (JNLPRuntime.isDebug()) {
                        if (ch == 10) {
                            System.out.println();
                            System.out.print("line: " + newline + " ");
                            newline++;
                        } else {
                            System.out.print(ch);
                        }
                    }
                }
                prev = next;
            }

            out.close();
            isr.close();
        } catch (Exception e) {
            // Print the stack trace here -- xml.parseFromReader() will
            // throw the ParseException if something goes wrong.
            e.printStackTrace();
        }
    }


Generated by  Doxygen 1.6.0   Back to index