List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:fi.laverca.ws.MSS_SignatureServiceLocator.java
/** * Set the endpoint address for the specified port name. * @param portName Name of the port/*ww w . j a v a2 s. c om*/ * @param address Address to set * @throws ServiceException if the port name is not recognized */ public void setEndpointAddress(final QName portName, final String address) throws ServiceException { this.setEndpointAddress(portName.getLocalPart(), address); }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static String declareXPathNamespaces(XmlObject xmlObject) { Map<QName, String> map = new HashMap<QName, String>(); XmlCursor cursor = xmlObject.newCursor(); while (cursor.hasNextToken()) { if (cursor.toNextToken().isNamespace()) map.put(cursor.getName(), cursor.getTextValue()); }/* ww w .j ava 2 s . c o m*/ cursor.dispose(); Iterator<QName> i = map.keySet().iterator(); int nsCnt = 0; StringBuffer buf = new StringBuffer(); Set<String> prefixes = new HashSet<String>(); Set<String> usedPrefixes = new HashSet<String>(); while (i.hasNext()) { QName name = i.next(); String prefix = name.getLocalPart(); if (prefix.length() == 0) prefix = "ns" + Integer.toString(++nsCnt); else if (prefix.equals("xsd") || prefix.equals("xsi")) continue; if (usedPrefixes.contains(prefix)) { int c = 1; while (usedPrefixes.contains(prefix + c)) c++; prefix = prefix + Integer.toString(c); } else prefixes.add(prefix); buf.append("declare namespace "); buf.append(prefix); buf.append("='"); buf.append(map.get(name)); buf.append("';\n"); usedPrefixes.add(prefix); } return buf.toString(); }
From source file:com.aionemu.gameserver.dataholders.loadingutils.XmlMerger.java
private boolean isImportQName(QName name) { return "import".equals(name.getLocalPart()); }
From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngester.java
@Override public Communication fromCharacterBasedFile(final Path path) throws IngestException { if (!Files.exists(path)) throw new IngestException("No file at: " + path.toString()); AnalyticUUIDGeneratorFactory f = new AnalyticUUIDGeneratorFactory(); AnalyticUUIDGenerator g = f.create(); Communication c = new Communication(); c.setUuid(g.next());/*from w w w .j a v a 2s . com*/ c.setType(this.getKind()); c.setMetadata(TooledMetadataConverter.convert(this)); try { ExistingNonDirectoryFile ef = new ExistingNonDirectoryFile(path); c.setId(ef.getName().split("\\.")[0]); } catch (NoSuchFileException | NotFileException e) { // might throw if path is a directory. throw new IngestException(path.toString() + " is not a file, or is a directory."); } String content; try (InputStream is = Files.newInputStream(path); BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 8);) { content = IOUtils.toString(bin, StandardCharsets.UTF_8); c.setText(content); } catch (IOException e) { throw new IngestException(e); } try (InputStream is = Files.newInputStream(path); BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 8); BufferedReader reader = new BufferedReader(new InputStreamReader(bin, StandardCharsets.UTF_8));) { XMLEventReader rdr = null; try { rdr = inF.createXMLEventReader(reader); // Below method moves the reader // to the headline end element. Section headline = this.handleBeginning(rdr, content, c); headline.setUuid(g.next()); c.addToSectionList(headline); TextSpan sts = headline.getTextSpan(); LOGGER.debug("headline text: {}", c.getText().substring(sts.getStart(), sts.getEnding())); int sectNumber = 1; int subSect = 0; int currOff = -1; // Big amounts of characters. while (rdr.hasNext()) { XMLEvent nextEvent = rdr.nextEvent(); currOff = nextEvent.getLocation().getCharacterOffset(); // First: see if document is going to end. // If yes: exit. if (nextEvent.isEndDocument()) break; // region // enables ingestion of quotes inside a usenet webpost. // by Tongfei Chen if (nextEvent.isStartElement() && nextEvent.asStartElement().getName().equals(QName.valueOf("QUOTE"))) { Attribute attrQuote = nextEvent.asStartElement() .getAttributeByName(QName.valueOf("PREVIOUSPOST")); String quote = StringEscapeUtils.escapeXml(attrQuote.getValue()); int location = attrQuote.getLocation().getCharacterOffset() + "<QUOTE PREVIOUSPOST=\"".length(); Section quoteSection = new Section(g.next(), "quote") .setTextSpan(new TextSpan(location, location + quote.length())); c.addToSectionList(quoteSection); } // endregion // Check if start element. if (nextEvent.isCharacters()) { Characters chars = nextEvent.asCharacters(); if (!chars.isWhiteSpace()) { String fpContent = chars.getData(); LOGGER.debug("Character offset: {}", currOff); LOGGER.debug("Character based data: {}", fpContent); SimpleImmutableEntry<Integer, Integer> pads = trimSpacing(fpContent); final int tsb = currOff + pads.getKey(); final int tse = currOff + fpContent.replace("\"", """).replace("<", "<") .replace(">", ">").length() - (pads.getValue()); // MAINTAIN CORRECT TEXT SPAN // CANNOT USE StringEscapeUtils.escapeXml because it will escape "'", which // is not escaped in the data // @tongfei LOGGER.debug("Section text: {}", content.substring(tsb, tse)); TextSpan ts = new TextSpan(tsb, tse); String sk; if (subSect == 0) sk = "poster"; else if (subSect == 1) sk = "postdate"; else sk = "post"; Section s = new Section(); s.setKind(sk); s.setTextSpan(ts); s.setUuid(g.next()); List<Integer> intList = new ArrayList<>(); intList.add(sectNumber); intList.add(subSect); s.setNumberList(intList); c.addToSectionList(s); subSect++; } } else if (nextEvent.isEndElement()) { EndElement ee = nextEvent.asEndElement(); currOff = ee.getLocation().getCharacterOffset(); QName name = ee.getName(); String localName = name.getLocalPart(); LOGGER.debug("Hit end element: {}", localName); if (localName.equalsIgnoreCase(POST_LOCAL_NAME)) { LOGGER.debug("Switching to new post."); sectNumber++; subSect = 0; } else if (localName.equalsIgnoreCase(TEXT_LOCAL_NAME)) { // done with document. break; } } } return c; } catch (XMLStreamException | ConcreteException | StringIndexOutOfBoundsException | ClassCastException x) { throw new IngestException(x); } finally { if (rdr != null) try { rdr.close(); } catch (XMLStreamException e) { // not likely. LOGGER.info("Error closing XMLReader.", e); } } } catch (IOException e) { throw new IngestException(e); } }
From source file:com.github.sardine.DavResource.java
/** * @return Additional metadata. This implementation does not take namespaces into account. *//*from w ww . j a v a2s .co m*/ public Map<String, String> getCustomProps() { Map<String, String> local = new HashMap<String, String>(); Map<QName, String> properties = this.getCustomPropsNS(); for (QName key : properties.keySet()) { local.put(key.getLocalPart(), properties.get(key)); } return local; }
From source file:no.digipost.api.interceptors.Wss4jInterceptor.java
private boolean wasSigned(final Document doc, final List<WSSecurityEngineResult> results, final QName... qnamePath) { String path = "/" + doc.getDocumentElement().getPrefix() + ":Envelope"; for (QName qn : qnamePath) { Node n = doc.getDocumentElement().getElementsByTagNameNS(qn.getNamespaceURI(), qn.getLocalPart()) .item(0);// ww w . j a v a2s. c o m if (n == null) { return false; } path += "/" + n.getPrefix() + ":" + n.getLocalName(); } for (WSSecurityEngineResult r : results) { if (r.containsKey("data-ref-uris")) { List<WSDataRef> refs = (List<WSDataRef>) r.get("data-ref-uris"); for (WSDataRef ref : refs) { if (ref.getName().equals(qnamePath[qnamePath.length - 1])) { if (ref.getXpath().equals(path)) { return true; } } } } } return false; }
From source file:com.evolveum.midpoint.prism.schema.PrismSchema.java
protected QName toElementQName(QName qname) { return new QName(qname.getNamespaceURI(), toElementName(qname.getLocalPart())); }
From source file:com.collabnet.ccf.pi.sfee.v44.SFEEAttachmentHandler.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. * //w w w.j a v a2 s. c o m * @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 */ public ArtifactSoapDO attachFileToArtifact(String sessionId, String artifactId, String comment, String fileName, String mimeType, GenericArtifact att, byte[] linkUrl) throws RemoteException { ArtifactSoapDO 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 = fileStorageApp.startFileUpload(sessionId); fileStorageApp.write(sessionId, fileDescriptor, data); fileStorageApp.endFileUpload(sessionId, fileDescriptor); } else { try { DataSource dataSource = new FileDataSource(new File(attachmentDataFileName)); DataHandler dataHandler = new DataHandler(dataSource); fileDescriptor = fileStorageSoapApp.uploadFile(sessionId, dataHandler); } catch (IOException e) { String message = "Exception while uploading the attachment " + attachmentDataFileName; log.error(message, e); throw new CCFRuntimeException(message, e); } } soapDo = mTrackerApp.getArtifactData(sessionId, artifactId); boolean fileAttached = true; while (fileAttached) { try { fileAttached = false; mTrackerApp.setArtifactData(sessionId, 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 = mTrackerApp.getArtifactData(sessionId, 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:net.javacrumbs.springws.test.lookup.PayloadRootBasedResourceLookup.java
public Resource lookupResource(URI uri, WebServiceMessage message) throws IOException { QName payloadQName; try {//from ww w .j av a 2 s . c om payloadQName = PayloadRootUtils.getPayloadRootQName(message.getPayloadSource(), TRANSFORMER_FACTORY); } catch (TransformerException e) { logger.warn("Can not resolve payload.", e); return null; } catch (XMLStreamException e) { logger.warn("Can not resolve payload.", e); return null; } String payloadName = payloadQName.getLocalPart(); String[] expressions = getDiscriminators(payloadName); Document document = getXmlUtil().loadDocument(message); Resource resource; int discriminatorsCount = expressions.length; do { String resourceName = getResourceName(uri, payloadName, expressions, discriminatorsCount, document); logger.debug("Looking for resource " + resourceName); resource = getResourceLoader().getResource(resourceName); discriminatorsCount--; } while ((resource == null || !resource.exists()) && discriminatorsCount >= 0); if (resource != null && resource.exists()) { logger.debug("Found resource " + resource); return processResource(uri, message, resource); } else { return null; } }
From source file:no.digipost.api.interceptors.Wss4jInterceptor.java
private void validateIsSigned(final Document doc, final List<WSSecurityEngineResult> results, final QName... qnamePath) { if (!wasSigned(doc, results, qnamePath)) { QName qName = qnamePath[qnamePath.length - 1]; throw new Wss4jSecurityValidationException( qName.getPrefix() + ":" + qName.getLocalPart() + " was not signed"); }// w w w . j a v a2 s . c o m }