本文整理汇总了Java中org.openide.xml.XMLUtil.createXMLReader方法的典型用法代码示例。如果您正苦于以下问题:Java XMLUtil.createXMLReader方法的具体用法?Java XMLUtil.createXMLReader怎么用?Java XMLUtil.createXMLReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.xml.XMLUtil
的用法示例。
在下文中一共展示了XMLUtil.createXMLReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildItemList
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
@Override
protected List<FeedItem> buildItemList() throws SAXException, ParserConfigurationException, IOException {
XMLReader reader = XMLUtil.createXMLReader( false, true );
FeedHandler handler = new FeedHandler( getMaxItemCount() );
reader.setContentHandler( handler );
reader.setEntityResolver( org.openide.xml.EntityCatalog.getDefault() );
reader.setErrorHandler( new ErrorCatcher() );
reader.parse( findInputSource(new URL(url1)) );
ArrayList<FeedItem> res = new ArrayList<FeedItem>( 2*getMaxItemCount() );
res.addAll( handler.getItemList() );
handler = new FeedHandler( getMaxItemCount() );
reader.setContentHandler( handler );
reader.parse( findInputSource(new URL(url2)) );
res.addAll( handler.getItemList() );
List<FeedItem> items = sortNodes( res );
if( items.size() > getMaxItemCount() ) {
items = items.subList( 0, getMaxItemCount() );
}
return items;
}
示例2: readDriverFromFile
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static JDBCDriver readDriverFromFile(FileObject fo) throws IOException, MalformedURLException {
Handler handler = new Handler();
// parse the XM file
try {
XMLReader reader = XMLUtil.createXMLReader();
InputSource is = new InputSource(fo.getInputStream());
is.setSystemId(fo.toURL().toExternalForm());
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(EntityCatalog.getDefault());
reader.parse(is);
} catch (SAXException ex) {
throw new IOException(ex.getMessage());
}
// read the driver from the handler
URL[] urls = new URL[handler.urls.size()];
int j = 0;
for (Iterator i = handler.urls.iterator(); i.hasNext(); j++) {
urls[j] = new URL((String)i.next());
}
if (checkClassPathDrivers(handler.clazz, urls) == false) {
return null;
}
if (handler.displayName == null) {
handler.displayName = handler.name;
}
return JDBCDriver.create(handler.name, handler.displayName, handler.clazz, urls);
}
示例3: getVersion
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/** Parsing just for detecting the version SAX parser used
*/
public static String getVersion(java.io.InputStream is, org.xml.sax.helpers.DefaultHandler versionHandler,
EntityResolver ddResolver) throws java.io.IOException, SAXException {
XMLReader reader = XMLUtil.createXMLReader(false);
reader.setContentHandler(versionHandler);
reader.setEntityResolver(ddResolver);
try {
reader.parse(new InputSource(is));
} catch (SAXException ex) {
is.close();
String message = ex.getMessage();
if (message != null && message.startsWith(EXCEPTION_PREFIX)) {
return message.substring(EXCEPTION_PREFIX.length());
} else {
throw new SAXException(NbBundle.getMessage(ParseUtils.class, "MSG_cannotParse"), ex);
}
}
is.close();
throw new SAXException(NbBundle.getMessage(ParseUtils.class, "MSG_cannotFindRoot"));
}
示例4: parse
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* The recognizer entry method taking an InputSource.
* @param input InputSource to be parsed.
* @throws java.io.IOException on I/O error.
* @throws SAXException propagated exception thrown by a DocumentHandler.
* @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
* @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
*
*/
public void parse(final InputSource input) throws SAXException, ParserConfigurationException, IOException {
if (used.getAndSet(true)) {
throw new IllegalStateException("The LibraryDeclarationParser was already used, create a new instance"); //NOI18N
}
try {
final XMLReader parser = XMLUtil.createXMLReader(false, true);
parser.setContentHandler(this);
parser.setErrorHandler(getDefaultErrorHandler());
parser.setEntityResolver(this);
parser.parse(input);
} finally {
//Recover recognizer internal state from exceptions to be reusable
if (!context.empty()) {
context.clear();
}
if (buffer.length() > 0) {
buffer.delete(0, buffer.length());
}
expectedNS = null;
}
}
示例5: loadAttributesFromXml
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private EntryAttributes loadAttributesFromXml(File entriesFile) throws IOException, SAXException {
//Parse the entries file
XMLReader saxReader = XMLUtil.createXMLReader();
XmlEntriesHandler xmlEntriesHandler = new XmlEntriesHandler();
saxReader.setContentHandler(xmlEntriesHandler);
saxReader.setErrorHandler(xmlEntriesHandler);
InputStream inputStream = new java.io.FileInputStream(entriesFile);
try {
saxReader.parse(new InputSource(inputStream));
} catch (SAXException ex) {
throw ex;
} finally {
inputStream.close();
}
return xmlEntriesHandler.getEntryAttributes();
}
示例6: parse
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private void parse(){
try{
Parser p = new XMLReaderAdapter(XMLUtil.createXMLReader());
p.setDocumentHandler(this);
String externalForm = url.toExternalForm();
InputSource is = new InputSource(externalForm);
try {
p.parse(is);
} catch (NullPointerException npe) {
npe.printStackTrace();
if (npe.getCause() != null) {
npe.getCause().printStackTrace();
}
}
}
catch(java.io.IOException ie){
ie.printStackTrace();
}
catch(org.xml.sax.SAXException se){
se.printStackTrace();
}
}
示例7: read
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
@Override
public Object read(Reader r) throws IOException, ClassNotFoundException {
Lookup lkp = findContext(r);
FileObject fo = lkp.lookup(FileObject.class);
String displayName = fo.getFileSystem().getDecorator().annotateName(fo.getName(), Collections.singleton(fo));
try {
XMLReader reader = XMLUtil.createXMLReader(true);
ToolbarParser parser = new ToolbarParser();
reader.setContentHandler(parser);
reader.setErrorHandler(parser);
reader.setEntityResolver(EntityCatalog.getDefault());
reader.parse(new InputSource(r));
return parser.createToolbarConfiguration( fo.getName(), displayName );
} catch( SAXException saxE ) {
IOException ioE = new IOException();
ioE.initCause(saxE);
throw ioE;
}
}
示例8: instanceCreate
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
@Override
@NonNull
public synchronized RemotePlatform instanceCreate() throws IOException, ClassNotFoundException {
RemotePlatform remotePlatform = platformRef == null ? null : platformRef.get();
if (remotePlatform == null) {
final SAXHandler handler = new SAXHandler();
try (InputStream in = store.getPrimaryFile().getInputStream()) {
final XMLReader reader = XMLUtil.createXMLReader();
InputSource is = new InputSource(in);
is.setSystemId(store.getPrimaryFile().toURL().toExternalForm());
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(handler);
reader.parse(is);
} catch (SAXException ex) {
final Exception x = ex.getException();
if (x instanceof java.io.IOException) {
throw (IOException)x;
} else {
throw new java.io.IOException(ex);
}
}
remotePlatform = RemotePlatform.create(
handler.name,
handler.properties,
handler.sysProperties);
remotePlatform.addPropertyChangeListener(this);
platformRef = new WeakReference<>(remotePlatform);
}
return remotePlatform;
}
示例9: instanceCreate
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
@Override
public Object instanceCreate() throws java.io.IOException, ClassNotFoundException {
synchronized (this) {
Object o = refConnection.get();
if (o != null) {
return o;
}
XMLDataObject obj = getHolder();
if (obj == null) {
return null;
}
FileObject connectionFO = obj.getPrimaryFile();
Handler handler = new Handler(connectionFO.getNameExt());
try {
XMLReader reader = XMLUtil.createXMLReader();
InputSource is = new InputSource(obj.getPrimaryFile().getInputStream());
is.setSystemId(connectionFO.toURL().toExternalForm());
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(EntityCatalog.getDefault());
reader.parse(is);
} catch (SAXException ex) {
Exception x = ex.getException();
LOGGER.log(Level.FINE, "Cannot read " + obj + ". Cause: " + ex.getLocalizedMessage(), ex);
if (x instanceof java.io.IOException) {
throw (IOException)x;
} else {
throw new java.io.IOException(ex.getMessage());
}
}
DatabaseConnection inst = createDatabaseConnection(handler);
refConnection = new WeakReference<>(inst);
attachListener();
return inst;
}
}
示例10: buildItemList
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
protected List<FeedItem> buildItemList() throws SAXException, ParserConfigurationException, IOException {
XMLReader reader = XMLUtil.createXMLReader( false, true );
FeedHandler handler = new FeedHandler( getMaxItemCount() );
reader.setContentHandler( handler );
reader.setEntityResolver( org.openide.xml.EntityCatalog.getDefault() );
reader.setErrorHandler( new ErrorCatcher() );
InputSource is = findInputSource(new URL(url));
reader.parse( is );
return handler.getItemList();
}
示例11: loadFile
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private void loadFile() {
fileLoaded = true;
PaletteItem item = paletteItem;
if (item == null)
item = new PaletteItem(this);
FileObject file = getPrimaryFile();
if (file.getSize() == 0L) { // item file is empty
// just derive the component class name from the file name
item.setComponentClassSource(new ClassSource(file.getName().replace('-', '.')));
paletteItem = item;
return;
}
// parse the XML file
try {
XMLReader reader = XMLUtil.createXMLReader();
PaletteItemHandler handler = new PaletteItemHandler();
reader.setContentHandler(handler);
InputSource input = new InputSource(getPrimaryFile().getURL().toExternalForm());
reader.parse(input);
// TODO report errors, validate using DTD?
item.setComponentExplicitType(handler.componentExplicitType);
item.setComponentInitializerId(handler.componentInitializerId);
if (handler.componentClassName != null || displayName_key != null) {
item.setComponentClassSource(new ClassSource(handler.componentClassName, handler.entries));
paletteItem = item;
}
} catch (SAXException saxex) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, saxex);
} catch (IOException ioex) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioex);
}
}
示例12: XmlOutputParser
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/** Creates a new instance of XMLOutputParser */
private XmlOutputParser(TestSession session) throws SAXException {
testSession = session;
xmlReader = XMLUtil.createXMLReader();
xmlReader.setContentHandler(this);
regexp = JavaRegexpUtils.getInstance();
}
示例13: getXMLReader
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private XMLReader getXMLReader() throws SAXException {
XMLReader res = null == cachedReader ? null : cachedReader.get();
if( null == res ) {
res = XMLUtil.createXMLReader(true);
res.setEntityResolver(EntityCatalog.getDefault());
cachedReader = new WeakReference<XMLReader>(res);
}
return res;
}
示例14: CatalogParser
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/** Parses the specified input source. */
public CatalogParser(InputSource source) throws SAXException, IOException {
XMLReader parser = XMLUtil.createXMLReader(true);
// setup parser
parser.setEntityResolver(new Resolver()); // overwrite system entity resolver
parser.setContentHandler(this);
parser.setErrorHandler(this);
// set initial base and parse
setBase(source.getSystemId());
parser.parse(source);
}
示例15: getParser
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private XMLReader getParser(boolean validate)
throws SAXException, ParserConfigurationException, FactoryConfigurationError {
XMLReader parser = XMLUtil.createXMLReader(validate);
// create document handler and register it
parser.setEntityResolver(this);
parser.setContentHandler(this);
parser.setErrorHandler(this);
return parser;
}