blob: db268436c9af53410fa0be7f01589756584f6382 [file] [log] [blame]
nitindb0f7b262004-11-23 19:12:23 +00001/*******************************************************************************
nsandonato798dac92009-10-12 14:36:19 +00002 * Copyright (c) 2004, 2009 IBM Corporation and others.
nitindb0f7b262004-11-23 19:12:23 +00003 * 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
amywu19526ad2007-04-10 17:03:52 +00007 *
nitindb0f7b262004-11-23 19:12:23 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
david_williams1a3e50d2005-03-17 03:17:23 +000011package org.eclipse.jst.jsp.ui.internal.editor;
nitindb0f7b262004-11-23 19:12:23 +000012
13
14
david_williams56777022005-04-11 06:21:55 +000015import org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter;
david_williams757ccfe2005-05-01 08:03:21 +000016import org.eclipse.jst.jsp.core.internal.provisional.JSP11Namespace;
17import org.eclipse.jst.jsp.core.internal.provisional.JSP12Namespace;
david_williams4ad020f2005-04-18 08:00:30 +000018import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
19import org.eclipse.wst.xml.ui.internal.provisional.XMLSourceEditingTextTools;
nitindb0f7b262004-11-23 19:12:23 +000020import org.w3c.dom.Document;
21import org.w3c.dom.Element;
22import org.w3c.dom.Node;
23import org.w3c.dom.NodeList;
24
25/**
nitindf6125a82005-06-06 20:10:44 +000026 * Implements ISourceEditingTextTools interface
nitindb0f7b262004-11-23 19:12:23 +000027 */
28public 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_williamsc39caaf2005-04-05 06:07:16 +000040 if (doc instanceof IDOMDocument) {
41 PageDirectiveAdapter adapter = (PageDirectiveAdapter) ((IDOMDocument) doc).getAdapterFor(PageDirectiveAdapter.class);
nitindb0f7b262004-11-23 19:12:23 +000042 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);
nitindb0f7b262004-11-23 19:12:23 +000050 // last one to declare a language wins
nsandonato798dac92009-10-12 14:36:19 +000051 if (pageDirective.hasAttribute(JSP11Namespace.ATTR_NAME_LANGUAGE))
52 language = pageDirective.getAttribute(JSP11Namespace.ATTR_NAME_LANGUAGE);
nitindb0f7b262004-11-23 19:12:23 +000053 }
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_williams1a3e50d2005-03-17 03:17:23 +000061}