Java Code Examples for org.openide.xml.XMLUtil#createDocument()

The following examples show how to use org.openide.xml.XMLUtil#createDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemotePlatformProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example 2
Source File: ProjectProfileHandlerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void enableProfile(String id, boolean shared) {
    lazyInit();
    Element element = ac.getConfigurationFragment(PROFILES, NAMESPACE, shared);
    if (element == null) {

        String root = "project-private"; // NOI18N"

        Document doc = XMLUtil.createDocument(root, NAMESPACE, null, null);
        element = doc.createElementNS(NAMESPACE, PROFILES);
    }


    String activeProfiles = element.getAttributeNS(NAMESPACE, ACTIVEPROFILES);
    element.setAttributeNS(NAMESPACE, ACTIVEPROFILES, activeProfiles + SEPARATOR + id);
    ac.putConfigurationFragment(element, shared);
    if (shared) {
        if (!sharedProfiles.contains(id)) {
            sharedProfiles.add(id);
        }
    } else {
        if (!privateProfiles.contains(id)) {
            privateProfiles.add(id);
        }
    }
}
 
Example 3
Source File: WebProjectNatureTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testUpgradeSchema() throws Exception {
    // Formatting has to be the same as Xerces' formatter produces for this test to pass:
    String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                  "<web-data xmlns=\"http://www.netbeans.org/ns/freeform-project-web/1\">\n" +
                  "    <!-- Hello there. -->\n" +
                  "    <foo bar=\"baz\" quux=\"whatever\">hello</foo>\n" +
                  "    <x>OK</x>\n" +
                  "</web-data>\n";
    String xml2expected = xml1.replaceAll("/1", "/2");
    Document doc1 = XMLUtil.parse(new InputSource(new StringReader(xml1)), false, true, null, null);
    Element el1 = doc1.getDocumentElement();
    Element el2 = LookupProviderImpl.upgradeSchema(el1);
    Document doc2 = XMLUtil.createDocument(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, null, null);
    doc2.removeChild(doc2.getDocumentElement());
    doc2.appendChild(doc2.importNode(el2, true));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLUtil.write(doc2, baos, "UTF-8");
    String xml2actual = baos.toString("UTF-8").replaceAll(System.getProperty("line.separator"), "\n");
    assertEquals("Correct upgrade result", xml2expected, xml2actual);
}
 
Example 4
Source File: ProjectXMLManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: JavaActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCreateDebugTargetFromScratch() throws Exception {
    Document doc = XMLUtil.createDocument("project", null, null, null);
    Element genTarget = ja.createDebugTargetFromScratch("debug", doc);
    doc.getDocumentElement().appendChild(genTarget);
    String expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<project>\n" +
        "    <target name=\"debug\">\n" +
        "        <path id=\"cp\">\n" +
        "            <!---->\n" +
        "        </path>\n" +
        "        <nbjpdastart addressproperty=\"jpda.address\" name=\"Simple Freeform Project\" transport=\"dt_socket\">\n" +
        "            <classpath refid=\"cp\"/>\n" +
        "        </nbjpdastart>\n" +
        "        <!---->\n" +
        "        <java classname=\"some.main.Class\" fork=\"true\">\n" +
        "            <classpath refid=\"cp\"/>\n" +
        "            <jvmarg value=\"-agentlib:jdwp=transport=dt_socket,address=${jpda.address}\"/>\n" +
        "        </java>\n" +
        "    </target>\n" +
        "</project>\n";
    assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
}
 
Example 6
Source File: LibraryDeclarationParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Document createLibraryDefinition2(
        final @NonNull LibraryImplementation library,
        final @NonNull LibraryTypeProvider libraryTypeProvider) {
    final Document doc = XMLUtil.createDocument(LIBRARY, LIBRARY_NS2, null, null);
    final Element libraryE = doc.getDocumentElement();
    libraryE.setAttribute(VERSION, VER_2); // NOI18N
    libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, NAME)).appendChild(doc.createTextNode(library.getName())); // NOI18N
    libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, TYPE)).appendChild(doc.createTextNode(library.getType())); // NOI18N
    String description = library.getDescription();
    if (description != null && description.length() > 0) {
        libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, DESCRIPTION)).appendChild(doc.createTextNode(description)); // NOI18N
    }
    String localizingBundle = library.getLocalizingBundle();
    if (localizingBundle != null && localizingBundle.length() > 0) {
        libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, BUNDLE)).appendChild(doc.createTextNode(localizingBundle)); // NOI18N
    }
    String displayname = LibrariesSupport.getDisplayName(library);
    if (displayname != null) {
        libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, DISPLAY_NAME)).appendChild(doc.createTextNode(displayname)); // NOI18N
    }
    for (String vtype : libraryTypeProvider.getSupportedVolumeTypes()) {
        Element volumeE = (Element) libraryE.appendChild(doc.createElementNS(LIBRARY_NS2,VOLUME)); // NOI18N
        volumeE.appendChild(doc.createElementNS(LIBRARY_NS2, TYPE)).appendChild(doc.createTextNode(vtype)); // NOI18N
        List<URL> volume = library.getContent(vtype);
        if (volume != null) {
            for (URL url : volume) {
                volumeE.appendChild(doc.createElementNS(LIBRARY_NS2, RESOURCE)).appendChild(doc.createTextNode(url.toString())); // NOI18N
            }
        }
    }
    return doc;
}
 
