Search in sources :

Example 11 with StringTokenizer

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;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) Attr(org.w3c.dom.Attr) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)

Example 12 with StringTokenizer

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;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) Attr(org.w3c.dom.Attr) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)

Example 13 with StringTokenizer

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());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) StringTokenizer(com.ibm.icu.util.StringTokenizer) IPath(org.eclipse.core.runtime.IPath)

Example 14 with StringTokenizer

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();
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer)

Example 15 with StringTokenizer

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;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer)

Aggregations

StringTokenizer (com.ibm.icu.util.StringTokenizer)53 ArrayList (java.util.ArrayList)9 List (java.util.List)6 HashSet (java.util.HashSet)4 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)4 Attr (org.w3c.dom.Attr)4 Set (java.util.Set)3 Point (org.eclipse.swt.graphics.Point)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 InputStream (java.io.InputStream)2 Iterator (java.util.Iterator)2 Pattern (java.util.regex.Pattern)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 IDocument (org.eclipse.jface.text.IDocument)2