Search in sources :

Example 16 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class PrefixHandler method execute.

/**
 * This will use the active editor, and try and retrieve a structured
 * model from it.  If successful, it setups the namespace edit dialog
 * to capture the namespace information.
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    XPathUIPlugin plugin = XPathUIPlugin.getDefault();
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    // suppress an NPE in the log (shouldn't happen with the enabledWhen rule)
    if (activeEditor == null)
        return null;
    IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getModelForRead(file);
        IDOMDocument document = model.getDocument();
        if (document != null) {
            List<NamespaceInfo> info = plugin.getNamespaceInfo(document);
            IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
            EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
            dlg.setNamespaceInfoList(info);
            if (SWT.OK == dlg.open()) {
            // Apply changes
            }
        }
    } catch (Exception ex) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return null;
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFile(org.eclipse.core.resources.IFile) XPathUIPlugin(org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IEditorPart(org.eclipse.ui.IEditorPart) EditNamespacePrefixDialog(org.eclipse.wst.xml.xpath.ui.internal.views.EditNamespacePrefixDialog) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 17 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class NamespaceInfoContentBuilder method createAnyElementNode.

protected void createAnyElementNode(CMAnyElement anyElement) {
    String uri = anyElement.getNamespaceURI();
    if (// $NON-NLS-1$
    (uri != null) && !uri.startsWith("##")) {
        if (table.get(uri) == null) {
            NamespaceInfo info = new NamespaceInfo();
            info.uri = uri;
            // $NON-NLS-1$
            info.prefix = "p" + count++;
            table.put(uri, info);
            list.add(info);
        }
    }
}
Also used : NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 18 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class NewXMLGenerator method createNamespaceInfoList.

public void createNamespaceInfoList() {
    List result = new Vector();
    if (cmDocument != null) {
        // $NON-NLS-1$
        List result2 = (List) cmDocument.getProperty("http://org.eclipse.wst/cm/properties/completeNamespaceInfo");
        if (result2 != null) {
            result = result2;
            int size = result.size();
            for (int i = 0; i < size; i++) {
                NamespaceInfo info = (NamespaceInfo) result.get(i);
                if (i == 0) {
                    String locationInfo = null;
                    if (xmlCatalogEntry != null) {
                        if (xmlCatalogEntry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) {
                            locationInfo = xmlCatalogEntry.getAttributeValue(ICatalogEntry.ATTR_WEB_URL);
                        } else {
                            locationInfo = xmlCatalogEntry.getKey();
                        }
                    }
                    if (locationInfo == null) {
                        locationInfo = defaultSystemId;
                    }
                    info.locationHint = locationInfo;
                    // $NON-NLS-1$ //$NON-NLS-2$
                    info.setProperty("locationHint-readOnly", "true");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    info.setProperty("uri-readOnly", "true");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    info.setProperty("unremovable", "true");
                } else {
                    info.locationHint = null;
                }
            }
        }
        NamespaceInfoContentBuilder builder = new NamespaceInfoContentBuilder();
        builder.setBuildPolicy(ContentBuilder.BUILD_ONLY_REQUIRED_CONTENT);
        builder.visitCMNode(cmDocument);
        result.addAll(builder.list);
    }
    namespaceInfoList = result;
}
Also used : List(java.util.List) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) Vector(java.util.Vector)

Example 19 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class EditSchemaInfoAction method createPrefixMapping.

protected Map createPrefixMapping(List oldList, List newList) {
    Map map = new Hashtable();
    Hashtable oldURIToPrefixTable = new Hashtable();
    for (Iterator i = oldList.iterator(); i.hasNext(); ) {
        NamespaceInfo oldInfo = (NamespaceInfo) i.next();
        oldURIToPrefixTable.put(oldInfo.uri, oldInfo);
    }
    for (Iterator i = newList.iterator(); i.hasNext(); ) {
        NamespaceInfo newInfo = (NamespaceInfo) i.next();
        // $NON-NLS-1$
        NamespaceInfo oldInfo = (NamespaceInfo) oldURIToPrefixTable.get(newInfo.uri != null ? newInfo.uri : "");
        // assuming that the user changed the URI and the prefix
        if (oldInfo == null) {
            // $NON-NLS-1$
            oldInfo = (NamespaceInfo) newInfo.getProperty("oldCopy");
        }
        if (oldInfo != null) {
            // $NON-NLS-1$
            String newPrefix = newInfo.prefix != null ? newInfo.prefix : "";
            // $NON-NLS-1$
            String oldPrefix = oldInfo.prefix != null ? oldInfo.prefix : "";
            if (!oldPrefix.equals(newPrefix)) {
                map.put(oldPrefix, newPrefix);
            }
        }
    }
    return map;
}
Also used : Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) Map(java.util.Map)

Example 20 with NamespaceInfo

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.

the class EditSchemaInfoAction method run.

public void run() {
    Shell shell = XMLUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
    if (validateEdit(manager.getModel(), shell)) {
        manager.beginNodeAction(this);
        // todo... change constructor to take an element
        Element element = getElement(node);
        if (element != null) {
            EditSchemaInfoDialog dialog = new EditSchemaInfoDialog(shell, new Path(resourceLocation));
            List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(element);
            List oldNamespaceInfoList = NamespaceInfo.cloneNamespaceInfoList(namespaceInfoList);
            // in response to these changes
            for (Iterator i = namespaceInfoList.iterator(); i.hasNext(); ) {
                NamespaceInfo info = (NamespaceInfo) i.next();
                NamespaceInfo oldCopy = new NamespaceInfo(info);
                // $NON-NLS-1$
                info.setProperty("oldCopy", oldCopy);
            }
            dialog.setNamespaceInfoList(namespaceInfoList);
            dialog.create();
            // dialog.getShell().setSize(500, 300);
            dialog.getShell().setText(XMLUIMessages._UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE);
            dialog.setBlockOnOpen(true);
            dialog.open();
            if (dialog.getReturnCode() == Window.OK) {
                List newInfoList = dialog.getNamespaceInfoList();
                namespaceInfoManager.removeNamespaceInfo(element);
                namespaceInfoManager.addNamespaceInfo(element, newInfoList, false);
                // see if we need to rename any prefixes
                Map prefixMapping = createPrefixMapping(oldNamespaceInfoList, namespaceInfoList);
                if (prefixMapping.size() > 0) {
                    try {
                        manager.getModel().aboutToChangeModel();
                        ReplacePrefixAction replacePrefixAction = new ReplacePrefixAction(manager, element, prefixMapping);
                        replacePrefixAction.run();
                    } finally {
                        manager.getModel().changedModel();
                    }
                }
            }
        }
        manager.endNodeAction(this);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Shell(org.eclipse.swt.widgets.Shell) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) NodeList(org.w3c.dom.NodeList) List(java.util.List) EditSchemaInfoDialog(org.eclipse.wst.xml.ui.internal.dialogs.EditSchemaInfoDialog) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) Map(java.util.Map)

Aggregations

NamespaceInfo (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)30 List (java.util.List)9 Iterator (java.util.Iterator)8 Element (org.w3c.dom.Element)6 NamespaceTable (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable)5 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)4 IFile (org.eclipse.core.resources.IFile)3 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)3 NodeList (org.w3c.dom.NodeList)3 Path (org.eclipse.core.runtime.Path)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Shell (org.eclipse.swt.widgets.Shell)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IPathEditorInput (org.eclipse.ui.IPathEditorInput)2 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)2