Example 7
Source File: ProjectXMLManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Create a library wrapper project.xml.
 *
 * @param publicPackages set of <code>String</code>s representing the packages
 * @param extensions &lt;key=runtime path(String), value=binary path (String)&gt;
 */
static void generateLibraryModuleTemplate(FileObject projectXml, String cnb,
        NbModuleType moduleType, Set<String> publicPackages, Map<String,String> extensions) throws IOException {

    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(NbModuleProject.TYPE));
    prjDoc.getDocumentElement().appendChild(typeEl);
    Element confEl = prjDoc.createElementNS(PROJECT_NS, "configuration"); // NOI18N
    prjDoc.getDocumentElement().appendChild(confEl);

    // generate NB Module project type specific elements
    Element dataEl = createModuleElement(confEl.getOwnerDocument(), DATA);
    confEl.appendChild(dataEl);
    Document dataDoc = dataEl.getOwnerDocument();
    dataEl.appendChild(createModuleElement(dataDoc, CODE_NAME_BASE, cnb));
    Element moduleTypeEl = createTypeElement(dataDoc, moduleType);
    if (moduleTypeEl != null) {
        dataEl.appendChild(moduleTypeEl);
    }
    dataEl.appendChild(createModuleElement(dataDoc, MODULE_DEPENDENCIES));
    Element packages = createModuleElement(dataDoc, PUBLIC_PACKAGES);
    dataEl.appendChild(packages);
    for (String pkg : publicPackages) {
        packages.appendChild(createModuleElement(dataDoc, PACKAGE, pkg));
    }
    for (Map.Entry<String,String> entry : extensions.entrySet()) {
        Element cp = createModuleElement(dataDoc, CLASS_PATH_EXTENSION);
        dataEl.appendChild(cp);
        cp.appendChild(createModuleElement(dataDoc, CLASS_PATH_RUNTIME_PATH, entry.getKey()));
        cp.appendChild(createModuleElement(dataDoc, CLASS_PATH_BINARY_ORIGIN, entry.getValue()));
    }

    // store document to disk
    ProjectXMLManager.safelyWrite(projectXml, prjDoc);
}
 
Example 8
Source File: JavaActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGetPathFromCU() throws Exception {
    Document doc = XMLUtil.createDocument("testdoc", null, null, null);
    Lookup context = contextDO(new FileObject[] {myAppJava});
    JavaActions.AntLocation root = ja.findPackageRoot(context);
    Element cpElem = ja.getPathFromCU(doc, root.virtual, "classpath");
    String expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<classpath>\n" +
        "    <pathelement path=\"${src.cp}\"/>\n" +
        "    <pathelement location=\"${classes.dir}\"/>\n" +
        "    <pathelement location=\"${main.jar}\"/>\n" +
        "</classpath>\n";
    assertEquals(expectedXml, xmlToString(cpElem));
}
 
Example 9
Source File: ProjectXMLManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a basic <em>project.xml</em> templates into the given
 * <code>projectXml</code> for <em>standalone</em> or <em>module in
 * suite</em> module.
 */
