예제 #1
0
  static boolean removeScript(CharSequence text) {
    try {
      WString wText = WString.toWString(text);

      XSSFilter filter = new XSSFilter();
      IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
      parser.setBuilder(filter);
      parser.setResolver(filter);
      IXMLReader reader = StdXMLReader.stringReader("<span>" + wText.getValue() + "</span>");
      parser.setReader(reader);
      parser.parse();

      String filtered = filter.result();

      // 6 and 7 correct for respectively <span> and </span>
      wText.set(filtered.substring(6, filtered.length() - 7));

      return true;
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (XMLException e) {
      logger.error("Error reading XHTML string: " + e.getMessage());
    }

    return false;
  }
 /**
  * Creates a default parser.
  *
  * @see #DEFAULT_CLASS
  * @see #CLASS_KEY
  * @param builder the XML builder.
  * @return the non-null parser.
  * @throws java.lang.ClassNotFoundException if the class of the parser could not be found.
  * @throws java.lang.InstantiationException if the parser could not be created
  * @throws java.lang.IllegalAccessException if the parser could not be created
  */
 public static IXMLParser createDefaultXMLParser(IXMLBuilder builder)
     throws ClassNotFoundException, InstantiationException, IllegalAccessException {
   // BEGIN PATCH W. Randelshofer catch AccessControlException
   String className = XMLParserFactory.DEFAULT_CLASS;
   try {
     className = System.getProperty(XMLParserFactory.CLASS_KEY, XMLParserFactory.DEFAULT_CLASS);
   } catch (AccessControlException e) {
     // do nothing
   }
   // END PATCH W. Randelshofer catch AccessControlException
   return XMLParserFactory.createXMLParser(className, builder);
 }
예제 #3
0
  public static void main(String args[]) throws Exception {
    if (args.length == 0) {
      System.err.println("Usage: java DumpXML file.xml");
      Runtime.getRuntime().exit(1);
    }

    IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
    IXMLReader reader = StdXMLReader.fileReader(args[0]);
    parser.setReader(reader);
    XMLElement xml = (XMLElement) parser.parse();

    Properties prop = xml.getAttributes();
    prop.list(System.out);
  }
예제 #4
0
  public static void main(String args[]) throws Exception {
    if (args.length == 0) {
      System.err.println("Usage: java DumpXML file.xml");
      Runtime.getRuntime().exit(1);
    }

    IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
    IXMLReader reader = StdXMLReader.fileReader(args[0]);
    parser.setReader(reader);
    XMLElement xml = (XMLElement) parser.parse();

    xml.addChild(null);
    (new XMLWriter(System.out)).write(xml);
  }