Refine search
public Element ccTrayXmlElement(String fullContextPath) { Element element = new Element("Project"); element.setAttribute("name", name); element.setAttribute("activity", activity); element.setAttribute("lastBuildStatus", lastBuildStatus); element.setAttribute("lastBuildLabel", lastBuildLabel); element.setAttribute("lastBuildTime", DateUtils.formatIso8601ForCCTray(lastBuildTime)); element.setAttribute("webUrl", fullContextPath + "/" + webUrl); if (!breakers.isEmpty()) { addBreakers(element); } return element; }
private void addBreakers(Element element) { Element messages = new Element("messages"); Element message = new Element("message"); String breakerNames = StringUtils.join(breakers, ", "); message.setAttribute("text", breakerNames); message.setAttribute("kind", "Breakers"); messages.addContent(message); element.addContent(messages); }
@SuppressWarnings( "unchecked" ) private void appendElement( Element source, Element target ) { for ( Iterator<Attribute> itr = source.getAttributes().iterator(); itr.hasNext(); ) { Attribute a = itr.next(); itr.remove(); Attribute mergedAtt = target.getAttribute( a.getName(), a.getNamespace() ); if ( mergedAtt == null ) { target.setAttribute( a ); } } for ( Iterator<Element> itr = source.getChildren().iterator(); itr.hasNext(); ) { Content n = itr.next(); itr.remove(); target.addContent( n ); } }
private Element createIFD() { Element ifd = new Element(GeoTiffConstants.GEOTIFF_IFD_TAG); ifd.setAttribute( GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME, BaselineTIFFTagSet.class.getName() + "," + GeoTIFFTagSet.class.getName()); if (modelPixelScale.isSet()) { ifd.addContent(createModelPixelScaleElement()); } if (isModelTiePointsSet()) { ifd.addContent(createModelTiePointsElement()); } else if (isModelTransformationSet()) { ifd.addContent(createModelTransformationElement()); } if (getNumGeoKeyEntries() > 1) { ifd.addContent(createGeoKeyDirectoryElement()); } if (numGeoTiffDoubleParams > 0) { ifd.addContent(createGeoDoubleParamsElement()); } if (numGeoTiffAsciiParams > 0) { ifd.addContent(createGeoAsciiParamsElement()); } if (isNodataSet) { ifd.addContent(createNoDataElement()); } if (isMetadataSet) { createMetadataElement(ifd); } return ifd; }
private Document createEmptyCruiseConfigDocument() { Element root = new Element("cruise"); Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS); root.addNamespaceDeclaration(xsiNamespace); registry.registerNamespacesInto(root); root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace); String xsds = registry.xsds(); if (!xsds.isEmpty()) { root.setAttribute("schemaLocation", xsds, xsiNamespace); } root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION)); return new Document(root); }
/** * Read an Element off the ObjectInputStream. * * @see #writeObject(ObjectOutputStream) * @param in where to read the Element from. * @throws IOException if there is a reading problem. * @throws ClassNotFoundException when a class cannot be found */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); content = new ContentList(this); int nss = in.readInt(); while (--nss >= 0) { addNamespaceDeclaration((Namespace)in.readObject()); } int ats = in.readInt(); while (--ats >= 0) { setAttribute((Attribute)in.readObject()); } int cs = in.readInt(); while (--cs >= 0) { addContent((Content)in.readObject()); } }
private static Element addTable(final Element body, final String id) { final Element table = new Element("table"); body.addContent(table); table.setAttribute("id", id); return table; }
private static Element elementFor(Class<?> aClass, ConfigCache configCache) { final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null) { final Element element = new Element(attributeAwareConfigTag.value(), namespaceFor(attributeAwareConfigTag)); element.setAttribute(attributeAwareConfigTag.attribute(), attributeAwareConfigTag.attributeValue()); return element; } ConfigTag configTag = annotationFor(aClass, ConfigTag.class); if (configTag == null) throw bomb(format("Cannot get config tag for {0}", aClass)); return new Element(configTag.value(), namespaceFor(configTag)); }
public void assignTo(Element element) { if (!element.getName().equals(GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME)) { throw new IllegalArgumentException( "root not found: " + GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME); } final Element ifd1 = element.getChild(GeoTiffConstants.GEOTIFF_IFD_TAG); if (ifd1 == null) { throw new IllegalArgumentException( "Unable to find child " + GeoTiffConstants.GEOTIFF_IFD_TAG); } final Element ifd2 = createIFD(); ifd1.setAttribute( GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME, ifd2.getAttributeValue(GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME)); final Element[] childElems = (Element[]) ifd2.getChildren().toArray(new Element[0]); for (int i = 0; i < childElems.length; i++) { final Element child = childElems[i]; ifd2.removeContent(child); ifd1.addContent(child); } }
private void addCoord(Element tableElem, String name, String kind) { if (name != null) { Element elem = new Element("coordinate").setAttribute("kind", kind); elem.addContent(name); tableElem.addContent(elem); } }
@Test(expected = RuntimeException.class) public void shouldValidateAndConvertOnlyIfAppropriate() throws NoSuchFieldException { final Foo object = new Foo(); final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("number"), object, configCache, null); final Element element = new Element("foo"); element.setAttribute("number", "anything"); field.setValueIfNotNull(element, object); }
private void addCoord(Element tableElem, String name, String kind) { if (name != null) { Element elem = new Element("coordinate").setAttribute("kind", kind); elem.addContent(name); tableElem.addContent(elem); } }
@Test public void shouldConvertFromXmlToJavaObjectCorrectly() throws Exception { final Foo object = new Foo(); final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("number"), object, configCache, null); final Element element = new Element("foo"); element.setAttribute("number", "100"); field.setValueIfNotNull(element, object); assertThat(object.number, is(100L)); }
private void addCoord(Element tableElem, String name, String kind) { if (name != null) { Element elem = new Element("coordinate").setAttribute("kind", kind); elem.addContent(name); tableElem.addContent(elem); } }
@Test public void shouldContinueParsingWhenConfigClassHasValidAttributeAwareConfigTagAnnotation() { final Element element = new Element("example"); element.setAttribute("type", "example-type"); when(configCache.getFieldCache()).thenReturn(new ClassAttributeCache.FieldCache()); final GoConfigClassLoader<ConfigWithAttributeAwareConfigTagAnnotation> loader = GoConfigClassLoader.classParser(element, ConfigWithAttributeAwareConfigTagAnnotation.class, configCache, goCipher, registry, referenceElements); final ConfigWithAttributeAwareConfigTagAnnotation configWithConfigTagAnnotation = loader.parse(); assertNotNull(configWithConfigTagAnnotation); }
protected void addAttr (Element e, String name, Object obj, String type) { String value = obj == null ? "null" : obj.toString(); Element attr = new Element ("attr"); attr.setAttribute ("name", name); if (type != null) attr.setAttribute ("type", type); attr.setText (value); e.addContent (attr); } protected Iterator getAttrs () {
@Test public void shouldConvertFileCorrectly() throws Exception { final Foo object = new Foo(); final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("directory"), object, configCache, null); final Element element = new Element("foo"); element.setAttribute("directory", "foo" + FileUtil.fileseparator() + "dir"); field.setValueIfNotNull(element, object); assertThat(object.directory.getPath(), is("foo" + FileUtil.fileseparator() + "dir")); }
private Element writeJoinParentIndex(JoinParentIndex join) { Element joinElem = new Element("join"); joinElem.setAttribute("class", join.getClass().toString()); if (join.parentStructure != null) joinElem.addContent( new Element("parentStructure").setAttribute("name", join.parentStructure.getFullName())); if (join.parentIndex != null) joinElem.addContent( new Element("parentIndex").setAttribute("name", join.parentIndex)); return joinElem; }
@Test public void shouldErrorOutWhenConfigClassHasAttributeAwareConfigTagAnnotationButAttributeValueIsNotMatching() { final Element element = new Element("example"); element.setAttribute("type", "foo-bar"); when(configCache.getFieldCache()).thenReturn(new ClassAttributeCache.FieldCache()); final GoConfigClassLoader<ConfigWithAttributeAwareConfigTagAnnotation> loader = GoConfigClassLoader.classParser(element, ConfigWithAttributeAwareConfigTagAnnotation.class, configCache, goCipher, registry, referenceElements); thrown.expect(RuntimeException.class); thrown.expectMessage("Unable to determine type to generate. Type: com.thoughtworks.go.config.parser.ConfigWithAttributeAwareConfigTagAnnotation Element: \n" + "\t<example type=\"foo-bar\" />"); loader.parse(); }
private Element writeJoinParentIndex(JoinParentIndex join) { Element joinElem = new Element("join"); joinElem.setAttribute("class", join.getClass().toString()); if (join.parentStructure != null) joinElem.addContent( new Element("parentStructure").setAttribute("name", join.parentStructure.getFullName())); if (join.parentIndex != null) joinElem.addContent( new Element("parentIndex").setAttribute("name", join.parentIndex)); return joinElem; }