Search in sources :

Example 31 with StringTokenizer

use of com.ibm.icu.util.StringTokenizer in project mycore by MyCoRe-Org.

the class MCRDefaultConfigurationLoader method loadFromContent.

private void loadFromContent(MCRContent input) throws IOException {
    try (InputStream in = input.getInputStream()) {
        properties.load(in);
    }
    String include = properties.getProperty("MCR.Configuration.Include", null);
    if (include != null) {
        StringTokenizer st = new StringTokenizer(include, ", ");
        properties.remove("MCR.Configuration.Include");
        while (st.hasMoreTokens()) {
            loadFromFile(st.nextToken());
        }
    }
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) TeeInputStream(org.apache.commons.io.input.TeeInputStream) InputStream(java.io.InputStream)

Example 32 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, IRegion region) {
    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
                // Being precise now
                // $NON-NLS-1$
                String attrText = "";
                int relativeOffset = -1;
                if (node instanceof IDOMNode) {
                    relativeOffset = region.getOffset() - ((IDOMNode) node).getStartOffset();
                    try {
                        attrText = document.get(((IDOMNode) node).getStartOffset(), ((IDOMNode) node).getLength());
                    } catch (BadLocationException e) {
                        Logger.logException(e);
                    }
                }
                StringTokenizer st = new StringTokenizer(attrValue);
                while (st.hasMoreTokens()) {
                    publicId = st.nextToken();
                    systemId = st.hasMoreTokens() ? st.nextToken() : null;
                    int startOffset = -1;
                    int endOffset = -1;
                    if (publicId != null) {
                        startOffset = attrText.indexOf(publicId);
                        if (systemId != null) {
                            endOffset = attrText.indexOf(systemId) + systemId.length();
                        } else {
                            endOffset = attrText.indexOf(publicId) + publicId.length();
                        }
                    }
                    if (startOffset <= relativeOffset && relativeOffset <= endOffset)
                        break;
                // else check if xmlns publicId = value
                }
            } else {
                systemId = attrValue;
            }
        }
    }
    resolvedURI = resolveURI(baseLoc, publicId, systemId);
    return resolvedURI;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Attr(org.w3c.dom.Attr) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 33 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 34 with StringTokenizer

use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.

the class ActionDescriptor method convertAccelerator.

/**
 * Parses the given accelerator text, and converts it to an accelerator
 * key code.
 *
 * @param acceleratorText
 *            the accelerator text
 * @result the SWT key code, or 0 if there is no accelerator
 */
private int convertAccelerator(String acceleratorText) {
    int accelerator = 0;
    // $NON-NLS-1$
    StringTokenizer stok = new StringTokenizer(acceleratorText, "+");
    int keyCode = -1;
    boolean hasMoreTokens = stok.hasMoreTokens();
    while (hasMoreTokens) {
        String token = stok.nextToken();
        hasMoreTokens = stok.hasMoreTokens();
        // Ctrl, Shift, or Alt.
        if (hasMoreTokens) {
            int modifier = Action.findModifier(token);
            if (modifier != 0) {
                accelerator |= modifier;
            } else {
                // Leave if there are none
                return 0;
            }
        } else {
            keyCode = Action.findKeyCode(token);
        }
    }
    if (keyCode != -1) {
        accelerator |= keyCode;
    }
    return accelerator;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer)

Example 35 with StringTokenizer

use of com.ibm.icu.util.StringTokenizer in project webtools.sourceediting by eclipse.

the class AbstractCompletionProposalCategoriesConfiguration method loadPageSortOrder.

/**
 * <p>Loads the user preferences for the sort order of the content assist pages</p>
 *
 * @param useDefaults if <code>true</code> then use the {@link IPreferenceStore} defaults,
 * otherwise use the user specified preferences
 */
private void loadPageSortOrder(boolean useDefaults) {
    // clear the current sort order
    this.fOwnPageSortOrder.clear();
    // parse either the default or user configuration preference
    String sortOrder;
    if (useDefaults) {
        sortOrder = getPreferenceStore().getDefaultString(getPageSortOrderPrefKey());
    } else {
        sortOrder = getPreferenceStore().getString(getPageSortOrderPrefKey());
    }
    StringTokenizer tokenizer = new StringTokenizer(sortOrder, PREFERENCE_CATEGORY_SEPERATOR);
    while (tokenizer.hasMoreTokens()) {
        String categoryID = tokenizer.nextToken();
        this.fOwnPageSortOrder.add(categoryID);
    }
}
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