david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
nitind | 74c1c85 | 2010-06-03 07:24:16 +0000 | [diff] [blame] | 2 | * Copyright (c) 2001, 2010 IBM Corporation and others. |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 7 | * |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | *******************************************************************************/ |
david_williams | 12ff79e | 2005-04-13 13:59:30 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.xml.ui.internal.contentassist; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 14 | |
david_williams | b5d0563 | 2006-02-27 09:24:00 +0000 | [diff] [blame] | 15 | import org.eclipse.wst.sse.core.StructuredModelManager; |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 16 | import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 17 | import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; |
david_williams | c06c86f | 2005-03-18 18:23:41 +0000 | [diff] [blame] | 18 | import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; |
| 19 | import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 20 | import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 21 | |
| 22 | |
| 23 | /** |
| 24 | * @author pavery |
| 25 | */ |
| 26 | public class ContextInfoModelUtil { |
| 27 | IStructuredDocument fDocument = null; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 28 | |
| 29 | ContextInfoModelUtil(IStructuredDocument doc) { |
| 30 | fDocument = doc; |
| 31 | } |
| 32 | |
| 33 | public IStructuredDocument getDocument() { |
| 34 | return fDocument; |
| 35 | } |
| 36 | |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 37 | public ModelQuery getModelQuery() { |
| 38 | ModelQuery mq = null; |
| 39 | |
nitind | 9a0f933 | 2005-02-03 06:57:23 +0000 | [diff] [blame] | 40 | IStructuredModel xmlModel = null; |
| 41 | try { |
| 42 | xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); |
| 43 | mq = ModelQueryUtil.getModelQuery(xmlModel); |
| 44 | } |
| 45 | finally { |
| 46 | if (xmlModel != null) { |
| 47 | xmlModel.releaseFromRead(); |
| 48 | } |
| 49 | } |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 50 | return mq; |
| 51 | } |
| 52 | |
david_williams | c39caaf | 2005-04-05 06:07:16 +0000 | [diff] [blame] | 53 | public IDOMNode getXMLNode(int offset) { |
nitind | 9a0f933 | 2005-02-03 06:57:23 +0000 | [diff] [blame] | 54 | IStructuredModel xmlModel = null; |
david_williams | c39caaf | 2005-04-05 06:07:16 +0000 | [diff] [blame] | 55 | IDOMNode xmlNode = null; |
nitind | 9a0f933 | 2005-02-03 06:57:23 +0000 | [diff] [blame] | 56 | try { |
| 57 | xmlModel = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); |
nitind | 74c1c85 | 2010-06-03 07:24:16 +0000 | [diff] [blame] | 58 | if (xmlModel != null) { |
| 59 | xmlNode = (IDOMNode) xmlModel.getIndexedRegion(offset); |
| 60 | } |
nitind | 9a0f933 | 2005-02-03 06:57:23 +0000 | [diff] [blame] | 61 | } |
| 62 | finally { |
amywu | 679e086 | 2007-09-26 19:05:32 +0000 | [diff] [blame] | 63 | if (xmlModel != null) |
| 64 | xmlModel.releaseFromRead(); |
nitind | 9a0f933 | 2005-02-03 06:57:23 +0000 | [diff] [blame] | 65 | } |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 66 | return xmlNode; |
| 67 | } |
| 68 | } |