當前位置: 首頁>>代碼示例>>Java>>正文


Java Namespace.getPrefix方法代碼示例

本文整理匯總了Java中javax.xml.stream.events.Namespace.getPrefix方法的典型用法代碼示例。如果您正苦於以下問題:Java Namespace.getPrefix方法的具體用法?Java Namespace.getPrefix怎麽用?Java Namespace.getPrefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.events.Namespace的用法示例。


在下文中一共展示了Namespace.getPrefix方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNamespacePrefix

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public String getNamespacePrefix(int index) {
    XMLSecEvent xmlSecEvent = getCurrentEvent();
    switch (xmlSecEvent.getEventType()) {
        case START_ELEMENT:
            return xmlSecEvent.asStartElement().getOnElementDeclaredNamespaces().get(index).getPrefix();
        case END_ELEMENT:
            int count = 0;
            Iterator<Namespace> namespaceIterator = xmlSecEvent.asEndElement().getNamespaces();
            while (namespaceIterator.hasNext()) {
                Namespace namespace = namespaceIterator.next();
                if (count == index) {
                    return namespace.getPrefix();
                }
                count++;
            }
            throw new ArrayIndexOutOfBoundsException(index);
        default:
            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
    }
}
 
開發者ID:Legostaev,項目名稱:xmlsec-gost,代碼行數:23,代碼來源:XMLSecurityStreamReader.java

示例2: buildByPrefixMap

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
private Map<String,Namespace> buildByPrefixMap()
{
    int len = mNamespaces.size();
    if (len == 0) {
        return Collections.emptyMap();
    }

    LinkedHashMap<String,Namespace> m = new LinkedHashMap<String,Namespace>(1 + len + (len>>1));
    for (int i = 0; i < len; ++i) {
        Namespace ns = mNamespaces.get(i);
        String prefix = ns.getPrefix();
        if (prefix == null) { // shouldn't happen but...
            prefix = "";
        }
        m.put(prefix, ns);
    }
    return m;
}
 
開發者ID:FasterXML,項目名稱:woodstox,代碼行數:19,代碼來源:MergedNsContext.java

