当前位置: 首页>>代码示例>>Java>>正文


Java DOMImplementation.hasFeature方法代码示例

本文整理汇总了Java中org.w3c.dom.DOMImplementation.hasFeature方法的典型用法代码示例。如果您正苦于以下问题:Java DOMImplementation.hasFeature方法的具体用法?Java DOMImplementation.hasFeature怎么用?Java DOMImplementation.hasFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.DOMImplementation的用法示例。


在下文中一共展示了DOMImplementation.hasFeature方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toXml

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
public static String toXml(Document domDoc) throws TransformerException {
    DOMImplementation domImplementation = domDoc.getImplementation();
    if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) {
        DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
        LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
        DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
        if (domConfiguration.canSetParameter("xml-declaration", Boolean.TRUE))
            lsSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
        if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
            lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
            LSOutput lsOutput = domImplementationLS.createLSOutput();
            lsOutput.setEncoding("UTF-8");
            StringWriter stringWriter = new StringWriter();
            lsOutput.setCharacterStream(stringWriter);
            lsSerializer.write(domDoc, lsOutput);
            return stringWriter.toString();
        }
    }
    return toXml((Node)domDoc);
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:21,代码来源:DomHelper.java

示例2: isSupported

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
/**
 * <b>DOM L2</b>
 * Consults the DOM implementation to determine if the requested
 * feature is supported.  DocumentType subclasses must override
 * this method, and associate themselves directly with the
 * DOMImplementation node used.  (This method relies on being able
 * to access the DOMImplementation from the owner document, but
 * DocumentType nodes can be created without an owner.)
 */
public boolean isSupported(String feature, String version)
{
  Document            doc = owner;
  DOMImplementation   impl = null;

  if (doc == null && nodeType == DOCUMENT_NODE)
    {
      doc = (Document) this;
    }

  if (doc == null)
    {
      // possible for DocumentType
      throw new IllegalStateException ("unbound ownerDocument");
    }

  impl = doc.getImplementation();
  return impl.hasFeature(feature, version);
}
 
开发者ID:vilie,项目名称:javify,代码行数:29,代码来源:DomNode.java

示例3: getImplementations

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
/**
 * Returns a list of the implementations that support the specified
 * features.
 */
private final List getImplementations(String features)
{
  List available = new ArrayList(Arrays.asList(implementations));
  for (Iterator i = parseFeatures(features).iterator(); i.hasNext(); )
    {
      String feature = (String) i.next();
      String version = null;
      int si = feature.indexOf(' ');
      if (si != -1)
        {
          version = feature.substring(si + 1);
          feature = feature.substring(0, si);
        }
      for (Iterator j = available.iterator(); j.hasNext(); )
        {
          DOMImplementation impl = (DOMImplementation) j.next();
          if (!impl.hasFeature(feature, version))
            {
              j.remove();
            }
        }
    }
  return available;
}
 
开发者ID:vilie,项目名称:javify,代码行数:29,代码来源:ImplementationSource.java

示例4: getDocumentTraversal

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
DocumentTraversal getDocumentTraversal(Document doc)
  throws XMLStreamException
{
  DOMImplementation dom = doc.getImplementation();
  if (!dom.hasFeature("Traversal", "2.0"))
    throw new XMLStreamException("Traversal not supported");
  return (DocumentTraversal) doc;
}
 
开发者ID:vilie,项目名称:javify,代码行数:9,代码来源:XIncludeFilter.java

示例5: getXPathEvaluator

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
XPathEvaluator getXPathEvaluator(Document doc)
  throws XMLStreamException
{
  DOMImplementation dom = doc.getImplementation();
  if (!dom.hasFeature("XPath", "3.0"))
    throw new XMLStreamException("XPath not supported");
  return (XPathEvaluator) doc;
}
 
开发者ID:vilie,项目名称:javify,代码行数:9,代码来源:XIncludeFilter.java

示例6: getFeature

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
public Object getFeature(String feature, String version)
{
  DOMImplementation impl = (nodeType == DOCUMENT_NODE) ?
    ((Document) this).getImplementation() : owner.getImplementation();
  if (impl.hasFeature(feature, version))
    {
      return this;
    }
  return null;
}
 
开发者ID:vilie,项目名称:javify,代码行数:11,代码来源:DomNode.java

示例7: prettyPrint

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
public void prettyPrint() {
	final String xml = xmlPane.getText();
	final InputSource src = new InputSource(new StringReader(xml));
       org.w3c.dom.Document document;
	try {
		document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src);
	} catch (SAXException | IOException | ParserConfigurationException e) {
		return;
	}
	
	final Pattern p = Pattern.compile("^<\\?xml.*\\?>");
	final Matcher m = p.matcher(xml);
	final String xmlDecl = (m.find()) ? m.group() : "";
	
	// Pretty-prints a DOM document to XML using DOM Load and Save's LSSerializer.
	// Note that the "format-pretty-print" DOM configuration parameter can only be set in JDK 1.6+.
       final DOMImplementation domImplementation = document.getImplementation();
	if (!domImplementation.hasFeature("LS", "3.0") || !domImplementation.hasFeature("Core", "2.0")) {
		return;
	}
	final DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
	final LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
	final DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
	if (domConfiguration.canSetParameter("format-pretty-print", true)) {
		domConfiguration.setParameter("format-pretty-print", true);
	}
	if (domConfiguration.canSetParameter("xml-declaration", false)) {
		domConfiguration.setParameter("xml-declaration", false);
	}
	
	final LSOutput lsOutput = domImplementationLS.createLSOutput();
	lsOutput.setEncoding("UTF-8");
	final StringWriter stringWriter = new StringWriter();
	if (!xmlDecl.isEmpty()) {
		stringWriter.write(xmlDecl);
		stringWriter.write("\n");
	}
	lsOutput.setCharacterStream(stringWriter);
	lsSerializer.write(document, lsOutput);
	final String xmlOut = stringWriter.toString();
	xmlPane.setText(xmlOut);
}
 
开发者ID:kiwiwings,项目名称:poi-visualizer,代码行数:43,代码来源:XMLEditor.java

示例8: testImpl

import org.w3c.dom.DOMImplementation; //导入方法依赖的package包/类
boolean testImpl(DOMImplementation impl, String features) {

        StringTokenizer st = new StringTokenizer(features);
        String feature = null;
        String version = null;

        if (st.hasMoreTokens()) {
           feature = st.nextToken();
        }
        while (feature != null) {
           boolean isVersion = false;
           if (st.hasMoreTokens()) {
               char c;
               version = st.nextToken();
               c = version.charAt(0);
               switch (c) {
               case '0': case '1': case '2': case '3': case '4':
               case '5': case '6': case '7': case '8': case '9':
                   isVersion = true;
               }
           } else {
               version = null;
           }
           if (isVersion) {
               if (!impl.hasFeature(feature, version)) {
                   return false;
               }
               if (st.hasMoreTokens()) {
                   feature = st.nextToken();
               } else {
                   feature = null;
               }
           } else {
               if (!impl.hasFeature(feature, null)) {
                   return false;
               }
               feature = version;
           }
        }
        return true;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:DOMImplementationSourceImpl.java


注:本文中的org.w3c.dom.DOMImplementation.hasFeature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。