use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class AnchorHyperlinkDetector method detectHyperlinks.
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
if (textViewer != null && region != null) {
IDocument document = textViewer.getDocument();
if (document != null) {
Node currentNode = getCurrentNode(document, region.getOffset());
if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) currentNode;
IStructuredDocumentRegion documentRegion = ((IStructuredDocument) document).getRegionAtCharacterOffset(region.getOffset());
ITextRegion textRegion = documentRegion.getRegionAtCharacterOffset(region.getOffset());
ITextRegion nameRegion = null;
ITextRegion valueRegion = null;
String name = null;
String value = null;
/*
* http://bugs.eclipse.org/475680 - possible after last offset in the file or
* by a faulty implementation
*/
if (textRegion != null) {
if (DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(textRegion.getType())) {
ITextRegionList regions = documentRegion.getRegions();
/*
* Could use 2, but there needs to be the tag open
* and name regions
*/
int index = regions.indexOf(textRegion);
if (index >= 4) {
nameRegion = regions.get(index - 2);
valueRegion = textRegion;
name = documentRegion.getText(nameRegion);
value = StringUtils.strip(documentRegion.getText(valueRegion));
}
} else if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(textRegion.getType())) {
ITextRegionList regions = documentRegion.getRegions();
int index = regions.indexOf(textRegion);
// minus 3 to leave equal and value regions
if (index <= regions.size() - 3) {
nameRegion = textRegion;
valueRegion = regions.get(index + 2);
name = documentRegion.getText(nameRegion);
value = StringUtils.strip(documentRegion.getText(valueRegion));
}
}
}
if (name != null && value != null) {
int idx = -1;
if (HTML40Namespace.ATTR_NAME_HREF.equalsIgnoreCase(name) && (idx = value.indexOf("#")) >= 0) {
// $NON-NLS-1$
String filename = value.substring(0, idx);
final String anchorName = idx < value.length() - 1 ? value.substring(idx + 1) : null;
if (anchorName != null) {
final IPath basePath = new Path(((IDOMNode) element).getModel().getBaseLocation());
if (basePath.segmentCount() > 1) {
if (filename.length() == 0) {
filename = basePath.lastSegment();
}
final IPath resolved = ModuleCoreSupport.resolve(basePath, filename);
final IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(resolved);
if (targetFile.isAccessible())
return createHyperlinksToAnchorNamed(textViewer, createHyperlinkRegion(documentRegion, valueRegion), element, value, canShowMultipleHyperlinks);
}
}
}
if (HTML40Namespace.ATTR_NAME_NAME.equalsIgnoreCase(name) || HTML40Namespace.ATTR_NAME_ID.equalsIgnoreCase(name)) {
return createReferrerHyperlinks(textViewer, createHyperlinkRegion(documentRegion, valueRegion), element, value, canShowMultipleHyperlinks);
}
}
}
}
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class HTMLDocumentLoader method newEncodedDocument.
/*
* @see AbstractLoader#createNewStructuredDocument()
*/
protected IEncodedDocument newEncodedDocument() {
IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
((BasicStructuredDocument) structuredDocument).setReParser(new XMLStructuredDocumentReParser());
return structuredDocument;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class HTMLFormatter method replaceSource.
/**
*/
protected void replaceSource(IDOMModel model, int offset, int length, String source) {
if (model == null)
return;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return;
if (source == null)
source = new String();
if (structuredDocument.containsReadOnly(offset, length))
return;
// We use 'structuredDocument' as the requester object just so this
// and the other
// format-related 'repalceText' (in replaceSource) can use the same
// requester.
// Otherwise, if requester is not identical,
// the undo group gets "broken" into multiple pieces based
// on the requesters being different. Technically, any unique, common
// requester object would work.
structuredDocument.replaceText(structuredDocument, offset, length, source);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class HTMLFormatter method setWidth.
/**
*/
protected void setWidth(HTMLFormatContraints contraints, Node node) {
if (contraints == null)
return;
if (node == null)
return;
IStructuredDocument structuredDocument = ((IDOMNode) node).getStructuredDocument();
if (structuredDocument == null)
// error
return;
if (!splitLines())
return;
int lineWidth = getLineWidth();
if (lineWidth < 0)
return;
int offset = ((IDOMNode) node).getStartOffset();
int line = structuredDocument.getLineOfOffset(offset);
int lineOffset = 0;
try {
lineOffset = structuredDocument.getLineOffset(line);
} catch (BadLocationException ex) {
// error
return;
}
if (lineOffset > offset)
// error
return;
int availableWidth = lineWidth - (offset - lineOffset);
if (availableWidth < 0)
availableWidth = 0;
contraints.setAvailableLineWidth(availableWidth);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StyleAttrAdapter method setValue.
/**
*/
private void setValue() {
Element element = getElement();
if (element == null)
return;
ICSSModel model = getExistingModel();
if (model == null)
return;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return;
String value = null;
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
if (flatNodes != null) {
int count = flatNodes.getLength();
if (count > 0) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < count; i++) {
IStructuredDocumentRegion flatNode = flatNodes.item(i);
if (flatNode == null)
continue;
buffer.append(flatNode.getText());
}
value = buffer.toString();
}
}
this.ignoreNotification = true;
if (value == null || value.length() == 0) {
element.removeAttribute(STYLE);
} else {
Attr attr = element.getAttributeNode(STYLE);
if (attr != null) {
((IDOMNode) attr).setValueSource(value);
} else {
Document document = element.getOwnerDocument();
attr = document.createAttribute(STYLE);
((IDOMNode) attr).setValueSource(value);
element.setAttributeNode(attr);
}
}
this.ignoreNotification = false;
notifyStyleChanged(element);
}
Aggregations