use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class TLDValidator method checkClass.
private Map checkClass(IJavaProject javaProject, Node classSpecifier, IScopeContext[] preferenceScopes, String preferenceKey, String errorMessage) {
String className = getTextContents(classSpecifier);
if (className != null && className.length() > 2) {
IType type = null;
try {
type = javaProject.findType(className);
} catch (JavaModelException e) {
return null;
}
if (type == null || !type.exists()) {
Object severity = getMessageSeverity(preferenceScopes, preferenceKey);
if (severity == null)
return null;
IDOMNode classElement = (IDOMNode) classSpecifier;
Map markerValues = new HashMap();
markerValues.put(IMarker.SEVERITY, severity);
int start = classElement.getStartOffset();
if (classElement.getStartStructuredDocumentRegion() != null && classElement.getEndStructuredDocumentRegion() != null)
start = classElement.getStartStructuredDocumentRegion().getEndOffset();
markerValues.put(IMarker.CHAR_START, new Integer(start));
int end = classElement.getEndOffset();
if (classElement.getStartStructuredDocumentRegion() != null && classElement.getEndStructuredDocumentRegion() != null)
end = classElement.getEndStructuredDocumentRegion().getStartOffset();
markerValues.put(IMarker.CHAR_END, new Integer(end));
int line = classElement.getStructuredDocument().getLineOfOffset(start);
markerValues.put(IMarker.LINE_NUMBER, new Integer(line + 1));
// $NON-NLS-1$
markerValues.put(IMarker.MESSAGE, NLS.bind(errorMessage, (errorMessage.indexOf("{1}") >= 0) ? new String[] { getTagName(classSpecifier), className } : new String[] { className }));
return markerValues;
}
}
return null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class JSPModelQueryExtension method getAvailableElementContent.
/**
* Originally taken from JSPContentAssistProcessor
*
* @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
*/
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
CMNode[] nodes = EMPTY_CMNODE_ARRAY;
ArrayList nodeList = new ArrayList();
// only returns anything if looking for child nodes
if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMNode) {
IDOMNode node = (IDOMNode) parentElement;
// get position dependent CMDocuments and insert their tags as
// proposals
ModelQueryAdapter mqAdapter = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
mqAdapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class);
} else {
mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
}
if (mqAdapter != null) {
CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node);
if (doc != null) {
CMDocument jcmdoc = getDefaultJSPCMDocument(node);
CMNamedNodeMap jspelements = jcmdoc.getElements();
/* For a built-in JSP action the content model is properly
* set up, so don't just blindly add the rest--unless this
* will be a direct child of the document
*/
if (jspelements != null && (!(doc instanceof JSPCMDocument) || node.getNodeType() == Node.DOCUMENT_NODE)) {
List rejectElements = new ArrayList();
// determine if the document is in XML form
Document domDoc = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
domDoc = (Document) node;
} else {
domDoc = node.getOwnerDocument();
}
// Show XML tag forms of JSP markers if jsp:root is
// the document element OR it's HTML but
// isn't really in the text.
// If the document isn't strictly XML, pull out the
// XML tag forms it is xml format
rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET);
rejectElements.add(JSP12Namespace.ElementName.EXPRESSION);
rejectElements.add(JSP12Namespace.ElementName.DECLARATION);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE);
rejectElements.add(JSP12Namespace.ElementName.TEXT);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_TAG);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_ATTRIBUTE);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_VARIABLE);
if (isXMLFormat(domDoc)) {
// jsp actions
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.USEBEAN);
rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.FORWARD);
rejectElements.add(JSP12Namespace.ElementName.PLUGIN);
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.PARAM);
rejectElements.add(JSP12Namespace.ElementName.PARAMS);
}
// don't show jsp:root if a document element already
// exists
Element docElement = domDoc.getDocumentElement();
if (docElement != null && ((docElement.getNodeName().equals(TAG_JSP_ROOT)) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null)))) {
rejectElements.add(JSP12Namespace.ElementName.ROOT);
}
for (int j = 0; j < jspelements.getLength(); j++) {
CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j);
if (!rejectElements.contains(ed.getNodeName())) {
nodeList.add(ed);
}
}
}
} else // No cm document (such as for the Document (a non-Element) node itself)
{
CMNamedNodeMap jspElements = getDefaultJSPCMDocument(node).getElements();
int length = jspElements.getLength();
for (int i = 0; i < length; i++) {
nodeList.add(jspElements.item(i));
}
}
}
nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class TagModelQuery method getEmbeddedMimeType.
private String getEmbeddedMimeType(Node node) {
String type = DEFAULT_MIMETYPE;
if (node instanceof IDOMNode) {
IStructuredModel model = ((IDOMNode) node).getModel();
String baseLocation = model.getBaseLocation();
if (!baseLocation.equals(IModelManager.UNMANAGED_MODEL)) {
IPath path = new Path(baseLocation);
if (path.segmentCount() > 1) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
if (project.isAccessible()) {
String key = createPreferenceKey(path);
IEclipsePreferences preferences = new ProjectScope(project).getNode(JSPCorePlugin.getDefault().getBundle().getSymbolicName());
type = preferences.get(key, DEFAULT_MIMETYPE);
}
}
}
}
return type;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class TaglibHyperlinkDetector method getHyperlinkRegion.
// the below methods were copied from URIHyperlinkDetector
private IRegion getHyperlinkRegion(Node node, IRegion boundingRegion) {
IRegion hyperRegion = null;
if (node != null) {
short nodeType = node.getNodeType();
if (nodeType == Node.DOCUMENT_TYPE_NODE) {
// handle doc type node
IDOMNode docNode = (IDOMNode) node;
hyperRegion = new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset());
} else if (nodeType == Node.ATTRIBUTE_NODE) {
// handle attribute nodes
IDOMAttr att = (IDOMAttr) node;
// do not include quotes in attribute value region
int regOffset = att.getValueRegionStartOffset();
ITextRegion valueRegion = att.getValueRegion();
if (valueRegion != null) {
int regLength = valueRegion.getTextLength();
String attValue = att.getValueRegionText();
if (StringUtils.isQuoted(attValue)) {
++regOffset;
regLength = regLength - 2;
}
hyperRegion = new Region(regOffset, regLength);
}
}
if (nodeType == Node.ELEMENT_NODE) {
// Handle doc type node
IDOMNode docNode = (IDOMNode) node;
hyperRegion = getNameRegion(docNode.getFirstStructuredDocumentRegion());
if (hyperRegion == null) {
hyperRegion = new Region(docNode.getStartOffset(), docNode.getFirstStructuredDocumentRegion().getTextLength());
}
}
}
/**
* Only return a hyperlink region that overlaps the search region.
* This will help us to not underline areas not under the cursor.
*/
if (hyperRegion != null && intersects(hyperRegion, boundingRegion))
return hyperRegion;
return null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyJSPJava method customizeDocumentCommand.
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
if (!supportsSmartInsert(document)) {
return;
}
IStructuredModel model = null;
try {
// Auto edit for JSP Comments
if ("-".equals(command.text) && isPreferenceEnabled(JSPUIPreferenceNames.TYPING_COMPLETE_COMMENTS)) {
// $NON-NLS-1$
if (prefixedWith(document, command.offset, "<%-")) {
// $NON-NLS-1$
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null) {
IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
IDOMNode parent = (node != null) ? (IDOMNode) node.getParentNode() : null;
// Parent is the scriptlet tag
if (parent != null && JSP11Namespace.ElementName.SCRIPTLET.equals(parent.getNodeName()) && !parent.getSource().endsWith("--%>")) {
// $NON-NLS-1$
IStructuredDocumentRegion end = parent.getEndStructuredDocumentRegion();
if (end != null) {
try {
// $NON-NLS-1$
document.replace(end.getStartOffset(), 0, "--");
} catch (BadLocationException e) {
Logger.logException(e);
}
}
}
}
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
Aggregations