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


Java XMLUtil类代码示例

本文整理汇总了Java中org.openide.xml.XMLUtil的典型用法代码示例。如果您正苦于以下问题:Java XMLUtil类的具体用法?Java XMLUtil怎么用?Java XMLUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: write

import org.openide.xml.XMLUtil; //导入依赖的package包/类
static void write(
    @NonNull final OutputStream out,
    @NonNull final RemotePlatform platform) throws IOException {
    Parameters.notNull("out", out); //NOI18N
    Parameters.notNull("platform", platform);   //NOI18N

    final Document doc = XMLUtil.createDocument(
            ELM_PLATFORM,
            null,
            REMOTE_PLATFORM_DTD_ID,
            REMOTE_PLATFORM_SYSTEM_ID);
    final Element platformElement = doc.getDocumentElement();
    platformElement.setAttribute(ATTR_NAME, platform.getDisplayName());

    final Map<String,String> props = platform.getProperties();
    final Element propsElement = doc.createElement(ELM_PROPERTIES);
    writeProperties(props, propsElement, doc);
    platformElement.appendChild(propsElement);

    final Map<String,String> sysProps = platform.getSystemProperties();
    final Element sysPropsElement = doc.createElement(ELM_SYSPROPERTIES);
    writeProperties(sysProps, sysPropsElement, doc);
    platformElement.appendChild(sysPropsElement);
    XMLUtil.write(doc, out, "UTF8");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:RemotePlatformProvider.java

示例2: createDetails

import org.openide.xml.XMLUtil; //导入依赖的package包/类
private JComponent createDetails(String text, ActionListener action) {
    try {
        text = (action == null ? "<html>" : "<html><a href=\"_blank\">") + XMLUtil.toElementContent(text); //NOI18N
    } catch (CharConversionException ex) {
        throw new IllegalArgumentException(ex);
    }
    if (null == action) {
        return new JLabel(text);
    }
    JButton btn = new JButton(text);
    btn.setFocusable(false);
    btn.setBorder(BorderFactory.createEmptyBorder());
    btn.setBorderPainted(false);
    btn.setFocusPainted(false);
    btn.setOpaque(false);
    btn.setContentAreaFilled(false);
    btn.addActionListener(action);
    btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    Color c = UIManager.getColor("nb.html.link.foreground"); //NOI18N
    if (c != null) {
        btn.setForeground(c);
    }
    return btn;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:NotificationImpl.java

示例3: findAllPackages

import org.openide.xml.XMLUtil; //导入依赖的package包/类
/**
 * Find packages in public-packages or friend-packages section. Method
 * considers both <em>package</em> and <em>subpackages</em> elements with
 * the recursivity flag set appropriately for returned entries.
 */
private static Set<ManifestManager.PackageExport> findAllPackages(Element parent) {
    Set<ManifestManager.PackageExport> packages = new HashSet<ManifestManager.PackageExport>();
    try {
        for (Element pkgEl : XMLUtil.findSubElements(parent)) {
            if (PACKAGE.equals(pkgEl.getTagName())) {
                packages.add(new ManifestManager.PackageExport(XMLUtil.findText(pkgEl), false));
            } else if (SUBPACKAGES.equals(pkgEl.getTagName())) {
                packages.add(new ManifestManager.PackageExport(XMLUtil.findText(pkgEl), true));
            }
        }
    } catch(IllegalArgumentException e) {
        LOG.log(Level.WARNING, "Error getting subelements, malformed xml");
        packages = new HashSet<ManifestManager.PackageExport>();
    }
    return packages;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ProjectXMLManager.java

示例4: generateEmptySuiteTemplate

import org.openide.xml.XMLUtil; //导入依赖的package包/类
/**
 * Generates a basic <em>project.xml</em> templates into the given
 * <code>projectXml</code> for <em>Suite</em>.
 */
public static void generateEmptySuiteTemplate(FileObject projectXml, String name) throws IOException {
    // XXX this method could be moved in a future (depends on how complex
    // suite's project.xml will be) to the .suite package dedicated class
    Document prjDoc = XMLUtil.createDocument("project", PROJECT_NS, null, null); // NOI18N

    // generate general project elements
    Element typeEl = prjDoc.createElementNS(PROJECT_NS, "type"); // NOI18N
    typeEl.appendChild(prjDoc.createTextNode(SuiteProjectType.TYPE));
    prjDoc.getDocumentElement().appendChild(typeEl);
    Element confEl = prjDoc.createElementNS(PROJECT_NS, "configuration"); // NOI18N
    prjDoc.getDocumentElement().appendChild(confEl);

    // generate NB Suite project type specific elements
    Element dataEl = createSuiteElement(confEl.getOwnerDocument(), DATA);
    confEl.appendChild(dataEl);
    Document dataDoc = dataEl.getOwnerDocument();
    dataEl.appendChild(createSuiteElement(dataDoc, "name", name)); // NOI18N

    // store document to disk
    ProjectXMLManager.safelyWrite(projectXml, prjDoc);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ProjectXMLManager.java

示例5: parseCNB

import org.openide.xml.XMLUtil; //导入依赖的package包/类
private String parseCNB(final ZipEntry projectXML) throws IOException {
    Document doc;
    InputStream is = nbSrcZip.getInputStream(projectXML);
    try {
        doc = XMLUtil.parse(new InputSource(is), false, true, null, null);
    } catch (SAXException e) {
        throw (IOException) new IOException(projectXML + ": " + e.toString()).initCause(e); // NOI18N
    } finally {
        is.close();
    }
    Element docel = doc.getDocumentElement();
    Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
    String cnb = null;
    if (XMLUtil.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N
        Element cfg = XMLUtil.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N
        Element data = XMLUtil.findElement(cfg, "data", null); // NOI18N
        if (data != null) {
            cnb = XMLUtil.findText(XMLUtil.findElement(data, "code-name-base", null)); // NOI18N
        }
    }
    return cnb;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:GlobalSourceForBinaryImpl.java

示例6: testCreateRunSingleTargetElem

import org.openide.xml.XMLUtil; //导入依赖的package包/类
public void testCreateRunSingleTargetElem() throws Exception {
    Document doc = XMLUtil.createDocument("project", null, null, null);
    Lookup context = contextDO(new FileObject[] {myAppJava});
    JavaActions.AntLocation root = ja.findPackageRoot(context);
    Element targetElem = ja.createRunSingleTargetElem(doc, "run-single-test-target", "test.class", root);
    doc.getDocumentElement().appendChild(targetElem);
    String expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<project>\n" +
        "    <target name=\"run-single-test-target\">\n" +
        "        <fail unless=\"test.class\">Must set property 'test.class'</fail>\n" +
        "        <ant antfile=\"build.xml\" inheritall=\"false\" target=\"jar\"/>\n" +
        "        <java classname=\"${test.class}\" failonerror=\"true\" fork=\"true\">\n" +
        "            <classpath>\n" +
        "                <pathelement path=\"${src.cp}\"/>\n" +
        "                <pathelement location=\"${classes.dir}\"/>\n" +
        "                <pathelement location=\"${main.jar}\"/>\n" +
        "            </classpath>\n" +
        "        </java>\n" +
        "    </target>\n" +
        "</project>\n";
    assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JavaActionsTest.java

示例7: getHtmlDisplayName

import org.openide.xml.XMLUtil; //导入依赖的package包/类
@Override
public String getHtmlDisplayName () {
    final Pair<String,JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder == null) {
        return null;
    }
    final JavaPlatform jp = platHolder.second();
    if (jp == null || !jp.isValid()) {
        String displayName = this.getDisplayName();
        try {
            displayName = XMLUtil.toElementContent(displayName);
        } catch (CharConversionException ex) {
            // OK, no annotation in this case
            return null;
        }
        return "<font color=\"#A40000\">" + displayName + "</font>"; //NOI18N
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:PlatformNode.java

示例8: getListCellRendererComponent

import org.openide.xml.XMLUtil; //导入依赖的package包/类
public Component getListCellRendererComponent(JList list, Object value,
        int index, boolean isSelected, boolean cellHasFocus) {
    String text;
    if (value == UIUtil.WAIT_VALUE) {
        text = UIUtil.WAIT_VALUE;
    } else if (value == INVALID_PLATFORM) {
        text = INVALID_PLATFORM;
        renderer.setHtml(true);
    } else {
        ModuleDependency md = (ModuleDependency) value;
        // XXX the following is wrong; spec requires additional logic:
        boolean bold = boldfaceApiModules && md.getModuleEntry().getPublicPackages().length > 0;
        boolean deprecated = md.getModuleEntry().isDeprecated();
        renderer.setHtml(bold || deprecated);
        String locName = md.getModuleEntry().getLocalizedName();
        text = locName;
        if (bold || deprecated) {
            try {
                text = "<html>" + (bold ? "<b>" : "") + (deprecated ? "<s>" : "") + XMLUtil.toElementContent(locName); // NOI18N
            } catch (CharConversionException e) {
                // forget it
            }
        }
    }
    return renderer.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CustomizerComponentFactory.java

示例9: createExecuteClasspath

import org.openide.xml.XMLUtil; //导入依赖的package包/类
private List<URL> createExecuteClasspath(List<String> packageRoots, Element compilationUnitEl) {
    for (Element e : XMLUtil.findSubElements(compilationUnitEl)) {
        if (e.getLocalName().equals("classpath") && e.getAttribute("mode").equals("execute")) { // NOI18N
            return createClasspath(e, new RemoveSources(helper, sfbqImpl));
        }
    }
    // None specified; assume it is same as compile classpath plus (cf. #49113) <built-to> dirs/JARs
    // if there are any (else include the source dir(s) as a fallback for the I18N wizard to work).
    Set<URL> urls = new LinkedHashSet<>();
    urls.addAll(createCompileClasspath(compilationUnitEl));
    final Project prj = FileOwnerQuery.getOwner(helper.getProjectDirectory());
    if (prj != null) {
        for (URL src : createSourcePath(packageRoots)) {
            urls.addAll(sfbqImpl.findBinaryRoots(src));
        }
    }
    return new ArrayList<>(urls);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Classpaths.java

示例10: encodePrimitiveValue

import org.openide.xml.XMLUtil; //导入依赖的package包/类
/** Encodes specified value into a String. Supported types are: <UL>
 * <LI> Class
 * <LI> String
 * <LI> Integer, Short, Byte, Long, Float, Double, Boolean, Character </UL>
 * 
 * @param value value to encode.
 * @return String containing encoded value or null if specified object is not of supported type
 */
public static String encodePrimitiveValue(Object value) {
    if (value instanceof Integer || value instanceof Short
            || value instanceof Byte || value instanceof Long
            || value instanceof Float || value instanceof Double
            || value instanceof Boolean || value instanceof Character)
        return value.toString();

    if (value instanceof String) {
        try {
            XMLUtil.toAttributeValue((String)value);
            return (String) value;
        } catch (CharConversionException ex) {
            // can't be stored in XML document, needs to be encoded as bytes
            return null;
        }
    }

    if (value instanceof Class)
        return ((Class)value).getName();

    if (value == null)
        return "null"; // NOI18N

    return null; // is not a primitive type
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:GandalfPersistenceManager.java

示例11: testCreatePathLikeElem

import org.openide.xml.XMLUtil; //导入依赖的package包/类
public void testCreatePathLikeElem() throws Exception {
    Document doc = XMLUtil.createDocument("testdoc", null, null, null);
    Element pathElem = ja.createPathLikeElem(doc, "path", "id",
            new String[] {"lib/File.jar;lib/File2.jar", "testlib/Lib1.jar;testlib/Lib2"},
            new String[] {"c:\\workfiles\\library.jar", "/workfiles/library2.jar"},
            "refid", "comment");
    String expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<path id=\"id\" refid=\"refid\">\n" +
        "    <!---->\n" +
        "    <pathelement path=\"lib/File.jar;lib/File2.jar\"/>\n" +
        "    <pathelement path=\"testlib/Lib1.jar;testlib/Lib2\"/>\n" +
        "    <pathelement location=\"c:\\workfiles\\library.jar\"/>\n" +
        "    <pathelement location=\"/workfiles/library2.jar\"/>\n" +
        "</path>\n";
    assertEquals(expectedXml, xmlToString(pathElem));
    pathElem = ja.createPathLikeElem(doc, "classpath", null, null, null, null, "comment");
    expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<classpath>\n" +
        "    <!---->\n" +
        "</classpath>\n";
    assertEquals(expectedXml, xmlToString(pathElem));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:JavaActionsTest.java

示例12: getHtmlDisplayName

import org.openide.xml.XMLUtil; //导入依赖的package包/类
public @Override String getHtmlDisplayName() {
    String htmlName = getOriginal().getHtmlDisplayName();
    if (htmlName == null) {
        try {
            htmlName = XMLUtil.toElementContent(getOriginal().getDisplayName());
        } catch (CharConversionException ex) {
            // ignore
        }
    }
    if (htmlName == null) {
        return null;
    }
    if (files != null && files.iterator().hasNext()) {
        try {
            String annotatedMagic = files.iterator().next().getFileSystem().
                    getDecorator().annotateNameHtml(MAGIC, files);
            if (annotatedMagic != null) {
                htmlName = annotatedMagic.replace(MAGIC, htmlName);
            }
        } catch (FileStateInvalidException e) {
            LOG.log(Level.INFO, null, e);
        }
    }      
    return isMainAsync()? "<b>" + htmlName + "</b>" : htmlName;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ProjectsRootNode.java

示例13: readCustomScript

import org.openide.xml.XMLUtil; //导入依赖的package包/类
/**
 * Read a generated script if it exists, else create a skeleton.
 * Imports jdk.xml if appropriate.
 * @param scriptPath e.g. {@link #FILE_SCRIPT_PATH} or {@link #GENERAL_SCRIPT_PATH}
 */
Document readCustomScript(String scriptPath) throws IOException, SAXException {
    // XXX if there is TAX support for rewriting XML files, use that here...
    FileObject script = helper.getProjectDirectory().getFileObject(scriptPath);
    Document doc;
    if (script != null) {
        InputStream is = script.getInputStream();
        try {
            doc = XMLUtil.parse(new InputSource(is), false, true, null, null);
        } finally {
            is.close();
        }
    } else {
        doc = XMLUtil.createDocument("project", /*XXX:"antlib:org.apache.tools.ant"*/null, null, null); // NOI18N
        Element root = doc.getDocumentElement();
        String projname = ProjectUtils.getInformation(project).getDisplayName();
        root.setAttribute("name", NbBundle.getMessage(JavaActions.class, "LBL_generated_script_name", projname));
    }
    if (helper.getProjectDirectory().getFileObject(JdkConfiguration.JDK_XML) != null) {
        JdkConfiguration.insertJdkXmlImport(doc);
    }
    return doc;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:JavaActions.java

示例14: sourceOutputDirectory

import org.openide.xml.XMLUtil; //导入依赖的package包/类
public @Override URL sourceOutputDirectory() {
    List<URL> result = sourceOutputCache;
    if (result != null) {
        return result.isEmpty() ? null : result.get(0);
    }
    result = new ArrayList<URL>(1);
    if (ap != null) {
        for (Element e : XMLUtil.findSubElements(ap)) {
            if (e.getLocalName().equals(EL_SOURCE_OUTPUT)) {
                try {
                    final String path = eval.evaluate(XMLUtil.findText(e));
                    result.add(Utilities.toURI(helper.resolveFile(path)).toURL());
                } catch (MalformedURLException ex) {
                    Exceptions.printStackTrace(ex);
                }
                break;
            }
        }
    }
    synchronized (LCK) {
        if (sourceOutputCache == null) {
            sourceOutputCache = result;
        }
    }
    return result.isEmpty() ? null : result.get(0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AnnotationProcessingQueryImpl.java

示例15: parse

import org.openide.xml.XMLUtil; //导入依赖的package包/类
public void parse(java.io.Reader src) throws IOException {
    try {
        org.xml.sax.XMLReader reader = org.openide.xml.XMLUtil.createXMLReader(false, false);
        reader.setContentHandler(this);
        reader.setEntityResolver(this);
        org.xml.sax.InputSource is =
            new org.xml.sax.InputSource(src);
        try {
            reader.setProperty("http://xml.org/sax/properties/lexical-handler", this);  //NOI18N
        } catch (SAXException sex) {
            XMLSettingsSupport.err.warning(
            "Warning: XML parser does not support lexical-handler feature.");  //NOI18N
        }
        reader.parse(is);
    } catch (SAXException ex) {
        IOException ioe = new IOException();
        ioe.initCause(ex);
        throw ioe;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:XMLPropertiesConvertor.java


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