org.w3c.dom.Element#setAttributeNode ( )源码实例Demo

下面列出了org.w3c.dom.Element#setAttributeNode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void marshalEmptyDOMResult() throws Exception {
	DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
	documentBuilderFactory.setNamespaceAware(true);
	DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
	DOMResult domResult = new DOMResult();
	marshaller.marshal(flights, domResult);
	assertTrue("DOMResult does not contain a Document", domResult.getNode() instanceof Document);
	Document result = (Document) domResult.getNode();
	Document expected = builder.newDocument();
	Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
	Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
	namespace.setNodeValue("http://samples.springframework.org/flight");
	flightsElement.setAttributeNode(namespace);
	expected.appendChild(flightsElement);
	Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
	flightsElement.appendChild(flightElement);
	Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
	flightElement.appendChild(numberElement);
	Text text = expected.createTextNode("42");
	numberElement.appendChild(text);
	assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected));
}
 
/**
 * Adds a property
 *
 * @param name:   Name of property
 * @param value:  Value
 * @param doc:    Document
 * @param parent: Parent element of the property to be added as a child
 */
private void addProperty(String name, String value, Document doc, Element parent, boolean encrypted) {
    Element property = doc.createElement("Property");
    Attr attr;
    if (encrypted) {
        attr = doc.createAttribute("encrypted");
        attr.setValue("true");
        property.setAttributeNode(attr);
    }

    attr = doc.createAttribute("name");
    attr.setValue(name);
    property.setAttributeNode(attr);

    property.setTextContent(value);
    parent.appendChild(property);
}
 
源代码3 项目: kogito-runtimes   文件: FlowTest.java
@Test
public void testExclusiveSplitXPathAdvancedWithVars() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced-with-vars.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email",
            new SystemOutWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    Document doc = DocumentBuilderFactory.newInstance()
            .newDocumentBuilder().newDocument();
    Element hi = doc.createElement("hi");
    Element ho = doc.createElement("ho");
    hi.appendChild(ho);
    Attr attr = doc.createAttribute("value");
    ho.setAttributeNode(attr);
    attr.setValue("a");
    params.put("x", hi);
    params.put("y", "Second");
    ProcessInstance processInstance = ksession.startProcess(
            "com.sample.test", params);
    assertProcessInstanceCompleted(processInstance);

}
 
private static Document getDocument(UserStoreDTO userStoreDTO, boolean editSecondaryUserStore,
                                    DocumentBuilder documentBuilder, String existingDomainName)
        throws IdentityUserStoreMgtException {

    Document doc = documentBuilder.newDocument();

    //create UserStoreManager element
    Element userStoreElement = doc.createElement(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_STORE_MANAGER);
    doc.appendChild(userStoreElement);

    Attr attrClass = doc.createAttribute("class");
    if (userStoreDTO != null) {
        attrClass.setValue(userStoreDTO.getClassName());
        userStoreElement.setAttributeNode(attrClass);
        if (userStoreDTO.getClassName() != null) {
            addProperties(existingDomainName, userStoreDTO.getClassName(), userStoreDTO.getProperties(),
                    doc, userStoreElement, editSecondaryUserStore);
        }
        addProperty(UserStoreConfigConstants.DOMAIN_NAME, userStoreDTO.getDomainId(), doc, userStoreElement, false);
        addProperty(UserStoreConfigurationConstant.DESCRIPTION, userStoreDTO.getDescription(), doc,
                    userStoreElement, false);
    }
    return doc;
}
 
源代码5 项目: xmlunit   文件: test_DifferenceEngine.java
private void testAttributeSequenceNS(int expected) throws Exception {
    Element control = document.createElementNS("ns", "foo");
    Element test = document.createElementNS("ns", "foo");
    OrderPreservingNamedNodeMap controlMap =
        new OrderPreservingNamedNodeMap();
    OrderPreservingNamedNodeMap testMap = new OrderPreservingNamedNodeMap();
    for (int i = 0; i < 2; i++) {
        int j = 1 - i;
        Attr attrI = document.createAttributeNS("ns", "attr" + i);
        attrI.setValue(String.valueOf(i));
        Attr attrJ = document.createAttributeNS("ns", "attr" + j);
        attrJ.setValue(String.valueOf(j));

        control.setAttributeNode(attrI);
        controlMap.add(attrI);
        test.setAttributeNode(attrJ);
        testMap.add(attrJ);
    }
    engine.compareElementAttributes(control, test, controlMap, testMap,
                                    listener);
    assertEquals(expected, listener.comparingWhat);
}
 