static void generateEmptyModuleTemplate(FileObject projectXml, String cnb,
        NbModuleType moduleType, String... compileDepsCnbs) throws IOException {

    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(NbModuleProject.TYPE));
    prjDoc.getDocumentElement().appendChild(typeEl);
    Element confEl = prjDoc.createElementNS(PROJECT_NS, "configuration"); // NOI18N
    prjDoc.getDocumentElement().appendChild(confEl);

    // generate NB Module project type specific elements
    Element dataEl = createModuleElement(confEl.getOwnerDocument(), DATA);
    confEl.appendChild(dataEl);
    Document dataDoc = dataEl.getOwnerDocument();
    dataEl.appendChild(createModuleElement(dataDoc, CODE_NAME_BASE, cnb));
    Element moduleTypeEl = createTypeElement(dataDoc, moduleType);
    if (moduleTypeEl != null) {
        dataEl.appendChild(moduleTypeEl);
    }
    final Element deps = createModuleElement(dataDoc, MODULE_DEPENDENCIES);
    for (String depCnb : compileDepsCnbs) {
        Element modDepEl = createModuleElement(dataDoc, ProjectXMLManager.DEPENDENCY);
        modDepEl.appendChild(createModuleElement(dataDoc, ProjectXMLManager.CODE_NAME_BASE, depCnb));
        modDepEl.appendChild(createModuleElement(dataDoc, ProjectXMLManager.BUILD_PREREQUISITE));
        modDepEl.appendChild(createModuleElement(dataDoc, ProjectXMLManager.COMPILE_DEPENDENCY));
        deps.appendChild(modDepEl);
    }
    dataEl.appendChild(deps);
    dataEl.appendChild(createModuleElement(dataDoc, PUBLIC_PACKAGES));

    // store document to disk
    ProjectXMLManager.safelyWrite(projectXml, prjDoc);
}
 
Example 10
Source File: JavaActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreateDebugSingleTargetElem() 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.createDebugSingleTargetElem(doc, "debug-single-test-target", "test.class", root);
    doc.getDocumentElement().appendChild(targetElem);
    String expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<project>\n" +
        "    <target name=\"debug-single-test-target\">\n" +
        "        <fail unless=\"test.class\">Must set property 'test.class'</fail>\n" +
        "        <ant antfile=\"build.xml\" inheritall=\"false\" target=\"jar\"/>\n" +
        "        <path id=\"cp\">\n" +
        "            <pathelement path=\"${src.cp}\"/>\n" +
        "            <pathelement location=\"${classes.dir}\"/>\n" +
        "            <pathelement location=\"${main.jar}\"/>\n" +
        "        </path>\n" +
        "        <nbjpdastart addressproperty=\"jpda.address\" name=\"Simple Freeform Project\" transport=\"dt_socket\">\n" +
        "            <classpath refid=\"cp\"/>\n" +
        "        </nbjpdastart>\n" +
        "        <java classname=\"${test.class}\" fork=\"true\">\n" +
        "            <classpath refid=\"cp\"/>\n" +
        "            <jvmarg value=\"-agentlib:jdwp=transport=dt_socket,address=${jpda.address}\"/>\n" +
        "        </java>\n" +
        "    </target>\n" +
        "</project>\n";
    assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
}
 
Example 11
Source File: XMLHintPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static HintPreferencesProviderImpl from(@NonNull URI settings) {
    Reference<HintPreferencesProviderImpl> ref = uri2Cache.get(settings);
    HintPreferencesProviderImpl cachedResult = ref != null ? ref.get() : null;
    
    if (cachedResult != null) return cachedResult;
    
    Document doc = null;
    File file = Utilities.toFile(settings); //XXX: non-file:// scheme
    
    if (file.canRead()) {
        try(InputStream in = new BufferedInputStream(new FileInputStream(file))) {
            doc = XMLUtil.parse(new InputSource(in), false, false, null, EntityCatalog.getDefault());
        } catch (SAXException | IOException ex) {
            LOG.log(Level.FINE, null, ex);
        }
    }
    
    if (doc == null) {
        doc = XMLUtil.createDocument("configuration", null, "-//NetBeans//DTD Tool Configuration 1.0//EN", "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd");
    }
    
    synchronized (uri2Cache) {
        ref = uri2Cache.get(settings);
        cachedResult = ref != null ? ref.get() : null;

        if (cachedResult != null) return cachedResult;
        
        uri2Cache.put(settings, new CleaneableSoftReference(cachedResult = new HintPreferencesProviderImpl(settings, doc), settings));
    }
    
    return cachedResult;
}
 
Example 12
Source File: GradleAuxiliaryConfigImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Document createNewSharedDocument() throws DOMException {
    String element = "project-shared-configuration";
    Document doc = XMLUtil.createDocument(element, null, null, null);
    doc.getDocumentElement().appendChild(doc.createComment(
            "\nThis file contains additional configuration written by modules in the NetBeans IDE.\n" +
            "The configuration is intended to be shared among all the users of project and\n" +
            "therefore it is assumed to be part of version control checkout.\n" +
            "Without this configuration present, some functionality in the IDE may be limited or fail altogether.\n"));
    return doc;
}
 
