DefaultCompletionProvider.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:powertext 作者:
/**
 * Loads completions from an XML input stream.  The XML should validate
 * against <code>CompletionXml.dtd</code>.
 *
 * @param in The input stream to read from.
 * @param cl The class loader to use when loading any extra classes defined
 *        in the XML, such as custom {@link FunctionCompletion}s.  This
 *        may be <code>null</code> if the default is to be used, or if no
 *        custom completions are defined in the XML.
 * @throws IOException If an IO error occurs.
 */
public void loadFromXML(InputStream in, ClassLoader cl) throws IOException {

    //long start = System.currentTimeMillis();

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
    CompletionXMLParser handler = new CompletionXMLParser(this, cl);
    BufferedInputStream bin = new BufferedInputStream(in);
    try {
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(bin, handler);
        List<Completion> completions =  handler.getCompletions();
        addCompletions(completions);
        char startChar = handler.getParamStartChar();
        if (startChar!=0) {
            char endChar = handler.getParamEndChar();
            String sep = handler.getParamSeparator();
            if (endChar!=0 && sep!=null && sep.length()>0) { // Sanity
                setParameterizedCompletionParams(startChar, sep, endChar);
            }
        }
    } catch (SAXException se) {
        throw new IOException(se.toString());
    } catch (ParserConfigurationException pce) {
        throw new IOException(pce.toString());
    } finally {
        //long time = System.currentTimeMillis() - start;
        //System.out.println("XML loaded in: " + time + "ms");
        bin.close();
    }

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号