nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
nsandonato | 798dac9 | 2009-10-12 14:36:19 +0000 | [diff] [blame] | 2 | * Copyright (c) 2004, 2009 IBM Corporation and others. |
nitind | b0f7b26 | 2004-11-23 19:12:23 +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 | 19526ad | 2007-04-10 17:03:52 +0000 | [diff] [blame] | 7 | * |
nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
david_williams | 1a3e50d | 2005-03-17 03:17:23 +0000 | [diff] [blame] | 11 | package org.eclipse.jst.jsp.ui.internal.editor; |
nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | |
david_williams | 5677702 | 2005-04-11 06:21:55 +0000 | [diff] [blame] | 15 | import org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter; |
david_williams | 757ccfe | 2005-05-01 08:03:21 +0000 | [diff] [blame] | 16 | import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace; |
| 17 | import org.eclipse.jst.jsp.core.internal.provisional.JSP12Namespace; |
david_williams | 4ad020f | 2005-04-18 08:00:30 +0000 | [diff] [blame] | 18 | import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; |
| 19 | import org.eclipse.wst.xml.ui.internal.provisional.XMLSourceEditingTextTools; |
nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 20 | import org.w3c.dom.Document; |
| 21 | import org.w3c.dom.Element; |
| 22 | import org.w3c.dom.Node; |
| 23 | import org.w3c.dom.NodeList; |
| 24 | |
| 25 | /** |
nitind | f6125a8 | 2005-06-06 20:10:44 +0000 | [diff] [blame] | 26 | * Implements ISourceEditingTextTools interface |
nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 27 | */ |
| 28 | public class JSPSourceEditingTextTools extends XMLSourceEditingTextTools { |
| 29 | |
| 30 | public String getPageLanguage(Node node) { |
| 31 | String language = null; |
| 32 | Document doc = null; |
| 33 | if (node.getNodeType() == Node.DOCUMENT_NODE) { |
| 34 | doc = (Document) node; |
| 35 | } |
| 36 | else { |
| 37 | doc = node.getOwnerDocument(); |
| 38 | } |
| 39 | if (doc != null) { |
david_williams | c39caaf | 2005-04-05 06:07:16 +0000 | [diff] [blame] | 40 | if (doc instanceof IDOMDocument) { |
| 41 | PageDirectiveAdapter adapter = (PageDirectiveAdapter) ((IDOMDocument) doc).getAdapterFor(PageDirectiveAdapter.class); |
nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 42 | if (adapter != null) |
| 43 | language = adapter.getLanguage(); |
| 44 | } |
| 45 | else { |
| 46 | // iterate through all of the page directives |
| 47 | NodeList pageDirectives = doc.getElementsByTagName(JSP12Namespace.ElementName.DIRECTIVE_PAGE); |
| 48 | for (int i = 0; i < pageDirectives.getLength(); i++) { |
| 49 | Element pageDirective = (Element) pageDirectives.item(i); |
nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 50 | // last one to declare a language wins |
nsandonato | 798dac9 | 2009-10-12 14:36:19 +0000 | [diff] [blame] | 51 | if (pageDirective.hasAttribute(JSP11Namespace.ATTR_NAME_LANGUAGE)) |
| 52 | language = pageDirective.getAttribute(JSP11Namespace.ATTR_NAME_LANGUAGE); |
nitind | b0f7b26 | 2004-11-23 19:12:23 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | // if no language was specified anywhere, assume Java |
| 57 | if (language == null) |
| 58 | language = JSP11Namespace.ATTR_VALUE_JAVA; |
| 59 | return language; |
| 60 | } |
david_williams | 1a3e50d | 2005-03-17 03:17:23 +0000 | [diff] [blame] | 61 | } |