Example usage for org.w3c.dom Element setAttribute

List of usage examples for org.w3c.dom Element setAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element setAttribute.

Prototype

public void setAttribute(String name, String value) throws DOMException;

Source Link

Document

Adds a new attribute.

Usage

From source file:de.mpg.mpdl.inge.citationmanager.data.FontStylesCollection.java

/**
 * Writes {@link FontStylesCollection} to xmlfile
 * /*from  w  w  w .  ja v a2s  .  c  om*/
 * @param xmlFileName
 * @throws IOException
 * @throws SAXException
 * @throws CitationStyleManagerException
 */
public void writeToXml(String xmlFileName) throws IOException, SAXException, CitationStyleManagerException {

    Document doc = XmlHelper.createDocument();

    Element root = doc.createElement("font-styles-collection");

    doc.appendChild(root);

    // here is the loop:

    for (FontStyle fs : fontStyles) {

        Element element = doc.createElement("font-style");

        element.setAttribute("def", "" + fs.getDef());
        element.setAttribute("name", fs.getName());
        element.setAttribute("font-size", "" + fs.getFontSize());
        element.setAttribute("font-name", fs.getFontName());
        element.setAttribute("is-bold", "" + fs.getIsBold());
        element.setAttribute("is-italic", "" + fs.getIsItalic());
        element.setAttribute("is-underline", "" + fs.getIsUnderline());
        element.setAttribute("is-strike-through", "" + fs.getIsStrikeThrough());
        element.setAttribute("pdf-font-name", fs.getPdfFontName());
        element.setAttribute("fore-color", fs.getForeColor());
        element.setAttribute("back-color", fs.getBackColor());
        element.setAttribute("pdf-encoding", fs.getPdfEncoding());
        element.setAttribute("is-pdf-embedded", "" + fs.getIsPdfEmbedded());
        element.setAttribute("is-pdf-simulated-bold", "" + fs.getIsPdfSimulatedBold());
        element.setAttribute("is-pdf-simulated-italic", "" + fs.getIsPdfSimulatedItalic());
        element.setAttribute("css-class", "" + fs.getCssClass());

        root.appendChild(element);
    }

    XmlHelper.output(doc, xmlFileName);

}

From source file:de.erdesignerng.model.serializer.xml50.XMLDomainSerializer.java

@Override
public void serialize(Domain aDomain, Document aDocument, Element aRootElement) {
    Element theDomainElement = addElement(aDocument, aRootElement, DOMAIN);

    // Basisdaten des Modelelementes speichern
    serializeProperties(aDocument, theDomainElement, aDomain);
    serializeCommentElement(aDocument, theDomainElement, aDomain);

    theDomainElement.setAttribute(DATATYPE, aDomain.getConcreteType().getName());

    // Bug Fixing 2876916 [ERDesignerNG] Reverse-Eng. PgSQL VARCHAR max-length wrong
    theDomainElement.setAttribute(SIZE, safeString(aDomain.getSize()));
    theDomainElement.setAttribute(FRACTION, safeString(aDomain.getFraction()));
    theDomainElement.setAttribute(SCALE, safeString(aDomain.getScale()));
    theDomainElement.setAttribute(NULLABLE, safeString(aDomain.isNullable()));
}

From source file:elaborate.editor.export.tei.TeiMaker.java

private Element interp(String type, String value) {
    Element interp = tei.createElement("interp");
    interp.setAttribute("type", SolrUtils.normalize(type));
    interp.setAttribute("value", StringEscapeUtils.escapeHtml(value));
    return interp;
}

From source file:de.ingrid.interfaces.csw.server.cswt.impl.GenericServerCSWT.java

private Document createErrorResponse(CSWTransactionResult result) throws ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setNamespaceAware(true);//from  w  w  w  .  j  a  va2 s . c o m
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    DOMImplementation domImpl = docBuilder.getDOMImplementation();
    Document doc = domImpl.createDocument(RESPONSE_NAMESPACE, "ows:ExceptionReport", null);

    // create summary
    Element exception = doc.createElementNS(RESPONSE_NAMESPACE, "ows:Exception");
    exception.setAttribute("exceptionCode", "NoApplicableCode");
    doc.getDocumentElement().appendChild(exception);

    exception.appendChild(doc.createElementNS(RESPONSE_NAMESPACE, "ows:ExceptionText"))
            .appendChild(doc.createTextNode("Cannot process transaction: " + result.getErrorMessage()));

    return doc;

}

From source file:de.mpg.escidoc.services.citationmanager.data.FontStylesCollection.java

/**
 * Writes {@link FontStylesCollection} to xmlfile
 * @param xmlFileName//from   ww w .  j  a  v a2s  .  c om
 * @throws IOException
 * @throws SAXException
 * @throws CitationStyleManagerException 
 */
