1 11 package org.eclipse.update.core.model; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.update.core.SiteFeatureReferenceModel; 19 import org.eclipse.update.core.Utilities; 20 import org.eclipse.update.internal.core.Messages; 21 import org.xml.sax.SAXException ; 22 23 39 public class SiteModelFactory { 40 41 private static DefaultSiteParser parser = new DefaultSiteParser(); 42 43 48 public SiteModelFactory() { 49 super(); 50 } 51 52 60 public boolean canParseSiteType(String type) { 61 return (type == null || type.trim().equals("")); } 64 65 76 public SiteModel parseSite(InputStream stream) 77 throws CoreException, InvalidSiteTypeException { 78 SiteModel result = null; 79 try { 80 parser.init(this); 81 result = parser.parse(stream); 82 if (parser.getStatus()!=null) { 83 IStatus status = parser.getStatus(); 85 throw new CoreException(status); 86 } 87 } catch (SAXException e) { 88 if (e.getException() instanceof InvalidSiteTypeException) { 90 throw (InvalidSiteTypeException) e.getException(); 91 } 92 93 throw Utilities.newCoreException(Messages.SiteModelObject_ErrorParsingSiteStream,e); 94 } catch (IOException e){ 95 throw Utilities.newCoreException(Messages.SiteModelObject_ErrorAccessingSiteStream,e); 96 } 97 return result; 98 } 99 100 107 public SiteModel createSiteMapModel() { 108 return new SiteModel(); 109 } 110 111 118 public SiteFeatureReferenceModel createFeatureReferenceModel() { 119 return new SiteFeatureReferenceModel(); 120 } 121 122 129 public ArchiveReferenceModel createArchiveReferenceModel() { 130 return new ArchiveReferenceModel(); 131 } 132 133 140 public URLEntryModel createURLEntryModel() { 141 return new URLEntryModel(); 142 } 143 144 151 public CategoryModel createSiteCategoryModel() { 152 return new CategoryModel(); 153 } 154 } 155 | Popular Tags |