List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:de.ingrid.iplug.csw.dsc.cswclient.impl.SoapRequest.java
/** * @see OpenGIS Catalogue Services Specification 2.0.2 - ISO Metadata * Application Profile 8.2.2.2//from w w w . j a v a2 s .c om */ @Override public Document doGetRecordById(String serverURL, CSWQuery query) throws Exception { // create the request OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace cswNs = fac.createOMNamespace(query.getSchema().getQName().getNamespaceURI(), query.getSchema().getQName().getPrefix()); // create method OMElement method = fac.createOMElement(Operation.GET_RECORD_BY_ID.toString(), cswNs); // add the default parameters method.addAttribute("service", CSWConstants.SERVICE_TYPE, null); // add the query specific parameters method.addAttribute("version", query.getVersion(), null); method.addAttribute("outputFormat", query.getOutputFormat().toString(), null); QName outputSchemaQN = query.getOutputSchema().getQName(); method.declareNamespace(outputSchemaQN.getNamespaceURI(), outputSchemaQN.getPrefix()); if (outputSchemaQN.getLocalPart().length() > 0) method.addAttribute("outputSchema", outputSchemaQN.getPrefix() + ":" + outputSchemaQN.getLocalPart(), null); else method.addAttribute("outputSchema", outputSchemaQN.getNamespaceURI(), null); // create Id OMElement idNode = fac.createOMElement("Id", cswNs); idNode.setText(query.getId()); method.addChild(idNode); // create ElementSetName element typename OMElement elementSetName = fac.createOMElement("ElementSetName", cswNs); elementSetName.setText(query.getElementSetName().toString()); method.addChild(elementSetName); // send the request try { return sendRequest(serverURL, method); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngester.java
private Section handleBeginning(final XMLEventReader rdr, final String content, final Communication cptr) throws XMLStreamException, ConcreteException { // The first type is always a document start event. Skip it. rdr.nextEvent();//w w w .ja va2 s .c o m // The second type is a document block. Skip it. rdr.nextEvent(); // The third type is a whitespace block. Skip it. rdr.nextEvent(); // The next type is a docid start tag. rdr.nextEvent(); // Text of the docid. Characters cc = rdr.nextEvent().asCharacters(); String idTxt = cc.getData().trim(); cptr.setId(idTxt); // The next part is the docid end element. Skip. rdr.nextEvent(); // Whitespace. Skip. rdr.nextEvent(); // Reader is now pointing at the doctype. // XMLEvent doctypeStart = rdr.nextEvent(); rdr.nextEvent(); // StartElement dtse = doctypeStart.asStartElement(); // Doc type content. Characters docTypeChars = rdr.nextEvent().asCharacters(); String docTypeContent = docTypeChars.getData().trim(); cptr.setType(docTypeContent); // Doctype end. Skip. rdr.nextEvent(); // Whitespace. skip. rdr.nextEvent(); // Datetime start. rdr.nextEvent(); // Datetime value. Characters dtChars = rdr.nextEvent().asCharacters(); // TODO: parse this String dtValue = dtChars.getData().trim(); DateTime dt = this.dtf.parseDateTime(dtValue).toDateTime(DateTimeZone.UTC); LOGGER.debug("Got DateTime: {}", dt.toString()); long millis = dt.getMillis(); cptr.setStartTime(millis / 1000); // Datetime end. rdr.nextEvent(); // WS rdr.nextEvent(); // Body begin. rdr.nextEvent(); // WS rdr.nextEvent(); // Headline begin. XMLEvent hl = rdr.nextEvent(); StartElement hlse = hl.asStartElement(); QName hlqn = hlse.getName(); final String hlPart = hlqn.getLocalPart(); LOGGER.debug("QN: {}", hlPart); // Headline text. Characters hlChars = rdr.nextEvent().asCharacters(); final int charOff = hlChars.getLocation().getCharacterOffset(); final int clen = hlChars.getData().length(); // Construct section, text span, etc. final int endTextOffset = charOff + clen; final String hlText = content.substring(charOff, endTextOffset); SimpleImmutableEntry<Integer, Integer> pads = trimSpacing(hlText); TextSpan ts = new TextSpan(charOff + pads.getKey(), endTextOffset - pads.getValue()); Section s = new Section(); s.setKind("headline"); s.setTextSpan(ts); List<Integer> intList = new ArrayList<>(); intList.add(0); s.setNumberList(intList); return s; }
From source file:com.evolveum.midpoint.repo.sql.query.QueryContext.java
private String createAlias(Definition def, QName qname) { String prefix;/*from w w w. java 2s .c om*/ if (def != null) { //we want to skip 'R' prefix for entity definition names int prefixIndex = (def instanceof EntityDefinition) ? 1 : 0; prefix = Character.toString(def.getJpaName().charAt(prefixIndex)).toLowerCase(); } else { prefix = Character.toString(qname.getLocalPart().charAt(0)).toLowerCase(); } int index = 1; String alias = prefix; while (hasAlias(alias)) { alias = prefix + Integer.toString(index); index++; if (index > 5) { throw new IllegalStateException("Alias index for definition '" + def + "' is more than 5? This probably should not happen."); } } return alias; }
From source file:com.centeractive.ws.builder.soap.SampleXmlUtil.java
private static final String formatQName(XmlCursor xmlc, QName qName) { XmlCursor parent = xmlc.newCursor(); parent.toParent();/* w w w. j a va2 s . com*/ String prefix = parent.prefixForNamespace(qName.getNamespaceURI()); parent.dispose(); String name; if (prefix == null || prefix.length() == 0) name = qName.getLocalPart(); else name = prefix + ":" + qName.getLocalPart(); return name; }
From source file:org.cleverbus.core.common.exception.AbstractSoapExceptionFilter.java
/** * Gets exception from fault detail.// w w w . j ava 2 s. c o m * <p/> * If there is no fault detail then no exception is returned. * If there is no supported exception in fault detail then {@link IntegrationException} is returned. * * @param faultDetail the fault detail * @return exception */ @Nullable private Exception getFaultException(@Nullable SoapFaultDetail faultDetail) { if (faultDetail != null) { DOMSource detailSource = (DOMSource) faultDetail.getSource(); Node detailNode = detailSource.getNode(); QName exName = getExceptionName(detailNode); Exception exception = createException(exName, detailNode); if (exception == null) { // throws common exception with specified exception exception = new IntegrationException(getErrorCodeForException(null), exName.getLocalPart()); } return exception; } return null; }
From source file:de.ingrid.iplug.csw.dsc.cswclient.impl.SoapRequest.java
/** * @see OpenGIS Catalogue Services Specification 2.0.2 - ISO Metadata * Application Profile 8.2.2.1// w w w.ja va 2 s . c o m */ @Override public Document doGetRecords(String serverURL, CSWQuery query) throws Exception { // create the request OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace cswNs = fac.createOMNamespace(query.getSchema().getQName().getNamespaceURI(), query.getSchema().getQName().getPrefix()); // create method OMElement method = fac.createOMElement(Operation.GET_RECORDS.toString(), cswNs); method.declareNamespace(Namespace.ISO.getQName().getNamespaceURI(), Namespace.ISO.getQName().getPrefix()); method.declareNamespace(Namespace.GML.getQName().getNamespaceURI(), Namespace.GML.getQName().getPrefix()); // add the default parameters method.addAttribute("service", CSWConstants.SERVICE_TYPE, null); // add the query specific parameters method.addAttribute("version", query.getVersion(), null); method.addAttribute("outputFormat", query.getOutputFormat().toString(), null); method.addAttribute("resultType", query.getResultType().toString(), null); method.addAttribute("startPosition", Integer.toString(query.getStartPosition()), null); method.addAttribute("maxRecords", Integer.toString(query.getMaxRecords()), null); QName outputSchemaQN = query.getOutputSchema().getQName(); method.declareNamespace(outputSchemaQN.getNamespaceURI(), outputSchemaQN.getPrefix()); if (outputSchemaQN.getLocalPart().length() > 0) method.addAttribute("outputSchema", outputSchemaQN.getPrefix() + ":" + outputSchemaQN.getLocalPart(), null); else method.addAttribute("outputSchema", outputSchemaQN.getNamespaceURI(), null); // create Query element typename OMElement queryElem = fac.createOMElement("Query", cswNs); // add typeNames attribute List<String> typeNames = new ArrayList<String>(); for (TypeName typeName : query.getTypeNames()) { QName typeNameQN = typeName.getQName(); method.declareNamespace(typeNameQN.getNamespaceURI(), typeNameQN.getPrefix()); typeNames.add(typeNameQN.getPrefix() + ":" + typeNameQN.getLocalPart()); } String typeNamesValue = StringUtils.join(typeNames.toArray(), ","); queryElem.addAttribute("typeNames", typeNamesValue, null); // create ElementSetName element typename OMElement elementSetName = fac.createOMElement("ElementSetName", cswNs); elementSetName.setText(query.getElementSetName().toString()); queryElem.addChild(elementSetName); // add the Filter if (query.getConstraint() != null) { // create Constraint // make sure the constraint element is only created when // we have a filter. OMElement constraint = fac.createOMElement("Constraint", cswNs); constraint.addAttribute("version", query.getConstraintLanguageVersion(), null); queryElem.addChild(constraint); OMElement filter = XMLUtils.toOM(query.getConstraint().getDocumentElement()); constraint.addChild(filter); } method.addChild(queryElem); // send the request try { return sendRequest(serverURL, method); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.evolveum.midpoint.util.DOMUtil.java
public static void setQNameAttribute(Element element, QName attributeName, QName attributeValue, Element definitionElement) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS(attributeName.getNamespaceURI(), attributeName.getLocalPart()); String namePrefix = lookupOrCreateNamespaceDeclaration(element, attributeName.getNamespaceURI(), attributeName.getPrefix(), element, true); attr.setPrefix(namePrefix);//from ww w. j a va 2s .co m setQNameAttribute(element, attr, attributeValue, definitionElement); }
From source file:com.evolveum.midpoint.notifications.impl.formatters.TextFormatter.java
private String localPart(QName qname) { return qname == null ? null : qname.getLocalPart(); }
From source file:com.collabnet.ccf.teamforge.TFAttachmentHandler.java
/** * This method uploads the file and gets the new file descriptor returned * from the TF system. It then associates the file descriptor to the * artifact there by adding the attachment to the artifact. * //ww w. ja v a 2 s. c om * @param sessionId * - The current session id * @param artifactId * - The artifact's id to which the attachment should be added. * @param comment * - Comment for the attachment addition * @param fileName * - Name of the file that is attached to this artifact * @param mimeType * - MIME type of the file that is being attached. * @param att * - the file content * @param linkUrl * * @throws RemoteException * - if any SOAP api call fails * @throws PlanningFolderRuleViolationException */ public ArtifactDO attachFileToArtifact(Connection connection, String artifactId, String comment, String fileName, String mimeType, GenericArtifact att, byte[] linkUrl) throws RemoteException, PlanningFolderRuleViolationException { ArtifactDO soapDo = null; String attachmentDataFileName = GenericArtifactHelper .getStringGAField(AttachmentMetaData.ATTACHMENT_DATA_FILE, att); boolean retryCall = true; while (retryCall) { retryCall = false; String fileDescriptor = null; try { byte[] data = null; if (StringUtils.isEmpty(attachmentDataFileName)) { if (linkUrl == null) { data = att.getRawAttachmentData(); } else { data = linkUrl; } fileDescriptor = connection.getFileStorageClient().startFileUpload(); connection.getFileStorageClient().write(fileDescriptor, data); connection.getFileStorageClient().endFileUpload(fileDescriptor); } else { try { DataSource dataSource = new FileDataSource(new File(attachmentDataFileName)); DataHandler dataHandler = new DataHandler(dataSource); fileDescriptor = connection.getFileStorageClient().uploadFile(dataHandler); } catch (IOException e) { String message = "Exception while uploading the attachment " + attachmentDataFileName; log.error(message, e); throw new CCFRuntimeException(message, e); } } soapDo = connection.getTrackerClient().getArtifactData(artifactId); boolean fileAttached = true; while (fileAttached) { try { fileAttached = false; connection.getTrackerClient().setArtifactData(soapDo, comment, fileName, mimeType, fileDescriptor); } catch (AxisFault e) { javax.xml.namespace.QName faultCode = e.getFaultCode(); if (!faultCode.getLocalPart().equals("VersionMismatchFault")) { throw e; } logConflictResolutor.warn("Stale attachment update, trying again ...:", e); soapDo = connection.getTrackerClient().getArtifactData(artifactId); fileAttached = true; } } } catch (AxisFault e) { javax.xml.namespace.QName faultCode = e.getFaultCode(); if (!faultCode.getLocalPart().equals("InvalidSessionFault")) { throw e; } if (connectionManager.isEnableReloginAfterSessionTimeout() && (!connectionManager.isUseStandardTimeoutHandlingCode())) { log.warn("While uploading an attachment, the session id became invalid, trying again", e); retryCall = true; } else { throw e; } } } // we have to increase the version after the update // TODO Find out whether this really works if last modified date differs // from actual last modified date soapDo.setVersion(soapDo.getVersion() + 1); return soapDo; }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static NodeList getChildElementsNS(Element elm, QName name) { return getChildElementsByTagNameNS(elm, name.getNamespaceURI(), name.getLocalPart()); }