List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:com.evolveum.midpoint.web.component.input.QNameEditorPanel.java
public QNameEditorPanel(String id, IModel<ItemPathType> model, String localPartTooltipKey, String namespaceTooltipKey, boolean markLocalPartAsRequired, boolean markNamespaceAsRequired) { super(id, model); this.itemPathModel = model; localpartModel = new IModel<String>() { @Override/*from w ww .jav a 2 s. c o m*/ public String getObject() { QName qName = itemPathToQName(); return qName != null ? qName.getLocalPart() : null; } @Override public void setObject(String object) { if (object == null) { itemPathModel.setObject(null); } else { itemPathModel.setObject( new ItemPathType(new ItemPath(new QName(namespaceModel.getObject(), object)))); } } @Override public void detach() { } }; namespaceModel = new IModel<String>() { @Override public String getObject() { QName qName = itemPathToQName(); return qName != null ? qName.getNamespaceURI() : null; } @Override public void setObject(String object) { if (StringUtils.isBlank(localpartModel.getObject())) { itemPathModel.setObject(null); } else { itemPathModel.setObject( new ItemPathType(new ItemPath(new QName(object, localpartModel.getObject())))); } } @Override public void detach() { } }; initLayout(localPartTooltipKey, namespaceTooltipKey, markLocalPartAsRequired, markNamespaceAsRequired); }
From source file:org.eclipse.winery.repository.resources.AbstractComponentsResource.java
/** * @return an instance of the requested resource *//*from ww w.j a v a 2 s .c o m*/ public AbstractComponentInstanceResource getComponentInstaceResource(QName qname) { return this.getComponentInstaceResource(qname.getNamespaceURI(), qname.getLocalPart(), false); }
From source file:com.twinsoft.convertigo.engine.migration.Migration7_0_0.java
public static void migrate(final String projectName) { try {//from w ww. j ava 2s . c o m Map<String, Reference> referenceMap = new HashMap<String, Reference>(); XmlSchema projectSchema = null; Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false); // Copy all xsd files to project's xsd directory File destDir = new File(project.getXsdDirPath()); copyXsdOfProject(projectName, destDir); String projectWsdlFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".wsdl"; File wsdlFile = new File(projectWsdlFilePath); String projectXsdFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".xsd"; File xsdFile = new File(projectXsdFilePath); if (xsdFile.exists()) { // Load project schema from old XSD file XmlSchemaCollection collection = new XmlSchemaCollection(); collection.setSchemaResolver(new DefaultURIResolver() { public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) { // Case of a c8o project location if (schemaLocation.startsWith("../") && schemaLocation.endsWith(".xsd")) { try { String targetProjectName = schemaLocation.substring(3, schemaLocation.indexOf("/", 3)); File pDir = new File(Engine.PROJECTS_PATH + "/" + targetProjectName); if (pDir.exists()) { File pFile = new File(Engine.PROJECTS_PATH + schemaLocation.substring(2)); // Case c8o project is already migrated if (!pFile.exists()) { Document doc = Engine.theApp.schemaManager .getSchemaForProject(targetProjectName).getSchemaDocument(); DOMSource source = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory.newInstance().newTransformer().transform(source, result); StringReader reader = new StringReader(writer.toString()); return new InputSource(reader); } } return null; } catch (Exception e) { Engine.logDatabaseObjectManager .warn("[Migration 7.0.0] Unable to find schema location \"" + schemaLocation + "\"", e); return null; } } else if (schemaLocation.indexOf("://") == -1 && schemaLocation.endsWith(".xsd")) { return super.resolveEntity(targetNamespace, schemaLocation, Engine.PROJECTS_PATH + "/" + projectName); } return super.resolveEntity(targetNamespace, schemaLocation, baseUri); } }); projectSchema = SchemaUtils.loadSchema(new File(projectXsdFilePath), collection); ConvertigoError.updateXmlSchemaObjects(projectSchema); SchemaMeta.setCollection(projectSchema, collection); for (Connector connector : project.getConnectorsList()) { for (Transaction transaction : connector.getTransactionsList()) { try { // Migrate transaction in case of a Web Service consumption project if (transaction instanceof XmlHttpTransaction) { XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) transaction; String reqn = xmlHttpTransaction.getResponseElementQName(); if (!reqn.equals("")) { boolean useRef = reqn.indexOf(";") == -1; // Doc/Literal case if (useRef) { try { String[] qn = reqn.split(":"); QName refName = new QName( projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]); xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName)); } catch (Exception e) { } } // RPC case else { int index, index2; try { index = reqn.indexOf(";"); String opName = reqn.substring(0, index); if ((index2 = reqn.indexOf(";", index + 1)) != -1) { String eltName = reqn.substring(index + 1, index2); String eltType = reqn.substring(index2 + 1); String[] qn = eltType.split(":"); QName typeName = new QName( projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]); String responseElementQName = opName + ";" + eltName + ";" + "{" + typeName.getNamespaceURI() + "}" + typeName.getLocalPart(); xmlHttpTransaction.setResponseElementQName(responseElementQName); } } catch (Exception e) { } } } } // Retrieve required XmlSchemaObjects for transaction QName requestQName = new QName(project.getTargetNamespace(), transaction.getXsdRequestElementName()); QName responseQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseElementName()); LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>(); XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, false); dw.walkByElementRef(projectSchema, requestQName); dw.walkByElementRef(projectSchema, responseQName); // Create transaction schema String targetNamespace = projectSchema.getTargetNamespace(); String prefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace); XmlSchema transactionSchema = SchemaUtils.createSchema(prefix, targetNamespace, XsdForm.unqualified.name(), XsdForm.unqualified.name()); // Add required prefix declarations List<String> nsList = new LinkedList<String>(); for (QName qname : map.keySet()) { String nsURI = qname.getNamespaceURI(); if (!nsURI.equals(Constants.URI_2001_SCHEMA_XSD)) { if (!nsList.contains(nsURI)) { nsList.add(nsURI); } } String nsPrefix = qname.getPrefix(); if (!nsURI.equals(targetNamespace)) { NamespaceMap nsMap = SchemaUtils.getNamespaceMap(transactionSchema); if (nsMap.getNamespaceURI(nsPrefix) == null) { nsMap.add(nsPrefix, nsURI); transactionSchema.setNamespaceContext(nsMap); } } } // Add required imports for (String namespaceURI : nsList) { XmlSchemaObjectCollection includes = projectSchema.getIncludes(); for (int i = 0; i < includes.getCount(); i++) { XmlSchemaObject xmlSchemaObject = includes.getItem(i); if (xmlSchemaObject instanceof XmlSchemaImport) { if (((XmlSchemaImport) xmlSchemaObject).getNamespace() .equals(namespaceURI)) { // do not allow import with same ns ! if (namespaceURI.equals(project.getTargetNamespace())) continue; String location = ((XmlSchemaImport) xmlSchemaObject) .getSchemaLocation(); // This is a convertigo project reference if (location.startsWith("../")) { // Copy all xsd files to xsd directory String targetProjectName = location.substring(3, location.indexOf("/", 3)); copyXsdOfProject(targetProjectName, destDir); } // Add reference addReferenceToMap(referenceMap, namespaceURI, location); // Add import addImport(transactionSchema, namespaceURI, location); } } } } QName responseTypeQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseTypeName()); // Add required schema objects for (QName qname : map.keySet()) { if (qname.getNamespaceURI().equals(targetNamespace)) { XmlSchemaObject ob = map.get(qname); if (qname.getLocalPart().startsWith("ConvertigoError")) continue; transactionSchema.getItems().add(ob); // Add missing response error element and attributes if (qname.equals(responseTypeQName)) { Transaction.addSchemaResponseObjects(transactionSchema, (XmlSchemaComplexType) ob); } } } // Add missing ResponseType (with document) if (map.containsKey(responseTypeQName)) { Transaction.addSchemaResponseType(transactionSchema, transaction); } // Add everything if (map.isEmpty()) { Transaction.addSchemaObjects(transactionSchema, transaction); } // Add c8o error objects (for internal xsd edition only) ConvertigoError.updateXmlSchemaObjects(transactionSchema); // Save schema to file String transactionXsdFilePath = transaction.getSchemaFilePath(); new File(transaction.getSchemaFileDirPath()).mkdirs(); SchemaUtils.saveSchema(transactionXsdFilePath, transactionSchema); } catch (Exception e) { Engine.logDatabaseObjectManager .error("[Migration 7.0.0] An error occured while migrating transaction \"" + transaction.getName() + "\"", e); } if (transaction instanceof TransactionWithVariables) { TransactionWithVariables transactionVars = (TransactionWithVariables) transaction; handleRequestableVariable(transactionVars.getVariablesList()); // Change SQLQuery variables : i.e. {id} --> {{id}} if (transaction instanceof SqlTransaction) { String sqlQuery = ((SqlTransaction) transaction).getSqlQuery(); sqlQuery = sqlQuery.replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{{$1}}"); ((SqlTransaction) transaction).setSqlQuery(sqlQuery); } } } } } else {// Should only happen for projects which version <= 4.6.0 XmlSchemaCollection collection = new XmlSchemaCollection(); String prefix = project.getName() + "_ns"; projectSchema = SchemaUtils.createSchema(prefix, project.getNamespaceUri(), XsdForm.unqualified.name(), XsdForm.unqualified.name()); ConvertigoError.addXmlSchemaObjects(projectSchema); SchemaMeta.setCollection(projectSchema, collection); for (Connector connector : project.getConnectorsList()) { for (Transaction transaction : connector.getTransactionsList()) { if (transaction instanceof TransactionWithVariables) { TransactionWithVariables transactionVars = (TransactionWithVariables) transaction; handleRequestableVariable(transactionVars.getVariablesList()); } } } } // Handle sequence objects for (Sequence sequence : project.getSequencesList()) { handleSteps(projectSchema, referenceMap, sequence.getSteps()); handleRequestableVariable(sequence.getVariablesList()); } // Add all references to project if (!referenceMap.isEmpty()) { for (Reference reference : referenceMap.values()) project.add(reference); } // Delete XSD file if (xsdFile.exists()) xsdFile.delete(); // Delete WSDL file if (wsdlFile.exists()) wsdlFile.delete(); } catch (Exception e) { Engine.logDatabaseObjectManager .error("[Migration 7.0.0] An error occured while migrating project \"" + projectName + "\"", e); } }
From source file:org.fcrepo.serialization.JcrXmlSerializer.java
private void validateJCRXML(final File file) throws InvalidSerializationFormatException, IOException { int depth = 0; try (final FileInputStream fis = new FileInputStream(file)) { final XMLEventReader reader = XMLInputFactory.newFactory().createXMLEventReader(fis); while (reader.hasNext()) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { depth++;/* w w w.j ava 2 s . c om*/ final StartElement startElement = event.asStartElement(); final Attribute nameAttribute = startElement .getAttributeByName(new QName("http://www.jcp.org/jcr/sv/1.0", "name")); if (depth == 1 && nameAttribute != null && "jcr:content".equals(nameAttribute.getValue())) { throw new InvalidSerializationFormatException( "Cannot import JCR/XML starting with content node."); } if (depth == 1 && nameAttribute != null && "jcr:frozenNode".equals(nameAttribute.getValue())) { throw new InvalidSerializationFormatException("Cannot import historic versions."); } final QName name = startElement.getName(); if (!(name.getNamespaceURI().equals("http://www.jcp.org/jcr/sv/1.0") && (name.getLocalPart().equals("node") || name.getLocalPart().equals("property") || name.getLocalPart().equals("value")))) { throw new InvalidSerializationFormatException( "Unrecognized element \"" + name.toString() + "\", in import XML."); } } else { if (event.isEndElement()) { depth--; } } } reader.close(); } catch (XMLStreamException e) { throw new InvalidSerializationFormatException( "Unable to parse XML" + (e.getMessage() != null ? " (" + e.getMessage() + ")." : ".")); } }
From source file:com.amalto.core.load.io.XMLStreamUnwrapper.java
/** * Moves to next record in stream and stores it in {@link #stringWriter}. *//* w w w .java2 s . com*/ private void moveToNext() { try { XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(stringWriter); boolean hasMadeChanges; do { if (!reader.hasNext()) { break; } hasMadeChanges = false; // Keep a state to skip line feeds final XMLEvent event = reader.nextEvent(); if (event.isEndElement()) { level--; } else if (event.isStartElement()) { level++; } else if (event.isEndDocument()) { level--; } if (level >= RECORD_LEVEL) { if (event.isEndElement()) { writer.writeEndElement(); hasMadeChanges = true; } else if (event.isStartElement()) { final StartElement startElement = event.asStartElement(); final QName name = startElement.getName(); writer.writeStartElement(name.getNamespaceURI(), name.getLocalPart()); boolean isRecordRootElement = (RECORD_LEVEL == level - 1); if (isRecordRootElement) { for (int i = 0; i < rootNamespaceList.size(); i++) { Namespace namespace = rootNamespaceList.get(i); writer.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI()); } } // Declare namespaces (if any) final Iterator elementNamespaces = startElement.getNamespaces(); while (elementNamespaces.hasNext()) { Namespace elementNamespace = (Namespace) elementNamespaces.next(); if (isRecordRootElement) { if (rootNamespaceList.size() > 0) { for (int i = 0; i < rootNamespaceList.size(); i++) { Namespace namespace = rootNamespaceList.get(i); if (!namespace.getPrefix().equals(elementNamespace.getPrefix()) || !namespace.getNamespaceURI() .equals(elementNamespace.getNamespaceURI())) { writer.writeNamespace(elementNamespace.getPrefix(), elementNamespace.getNamespaceURI()); } } } else { writer.writeNamespace(elementNamespace.getPrefix(), elementNamespace.getNamespaceURI()); } } else { writer.writeNamespace(elementNamespace.getPrefix(), elementNamespace.getNamespaceURI()); } } // Write attributes final Iterator attributes = startElement.getAttributes(); while (attributes.hasNext()) { Attribute attribute = (Attribute) attributes.next(); QName attributeName = attribute.getName(); String value = attribute.getValue(); if (StringUtils.isEmpty(attributeName.getNamespaceURI())) { writer.writeAttribute(attributeName.getLocalPart(), value); } else { writer.writeAttribute(attributeName.getNamespaceURI(), attributeName.getLocalPart(), value); } } hasMadeChanges = true; } else if (event.isCharacters()) { final String text = event.asCharacters().getData().trim(); if (!text.isEmpty()) { writer.writeCharacters(text); hasMadeChanges = true; } } } } while (level > RECORD_LEVEL || !hasMadeChanges); writer.flush(); } catch (XMLStreamException e) { throw new RuntimeException("Unexpected parsing exception.", e); } }
From source file:com.bluexml.side.portal.alfresco.reverse.reverser.EclipseReverser.java
protected void readAnyElements(Map<String, String> props, List<Object> any) { for (Object object : any) { String nodeName = null;/*from w w w.j ava 2 s . c om*/ String nodeValue = null; if (object instanceof Element) { System.out.println(" any Element (w3c) ?" + object); Element el = (Element) object; nodeName = el.getNodeName(); nodeValue = el.getTextContent(); props.put(nodeName, nodeValue); } else if (object instanceof JAXBElement) { JAXBElement<String> jaxbE = (JAXBElement<String>) object; QName name = jaxbE.getName(); nodeName = name.getLocalPart(); nodeValue = jaxbE.getValue(); } props.put(nodeName, nodeValue); } }
From source file:com.evolveum.midpoint.web.component.input.QNameChoiceRenderer.java
@Override public Object getDisplayValue(QName object) { StringBuilder sb = new StringBuilder(); if (usePrefix) { String prefix = prefixMap.get(object.getNamespaceURI()); if (StringUtils.isNotBlank(prefix)) { sb.append(prefix);// w w w. j a v a 2s . c om } } sb.append(object.getLocalPart()); return sb.toString(); }
From source file:org.socialhistoryservices.pid.controllers.QRController.java
/** * metadata/*from ww w . j ava 2 s .com*/ * <p/> * Show the PID and it's local URLs * <p/> * Return model: * type | handle | resolveUrl * * @param na * @param id * @param handleResolverBaseUrl * @param model * @return * @throws HandleException */ @RequestMapping("/metadata/{na}/{id:.*}") public String metadata(@PathVariable("na") String na, @PathVariable("id") String id, @RequestParam(value = "r", required = false, defaultValue = "http://hdl.handle.net/") String handleResolverBaseUrl, Model model, HttpServletResponse response) throws HandleException { final String pid = na + "/" + id; final PidType pidType = qrService.getPid(pid); if (pidType == null) { model.addAttribute("pid", pid); response.setStatus(404); return "metadata404"; } if (!handleResolverBaseUrl.endsWith("/")) handleResolverBaseUrl += "/"; final List<String[]> handles = new ArrayList<String[]>(); if (pidType.getResolveUrl() == null) { for (LocationType location : pidType.getLocAtt().getLocation()) { if (location.getOtherAttributes().isEmpty()) { if (location.getView() == null) handles.add(new String[] { "LOC", handleResolverBaseUrl + pid, location.getHref(), pid }); else handles.add(new String[] { "LOC", handleResolverBaseUrl + pid + "?locatt=view:" + location.getView(), location.getHref(), pid + "?locatt=view:" + location.getView() }); } else for (QName key : location.getOtherAttributes().keySet()) { handles.add(new String[] { "LOC", handleResolverBaseUrl + pid + "?locatt=" + key.getLocalPart() + ":" + location.getOtherAttributes(), location.getHref(), pid + "?locatt=" + key.getLocalPart() + ":" + location.getOtherAttributes() }); } } } else { handles.add(new String[] { "URL", handleResolverBaseUrl + pid, pidType.getResolveUrl(), pid }); } model.addAttribute("pid", pid); model.addAttribute("handles", handles); return "metadata"; }
From source file:com.amalto.core.history.accessor.AttributeAccessor.java
private Node getAttribute() { Node parentNode = parent.getNode(); if (parentNode == null) { throw new IllegalStateException( "Could not find a parent node in document (check if document has a root element)."); //$NON-NLS-1$ }//from w w w . j a v a 2s. com NamedNodeMap attributes = parentNode.getAttributes(); if (attributes == null) { throw new IllegalStateException("Could not find attributes on parent node."); //$NON-NLS-1$ } QName qName = getQName(document.asDOM()); Node attribute = attributes.getNamedItemNS(qName.getNamespaceURI(), qName.getLocalPart()); if (attribute == null) { // Look up with namespace didn't work, falls back to standard getNamedItem attribute = attributes.getNamedItem(qName.getLocalPart()); } return attribute; }
From source file:com.amalto.core.history.accessor.AttributeAccessor.java
private Attr createAttribute(Node parentNode, Document domDocument) { // Ensure xsi prefix is declared if (attributeName.indexOf(':') > 0) { String attributePrefix = StringUtils.substringBefore(attributeName, ":"); //$NON-NLS-1$ String namespaceURI = domDocument.lookupNamespaceURI(attributePrefix); if (namespaceURI == null) { if ("xsi".equals(attributePrefix)) { //$NON-NLS-1$ domDocument.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); //$NON-NLS-1$ } else if ("tmdm".equals(attributePrefix)) { //$NON-NLS-1$ domDocument.getDocumentElement().setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:tmdm", SkipAttributeDocumentBuilder.TALEND_NAMESPACE); //$NON-NLS-1$ } else { throw new IllegalArgumentException("Unrecognized attribute prefix: '" + attributePrefix + "'."); //$NON-NLS-1$ //$NON-NLS-2$ }/*from www. j a va 2 s. c o m*/ } } QName qName = getQName(domDocument); Attr newAttribute = domDocument.createAttributeNS(qName.getNamespaceURI(), qName.getLocalPart()); String prefix = qName.getPrefix(); newAttribute.setPrefix(prefix); parentNode.getAttributes().setNamedItemNS(newAttribute); return newAttribute; }