Code example for InputSource

Methods: getSystemId, setSystemId

0
    } 
 
    public InputSource createInputSource(String text)
    { 
        this.sourceText = text;
        InputSource is = new InputSource(new StringReader(text));
        is.setSystemId("text://");
        return is;
    } 
 
    public InputSource createInputSource(File srcFile) throws FileNotFoundException
    { 
        String uri = "file:" + srcFile.getAbsolutePath().replace('\\', '/');
        for(int index = uri.indexOf('#'); index != -1; index = uri.indexOf('#'))
        { 
            uri = uri.substring(0, index) + "%23" + uri.substring(index + 1);
        } 
 
        activeFileInputStream = new FileInputStream(srcFile);
        BufferedInputStream inputStream = new BufferedInputStream(activeFileInputStream);
        InputSource inputSource = new InputSource(inputStream);
        inputSource.setSystemId(uri);
 
        this.inputSrcTracker = new FileTracker();
        ((FileTracker) this.inputSrcTracker).setFile(srcFile);
        if(parentSrcTracker != null)
            this.inputSrcTracker.setParent(parentSrcTracker);
        this.sourceFile = srcFile;
 
        return inputSource;
    } 
 
    public InputSource createInputSource(Resource resource) throws IOException
    { 
        this.sourceResource = resource;
 
        InputStream stream = resource.getResourceAsStream();
        if(stream != null)
        { 
            InputSource inputSource = new InputSource(stream);
            inputSource.setSystemId(resource.getSystemId());
 
            this.inputSrcTracker = new URLTracker();
            ((URLTracker) this.inputSrcTracker).setUrl(resource.getResource());
            if(parentSrcTracker != null)
                this.inputSrcTracker.setParent(parentSrcTracker);
 
            return inputSource;
        } 
        else 
            throw new IOException("Resource '" + resource.getSystemId() + "' not found. ClassPath is " + System.getProperty("java.class.path") + ".");
    } 
 
    public InputSource createInputSource(File jarFile, ZipEntry jarFileEntry) throws FileNotFoundException, IOException
    { 
        this.sourceFile = jarFile;
        this.sourceJarEntry = jarFileEntry;
        this.sourceJarFile = new ZipFile(jarFile);
 
        InputStream stream = sourceJarFile.getInputStream(jarFileEntry);
        if(stream != null)
        { 
            InputSource inputSource = new InputSource(stream);
            inputSource.setSystemId(sourceJarFile.getName() + "!" + jarFileEntry.getName());
 
            this.inputSrcTracker = new FileTracker();
            ((FileTracker) this.inputSrcTracker).setFile(jarFile);
            if(parentSrcTracker != null)
                this.inputSrcTracker.setParent(parentSrcTracker);
 
            return inputSource;
        } 
        else 
            throw new FileNotFoundException("Zip entry '" + jarFileEntry.getName() + "' not found in zip file '" + jarFile.getAbsolutePath() + "'.");
    } 
 
    public void init(InputSource inputSource) throws ParserConfigurationException, SAXException
    { 
        this.inputSource = inputSource;
        this.errors = new ArrayList();
        this.warnings = new ArrayList();
 
        if(inputSource.getSystemId() == null)
            throw new ParserConfigurationException("Please set the system id.");
 
        SAXParser saxParser = getParserFactory().newSAXParser();
        parser = saxParser.getXMLReader();
    }