use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class XMLHyperlinkDetector method getLocationHint.
/**
* Find the location hint for the given namespaceURI if it exists
*
* @param elementNode -
* cannot be null
* @param namespaceURI -
* cannot be null
* @return location hint (systemId) if it was found, null otherwise
*/
private String getLocationHint(Element elementNode, String namespaceURI) {
Attr schemaLocNode = elementNode.getAttributeNodeNS(XSI_NAMESPACE_URI, SCHEMA_LOCATION);
if (schemaLocNode != null) {
StringTokenizer st = new StringTokenizer(schemaLocNode.getValue());
while (st.hasMoreTokens()) {
String publicId = st.hasMoreTokens() ? st.nextToken() : null;
String systemId = st.hasMoreTokens() ? st.nextToken() : null;
// found location hint
if (namespaceURI.equalsIgnoreCase(publicId)) {
return systemId;
}
}
}
return null;
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class XMLHyperlinkDetector method getURIString.
/**
* Returns the URI string
*
* @param node -
* assumes not null
*/
private String getURIString(Node node, IDocument document) {
String resolvedURI = null;
// need the base location, publicId, and systemId for URIResolver
String baseLoc = null;
String publicId = null;
String systemId = null;
short nodeType = node.getNodeType();
// handle doc type node
if (nodeType == Node.DOCUMENT_TYPE_NODE) {
baseLoc = getBaseLocation(document);
publicId = ((DocumentType) node).getPublicId();
systemId = ((DocumentType) node).getSystemId();
} else if (nodeType == Node.ATTRIBUTE_NODE) {
// handle attribute node
Attr attrNode = (Attr) node;
String attrName = attrNode.getName();
String attrValue = attrNode.getValue();
attrValue = StringUtils.strip(attrValue);
if (attrValue != null && attrValue.length() > 0) {
baseLoc = getBaseLocation(document);
// handle schemaLocation attribute
String prefix = DOMNamespaceHelper.getPrefix(attrName);
String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName);
if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) {
publicId = attrValue;
systemId = getLocationHint(attrNode.getOwnerElement(), publicId);
if (systemId == null) {
systemId = attrValue;
}
} else if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attrNode))) && (SCHEMA_LOCATION.equals(unprefixedName))) {
// for now just use the first pair
// need to look into being more precise
StringTokenizer st = new StringTokenizer(attrValue);
publicId = st.hasMoreTokens() ? st.nextToken() : null;
systemId = st.hasMoreTokens() ? st.nextToken() : null;
// else check if xmlns publicId = value
} else {
systemId = attrValue;
}
}
}
resolvedURI = resolveURI(baseLoc, publicId, systemId);
return resolvedURI;
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class ProjectResolver method getPath.
/**
* @param url
* @return String
*/
private String getPath(URL url) {
// $NON-NLS-1$ //$NON-NLS-2$
String ref = url.getRef() == null ? "" : "#" + url.getRef();
String strPath = url.getFile() + ref;
IPath path;
if (strPath.length() == 0) {
path = Path.ROOT;
} else {
path = new Path(strPath);
String query = null;
// $NON-NLS-1$
StringTokenizer parser = new StringTokenizer(strPath, "?");
int tokenCount = parser.countTokens();
if (tokenCount == 2) {
path = new Path((String) parser.nextElement());
query = (String) parser.nextElement();
}
if (query == null) {
// $NON-NLS-1$
parser = new StringTokenizer(path.toString(), "#");
tokenCount = parser.countTokens();
if (tokenCount == 2) {
path = new Path((String) parser.nextElement());
}
}
}
return getPath(path, url.getHost());
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class StringUtils method escape.
/**
* Converts a string into a form that will not conflict with saving it
* into an INI file
*/
public static String escape(String normalString) {
if (normalString == null)
return null;
StringBuffer escapedBuffer = new StringBuffer();
StringTokenizer toker = new StringTokenizer(normalString, EQUAL_SIGN + LINE_FEED + CARRIAGE_RETURN + LINE_TAB, true);
String chunk = null;
while (toker.hasMoreTokens()) {
chunk = toker.nextToken();
if (chunk.equals(EQUAL_SIGN)) {
escapedBuffer.append(EQUAL_SIGN_ENTITY);
} else if (chunk.equals(LINE_FEED)) {
escapedBuffer.append(LINE_FEED_ENTITY);
} else if (chunk.equals(CARRIAGE_RETURN)) {
escapedBuffer.append(CARRIAGE_RETURN_ENTITY);
} else if (chunk.equals(LINE_TAB)) {
escapedBuffer.append(LINE_TAB_ENTITY);
} else {
escapedBuffer.append(chunk);
}
}
return escapedBuffer.toString();
}
use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.
the class DocumentProvider method getNode.
/**
***********************************************************************
* Takes a single string of the form "a/b/c" and ensures that that
* structure exists below the head element, down through 'c', and returns
* the element 'c'.
***********************************************************************
*/
private Node getNode(Node node, String name) {
// $NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(name, "/");
String token = null;
while (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
if (getNamedChild(node, token) == null)
node.appendChild(document.createElement(token));
node = getNamedChild(node, token);
}
return node;
}
Aggregations