public CMDocument getCMDocument(Element element, String namespaceURI) { CMDocument result = null; if ((namespaceURI != null) && (namespaceURI.trim().length() > 0)) { String locationHint = null; for (Iterator i = namespaceInfoList1.iterator(); i.hasNext();) { NamespaceInfo info = (NamespaceInfo) i.next(); if (namespaceURI.equals(info.uri)) { locationHint = info.locationHint; break; } } if (locationHint != null) { grammarURI = idResolver.resolve(resourceLocation, locationHint, locationHint); result = ContentModelManager.getInstance().createCMDocument(getGrammarURI(), null); } } else { result = cmDocument; } return result; } }
public static ContentModelManager getInstance() { if (instance == null) { instance = new ContentModelManager(); } return instance; }
public List getAnnotationFilesInfos(String publicId) { return getAnnotationFileRegistry().getAnnotationFilesInfos(publicId); }
public static void loadAnnotationsForGrammar(String publicId, CMDocument cmDocument) { List annotationFiles = ContentModelManager.getInstance().getAnnotationFilesInfos(publicId); AnnotationMap map = (AnnotationMap) cmDocument.getProperty("annotationMap"); //$NON-NLS-1$ if (map != null) { for (Iterator i = annotationFiles.iterator(); i.hasNext();) { try { AnnotationFileInfo annotationFileInfo = (AnnotationFileInfo) i.next(); AnnotationFileParser parser = new AnnotationFileParser(); parser.parse(map, annotationFileInfo); } catch (Exception e) { Logger.logException(e); } } } } }
public CMDocument createCMDocument(String uri, String resourceType) { if (resourceType == null && uri != null) { int index = uri.lastIndexOf("."); //$NON-NLS-1$ resourceType = uri.substring(index + 1); } if (resourceType != null) { resourceType = resourceType.toLowerCase(); } CMDocumentFactory factory = getCMDocumentFactoryRegistry().getFactory(resourceType); return factory != null ? factory.createCMDocument(uri) : null; }
/** * Get the annotation map associated with this document. Lazily creates * and loads annotation map. * @return AnnotationMap */ private AnnotationMap getAnnotationMap() { // create a new annotation map and load it up if (fAnnotationMap == null) { fAnnotationMap = new AnnotationMap(); List annotationFiles = ContentModelManager.getInstance().getAnnotationFilesInfos(getUri()); for (Iterator i = annotationFiles.iterator(); i.hasNext();) { try { AnnotationFileInfo fileInfo = (AnnotationFileInfo) i.next(); AnnotationFileParser parser = new AnnotationFileParser(); parser.parse(fAnnotationMap, fileInfo); } catch (Exception e) { Logger.log(Logger.WARNING_DEBUG, "Exception thrown in CMDocumentImpl#getAnnotationMap", e); //$NON-NLS-1$ } } } return fAnnotationMap; } /**
public synchronized CMDocument buildCMDocument(String publicId, String resolvedURI, String type) { cmDocumentCache.setStatus(resolvedURI, CMDocumentCache.STATUS_LOADING); CMDocument result = null; if (resolvedURI != null && resolvedURI.length() > 0) { // TODO... pass the TYPE thru to the CMDocumentBuilder result = ContentModelManager.getInstance().createCMDocument(resolvedURI, type); } if (result != null) { // load the annotation files for the document if (publicId != null) { AnnotationUtility.loadAnnotationsForGrammar(publicId, result); } cmDocumentCache.putCMDocument(resolvedURI, result); } else { cmDocumentCache.setStatus(resolvedURI, CMDocumentCache.STATUS_ERROR); } return result; }
public static void testPopulateDocumentFromGrammarFile(Document document, String grammarFileName, String rootElementName, boolean hack) { try { CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null); CMNamedNodeMap elementMap = cmDocument.getElements(); CMElementDeclaration element = (CMElementDeclaration) elementMap.getNamedItem(rootElementName); DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(document); contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = hack; contentBuilder.createDefaultRootContent(cmDocument, element); System.out.println(); System.out.println("-----------------------------"); //$NON-NLS-1$ DOMWriter writer = new DOMWriter(); if (hack) { writer.print(document, grammarFileName); } else { writer.print(document); } System.out.println("-----------------------------"); //$NON-NLS-1$ } catch (Exception e) { System.out.println("Error: " + e); //$NON-NLS-1$ e.printStackTrace(); } }
cmDocument = ContentModelManager.getInstance().createCMDocument(uri, null);
CMDocument document = ContentModelManager.getInstance().createCMDocument(grammarURI, "xsd"); //$NON-NLS-1$ List namespaceInfoList = (List) document.getProperty("http://org.eclipse.wst/cm/properties/namespaceInfo"); //$NON-NLS-1$ NamespaceInfo info = (NamespaceInfo) namespaceInfoList.get(0);