Example 13
Source File: LibraryDeclarationParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Document createLibraryDefinition1(
        final @NonNull LibraryImplementation library,
        final @NonNull LibraryTypeProvider libraryTypeProvider) {
    final Document doc = XMLUtil.createDocument(LIBRARY, null,
            LIBRARY_DEF_1,
            LIBRARY_DTD_1);
    final Element libraryE = doc.getDocumentElement();
    libraryE.setAttribute(VERSION, VER_1); // NOI18N
    libraryE.appendChild(doc.createElement(NAME)).appendChild(doc.createTextNode(library.getName())); // NOI18N
    libraryE.appendChild(doc.createElement(TYPE)).appendChild(doc.createTextNode(library.getType())); // NOI18N
    String description = library.getDescription();
    if (description != null && description.length() > 0) {
        libraryE.appendChild(doc.createElement(DESCRIPTION)).appendChild(doc.createTextNode(description)); // NOI18N
    }
    String localizingBundle = library.getLocalizingBundle();
    if (localizingBundle != null && localizingBundle.length() > 0) {
        libraryE.appendChild(doc.createElement(BUNDLE)).appendChild(doc.createTextNode(localizingBundle)); // NOI18N
    }
    String displayname = LibrariesSupport.getDisplayName(library);
    if (displayname != null) {
        libraryE.appendChild(doc.createElement(DISPLAY_NAME)).appendChild(doc.createTextNode(displayname)); // NOI18N
    }
    for (String vtype : libraryTypeProvider.getSupportedVolumeTypes()) {
        Element volumeE = (Element) libraryE.appendChild(doc.createElement(VOLUME)); // NOI18N
        volumeE.appendChild(doc.createElement(TYPE)).appendChild(doc.createTextNode(vtype)); // NOI18N
        List<URL> volume = library.getContent(vtype);
        if (volume != null) {
            //If null -> broken library, repair it.
            for (URL url : volume) {
                volumeE.appendChild(doc.createElement(RESOURCE)).appendChild(doc.createTextNode(url.toString())); // NOI18N
            }
        }
    }
    return doc;
}
 
Example 14
Source File: JavaActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreateDebugTargetFromTemplate() throws Exception {
    Document doc = XMLUtil.createDocument("project", null, null, null);
    Document origDoc = XMLUtil.createDocument("target", null, null, null);
    Element origTarget = origDoc.getDocumentElement();
    origTarget.setAttribute("name", "ignored");
    origTarget.setAttribute("depends", "compile");
    origTarget.appendChild(origDoc.createElement("task1"));
    Element task = origDoc.createElement("java");
    // XXX also test nested <classpath>:
    task.setAttribute("classpath", "${cp}");
    task.appendChild(origDoc.createElement("stuff"));
    origTarget.appendChild(task);
    origTarget.appendChild(origDoc.createElement("task2"));
    Element genTarget = ja.createDebugTargetFromTemplate("debug", origTarget, task, doc);
    doc.getDocumentElement().appendChild(genTarget);
    String expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<project>\n" +
        "    <target depends=\"compile\" name=\"debug\">\n" +
        "        <task1/>\n" +
        "        <nbjpdastart addressproperty=\"jpda.address\" name=\"Simple Freeform Project\" transport=\"dt_socket\">\n" +
        "            <classpath path=\"${cp}\"/>\n" +
        "        </nbjpdastart>\n" +
        "        <java classpath=\"${cp}\" fork=\"true\">\n" +
        "            <stuff/>\n" +
        "            <jvmarg value=\"-agentlib:jdwp=transport=dt_socket,address=${jpda.address}\"/>\n" +
        "        </java>\n" +
        "        <task2/>\n" +
        "    </target>\n" +
        "</project>\n";
    assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
}
 