示例3: fillDeclaredPrefixes

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
/** Fills in the list of declared prefixes. */
private void fillDeclaredPrefixes(Iterator namespaces) {
    fDeclaredPrefixes.clear();
    while (namespaces.hasNext()) {
        Namespace ns = (Namespace) namespaces.next();
        String prefix = ns.getPrefix();
        fDeclaredPrefixes.add(prefix != null ? prefix : "");
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:StAXSchemaParser.java

示例4: doGetPrefix

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
@Override
public String doGetPrefix(String nsURI)
{
    // Note: base class checks for 'known' problems and prefixes:
    if (mNsByURI == null) {
        mNsByURI = buildByNsURIMap();
    }
    Namespace ns = mNsByURI.get(nsURI);
    if (ns == null && mParentCtxt != null) {
        return mParentCtxt.getPrefix(nsURI);
    }
    return (ns == null) ? null : ns.getPrefix();
}
 
開發者ID:FasterXML,項目名稱:woodstox,代碼行數:14,代碼來源:MergedNsContext.java

示例5: doGetPrefixes

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
@Override
public Iterator<String> doGetPrefixes(String nsURI)
{
    // Note: base class checks for 'known' problems and prefixes:
    ArrayList<String> l = null;

    for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
        Namespace ns = mNamespaces.get(i);
        String uri = ns.getNamespaceURI();
        if (uri == null) {
            uri = "";
        }
        if (uri.equals(nsURI)) {
            if (l == null) {
                l = new ArrayList<String>();
            }
            String prefix = ns.getPrefix();
            l.add((prefix == null) ? "" : prefix);
        }
    }

    if (mParentCtxt != null) {
        @SuppressWarnings("unchecked")
        Iterator<String> it = /*(Iterator<String>)*/mParentCtxt.getPrefixes(nsURI);
        if (l == null) {
            return it;
        }
        while (it.hasNext()) {
            l.add(it.next());
        }
    }

    if (l == null) {
        return DataUtil.emptyIterator();
    }
    return l.iterator();
}
 
開發者ID:FasterXML,項目名稱:woodstox,代碼行數:38,代碼來源:MergedNsContext.java

示例6: buildNamespaceDeclarations

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
private String buildNamespaceDeclarations(ParentNode parent) {
	final Map<String, String> namespaces = new HashMap<String, String>();

	for (parent = (ParentNode) parent.getParentNode(); parent != null; parent = (ParentNode) parent.getParentNode()) {
		// Only Element nodes may have namespace declarations on them
		if (!(parent instanceof Element)) {
			continue;
		}

		final List<Namespace> declaredNamespaces = parent.getDeclaredNamespaces();
		for (final Namespace declaredNamespace : declaredNamespaces) {
			final String key = declaredNamespace.getPrefix();
			if (namespaces.containsKey(key)) {
				continue; // NS has been redefined further down the tree
			}

			namespaces.put(key, declaredNamespace.getNamespaceURI());
		}
	}

	// Build namespace string
	final StringBuilder sb = new StringBuilder();
	for (final Entry<String, String> e : namespaces.entrySet()) {
		sb.append(XMLConstants.XMLNS_ATTRIBUTE);
		if (!e.getKey().isEmpty()) {
			sb.append(':');
			sb.append(e.getKey());
		}
		sb.append("=\"");
		sb.append(e.getValue());
		sb.append("\" ");
	}

	final String namespaceDeclarations = sb.toString();
	log.debug("Built namespace declaration string: " + namespaceDeclarations);
	return namespaceDeclarations;
}
 
開發者ID:whummer,項目名稱:scaleDOM,代碼行數:38,代碼來源:ScaleDomDocument.java

示例7: qname

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
/**
 * Combines a Namespace and local name into a QName.
 */
public static QName qname(Namespace ns, String name) {
    return new QName(ns.getNamespaceURI(), name, ns.getPrefix());
}
 
開發者ID:Tradeshift,項目名稱:ts-reaktive,代碼行數:7,代碼來源:XMLProtocol.java

示例8: add

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
public void add(XMLEvent event) throws XMLStreamException {
	if (event.isStartDocument()) {
		streamWriter.writeStartDocument();
	} else if (event.isStartElement()) {
		StartElement element = event.asStartElement();
		QName elQName = element.getName();
		if (elQName.getPrefix().length() > 0
				&& elQName.getNamespaceURI().length() > 0)
			streamWriter.writeStartElement(elQName.getPrefix(), elQName
					.getLocalPart(), elQName.getNamespaceURI());
		else if (elQName.getNamespaceURI().length() > 0)
			streamWriter.writeStartElement(elQName.getNamespaceURI(),
					elQName.getLocalPart());
		else
			streamWriter.writeStartElement(elQName.getLocalPart());

		// Add element namespaces
		Iterator namespaces = element.getNamespaces();
		while (namespaces.hasNext()) {
			Namespace ns = (Namespace) namespaces.next();
			String prefix = ns.getPrefix();
			String nsURI = ns.getNamespaceURI();
			streamWriter.writeNamespace(prefix, nsURI);
		}

		// Add element attributes
		Iterator attris = element.getAttributes();
		while (attris.hasNext()) {
			Attribute attr = (Attribute) attris.next();
			QName atQName = attr.getName();
			String value = attr.getValue();
			if (atQName.getPrefix().length() > 0
					&& atQName.getNamespaceURI().length() > 0)
				streamWriter.writeAttribute(atQName.getPrefix(), atQName
						.getNamespaceURI(), atQName.getLocalPart(), value);
			else if (atQName.getNamespaceURI().length() > 0)
				streamWriter.writeAttribute(atQName.getNamespaceURI(),
						atQName.getLocalPart(), value);
			else
				streamWriter.writeAttribute(atQName.getLocalPart(), value);
		}
	} else if (event.isCharacters()) {
		Characters chars = event.asCharacters();
		streamWriter.writeCharacters(chars.getData());
	} else if (event.isEndElement()) {
		streamWriter.writeEndElement();
	} else if (event.isEndDocument()) {
		streamWriter.writeEndDocument();
	} else {
		throw new XMLStreamException("Unsupported event type: " + event);
	}
}
 
開發者ID:jettison-json,項目名稱:jettison,代碼行數:53,代碼來源:AbstractXMLEventWriter.java

示例9: retriveDocument

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
/**
 * @return document
 * @throws javax.xml.parsers.ParserConfigurationException
 */
public Document retriveDocument(XMLEventReader xmlEventReader)
    throws ParserConfigurationException {
  DocumentBuilderFactory dbfInstance = DocumentBuilderFactory
      .newInstance();
  DocumentBuilder documentBuilder = dbfInstance.newDocumentBuilder();
  Document document = documentBuilder.newDocument();

  Element currentElement = document.getDocumentElement();

  while (xmlEventReader.hasNext()) {
    XMLEvent xmleve = (XMLEvent) xmlEventReader.next();

    if (xmleve.getEventType() == XmlNodeType.END_ELEMENT) {
      Node node = currentElement.getParentNode();
      if (node instanceof Document) {
        currentElement = ((Document) node).getDocumentElement();
      } else {
        currentElement = (Element) currentElement.getParentNode();
      }
    }

    if (xmleve.getEventType() == XmlNodeType.START_ELEMENT) {
      // startElement((StartElement) xmleve,doc);
      StartElement ele = (StartElement) xmleve;
      Element element = null;
      element = document.createElementNS(ele.getName()
          .getNamespaceURI(), ele.getName().getLocalPart());

      Iterator<Attribute> ite = ele.getAttributes();

      while (ite.hasNext()) {
        Attribute attr = ite.next();
        element.setAttribute(attr.getName().getLocalPart(),
            attr.getValue());
      }

      String xmlns = EwsUtilities.WSTrustFebruary2005Namespace;//"http://schemas.xmlsoap.org/wsdl/";
      ite = ele.getNamespaces();
      while (ite.hasNext()) {
        Namespace ns = (Namespace) ite.next();
        String name = ns.getPrefix();
        if (!name.isEmpty()) {
          element.setAttributeNS(xmlns, name,
              ns.getNamespaceURI());
        } else {
          xmlns = ns.getNamespaceURI();
        }
      }

      if (currentElement == null) {
        document.appendChild(element);
      } else {
        currentElement.appendChild(element);
      }

      currentElement = element;
      element.setUserData("location", ele.getLocation(), null);
    }
  }
  return document;
}
 
開發者ID:OfficeDev,項目名稱:ews-java-api,代碼行數:66,代碼來源:ExecuteDiagnosticMethodResponse.java

示例10: retriveDocument

import javax.xml.stream.events.Namespace; //導入方法依賴的package包/類
/**
 * 
 * @param xmlEventReader
 * @return document
 * @throws ParserConfigurationException
 */
public Document retriveDocument(XMLEventReader xmlEventReader)
		throws ParserConfigurationException {
	DocumentBuilderFactory dbfInstance = DocumentBuilderFactory
			.newInstance();
	DocumentBuilder documentBuilder = dbfInstance.newDocumentBuilder();
	Document document = documentBuilder.newDocument();

	Element currentElement = document.getDocumentElement();

	while (xmlEventReader.hasNext()) {
		XMLEvent xmleve = (XMLEvent) xmlEventReader.next();

		if (xmleve.getEventType() == XMLNodeType.END_ELEMENT) {
			Node node = currentElement.getParentNode();
			if (node instanceof Document) {
				currentElement = ((Document) node).getDocumentElement();
			} else {
				currentElement = (Element) currentElement.getParentNode();
			}
		}

		if (xmleve.getEventType() == XMLNodeType.START_ELEMENT) {
			// startElement((StartElement) xmleve,doc);
			StartElement ele = (StartElement) xmleve;
			Element element = null;
			element = document.createElementNS(ele.getName()
					.getNamespaceURI(), ele.getName().getLocalPart());

			Iterator ite = ele.getAttributes();

			while (ite.hasNext()) {
				Attribute attr = (Attribute) ite.next();
				element.setAttribute(attr.getName().getLocalPart(),
						attr.getValue());
			}

			String xmlns = EwsUtilities.WSTrustFebruary2005Namespace;//"http://schemas.xmlsoap.org/wsdl/";
			ite = ele.getNamespaces();
			while (ite.hasNext()) {
				Namespace ns = (Namespace) ite.next();
				String name = ns.getPrefix();
				if (!name.isEmpty()) {
					element.setAttributeNS(xmlns, name,
							ns.getNamespaceURI());
				} else {
					xmlns = ns.getNamespaceURI();
				}
			}

			if (currentElement == null) {
				document.appendChild(element);
			} else {
				currentElement.appendChild(element);
			}

			currentElement = element;
			element.setUserData("location", ele.getLocation(), null);
		}
	}
	return document;
}
 
開發者ID:sheymans,項目名稱:todopl,代碼行數:68,代碼來源:ExecuteDiagnosticMethodResponse.java


注:本文中的javax.xml.stream.events.Namespace.getPrefix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。