源代码6 项目: sakai   文件: LessonBuilderEntityProducer.java
protected void addAttr(Document doc, Element element, String name, String value) {
if (value == null)
    return;
Attr attr = doc.createAttribute(name);
attr.setValue(value);
element.setAttributeNode(attr);
   }
 
源代码7 项目: teamengine   文件: TECore.java
private void appendEndTestElement( TestEntry test, Document doc, Element root ) {
    Element endtest = doc.createElement( "endtest" );

    Attr resultAttribute = doc.createAttribute( "result" );
    resultAttribute.setValue( Integer.toString( test.getResult() ) );

    endtest.setAttributeNode( resultAttribute );
    root.appendChild( endtest );
}
 
源代码8 项目: mappwidget   文件: ImageXML.java
private static void addSizeAttr(Element sizeElement, Document doc, int w, int h)
{
	Attr attr = doc.createAttribute(Constants.Attr.WIDTH);
	attr.setValue("" + w);
	sizeElement.setAttributeNode(attr);

	attr = doc.createAttribute(Constants.Attr.HEIGHT);
	attr.setValue("" + h);
	sizeElement.setAttributeNode(attr);
}
 
private void addElementAttribute(Document doc, Element parent, String name, String value) {
  Attr attr = doc.createAttribute(name);
  attr.setValue(value);
  parent.setAttributeNode(attr);
}
 
源代码10 项目: yt-java-game   文件: Save.java
private void saveMap(TileManager tm) {
    try {

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        Document doc = docBuilder.newDocument();
        Element rootElement = doc.createElement("map");

        Attr width = doc.createAttribute("width");
        width.setValue(Integer.toString(tm.getChunkSize()));
        rootElement.setAttributeNode(width);

        Attr height = doc.createAttribute("height");
        height.setValue(Integer.toString(tm.getChunkSize()));
        rootElement.setAttributeNode(height);

        Attr tilewidth = doc.createAttribute("tilewidth");
        tilewidth.setValue(Integer.toString(tm.getBlockWidth()));
        rootElement.setAttributeNode(tilewidth);

        Attr tileheight = doc.createAttribute("tileheight");
        tileheight.setValue(Integer.toString(tm.getBlockHeight()));
        rootElement.setAttributeNode(tileheight);

        doc.appendChild(rootElement);

        Element tileset = doc.createElement("tileset");
        Attr name = doc.createAttribute("name");
        name.setValue(tm.getFilename());
        tileset.setAttributeNode(name);

        Attr columns = doc.createAttribute("columns");
        columns.setValue(Integer.toString(tm.getColumns()));
        tileset.setAttributeNode(columns);
        tileset.setAttributeNode(tilewidth);
        tileset.setAttributeNode(tileheight);

        rootElement.appendChild(tileset);

        // create function for layers?

        Element solid = doc.createElement("data");
        Attr nameSolid = doc.createAttribute("name");
        nameSolid.setValue("Solid");
        solid.setAttributeNode(nameSolid);
        solid.setAttributeNode(width);
        solid.setAttributeNode(height);

        Element data = doc.createElement("data");
        data.appendChild(doc.createTextNode(tm.getSolid()));
        solid.appendChild(data);

        rootElement.appendChild(solid);

        Element layer1 = doc.createElement("data");
        Attr nameLayer1 = doc.createAttribute("name");
        nameLayer1.setValue("Layer1");
        layer1.setAttributeNode(nameLayer1);
        layer1.setAttributeNode(width);
        layer1.setAttributeNode(height);

        Element data1 = doc.createElement("data");
        data1.appendChild(doc.createTextNode(tm.getGenMap()));
        layer1.appendChild(data1);

        rootElement.appendChild(layer1);

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File("C:\\file.xml"));

        transformer.transform(source, result);
        System.out.println("Map saved!");

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码11 项目: jdk8u60   文件: DOMResultBuilder.java
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}
 
