Example usage for org.w3c.dom Element setAttributeNS

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

Introduction

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

Prototype

public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException;

Source Link

Document

Adds a new attribute.

Usage

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Set the visibility of the composite plot based on the preferences.
 *//* ww  w  .  java  2  s.  co m*/
public void setCompositePlotVisibility() {

    boolean isVisible = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_COMPOSITE_PLOT, true);
    Element plot_grouper = doc.getElementById("comp_plot");

    if (!isVisible) {
        plot_grouper.setAttributeNS(null, "display", "none");
    } else {
        plot_grouper.setAttributeNS(null, "display", "inline");
    }

    positionChartGroupersAndDrawTimeAxis();
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Set the visibility of the legend based on the preferences.
 *///  www .  j a v  a  2s  .  c o m
public void setLegendVisibility() {

    boolean legendVisible = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_LEGEND, true);
    Element legend = doc.getElementById("legend");

    if (legendVisible) {
        legend.setAttributeNS(null, "display", "inline");
    } else {
        legend.setAttributeNS(null, "display", "none");
    }
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Set the visibility of the series labels based on the preferences.
 *///  w w  w  .j  a v a  2 s . c  om
public void setSeriesLabelsVisibility() {

    boolean isSeriesLabelVisible = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHRONOLOGY_PLOT_LABELS, true);

    for (FHSeriesSVG seriesSVG : seriesSVGList) {
        Element ser = doc.getElementById("series_label_" + seriesSVG.getTitle());
        if (isSeriesLabelVisible)
            ser.setAttributeNS(null, "display", "inline");
        else
            ser.setAttributeNS(null, "display", "none");
    }

    for (int i = 0; i < seriesSVGList.size(); i++) {
        Element upButton = doc.getElementById("up_button" + i);
        Element downButton = doc.getElementById("down_button" + i);
        if (isSeriesLabelVisible) {
            upButton.setAttributeNS(null, "display", "inline");
            downButton.setAttributeNS(null, "display", "inline");
        } else {
            upButton.setAttributeNS(null, "display", "none");
            downButton.setAttributeNS(null, "display", "none");
        }
    }
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Set the visibility of the no-export elements based on the input parameter.
 * /*www . ja va  2 s . com*/
 * @param isVisible
 */
