use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.
the class PortletURLHyperlinkDetector method detectHyperlinks.
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
IHyperlink[] retval = null;
if (_shouldDetectHyperlinks(textViewer, region)) {
IDocument document = textViewer.getDocument();
int offset = region.getOffset();
IDOMNode currentNode = DOMUtils.getNodeByOffset(document, offset);
IRegion nodeRegion = new Region(currentNode.getStartOffset(), currentNode.getEndOffset() - currentNode.getStartOffset());
if (_isActionURL(currentNode)) {
Node name = currentNode.getAttributes().getNamedItem("name");
if (name != null) {
long modStamp = ((IDocumentExtension4) document).getModificationStamp();
IFile file = DOMUtils.getFile(document);
IMethod[] actionUrlMethods = null;
if (file.equals(_lastFile) && (modStamp == _lastModStamp) && nodeRegion.equals(_lastNodeRegion)) {
actionUrlMethods = _lastActionUrlMethods;
} else {
String nameValue = name.getNodeValue();
// search for this method in any portlet classes
actionUrlMethods = _findPortletMethods(document, nameValue);
_lastModStamp = modStamp;
_lastFile = file;
_lastNodeRegion = nodeRegion;
_lastActionUrlMethods = actionUrlMethods;
}
if (ListUtil.isNotEmpty(actionUrlMethods)) {
List<IHyperlink> links = new ArrayList<>();
for (IMethod method : actionUrlMethods) {
if (method.exists()) {
links.add(new BasicJavaElementHyperlink(nodeRegion, method));
}
}
if (ListUtil.isNotEmpty(links)) {
if (canShowMultipleHyperlinks) {
retval = links.toArray(new IHyperlink[0]);
} else {
retval = new IHyperlink[] { links.get(0) };
}
}
}
}
}
}
return retval;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.
the class JSPFileWTP method findJSPTags.
@Override
public List<SearchResult> findJSPTags(String tagName, String[] attrNames) {
if ((tagName == null) || tagName.isEmpty() || ListUtil.isEmpty(attrNames)) {
throw new IllegalArgumentException("tagName can not be null or empty");
}
List<SearchResult> searchResults = new ArrayList<>();
NodeList nodeList = _getTagNodes(tagName);
for (int i = 0; i < nodeList.getLength(); i++) {
IDOMNode domNode = (IDOMNode) nodeList.item(i);
for (String attrName : attrNames) {
IDOMNode attrNode = (IDOMNode) domNode.getAttributes().getNamedItem(attrName);
if (attrNode != null) {
int startOffset = attrNode.getStartOffset();
int endOffset = startOffset + attrName.length();
int jspStartLine = _getJspLine(startOffset);
int jspEndLine = _getJspLine(endOffset);
searchResults.add(super.createSearchResult(null, startOffset, endOffset, jspStartLine, jspEndLine, true));
}
}
}
return searchResults;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.
the class JSPFileWTP method findJSPTags.
@Override
public List<SearchResult> findJSPTags(String tagName) {
if ((tagName == null) || tagName.isEmpty()) {
throw new IllegalArgumentException("tagName can not be null or empty");
}
List<SearchResult> searchResults = new ArrayList<>();
NodeList nodeList = _getTagNodes(tagName);
for (int i = 0; i < nodeList.getLength(); i++) {
IDOMNode domNode = (IDOMNode) nodeList.item(i);
int startOffset = domNode.getStartOffset();
int endOffset = domNode.getEndOffset();
int jspStartLine = _getJspLine(startOffset);
int jspEndLine = _getJspLine(endOffset);
searchResults.add(super.createSearchResult(null, startOffset, endOffset, jspStartLine, jspEndLine, true));
}
return searchResults;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.
the class CUCacheWTP method _createJSPTranslation.
private JSPTranslationPrime _createJSPTranslation(File file) {
IDOMModel jspModel = null;
try {
// try to find the file in the current workspace, if it can't find
// it then fall back to copy
IFile jspFile = getIFile(file);
jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(jspFile);
IDOMDocument domDocument = jspModel.getDocument();
IDOMNode domNode = (IDOMNode) domDocument.getDocumentElement();
IProgressMonitor npm = new NullProgressMonitor();
JSPTranslator translator = new JSPTranslatorPrime();
if (domNode != null) {
translator.reset((IDOMNode) domDocument.getDocumentElement(), npm);
} else {
translator.reset((IDOMNode) domDocument.getFirstChild(), npm);
}
translator.translate();
IJavaProject javaProject = JavaCore.create(jspFile.getProject());
return new JSPTranslationPrime(javaProject, translator, jspFile);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jspModel != null) {
jspModel.releaseFromRead();
}
}
return null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.
the class ServiceBuilderDescriptorValidator method validateSyntax.
@Override
protected boolean validateSyntax(IXMLReference reference, IDOMNode node, IFile file, IValidator validator, IReporter reporter, boolean batchMode) {
int severity = getServerity(ValidationType.SYNTAX_INVALID, file);
if (severity != ValidationMessage.IGNORE) {
String validationMsg = null;
if (node.getNodeType() == Node.TEXT_NODE) {
Node parentNode = node.getParentNode();
if (parentNode.getNodeName().equals("namespace")) {
String nodeValue = DOMUtils.getNodeValue(node);
if (!ValidatorUtil.isValidNamespace(nodeValue)) {
validationMsg = getMessageText(ValidationType.SYNTAX_INVALID, node);
}
}
} else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
if ("package-path".equals(node.getNodeName()) && "service-builder".equals(((Attr) node).getOwnerElement().getNodeName())) {
String nodeValue = DOMUtils.getNodeValue(node);
if (nodeValue != null) {
// Use standard java conventions to validate the package
// name
IStatus javaStatus = JavaConventions.validatePackageName(nodeValue, CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
if ((javaStatus.getSeverity() == IStatus.ERROR) || (javaStatus.getSeverity() == IStatus.WARNING)) {
validationMsg = J2EECommonMessages.ERR_JAVA_PACAKGE_NAME_INVALID + javaStatus.getMessage();
}
}
}
}
if (validationMsg != null) {
String liferayPluginValidationType = getLiferayPluginValidationType(ValidationType.SYNTAX_INVALID, file);
addMessage(node, file, validator, reporter, batchMode, validationMsg, severity, liferayPluginValidationType);
return false;
}
}
return true;
}
Aggregations