源代码12 项目: MeteoInfo   文件: MapFrame.java
private void addMapFrameElement(Document m_Doc, Element parent, String projectFilePath) {
    Element mapFrame = m_Doc.createElement("MapFrame");
    Attr name = m_Doc.createAttribute("Name");
    Attr active = m_Doc.createAttribute("Active");
    Attr expanded = m_Doc.createAttribute("Expanded");
    Attr order = m_Doc.createAttribute("Order");
    Attr Left = m_Doc.createAttribute("Left");
    Attr Top = m_Doc.createAttribute("Top");
    Attr Width = m_Doc.createAttribute("Width");
    Attr Height = m_Doc.createAttribute("Height");
    Attr DrawMapNeatLine = m_Doc.createAttribute("DrawNeatLine");
    Attr MapNeatLineColor = m_Doc.createAttribute("NeatLineColor");
    Attr MapNeatLineSize = m_Doc.createAttribute("NeatLineSize");
    Attr GridLineColor = m_Doc.createAttribute("GridLineColor");
    Attr GridLineSize = m_Doc.createAttribute("GridLineSize");
    Attr GridLineStyle = m_Doc.createAttribute("GridLineStyle");
    Attr DrawGridLine = m_Doc.createAttribute("DrawGridLine");
    Attr DrawGridLabel = m_Doc.createAttribute("DrawGridLabel");
    Attr GridFontName = m_Doc.createAttribute("GridFontName");
    Attr GridFontSize = m_Doc.createAttribute("GridFontSize");
    Attr GridXDelt = m_Doc.createAttribute("GridXDelt");
    Attr GridYDelt = m_Doc.createAttribute("GridYDelt");
    Attr GridXOrigin = m_Doc.createAttribute("GridXOrigin");
    Attr GridYOrigin = m_Doc.createAttribute("GridYOrigin");

    name.setValue(this.getText());
    active.setValue(String.valueOf(this.isActive()));
    expanded.setValue(String.valueOf(this.isExpanded()));
    order.setValue(String.valueOf(_order));
    Left.setValue(String.valueOf(_layoutBounds.x));
    Top.setValue(String.valueOf(_layoutBounds.y));
    Width.setValue(String.valueOf(_layoutBounds.width));
    Height.setValue(String.valueOf(_layoutBounds.height));
    DrawMapNeatLine.setValue(String.valueOf(_drawNeatLine));
    MapNeatLineColor.setValue(ColorUtil.toHexEncoding(_neatLineColor));
    MapNeatLineSize.setValue(String.valueOf(_neatLineSize));
    GridLineColor.setValue(ColorUtil.toHexEncoding(this.getGridLineColor()));
    GridLineSize.setValue(String.valueOf(this.getGridLineSize()));
    GridLineStyle.setValue(this.getGridLineStyle().toString());
    DrawGridLine.setValue(String.valueOf(this.isDrawGridLine()));
    DrawGridLabel.setValue(String.valueOf(this.isDrawGridLabel()));
    GridFontName.setValue(this.getGridFont().getFontName());
    GridFontSize.setValue(String.valueOf(this.getGridFont().getSize()));
    GridXDelt.setValue(String.valueOf(this.getGridXDelt()));
    GridYDelt.setValue(String.valueOf(this.getGridYDelt()));
    GridXOrigin.setValue(String.valueOf(this.getGridXOrigin()));
    GridYOrigin.setValue(String.valueOf(this.getGridYOrigin()));

    mapFrame.setAttributeNode(name);
    mapFrame.setAttributeNode(active);
    mapFrame.setAttributeNode(expanded);
    mapFrame.setAttributeNode(order);
    mapFrame.setAttributeNode(Left);
    mapFrame.setAttributeNode(Top);
    mapFrame.setAttributeNode(Width);
    mapFrame.setAttributeNode(Height);
    mapFrame.setAttributeNode(DrawMapNeatLine);
    mapFrame.setAttributeNode(MapNeatLineColor);
    mapFrame.setAttributeNode(MapNeatLineSize);
    mapFrame.setAttributeNode(GridLineColor);
    mapFrame.setAttributeNode(GridLineSize);
    mapFrame.setAttributeNode(GridLineStyle);
    mapFrame.setAttributeNode(DrawGridLine);
    mapFrame.setAttributeNode(DrawGridLabel);
    mapFrame.setAttributeNode(GridFontName);
    mapFrame.setAttributeNode(GridFontSize);
    mapFrame.setAttributeNode(GridXDelt);
    mapFrame.setAttributeNode(GridYDelt);
    mapFrame.setAttributeNode(GridXOrigin);
    mapFrame.setAttributeNode(GridYOrigin);

    _mapView.exportExtentsElement(m_Doc, mapFrame);
    _mapView.exportMapPropElement(m_Doc, mapFrame);
    _mapView.exportGridLineElement(m_Doc, mapFrame);
    _mapView.exportMaskOutElement(m_Doc, mapFrame);
    _mapView.exportProjectionElement(m_Doc, mapFrame);
    addGroupLayerElement(m_Doc, mapFrame, projectFilePath);
    _mapView.exportGraphics(m_Doc, mapFrame, _mapView.getGraphicCollection().getGraphics());

    parent.appendChild(mapFrame);
}
 
