All pastes #355228 Raw Edit

Anonymous

public java v1 · immutable
·published 2007-02-14 11:04 UTC
rendered paste body
/* * DTDCompletionParser.java * * Created on February 7, 2007, 7:41 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package net.sf.xpontus.codecompletion.xml;import java.io.FileReader;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.commons.vfs.FileObject;import org.apache.commons.vfs.VFS;import org.apache.xerces.impl.dtd.DTDGrammar;import org.apache.xerces.impl.dtd.XMLDTDLoader;import org.apache.xerces.xni.parser.XMLInputSource;import java.io.Reader;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Vector;import org.apache.xerces.util.XMLResourceIdentifierImpl;import org.apache.xerces.xni.XMLResourceIdentifier;import org.apache.xml.resolver.Catalog;import org.apache.xml.resolver.CatalogManager;import org.xml.sax.InputSource;/** * * @author Yves Zoundi */public class DTDCompletionParser implements ICompletionParser {    private Log logger = LogFactory.getLog(DTDCompletionParser.class);    private List tagList = new ArrayList();    private Map nsTagListMap = new HashMap();    /** Creates a new instance of DTDCompletionParser */    public DTDCompletionParser() {    }    public void init(List tagList, Map nsTagListMap) {        this.tagList = tagList;        this.nsTagListMap = nsTagListMap;    }    public void updateCompletionInfo(String pubid, String uri, Reader in) {        try {            XMLDTDLoader loader = new XMLDTDLoader() {                    public void element(java.lang.String elementName,                        org.apache.xerces.xni.Augmentations augs)                        throws org.apache.xerces.xni.XNIException {                        super.element(elementName, augs);                        if(!tagList.contains(elementName)){                            tagList.add(elementName);                        }                    }                };//            FileObject fo = VFS.getManager().resolveFile(uri);////            DTDGrammar grammar = (DTDGrammar) loader.loadGrammar((new XMLInputSource(//                        pubid, uri, fo.getURL().toExternalForm(), in, null)));                System.setProperty("xml.catalog.staticCatalog", "true");        System.setProperty("xml.catalog.files", "C:\\tests\\docbook-xml-4.4\\docbook.cat");        CatalogManager manager = new CatalogManager();        Vector catalogs = manager.catalogFiles();        System.out.println("number of catalogs:" + catalogs.size());        Catalog catalog = manager.getCatalog();        pubid = pubid.substring(1, pubid.length()-1);        System.out.println("public id:" + pubid);        System.out.println("uri:" + uri);        String s = manager.getCatalog().resolvePublic(pubid, uri);                s = s.substring(5, s.length());                         InputSource is = new InputSource(new FileReader(s));                         XMLResourceIdentifier identifier = new XMLResourceIdentifierImpl();        identifier.setPublicId(pubid);        identifier.setLiteralSystemId(s);        identifier.setBaseSystemId(s);                  DTDGrammar grammar = (DTDGrammar) loader.loadGrammar(new XMLInputSource(identifier));        } catch (Exception ex) {            ex.printStackTrace();            ;        }    }}