コード例 #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;
  }
コード例 #2
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);
  }
コード例 #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();

    xml.addChild(null);
    (new XMLWriter(System.out)).write(xml);
  }
コード例 #4
0
  public void loadSocialsElement(IXMLElement xml) throws Exception {
    String src = xml.getAttribute(PROPERTY_SRC, null);

    // If the passed xml element just points to a file
    if (src != null) {
      IXMLParser xmp = new StdXMLParser();
      xmp.setBuilder(new StdXMLBuilder());
      xmp.setValidator(new NonValidator());
      xmp.setReader(StdXMLReader.fileReader(src));

      xml = (XMLElement) xmp.parse();
      xmp = null;
    }

    int count = 0;
    for (Enumeration enu = xml.getChildrenNamed(Social.MARKUP).elements();
        enu.hasMoreElements();
        count++) {

      IXMLElement nxt = (IXMLElement) enu.nextElement();
      this.socials.addCommand(Social.loadSocial(nxt));
    }
  }