源代码13 项目: cougar   文件: ResponseToSimpleResponseMangler.java
@Override
public void mangleDocument(Node doc) {

    final XPathFactory factory = XPathFactory.newInstance();

    try {
        //Get all parameters nodes, and recurse through to find any that have a "response" element defined
        NodeList nodes = (NodeList)factory.newXPath().evaluate("//parameters", doc, XPathConstants.NODESET);
        if (nodes != null) {
            for (int i = 0; i < nodes.getLength(); i++) {
                Node parametersNode = nodes.item(i);
                Node toBeReplaced = getNodeToBeReplaced(parametersNode);
                if (toBeReplaced != null) {
                    //There is no way to simply change the qualifiedName or localName of the element, so we need to
                    //go through all this palarva of making a copy and replacing it
                    String qualifiedName = toBeReplaced.getPrefix() != null ? toBeReplaced.getPrefix() + ".simpleResponse" : "simpleResponse";
                    Element replacementNode = parametersNode.getOwnerDocument().createElementNS(toBeReplaced.getNamespaceURI(), qualifiedName);
                    //Copy all the child nodes (which surprisingly does not include attributes, even though they are nodes)
                    NodeList replacementChildNodes = toBeReplaced.getChildNodes();
                    if (replacementChildNodes != null) {
                        for (int j = 0; j < replacementChildNodes.getLength(); j++) {
                            replacementNode.appendChild(replacementChildNodes.item(j).cloneNode(true));
                        }
                    }
                    //Copy all the attributes
                    NamedNodeMap attributes = toBeReplaced.getAttributes();
                    if (attributes != null) {
                        for (int j = 0; j < attributes.getLength(); j++) {
                            Attr attribute = (Attr)attributes.item(j);
                            //Strangely, it is possible to get a null attribute from this collection... check for it
                            if (attribute != null) {
                                replacementNode.setAttributeNode((Attr)attribute.cloneNode(true));
                            }
                        }
                    }
                    //Replace the existing node with a new
                    parametersNode.replaceChild(replacementNode, toBeReplaced);
                }
            }
        }
    } catch (XPathExpressionException e) {
        throw new IllegalArgumentException("XPath failed to get parameters", e);
    }
}
 
源代码14 项目: Bytecoder   文件: DOMResultBuilder.java
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}
 
源代码15 项目: JDKSourceCode1.8   文件: DOMResultBuilder.java
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}
 
