List of usage examples for org.dom4j Namespace getPrefix
public String getPrefix()
From source file:com.cladonia.xngreditor.actions.ToolsRemoveUnusedNSAction.java
License:Open Source License
private String removeUnusedNS(ExchangerDocument document) throws Exception { Vector allNamespaces = document.getDeclaredNamespaces(); if (allNamespaces.size() < 1) { MessageHandler.showError(parent, "Cannot Find Any Namespace Declarations", "Tools Remove Unused Namespace Error"); return (null); } else {// w w w. j a v a 2 s. com XElement e = (XElement) document.getRoot(); Namespace elementNamespace = e.getNamespace(); int index = findInList(elementNamespace, allNamespaces); if (index > -1) { allNamespaces.remove(index); } //sort out the attributes if (e.attributeCount() > 0) { XAttribute[] atts = e.getAttributes(); for (int cnt = 0; cnt < e.attributeCount(); ++cnt) { XAttribute a = atts[cnt]; Namespace attributeNamespace = a.getNamespace(); index = findInList(attributeNamespace, allNamespaces); if (index > -1) { allNamespaces.remove(index); } } } treeWalk(document.getRoot(), allNamespaces); } if (allNamespaces.size() == 0) { MessageHandler.showError(parent, "Cannot Find Any Unused Namespace Declarations", "Tools Remove Unused Namespace Error"); return (null); } else { boolean deleteAll = false; for (int cnt = 0; cnt < allNamespaces.size(); ++cnt) { // if the deleteAll flag is false, then ask the user about each individual object if (deleteAll == false) { //create the message for the user String message = "Are you sure you want to delete:\n "; Namespace temp = (Namespace) allNamespaces.get(cnt); if ((temp.getPrefix().length() > 0) && (temp.getPrefix() != null)) { message += "xmlns:" + temp.getPrefix() + "=" + temp.getURI(); } else { message += "xmlns=" + temp.getURI(); } //ask the question int questionResult = -1; if (allNamespaces.size() > 1) { questionResult = MessageHandler.showConfirmYesNoAll(parent, message); } else { questionResult = MessageHandler.showConfirm(parent, message); } //if the user answered All, don't do anything for now and delete them all later if (questionResult == MessageHandler.CONFIRM_ALL_OPTION) { if (!removeNamespaceDeclaration(document.getRoot(), (Namespace) allNamespaces.get(cnt))) { //then walk the tree treeWalk(document.getRoot(), (Namespace) allNamespaces.get(cnt)); } deleteAll = true; } //user choose to delete this object, remove it from the list else if (questionResult == JOptionPane.YES_OPTION) { if (!removeNamespaceDeclaration(document.getRoot(), (Namespace) allNamespaces.get(cnt))) { //then walk the tree treeWalk(document.getRoot(), (Namespace) allNamespaces.get(cnt)); } } } else { if (!removeNamespaceDeclaration(document.getRoot(), (Namespace) allNamespaces.get(cnt))) { //then walk the tree treeWalk(document.getRoot(), (Namespace) allNamespaces.get(cnt)); } } /* //System.out.println(allNamespaces.get(cnt)); int questionResult=-1; if(!deleteAll) { String message = "Are you sure you want to delete:\n "; Namespace temp = (Namespace)allNamespaces.get(cnt); if((temp.getPrefix().length()>0) && (temp.getPrefix()!=null)) { message += "xmlns:"+temp.getPrefix()+"="+temp.getURI(); } else { message += "xmlns="+temp.getURI(); } questionResult = MessageHandler.showConfirmYesNoAll(parent,message); if(questionResult==MessageHandler.CONFIRM_ALL_OPTION) deleteAll=true; if(questionResult==JOptionPane.YES_OPTION) { //delete these namespace declarations //first from the root if(!removeNamespaceDeclaration(document.getRoot(),(Namespace)allNamespaces.get(cnt))) { //then walk the tree treeWalk(document.getRoot(),(Namespace)allNamespaces.get(cnt)); } } }*/ } //now need to check if all was pressed after the first dialog was shown, //in which case need to act on the initial entries /*if(deleteAll) { for(int cnt=0;cnt<allNamespaces.size();++cnt) { if(!removeNamespaceDeclaration(document.getRoot(),(Namespace)allNamespaces.get(cnt))) { //then walk the tree treeWalk(document.getRoot(),(Namespace)allNamespaces.get(cnt)); } } }*/ document.update(); return (document.getText()); } }
From source file:com.cladonia.xngreditor.grammar.GrammarProperties.java
License:Open Source License
/** * Constructor for the grammar properties. * * @param element the element that contains the properties, * for the editor./* w ww. j av a 2 s .c o m*/ */ public GrammarProperties(ConfigurationProperties props, ExchangerDocument document) { super(new XElement(GRAMMAR_PROPERTIES)); this.properties = props; if (document != null) { String name = document.getName(); int dotPos = name.lastIndexOf('.'); if (dotPos != -1) { setExtensions(name.substring(dotPos + 1, name.length())); } if (!document.isError()) { XElement root = document.getRoot(); if (root != null) { setRootElementName(root.getName()); setNamespace(root.getNamespaceURI()); setNamespacePrefix(root.getNamespacePrefix()); } List namespaces = root.additionalNamespaces(); for (int i = 0; i < namespaces.size(); i++) { Namespace namespace = (Namespace) namespaces.get(i); addNamespace(new NamespaceProperties(namespace.getURI(), namespace.getPrefix())); } DocumentType docType = document.getDocument().getDocType(); if (docType != null) { setPublicID(docType.getPublicID()); setSystemID(docType.getSystemID()); setValidationLocation(docType.getSystemID()); setUseXMLValidationLocation(true); addTagCompletion(new TagCompletionProperties(docType.getSystemID(), XMLGrammar.TYPE_DTD)); // setTemplateLocation( docType.getSystemID()); // setTemplateGrammar( XMLGrammar.TYPE_DTD); setValidationGrammar(XMLGrammar.TYPE_DTD); } else { String location = root.getAttribute("schemaLocation"); if (location == null) { location = root.getAttribute("noNamespaceSchemaLocation"); } if (location != null) { StringTokenizer tokenizer = new StringTokenizer(location, " \t\n\r\f"); String targetURI = null; // if there is only one token than use this as the uri if (tokenizer.hasMoreTokens()) { targetURI = tokenizer.nextToken(); } // there is more than one token, use this token as the uri if (tokenizer.hasMoreTokens()) { targetURI = tokenizer.nextToken(); } setValidationLocation(targetURI); addTagCompletion(new TagCompletionProperties(targetURI, XMLGrammar.TYPE_XSD)); setUseXMLValidationLocation(true); setValidationGrammar(XMLGrammar.TYPE_XSD); } } setDescription(getRootElementName()); } else { setDescription(getExtensions()); } } }
From source file:com.cladonia.xngreditor.ToolsAddNodeDialog.java
License:Open Source License
private String getPrefixForURI(String uri) { for (int cnt = 0; cnt < namespaces.size(); ++cnt) { Namespace ns = (Namespace) namespaces.get(cnt); if (ns.getURI().equalsIgnoreCase(uri)) { return (ns.getPrefix()); }//from www. j a v a 2s . c o m } return (null); }
From source file:com.cladonia.xngreditor.ToolsChangeNSPrefixDialog.java
License:Open Source License
public void show(Vector ns) { this.namespaces = ns; listModel.removeAllElements();//from w ww. ja v a 2 s .c o m for (int cnt = 0; cnt < namespaces.size(); ++cnt) { Namespace newNs = (Namespace) namespaces.get(cnt); listModel.addElement(newNs.getPrefix() + ":" + newNs.getURI()); } //pack(); super.show(); }
From source file:com.cladonia.xngreditor.ToolsChangeNSPrefixDialog.java
License:Open Source License
public void updateMainDialog(Vector prefixes) { this.namespaces = prefixes; listModel.removeAllElements();/*from w w w . j a v a2s. c o m*/ for (int cnt = 0; cnt < namespaces.size(); ++cnt) { Namespace newNs = (Namespace) namespaces.get(cnt); listModel.addElement(newNs.getPrefix() + ":" + newNs.getURI()); } }
From source file:com.panet.imeta.trans.steps.getxmldata.GetXMLData.java
License:Open Source License
@SuppressWarnings("unchecked") public void prepareNSMap(Element l) { for (Namespace ns : (List<Namespace>) l.declaredNamespaces()) { if (ns.getPrefix().trim().length() == 0) { data.NAMESPACE.put("pre" + data.NSPath.size(), ns.getURI()); String path = ""; Element element = l;//from www . j a v a2 s.c om while (element != null) { if (element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0) { path = "/" + element.getNamespacePrefix() + ":" + element.getName() + path; } else { path = "/" + element.getName() + path; } element = element.getParent(); } data.NSPath.add(path); } else { data.NAMESPACE.put(ns.getPrefix(), ns.getURI()); } } for (Element e : (List<Element>) l.elements()) { prepareNSMap(e); } }
From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.FaultExtractor.java
License:Open Source License
FaultExtractor(String expr, Namespace ns) { this.expr = expr; this.ns = ns; namespaceContext = new SimpleNamespaceContext(); namespaceContext.addNamespace(ns.getPrefix(), ns.getURI()); }
From source file:com.webslingerz.jpt.PageTemplateImpl.java
License:Open Source License
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, Interpreter beanShell, Stack<Map<String, Slot>> slotStack) throws SAXException, PageTemplateException, IOException { // Use default template content for (Iterator i = element.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, beanShell, slotStack); break; case Node.TEXT_NODE: char[] text = Expression.evaluateText(node.getText().toString(), beanShell).toCharArray(); contentHandler.characters(text, 0, text.length); break; case Node.COMMENT_NODE: char[] comment = node.getText().toCharArray(); lexicalHandler.comment(comment, 0, comment.length); break; case Node.CDATA_SECTION_NODE: lexicalHandler.startCDATA(); char[] cdata = node.getText().toCharArray(); contentHandler.characters(cdata, 0, cdata.length); lexicalHandler.endCDATA();/* www. j av a 2s. c o m*/ break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; // System.err.println( "Declared namespace: " + // declared.getPrefix() + ":" + declared.getURI() ); namespaces.put(declared.getPrefix(), declared.getURI()); // if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) { // this.talNamespacePrefix = declared.getPrefix(); // } // else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) { // this.metalNamespacePrefix = declared.getPrefix(); // } break; case Node.ATTRIBUTE_NODE: // Already handled break; case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: // System.err.println( "WARNING: Node type not supported: " + // node.getNodeTypeName() ); } } }
From source file:com.webslingerz.jpt.PageTemplateImpl.java
License:Open Source License
AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = element.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); Namespace namespace = attribute.getNamespace(); Namespace elementNamespace = element.getNamespace(); if (!namespace.hasContent() && elementNamespace.hasContent()) namespace = elementNamespace; // String prefix = namespace.getPrefix(); // System.err.println( "attribute: name=" + attribute.getName() + // "\t" + // "qualified name=" + attribute.getQualifiedName() + "\t" + // "ns prefix=" + namespace.getPrefix() + "\t" + // "ns uri=" + namespace.getURI() ); // String qualifiedName = attribute.getName(); // String name = qualifiedName; // if ( qualifiedName.startsWith( prefix + ":" ) ) { // name = qualifiedName.substring( prefix.length() + 1 ); // }/*from w w w . j ava 2s.c om*/ String name = attribute.getName(); // Handle JPT attributes // if ( prefix.equals( talNamespacePrefix ) ) { if (TAL_NAMESPACE_URI.equals(namespace.getURI()) || (!strict && TAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) { // tal:define if (name.equals("define")) { expressions.define = attribute.getValue(); } // tal:condition else if (name.equals("condition")) { expressions.condition = attribute.getValue(); } // tal:repeat else if (name.equals("repeat")) { expressions.repeat = attribute.getValue(); } // tal:content else if (name.equals("content")) { expressions.content = attribute.getValue(); } // tal:replace else if (name.equals("replace")) { if (expressions.omitTag == null) { expressions.omitTag = ""; } expressions.content = attribute.getValue(); } // tal:attributes else if (name.equals("attributes")) { expressions.attributes = attribute.getValue(); } // tal:omit-tag else if (name.equals("omit-tag")) { expressions.omitTag = attribute.getValue(); } // error else { throw new PageTemplateException("unknown tal attribute: " + name); } } // else if ( prefix.equals( metalNamespacePrefix ) ) else if (METAL_NAMESPACE_URI.equals(namespace.getURI()) || (!strict && METAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) { // metal:use-macro if (name.equals("use-macro")) { expressions.useMacro = attribute.getValue(); } // metal:define-slot else if (name.equals("define-slot")) { expressions.defineSlot = attribute.getValue(); } // metal:define-macro else if (name.equals("define-macro")) { //System.out.println("Defining macro: " + attribute.getValue()); Element el = element.createCopy(); el.remove(attribute); macros.put(attribute.getValue(), new MacroImpl(el)); expressions.macro = true; } // metal:fill-slot else if (name.equals("fill-slot")) { // these are ignored here, as they don't affect processing // of current template, but are called from other templates } // error else { throw new PageTemplateException("unknown metal attribute: " + name); } } // Pass on all other attributes else { String nsURI = namespace.getURI(); // String qualifiedName = namespace.getPrefix() + ":" + name; attributes.addAttribute(nsURI, name, attribute.getQualifiedName(), "CDATA", attribute.getValue()); if (nsURI != "" && namespace != elementNamespace) { String prefix = namespace.getPrefix(); String qName = "xmlns:" + prefix; if (attributes.getIndex(qName) == -1) { // add xmlns for this attribute attributes.addAttribute("", prefix, qName, "CDATA", nsURI); } } // attributes.addAttribute( getNamespaceURIFromPrefix(prefix), // name, qualifiedName, "CDATA", attribute.getValue() ); } } return attributes; }
From source file:com.xebialabs.overthere.cifs.winrm.ResponseExtractor.java
License:Open Source License
ResponseExtractor(String expr, Namespace ns) { this.expr = expr; this.ns = ns; namespaceContext = new SimpleNamespaceContext(); namespaceContext.addNamespace(ns.getPrefix(), ns.getURI()); }