Example 15
Source File: SceneSerializer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void serialize(PageFlowSceneData sceneData, FileObject file) {
    if( file == null || !file.isValid()){
        LOG.warning("Can not serialize locations because file is null.");
        return;
    }
    LOG.entering("SceneSerializer", "serialize");
    Document document = XMLUtil.createDocument(SCENE_ELEMENT, null, null, null);

    Node sceneElement = document.getFirstChild();
    setAttribute(document, sceneElement, VERSION_ATTR, VERSION_VALUE_2);
    setAttribute(document, sceneElement, SCENE_LAST_USED_SCOPE_ATTR, XmlScope.getInstance(sceneData.getCurrentScopeStr() ).toString());
    Node scopeFacesElement = createScopeElement(document, sceneData, XmlScope.SCOPE_FACES);
    if( scopeFacesElement != null ) {
        sceneElement.appendChild( scopeFacesElement );
    }
    Node scopeProjectElement = createScopeElement(document, sceneData, XmlScope.SCOPE_PROJECT);
    if( scopeProjectElement != null ) {
        sceneElement.appendChild( scopeProjectElement );
    }
    Node scopeAllElement = createScopeElement(document, sceneData, XmlScope.SCOPE_ALL);
    if( scopeAllElement != null ) {
        sceneElement.appendChild( scopeAllElement );
    }

    writeToFile(document, file);
    LOG.finest("Serializing to the follwoing file: " + file.toString());

    LOG.exiting("SceneSerializer", "serialize");
}
 
Example 16
Source File: JavaActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testEnsurePropertiesCopied() throws Exception {
    Document doc = XMLUtil.createDocument("project", null, null, null);
    Element root = doc.getDocumentElement();
    ja.ensurePropertiesCopied(root);
    String expectedXml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<project basedir=\"..\">\n" +
        "    <property name=\"build.properties\" value=\"build.properties\"/>\n" +
        "    <property file=\"${build.properties}\"/>\n" +
        "</project>\n";
    assertEquals("Correct code generated", expectedXml, xmlToString(root));
    ja.ensurePropertiesCopied(root);
    assertEquals("Idempotent", expectedXml, xmlToString(root));
}
 
Example 17
Source File: WebFreeFormActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates custom script.
 * @return script document.
 */
Document createCustomScript() {
    //create document, set root and its attributes
    Document script = XMLUtil.createDocument("project", null, null, null); // NOI18N
    Element scriptRoot = script.getDocumentElement();
    scriptRoot.setAttribute("basedir", /* ".." times count('/', FILE_SCRIPT_PATH) */".."); // NOI18N
    String projname = ProjectUtils.getInformation(project).getDisplayName();
    scriptRoot.setAttribute("name", NbBundle.getMessage(WebFreeFormActionProvider.class, "LBL_generated_script_name", projname));

    //copy properties from project.xml to the script
    copyProperties(Util.getPrimaryConfigurationData(helper), scriptRoot);
    
    return script;
}
 
Example 18
Source File: JdkConfiguration.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Document createNbjdkXmlSkeleton() {
    Document nbjdkDoc = XMLUtil.createDocument("project", null, null, null); // NOI18N
    Element projectE = nbjdkDoc.getDocumentElement();
    // XXX for better fidelity would use ${ant.script}#/project[@name]
    projectE.setAttribute("name", ProjectUtils.getInformation(project).getName()); // NOI18N
    projectE.setAttribute("basedir", ".."); // NOI18N
    insertJdkXmlImport(nbjdkDoc);
    return nbjdkDoc;
}
 
Example 19
Source File: ProjectProfileHandlerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void disableProfile(String id, boolean shared) {
    lazyInit();
    Element element = ac.getConfigurationFragment(PROFILES, NAMESPACE, shared);
    if (element == null) {

        String root = "project-private"; // NOI18N"

        Document doc = XMLUtil.createDocument(root, NAMESPACE, null, null);
        element = doc.createElementNS(NAMESPACE, PROFILES);
    }
    String activeProfiles = element.getAttributeNS(NAMESPACE, ACTIVEPROFILES);

    if (activeProfiles != null && activeProfiles.length() > 0) {
        StringTokenizer tokenizer = new StringTokenizer(activeProfiles, SEPARATOR);
        Set<String> set = new HashSet<String>(tokenizer.countTokens());
        while (tokenizer.hasMoreTokens()) {
            set.add(tokenizer.nextToken());
        }
        set.remove(id);
        StringBuilder buffer = new StringBuilder();
        for (String profle : set) {
            buffer.append(profle).append(SEPARATOR);
        }
        element.setAttributeNS(NAMESPACE, ACTIVEPROFILES, buffer.toString().trim());
    }

    ac.putConfigurationFragment(element, shared);
    if(shared){
        sharedProfiles.remove(id);
    }else{
        privateProfiles.remove(id);
    }
}
 
Example 20
Source File: AuxiliaryConfigBasedPreferencesProviderTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public TestAuxiliaryConfigurationImpl() {
    sharedDOM = XMLUtil.createDocument("test", null, null, null);
    privDOM = XMLUtil.createDocument("test", null, null, null);
}