源代码16 项目: MeteoInfo   文件: MapLayout.java
private void addLayoutScaleBarElement(Document doc, Element parent, LayoutScaleBar aScaleBar) {
    Element scaleBar = doc.createElement("LayoutScaleBar");
    Attr elementType = doc.createAttribute("ElementType");
    Attr layoutMapIndex = doc.createAttribute("LayoutMapIndex");
    Attr scaleBarType = doc.createAttribute("ScaleBarType");
    Attr BackColor = doc.createAttribute("BackColor");
    Attr foreColor = doc.createAttribute("ForeColor");
    Attr DrawNeatLine = doc.createAttribute("DrawNeatLine");
    Attr NeatLineColor = doc.createAttribute("NeatLineColor");
    Attr NeatLineSize = doc.createAttribute("NeatLineSize");
    Attr Left = doc.createAttribute("Left");
    Attr Top = doc.createAttribute("Top");
    Attr Width = doc.createAttribute("Width");
    Attr Height = doc.createAttribute("Height");
    Attr FontName = doc.createAttribute("FontName");
    Attr FontSize = doc.createAttribute("FontSize");
    Attr drawScaleText = doc.createAttribute("DrawScaleText");
    Attr drawBackColor = doc.createAttribute("DrawBackColor");

    elementType.setValue(aScaleBar.getElementType().toString());
    layoutMapIndex.setValue(String.valueOf(getLayoutMapIndex(aScaleBar.getLayoutMap())));
    scaleBarType.setValue(aScaleBar.getScaleBarType().toString());
    BackColor.setValue(ColorUtil.toHexEncoding(aScaleBar.getBackColor()));
    foreColor.setValue(ColorUtil.toHexEncoding(aScaleBar.getForeColor()));
    DrawNeatLine.setValue(String.valueOf(aScaleBar.isDrawNeatLine()));
    NeatLineColor.setValue(ColorUtil.toHexEncoding(aScaleBar.getNeatLineColor()));
    NeatLineSize.setValue(String.valueOf(aScaleBar.getNeatLineSize()));
    Left.setValue(String.valueOf(aScaleBar.getLeft()));
    Top.setValue(String.valueOf(aScaleBar.getTop()));
    Width.setValue(String.valueOf(aScaleBar.getWidth()));
    Height.setValue(String.valueOf(aScaleBar.getHeight()));
    FontName.setValue(aScaleBar.getFont().getFontName());
    FontSize.setValue(String.valueOf(aScaleBar.getFont().getSize()));
    drawScaleText.setValue(String.valueOf(aScaleBar.isDrawScaleText()));
    drawBackColor.setValue(String.valueOf(aScaleBar.isDrawBackColor()));

    scaleBar.setAttributeNode(elementType);
    scaleBar.setAttributeNode(layoutMapIndex);
    scaleBar.setAttributeNode(scaleBarType);
    scaleBar.setAttributeNode(BackColor);
    scaleBar.setAttributeNode(foreColor);
    scaleBar.setAttributeNode(DrawNeatLine);
    scaleBar.setAttributeNode(NeatLineColor);
    scaleBar.setAttributeNode(NeatLineSize);
    scaleBar.setAttributeNode(Left);
    scaleBar.setAttributeNode(Top);
    scaleBar.setAttributeNode(Width);
    scaleBar.setAttributeNode(Height);
    scaleBar.setAttributeNode(FontName);
    scaleBar.setAttributeNode(FontSize);
    scaleBar.setAttributeNode(drawScaleText);
    scaleBar.setAttributeNode(drawBackColor);

    parent.appendChild(scaleBar);
}
 
源代码17 项目: MeteoInfo   文件: MapLayout.java
private void addLayoutNorthArrowElement(Document doc, Element parent, LayoutNorthArrow aNorthArrow) {
    Element northArrow = doc.createElement("LayoutNorthArrow");
    Attr elementType = doc.createAttribute("ElementType");
    Attr layoutMapIndex = doc.createAttribute("LayoutMapIndex");
    Attr BackColor = doc.createAttribute("BackColor");
    Attr foreColor = doc.createAttribute("ForeColor");
    Attr DrawNeatLine = doc.createAttribute("DrawNeatLine");
    Attr NeatLineColor = doc.createAttribute("NeatLineColor");
    Attr NeatLineSize = doc.createAttribute("NeatLineSize");
    Attr Left = doc.createAttribute("Left");
    Attr Top = doc.createAttribute("Top");
    Attr Width = doc.createAttribute("Width");
    Attr Height = doc.createAttribute("Height");
    Attr angle = doc.createAttribute("Angle");
    Attr drawBackColor = doc.createAttribute("DrawBackColor");

    elementType.setValue(aNorthArrow.getElementType().toString());
    layoutMapIndex.setValue(String.valueOf(getLayoutMapIndex(aNorthArrow.getLayoutMap())));
    BackColor.setValue(ColorUtil.toHexEncoding(aNorthArrow.getBackColor()));
    foreColor.setValue(ColorUtil.toHexEncoding(aNorthArrow.getForeColor()));
    DrawNeatLine.setValue(String.valueOf(aNorthArrow.isDrawNeatLine()));
    NeatLineColor.setValue(ColorUtil.toHexEncoding(aNorthArrow.getNeatLineColor()));
    NeatLineSize.setValue(String.valueOf(aNorthArrow.getNeatLineSize()));
    Left.setValue(String.valueOf(aNorthArrow.getLeft()));
    Top.setValue(String.valueOf(aNorthArrow.getTop()));
    Width.setValue(String.valueOf(aNorthArrow.getWidth()));
    Height.setValue(String.valueOf(aNorthArrow.getHeight()));
    angle.setValue(String.valueOf(aNorthArrow.getAngle()));
    drawBackColor.setValue(String.valueOf(aNorthArrow.isDrawBackColor()));

    northArrow.setAttributeNode(elementType);
    northArrow.setAttributeNode(layoutMapIndex);
    northArrow.setAttributeNode(BackColor);
    northArrow.setAttributeNode(foreColor);
    northArrow.setAttributeNode(DrawNeatLine);
    northArrow.setAttributeNode(NeatLineColor);
    northArrow.setAttributeNode(NeatLineSize);
    northArrow.setAttributeNode(Left);
    northArrow.setAttributeNode(Top);
    northArrow.setAttributeNode(Width);
    northArrow.setAttributeNode(Height);
    northArrow.setAttributeNode(angle);
    northArrow.setAttributeNode(drawBackColor);

    parent.appendChild(northArrow);
}
 