public void setVisibilityOfNoExportElements(boolean isVisible) {

    String visibility_setting = isVisible ? "inline" : "none";
    NodeList n = doc.getElementsByTagName("*");

    for (int i = 0; i < n.getLength(); i++) {
        Element temp = (Element) n.item(i);

        if (temp.getAttribute("class").equals("no_export")) {
            temp.setAttributeNS(null, "display", visibility_setting);
        }
    }
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Gets the annote canvas as an element.
 * //from www.  j av a 2 s . com
 * @return annote_canvas
 */
public Element getAnnoteCanvas() {

    try {
        Element annote_canvas = doc.createElementNS(svgNS, "rect");
        annote_canvas.setAttributeNS(null, "id", "annote_canvas");
        annote_canvas.setAttributeNS(null, "width", this.chartWidth + "");
        annote_canvas.setAttributeNS(null, "height", "999");
        annote_canvas.setAttributeNS(null, "onmousedown", "paddingGrouperOnClick(evt)");
        annote_canvas.setAttributeNS(null, "opacity", "0.0");
        return annote_canvas;
    } catch (BridgeException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Draws a line on the annotation grouper.
 * //  w w  w.j a  va2  s . c  o  m
 * @param x
 * @return
 */
public String drawAnnoteLine(int x) {

    if (annotemode == AnnoteMode.LINE) {
        Element annote_g = doc.getElementById("annote_g");
        Element annote_canvas = doc.getElementById("annote_canvas");
        Element annote_line = doc.createElementNS(svgNS, "line");
        SVGRect annote_canvas_rc = SVGLocatableSupport.getBBox(annote_canvas);

        String id = "annote_line_" + (lineGensym++);
        annote_line.setAttributeNS(null, "id", id);
        annote_line.setAttributeNS(null, "x1", Float.toString(x - chartXOffset));
        annote_line.setAttributeNS(null, "y1", "0");
        annote_line.setAttributeNS(null, "x2", Float.toString(x - chartXOffset));
        annote_line.setAttributeNS(null, "y2", Float.toString(annote_canvas_rc.getHeight()));
        annote_line.setAttributeNS(null, "stroke", "black");
        annote_line.setAttributeNS(null, "stroke-width", "3");
        annote_line.setAttributeNS(null, "opacity", "0.5");
        annote_line.setAttributeNS(null, "onmousedown",
                "FireChartSVG.getChart(chart_num).deleteAnnoteLine('" + id + "')");

        annote_g.appendChild(annote_line);
        annotemode = AnnoteMode.NONE;

        return id;
    }

    return "wrong_annotemode";
}

From source file:org.fireflow.webdesigner.transformer.FpdlDiagramSerializerSvgImpl.java

public Document serializeDiagramToDoc(WorkflowProcess workflowProcess, String subProcessName)
        throws SerializerException {
    _init(workflowProcess, subProcessName);

    ///*from  ww  w  .  j  a v  a2s  .c  o  m*/
    Element root = document.createElement("svg");
    root.setAttribute("id", diagram.getId());
    if (diagram.getWorkflowElementRef() != null) {
        root.setAttribute(FPDLNames.REF, diagram.getWorkflowElementRef().getId());
    }

    root.setAttribute("version", "1.1");
    root.setAttribute("xmlns", "http://www.w3.org/2000/svg");
    root.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
    root.setAttribute("onload", "fireflowSvgInit('" + diagram.getId() + "');");
    root.setAttribute("onunload", "fireflowSvgDestroy('" + diagram.getId() + "')");

    document.appendChild(root);

    //javascript
    Element scriptElm = document.createElement("script");
    scriptElm.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", this.resourcePathPrefix
            + "/org/fireflow/clientwidget/resources/jquery-ui-1.10.3.custom/js/jquery-1.10.2.min.js");
    root.appendChild(scriptElm);

    scriptElm = document.createElement("script");
    scriptElm.setAttribute("type", "application/ecmascript");
    root.appendChild(scriptElm);
    String data = "$ff=$;";
    CDATASection cdata = document.createCDATASection(data);
    scriptElm.appendChild(cdata);

    scriptElm = document.createElement("script");
    scriptElm.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href",
            this.resourcePathPrefix + "/org/fireflow/webdesigner/resources/svg/FireflowSvgControl.js");
    root.appendChild(scriptElm);

    //defs
    defsElement = document.createElement("defs");
    root.appendChild(defsElement);

    //markers
    //
    Element circleMk = document.createElement("marker");
    circleMk.setAttribute("id", BASIC_CIRCLE_MARKER_ID);
    circleMk.setAttribute("markerWidth", "8");
    circleMk.setAttribute("markerHeight", "8");
    circleMk.setAttribute("refX", "4");
    circleMk.setAttribute("refY", "4");
    circleMk.setAttribute("markerUnits", "userSpaceOnUse");
    defsElement.appendChild(circleMk);

    Element circleTmp = document.createElement("circle");
    circleTmp.setAttribute("cx", "4");
    circleTmp.setAttribute("cy", "4");
    circleTmp.setAttribute("r", "4");
    circleTmp.setAttribute("style", "stroke:#000000;fill:none;stroke-dasharray:2 0;");
    circleMk.appendChild(circleTmp);

    circleMarkerMap.put("#000000", circleMk);

    //Block?
    Element blockArrowMk = document.createElement("marker");
    blockArrowMk.setAttribute("id", BASIC_BLOCK_ARROW_MARKER_ID);
    blockArrowMk.setAttribute("markerWidth", "13");
    blockArrowMk.setAttribute("markerHeight", "12");
    blockArrowMk.setAttribute("refX", "11");
    blockArrowMk.setAttribute("refY", "6");
    blockArrowMk.setAttribute("orient", "auto");
    blockArrowMk.setAttribute("markerUnits", "userSpaceOnUse");
    defsElement.appendChild(blockArrowMk);

    Element blockArrow = document.createElement("path");
    blockArrow.setAttribute("d", "M2,2 L2,10 L11,6 L2,2");
    blockArrow.setAttribute("style", "stroke:none;fill:#000000;");
    blockArrowMk.appendChild(blockArrow);

    blockArrowMarkerMap.put("#000000", blockArrowMk);

    //Block?
    Element blockArrowMk2 = document.createElement("marker");
    blockArrowMk2.setAttribute("id", BASIC_BLOCK_ARROW_MARKER2_ID);
    blockArrowMk2.setAttribute("markerWidth", "13");
    blockArrowMk2.setAttribute("markerHeight", "12");
    blockArrowMk2.setAttribute("refX", "11");
    blockArrowMk2.setAttribute("refY", "6");
    blockArrowMk2.setAttribute("orient", "auto");
    blockArrowMk2.setAttribute("markerUnits", "userSpaceOnUse");
    defsElement.appendChild(blockArrowMk2);

    Element blockArrow2 = document.createElement("path");
    blockArrow2.setAttribute("d", "M2,2 L2,10 L11,6 L2,2");
    blockArrow2.setAttribute("style", "stroke:#000000;fill:none;stroke-dasharray:2,0;");
    blockArrowMk2.appendChild(blockArrow2);

    blockArrowMarker2Map.put("#000000", blockArrowMk2);

    //id=viewportg
    Element g = document.createElement("g");
    g.setAttribute("id", "viewport");
    root.appendChild(g);

    //?
    List<ProcessNodeShape> processNodeShapeList = diagram.getProcessNodeShapes();
    if (processNodeShapeList != null && processNodeShapeList.size() > 0) {
        for (ProcessNodeShape nodeShape : processNodeShapeList) {
            Element cell = this.transformProcessNodeShape2Svg(nodeShape, true);
            if (cell != null) {
                g.appendChild(cell);
            }
        }
    }

    //
    List<CommentShape> commentShapeList = diagram.getComments();
    if (commentShapeList != null && commentShapeList.size() > 0) {
        for (CommentShape commentShape : commentShapeList) {
            Element cell = transformCommentShape2Svg(commentShape, true);
            if (cell != null) {
                g.appendChild(cell);
            }

        }
    }

    //Group
    List<GroupShape> groupShapeList = diagram.getGroups();
    if (groupShapeList != null && groupShapeList.size() > 0) {
        for (GroupShape groupShape : groupShapeList) {
            Element cell = transformGroupShape2Svg(groupShape, true);
            if (cell != null) {
                g.appendChild(cell);
            }
        }
    }

    //Pool
    List<PoolShape> poolShapeList = diagram.getPools();
    if (poolShapeList != null && poolShapeList.size() > 0) {
        for (PoolShape poolShape : poolShapeList) {
            Element cell = this.transformPool2Svg(poolShape, true);
            if (cell != null) {
                g.appendChild(cell);
            }
        }
    }

    //
    //transition
    List<TransitionShape> transitionShapeList = diagram.getTransitions();
    if (transitionShapeList != null && transitionShapeList.size() > 0) {
        for (TransitionShape transitionShape : transitionShapeList) {
            Element cell = transformConnectorShape2Svg(transitionShape);
            if (cell != null) {
                g.appendChild(cell);
            }
        }
    }

    //association
    List<AssociationShape> associationShapeList = diagram.getAssociations();
    if (associationShapeList != null && associationShapeList.size() > 0) {
        for (AssociationShape associationShape : associationShapeList) {
            Element cell = transformConnectorShape2Svg(associationShape);
            if (cell != null) {
                g.appendChild(cell);
            }
        }
    }
    //      
    //      //messageflow
    List<MessageFlowShape> messageFlowShapeList = diagram.getMessageFlows();
    if (messageFlowShapeList != null && messageFlowShapeList.size() > 0) {
        for (MessageFlowShape messageFlowShape : messageFlowShapeList) {
            Element cell = this.transformConnectorShape2Svg(messageFlowShape);
            if (cell != null) {
                g.appendChild(cell);
            }
        }
    }

    //?root
    int width = this.rightDownX - this.leftTopX;
    int height = this.rightDownY - this.leftTopY;
    root.setAttribute("width", Integer.toString(width));
    root.setAttribute("height", Integer.toString(height));

    /*
    int origX = 0;
    int origY = 0;
    if (this.leftTopX<0){
       origX = this.leftTopX;
    }
    if (this.leftTopY<0){
       origY = this.leftTopY;
    }
    root.setAttribute("coordorigin", origX+","+origY);
     */

    return document;
}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

/**
 * Returns the layout for a user. This method overrides the same
 * method in the superclass to return a composite layout for non
 * fragment owners and a regular layout for layout owners. A
 * composite layout is made up of layout pieces from potentially
 * multiple incorporated layouts. If no layouts are defined then
 * the composite layout will be the same as the user's personal
 * layout fragment or PLF, the one holding only those UI elements
 * that they own or incorporated elements that they have been
 * allowed to changed.//from  w  w  w.java 2  s .c  o m
 **/
private DistributedUserLayout _getUserLayout(IPerson person, IUserProfile profile)

{
    final String userName = (String) person.getAttribute("username");
    final FragmentDefinition ownedFragment = this.getOwnedFragment(person);
    final boolean isLayoutOwnerDefault = this.isLayoutOwnerDefault(person);

    // if this user is an owner then ownedFragment will be non null. For
    // fragment owners and owners of any default layout from which a
    // fragment owners layout is copied there should not be any imported
    // distributed layouts. Instead, load their plf, mark as an owned
    // if a fragment owner, and return.

    if (ownedFragment != null || isLayoutOwnerDefault) {
        Document PLF, ILF = null;
        PLF = this._safeGetUserLayout(person, profile);
        ILF = (Document) PLF.cloneNode(true);

        final Element layoutNode = ILF.getDocumentElement();

        if (ownedFragment != null) {
            layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_FRAGMENT_NAME, ownedFragment.getName());
            if (LOG.isDebugEnabled()) {
                LOG.debug("User '" + userName + "' is owner of '" + ownedFragment.getName() + "' fragment.");
            }
        } else if (isLayoutOwnerDefault) {
            layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_IS_TEMPLATE_USER, "true");
            layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_TEMPLATE_LOGIN_ID,
                    (String) person.getAttribute("username"));
        }
        // cache in person as PLF for storage later like normal users
        person.setAttribute(Constants.PLF, PLF);
        return new DistributedUserLayout(ILF);
    }

    return this.getCompositeLayout(person, profile);
}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