public void writeToXml(String xmlFileName) throws IOException, SAXException, CitationStyleManagerException {

    Document doc = XmlHelper.createDocument();

    Element root = doc.createElement("font-styles-collection");

    doc.appendChild(root);

    //here is the loop:

    for (FontStyle fs : fontStyles) {

        Element element = doc.createElement("font-style");

        element.setAttribute("def", "" + fs.getDef());
        element.setAttribute("name", fs.getName());
        element.setAttribute("font-size", "" + fs.getFontSize());
        element.setAttribute("font-name", fs.getFontName());
        element.setAttribute("is-bold", "" + fs.getIsBold());
        element.setAttribute("is-italic", "" + fs.getIsItalic());
        element.setAttribute("is-underline", "" + fs.getIsUnderline());
        element.setAttribute("is-strike-through", "" + fs.getIsStrikeThrough());
        element.setAttribute("pdf-font-name", fs.getPdfFontName());
        element.setAttribute("fore-color", fs.getForeColor());
        element.setAttribute("back-color", fs.getBackColor());
        element.setAttribute("pdf-encoding", fs.getPdfEncoding());
        element.setAttribute("is-pdf-embedded", "" + fs.getIsPdfEmbedded());
        element.setAttribute("is-pdf-simulated-bold", "" + fs.getIsPdfSimulatedBold());
        element.setAttribute("is-pdf-simulated-italic", "" + fs.getIsPdfSimulatedItalic());
        element.setAttribute("css-class", "" + fs.getCssClass());

        root.appendChild(element);
    }

    XmlHelper.output(doc, xmlFileName);

}

From source file:aurelienribon.gdxsetupui.ProjectUpdate.java