源代码18 项目: knox   文件: XmlFilterReader.java
private void streamAttribute( Element element, Attribute attribute ) throws XPathExpressionException {
  Attr node;
  QName name = attribute.getName();
  String prefix = name.getPrefix();
  String uri = name.getNamespaceURI();
  if( uri == null || uri.isEmpty() ) {
    node = document.createAttribute( name.getLocalPart() );
    element.setAttributeNode( node );
  } else {
    node = document.createAttributeNS( uri, name.getLocalPart() );
    if( prefix != null && !prefix.isEmpty() ) {
      node.setPrefix( prefix );
    }
    element.setAttributeNodeNS( node );
  }

  String value = attribute.getValue();
  Level level = stack.peek();
  if( ( level.scopeConfig ) == null || ( level.scopeConfig.getSelectors().isEmpty() ) ) {
    value = filterAttribute( null, attribute.getName(), value, null );
    node.setValue( value );
  } else {
    UrlRewriteFilterPathDescriptor path = pickFirstMatchingPath( level );
    if( path instanceof UrlRewriteFilterApplyDescriptor ) {
      String rule = ((UrlRewriteFilterApplyDescriptor)path).rule();
      value = filterAttribute( null, attribute.getName(), value, rule );
      node.setValue( value );
    }
  }

  if( prefix == null || prefix.isEmpty() ) {
    writer.write( " " );
    writer.write( name.getLocalPart() );
  } else {
    writer.write( " " );
    writer.write( prefix );
    writer.write( ":" );
    writer.write( name.getLocalPart() );
  }
  writer.write( "=\"" );
  writer.write( value );
  writer.write( "\"" );
  element.removeAttributeNode( node );
}
 
源代码19 项目: ReactionDecoder   文件: Annotator.java
/**
 *
 * @param annotateRXNQ
 * @param reactionQID
 * @param annotateRXNT
 * @param reactionTID
 * @param doc
 * @param rootElement
 * @throws Exception
 */