@Override
protected Element getStructure(Document doc, LayoutStructure ls) {
    Element structure = null;

    // handle migration of legacy namespace
    String type = ls.getType();//  w w w .j  a  v a 2  s  .c  om
    if (type != null && type.startsWith(Constants.LEGACY_NS)) {
        type = Constants.NS + type.substring(Constants.LEGACY_NS.length());
    }

    if (ls.isChannel()) {
        final IPortletDefinition channelDef = this.portletDefinitionRegistry
                .getPortletDefinition(String.valueOf(ls.getChanId()));
        if (channelDef != null && channelApproved(channelDef.getApprovalDate())) {
            structure = this.getElementForChannel(doc, channelPrefix + ls.getStructId(), channelDef,
                    ls.getLocale());
        } else {
            // Create an error channel if channel is missing or not approved
            String missingChannel = "Unknown";
            if (channelDef != null) {
                missingChannel = channelDef.getName();
            }
            structure = this.getElementForChannel(doc, channelPrefix + ls.getStructId(),
                    MissingPortletDefinition.INSTANCE, null);
            //        structure = MissingPortletDefinition.INSTANCE.getDocument(doc, channelPrefix + ls.getStructId());
            //        structure = MissingPortletDefinition.INSTANCE.getDocument(doc, channelPrefix + ls.getStructId(),
            //                "The '" + missingChannel + "' channel is no longer available. " +
            //                "Please remove it from your layout.",
            //                -1);
        }
    } else {
        // create folder objects including dlm new types in cp namespace
        if (type != null && type.startsWith(Constants.NS)) {
            structure = doc.createElementNS(Constants.NS_URI, type);
        } else {
            structure = doc.createElement("folder");
        }
        structure.setAttribute("name", ls.getName());
        structure.setAttribute("type", (type != null ? type : "regular"));
    }

    structure.setAttribute("hidden", (ls.isHidden() ? "true" : "false"));
    structure.setAttribute("immutable", (ls.isImmutable() ? "true" : "false"));
    structure.setAttribute("unremovable", (ls.isUnremovable() ? "true" : "false"));
    if (localeAware) {
        structure.setAttribute("locale", ls.getLocale()); // for i18n by Shoji
    }

    /*
     * Parameters from up_layout_param are loaded slightly differently for
     * folders and channels. For folders all parameters are added as attributes
     * of the Element. For channels only those parameters with names starting
     * with the dlm namespace Constants.NS are added as attributes to the Element.
     * Others are added as child parameter Elements.
     */
    if (ls.getParameters() != null) {
        for (final Iterator itr = ls.getParameters().iterator(); itr.hasNext();) {
            final StructureParameter sp = (StructureParameter) itr.next();
            String pName = sp.getName();

            // handle migration of legacy namespace
            if (pName.startsWith(Constants.LEGACY_NS)) {
                pName = Constants.NS + sp.getName().substring(Constants.LEGACY_NS.length());
            }

            if (!ls.isChannel()) { // Folder
                if (pName.startsWith(Constants.NS)) {
                    structure.setAttributeNS(Constants.NS_URI, pName, sp.getValue());
                } else {
                    structure.setAttribute(pName, sp.getValue());
                }
            } else // Channel
            {
                // if dealing with a dlm namespace param add as attribute
                if (pName.startsWith(Constants.NS)) {
                    structure.setAttributeNS(Constants.NS_URI, pName, sp.getValue());
                    itr.remove();
                } else {
                    /*
                     * do traditional override processing. some explanation is in
                     * order. The structure element was created by the
                     * ChannelDefinition and only contains parameter children if the
                     * definition had defined parameters. These are checked for each
                     * layout loaded parameter as found in LayoutStructure.parameters.
                     * If a name match is found then we need to see if overriding is
                     * allowed and if so we set the value on the child parameter
                     * element. At that point we are done with that version loaded
                     * from the layout so we remove it from the in-memory set of
                     * parameters that are being merged-in. Then, after all such have
                     * been checked against those added by the channel definition we
                     * add in any remaining as adhoc, unregulated parameters.
                     */
                    final NodeList nodeListParameters = structure.getElementsByTagName("parameter");
                    for (int j = 0; j < nodeListParameters.getLength(); j++) {
                        final Element parmElement = (Element) nodeListParameters.item(j);
                        final NamedNodeMap nm = parmElement.getAttributes();

                        final String nodeName = nm.getNamedItem("name").getNodeValue();
                        if (nodeName.equals(pName)) {
                            final Node override = nm.getNamedItem("override");
                            if (override != null && override.getNodeValue().equals("yes")) {
                                final Node valueNode = nm.getNamedItem("value");
                                valueNode.setNodeValue(sp.getValue());
                            }
                            itr.remove();
                            break; // found the corresponding one so skip the rest
                        }
                    }
                }
            }
        }
        // For channels, add any remaining parameter elements loaded with the
        // layout as adhoc, unregulated, parameter children that can be overridden.
        if (ls.isChannel()) {
            for (final Iterator itr = ls.getParameters().iterator(); itr.hasNext();) {
                final StructureParameter sp = (StructureParameter) itr.next();
                final Element parameter = doc.createElement("parameter");
                parameter.setAttribute("name", sp.getName());
                parameter.setAttribute("value", sp.getValue());
                parameter.setAttribute("override", "yes");
                structure.appendChild(parameter);
            }
        }
    }
    // finish setting up elements based on loaded params
    final String origin = structure.getAttribute(Constants.ATT_ORIGIN);
    final String prefix = ls.isChannel() ? channelPrefix : folderPrefix;

    // if not null we are dealing with a node incorporated from another
    // layout and this node contains changes made by the user so handle
    // id swapping.
    if (!origin.equals("")) {
        structure.setAttributeNS(Constants.NS_URI, Constants.ATT_PLF_ID, prefix + ls.getStructId());
        structure.setAttribute("ID", origin);
    } else if (!ls.isChannel())
    // regular folder owned by this user, need to check if this is a
    // directive or ui element. If the latter then use traditional id
    // structure
    {
        if (type != null && type.startsWith(Constants.NS)) {
            structure.setAttribute("ID", Constants.DIRECTIVE_PREFIX + ls.getStructId());
        } else {
            structure.setAttribute("ID", folderPrefix + ls.getStructId());
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Adding identifier " + folderPrefix + ls.getStructId());
        }
        structure.setAttribute("ID", channelPrefix + ls.getStructId());
    }
    structure.setIdAttribute(Constants.ATT_ID, true);
    return structure;
}

From source file:org.jboss.bpm.console.server.util.DOMUtils.java

/** Copy attributes between elements
 *//*  ww w. j  av  a  2s  .  c o  m*/
public static void copyAttributes(Element destElement, Element srcElement) {
    NamedNodeMap attribs = srcElement.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++) {
        Attr attr = (Attr) attribs.item(i);
        String uri = attr.getNamespaceURI();
        String qname = attr.getName();
        String value = attr.getNodeValue();

        // Prevent DOMException: NAMESPACE_ERR: An attempt is made to create or
        // change an object in a way which is incorrect with regard to namespaces.
        if (uri == null && qname.startsWith("xmlns")) {
            log.trace("Ignore attribute: [uri=" + uri + ",qname=" + qname + ",value=" + value + "]");
        } else {
            destElement.setAttributeNS(uri, qname, value);
        }
    }
}