private void writeClasspath(File classpathFile, List<ClasspathEntry> classpath) {
    try {/*  w  w w.  j  a  v  a  2 s .  c o  m*/
        Document doc = XmlUtils.createParser().parse(classpathFile);
        Node root = (Node) XmlUtils.xpath("classpath", doc, XPathConstants.NODE);
        NodeList libsNodes = (NodeList) XmlUtils.xpath("classpath/classpathentry[@kind='lib' and @path]", doc,
                XPathConstants.NODESET);

        for (int i = 0; i < libsNodes.getLength(); i++) {
            root.removeChild(libsNodes.item(i));
        }

        for (ClasspathEntry entry : classpath) {
            Element elem = doc.createElement("classpathentry");
            root.appendChild(elem);

            elem.setAttribute("kind", "lib");
            if (entry.exported)
                elem.setAttribute("exported", "true");
            elem.setAttribute("path", entry.path);
            if (entry.sourcepath != null)
                elem.setAttribute("sourcepath", entry.sourcepath);
        }

        XmlUtils.clean(doc);
        String str = XmlUtils.transform(doc);
        FileUtils.writeStringToFile(classpathFile, str);

    } catch (SAXException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } catch (TransformerException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.XmlContentBuilder.java

private Element createJcrRoot(Document doc, String primaryType) {
    Element jcrRoot = doc.createElementNS(NS_JCR, "jcr:root");
    for (Map.Entry<String, String> namespace : xmlNamespaces.entrySet()) {
        jcrRoot.setAttribute("xmlns:" + namespace.getKey(), namespace.getValue());
    }/* www  .  jav a 2s .  c  om*/
    setAttributeNamespaceAware(jcrRoot, PN_PRIMARY_TYPE, primaryType);
    doc.appendChild(jcrRoot);
    return jcrRoot;
}

From source file:com.icesoft.faces.component.style.OutputStyleRenderer.java

private Element buildCssElement(DOMContext domContext) {
    Element styleEle = domContext.createElement("link");
    styleEle.setAttribute(HTML.REL_ATTR, "stylesheet");
    styleEle.setAttribute(HTML.TYPE_ATTR, "text/css");
    return styleEle;
}

From source file:com.weaforce.system.component.fckeditor.response.XmlResponse.java

/**
 * Use this contructor if want to respond a positive message.
 * //w w  w. j av  a 2  s .  c o m
 * @param command
 * @param resourceType
 * @param currentFolder
 * @param constructedUrl
 */
public XmlResponse(CommandHandler command, ResourceTypeHandler resourceType, String currentFolder,
        String constructedUrl) {

    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }

    Element root = document.createElement("Connector");
    document.appendChild(root);
    root.setAttribute("command", command.toString());
    root.setAttribute("resourceType", resourceType.toString());

    Element currentFolderElement = document.createElement("CurrentFolder");
    currentFolderElement.setAttribute("path", currentFolder);

    currentFolderElement.setAttribute("url", constructedUrl);
    root.appendChild(currentFolderElement);

}

From source file:com.twinsoft.convertigo.engine.admin.services.mobiles.LaunchBuild.java

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    synchronized (buildLock) {
        final MobileResourceHelper mobileResourceHelper = new MobileResourceHelper(request, "mobile/www");
        MobileApplication mobileApplication = mobileResourceHelper.mobileApplication;

        if (mobileApplication == null) {
            throw new ServiceException("no such mobile application");
        } else {/* w  ww .  j av  a2 s  .c o  m*/
            boolean bAdminRole = Engine.authenticatedSessionManager.hasRole(request.getSession(),
                    Role.WEB_ADMIN);
            if (!bAdminRole && mobileApplication.getAccessibility() == Accessibility.Private) {
                throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
            }
        }

        MobilePlatform mobilePlatform = mobileResourceHelper.mobilePlatform;

        String finalApplicationName = mobileApplication.getComputedApplicationName();
        File mobileArchiveFile = mobileResourceHelper.makeZipPackage();

        // Login to the mobile builder platform
        String mobileBuilderPlatformURL = EnginePropertiesManager
                .getProperty(PropertyName.MOBILE_BUILDER_PLATFORM_URL);

        Map<String, String[]> params = new HashMap<String, String[]>();

        params.put("application", new String[] { finalApplicationName });
        params.put("platformName", new String[] { mobilePlatform.getName() });
        params.put("platformType", new String[] { mobilePlatform.getType() });
        params.put("auth_token", new String[] { mobileApplication.getComputedAuthenticationToken() });

        //revision and endpoint params
        params.put("revision", new String[] { mobileResourceHelper.getRevision() });
        params.put("endpoint", new String[] { mobileApplication.getComputedEndpoint(request) });

        //iOS
        if (mobilePlatform instanceof IOs) {
            IOs ios = (IOs) mobilePlatform;

            String pw, title = ios.getiOSCertificateTitle();

            if (!title.equals("")) {
                pw = ios.getiOSCertificatePw();
            } else {
                title = EnginePropertiesManager.getProperty(PropertyName.MOBILE_BUILDER_IOS_CERTIFICATE_TITLE);
                pw = EnginePropertiesManager.getProperty(PropertyName.MOBILE_BUILDER_IOS_CERTIFICATE_PW);
            }

            params.put("iOSCertificateTitle", new String[] { title });
            params.put("iOSCertificatePw", new String[] { pw });
        }

        //Android
        if (mobilePlatform instanceof Android) {
            Android android = (Android) mobilePlatform;

            String certificatePw, keystorePw, title = android.getAndroidCertificateTitle();

            if (!title.equals("")) {
                certificatePw = android.getAndroidCertificatePw();
                keystorePw = android.getAndroidKeystorePw();
            } else {
                title = EnginePropertiesManager
                        .getProperty(PropertyName.MOBILE_BUILDER_ANDROID_CERTIFICATE_TITLE);
                certificatePw = EnginePropertiesManager
                        .getProperty(PropertyName.MOBILE_BUILDER_ANDROID_CERTIFICATE_PW);
                keystorePw = EnginePropertiesManager
                        .getProperty(PropertyName.MOBILE_BUILDER_ANDROID_KEYSTORE_PW);
            }

            params.put("androidCertificateTitle", new String[] { title });
            params.put("androidCertificatePw", new String[] { certificatePw });
            params.put("androidKeystorePw", new String[] { keystorePw });
        }

        //Windows Phone
        if (mobilePlatform instanceof WindowsPhoneKeyProvider) {
            WindowsPhoneKeyProvider windowsPhone = (WindowsPhoneKeyProvider) mobilePlatform;

            String title = windowsPhone.getWinphonePublisherIdTitle();

            if (title.equals("")) {
                title = EnginePropertiesManager
                        .getProperty(PropertyName.MOBILE_BUILDER_WINDOWSPHONE_PUBLISHER_ID_TITLE);
            }

            params.put("winphonePublisherIdTitle", new String[] { title });
        }

        // Launch the mobile build
        URL url = new URL(mobileBuilderPlatformURL + "/build?" + URLUtils.mapToQuery(params));

        HostConfiguration hostConfiguration = new HostConfiguration();
        hostConfiguration.setHost(url.getHost());
        HttpState httpState = new HttpState();
        Engine.theApp.proxyManager.setProxy(hostConfiguration, httpState, url);

        PostMethod method = new PostMethod(url.toString());

        FileRequestEntity entity = new FileRequestEntity(mobileArchiveFile, null);
        method.setRequestEntity(entity);

        int methodStatusCode = Engine.theApp.httpClient.executeMethod(hostConfiguration, method, httpState);
        String sResult = IOUtils.toString(method.getResponseBodyAsStream(), "UTF-8");

        if (methodStatusCode != HttpStatus.SC_OK) {
            throw new ServiceException(
                    "Unable to build application '" + finalApplicationName + "'.\n" + sResult);
        }

        JSONObject jsonObject = new JSONObject(sResult);
        Element statusElement = document.createElement("application");
        statusElement.setAttribute("id", jsonObject.getString("id"));
        document.getDocumentElement().appendChild(statusElement);
    }
}