protected synchronized void compareRXNXML(ReactionMechanismTool annotateRXNQ, String reactionQID, ReactionMechanismTool annotateRXNT, String reactionTID, Document doc, Element rootElement) throws Exception {
    NumberFormat myFormatter = NumberFormat.getInstance();
    myFormatter.setMinimumFractionDigits(2);
    myFormatter.setMaximumFractionDigits(2);
    Element element = doc.createElement("COMPARISON");
    rootElement.appendChild(element);
    //Start of Fingerprint elements
    Element query = doc.createElement("QUERY");
    element.appendChild(query);
    annotateReactionAsXML(annotateRXNQ, reactionQID, doc, query);
    BondChangeCalculator bondChangeCalculatorQ = annotateRXNQ.getSelectedSolution().getBondChangeCalculator();
    //Start of Fingerprint elements
    Element target = doc.createElement("TARGET");
    element.appendChild(target);
    annotateReactionAsXML(annotateRXNT, reactionTID, doc, target);
    BondChangeCalculator bondChangeCalculatorT = annotateRXNT.getSelectedSolution().getBondChangeCalculator();
    IPatternFingerprinter fpQ = new PatternFingerprinter();
    fpQ.add(bondChangeCalculatorQ.getFormedCleavedWFingerprint());
    fpQ.add(bondChangeCalculatorQ.getOrderChangesWFingerprint());
    fpQ.add(bondChangeCalculatorQ.getStereoChangesWFingerprint());
    IPatternFingerprinter fpT = new PatternFingerprinter();
    fpT.add(bondChangeCalculatorT.getFormedCleavedWFingerprint());
    fpT.add(bondChangeCalculatorT.getOrderChangesWFingerprint());
    fpT.add(bondChangeCalculatorT.getStereoChangesWFingerprint());
    double similarityBondChanges = getSimilarity(fpQ, fpT);
    //Start of Fingerprint elements
    Element sim = doc.createElement("SIMILARITY");
    element.appendChild(sim);
    //Start of RC as child node of Fingerprint elements
    Attr attr = doc.createAttribute("BC");
    attr.setValue("1");
    sim.setAttributeNode(attr);
    // AAM elements
    Element score = doc.createElement("SCORE");
    score.appendChild(doc.createTextNode(myFormatter.format(similarityBondChanges)));
    sim.appendChild(score);
    double similarityReactionCentres = getSimilarity(bondChangeCalculatorQ.getReactionCenterWFingerprint(), bondChangeCalculatorT.getReactionCenterWFingerprint());
    //Start of Fingerprint elements
    sim = doc.createElement("SIMILARITY");
    element.appendChild(sim);
    //Start of RC as child node of Fingerprint elements
    attr = doc.createAttribute("RC");
    attr.setValue("2");
    sim.setAttributeNode(attr);
    // AAM elements
    score = doc.createElement("SCORE");
    score.appendChild(doc.createTextNode(myFormatter.format(similarityReactionCentres)));
    sim.appendChild(score);
    ReactionFingerprinter rfQ = new ReactionFingerprinter(bondChangeCalculatorQ.getReaction());
    ReactionFingerprinter rfT = new ReactionFingerprinter(bondChangeCalculatorT.getReaction());
    double similarityReactionStructure = getSimilarity(rfQ.getReactionStruturalFingerprint(), rfT.getReactionStruturalFingerprint());
    //Start of Fingerprint elements
    sim = doc.createElement("SIMILARITY");
    element.appendChild(sim);
    //Start of RC as child node of Fingerprint elements
    attr = doc.createAttribute("ST");
    attr.setValue("3");
    sim.setAttributeNode(attr);
    // AAM elements
    score = doc.createElement("SCORE");
    score.appendChild(doc.createTextNode(myFormatter.format(similarityReactionStructure)));
    sim.appendChild(score);
}
 
源代码20 项目: hottub   文件: DOMResultBuilder.java
public void startElement(QName element, XMLAttributes attributes,
        Augmentations augs) throws XNIException {
    Element elem;
    int attrCount = attributes.getLength();
    if (fDocumentImpl == null) {
        elem = fDocument.createElementNS(element.uri, element.rawname);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            elem.setAttributeNS(fAttributeQName.uri, fAttributeQName.rawname, attributes.getValue(i));
        }
    }
    // If it's a Xerces DOM store type information for attributes, set idness, etc..
    else {
        elem = fDocumentImpl.createElementNS(element.uri, element.rawname, element.localpart);
        for (int i = 0; i < attrCount; ++i) {
            attributes.getName(i, fAttributeQName);
            AttrImpl attr = (AttrImpl) fDocumentImpl.createAttributeNS(fAttributeQName.uri,
                    fAttributeQName.rawname, fAttributeQName.localpart);
            attr.setValue(attributes.getValue(i));

            // write type information to this attribute
            AttributePSVI attrPSVI = (AttributePSVI) attributes.getAugmentations(i).getItem (Constants.ATTRIBUTE_PSVI);
            if (attrPSVI != null) {
                if (fStorePSVI) {
                    ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
                }
                Object type = attrPSVI.getMemberTypeDefinition();
                if (type == null) {
                    type = attrPSVI.getTypeDefinition();
                    if (type != null) {
                        attr.setType (type);
                        if (((XSSimpleType) type).isIDType()) {
                            ((ElementImpl) elem).setIdAttributeNode (attr, true);
                        }
                    }
                }
                else {
                    attr.setType (type);
                    if (((XSSimpleType) type).isIDType()) {
                        ((ElementImpl) elem).setIdAttributeNode (attr, true);
                    }
                }
            }
            attr.setSpecified(attributes.isSpecified(i));
            elem.setAttributeNode(attr);
        }
    }
    append(elem);
    fCurrentNode = elem;
    if (fFragmentRoot == null) {
        fFragmentRoot = elem;
    }
}