Search in sources :

Example 6 with DefaultElement

use of org.dom4j.tree.DefaultElement in project zm-mailbox by Zimbra.

the class ResourceProperty method addChild.

/* Adds child Element. */
public Element addChild(QName e) {
    Element child = new DefaultElement(e);
    mChildren.add(child);
    return child;
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element)

Example 7 with DefaultElement

use of org.dom4j.tree.DefaultElement in project gocd by gocd.

the class PipelineXmlViewModelTest method shouldReturnProperXMLWhenTherAreNullAttributesOnAMaterial.

@Test
public void shouldReturnProperXMLWhenTherAreNullAttributesOnAMaterial() {
    PipelineXmlViewModel.ScmXmlViewModel model = new PipelineXmlViewModel.ScmXmlViewModel(MaterialsMother.svnMaterial("url", "folder", null, null, false, null));
    DefaultElement materials = new DefaultElement("materials");
    model.populateXml(materials, new Modifications(), mock(XmlWriterContext.class));
    assertThat(materials.selectSingleNode("./material/@username"), is(nullValue()));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) DefaultElement(org.dom4j.tree.DefaultElement) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Test(org.junit.Test)

Example 8 with DefaultElement

use of org.dom4j.tree.DefaultElement in project Openfire by igniterealtime.

the class SearchGroupServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String param = req.getParameter("search");
    Element root = new DefaultElement("result");
    if (param != null && param.length() > 0) {
        GroupManager manager = GroupManager.getInstance();
        Collection<Group> groups = manager.getGroups();
        for (Group gr : groups) {
            if (gr.getName().startsWith(param)) {
                root.addElement("item").addText(gr.getName());
            }
        }
    }
    resp.getOutputStream().write(root.asXML().getBytes());
    resp.getOutputStream().close();
}
Also used : Group(org.jivesoftware.openfire.group.Group) DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) GroupManager(org.jivesoftware.openfire.group.GroupManager)

Example 9 with DefaultElement

use of org.dom4j.tree.DefaultElement in project tdi-studio-se by Talend.

the class RetrieveSchemaHelper method retrieveSchemasCommand.

public static Command retrieveSchemasCommand(Node node) {
    IElementParameter param = node.getElementParameter("SCHEMA");
    IMetadataTable inputMeta = node.getMetadataFromConnector("FLOW");
    IMetadataTable inputMetaCopy = inputMeta.clone(true);
    IElementParameter outParam = node.getElementParameter("SCHEMA_OUT");
    IMetadataTable outputMeta = node.getMetadataFromConnector(outParam.getContext());
    IMetadataTable outputMetaCopy = outputMeta.clone(true);
    File xmlFile = new File(TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString()));
    if (!xmlFile.exists())
        try {
            xmlFile.createNewFile();
        } catch (IOException e1) {
            ExceptionHandler.process(e1);
        }
    SAXReader saxReader = new SAXReader();
    Document document;
    AutoApi a = null;
    try {
        // get the schema file from server
        a = new AutoApi();
        String hostName = TalendTextUtils.removeQuotes(node.getElementParameter("HOSTNAME").getValue().toString());
        int port = Integer.parseInt(TalendTextUtils.removeQuotes(node.getElementParameter("PORT").getValue().toString()));
        String mandant = TalendTextUtils.removeQuotes(node.getElementParameter("MANDANT").getValue().toString());
        String userName = TalendTextUtils.removeQuotes(node.getElementParameter("USERNAME").getValue().toString());
        String passWord = TalendTextUtils.removeQuotes(node.getElementParameter("PASSWORD").getValue().toString());
        String jobDir = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_DIR").getValue().toString());
        String jobName = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_NAME").getValue().toString());
        String jobDef = TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString());
        a.openConnection(hostName, port, mandant, userName, passWord);
        a.getJobDefinitionFile(jobDir, jobName, jobDef);
        document = saxReader.read(xmlFile);
        List inputList = document.selectNodes("//Job//Lines//Line//Steps//Input//Sources//Source//Format//Fields//Field");
        List inputMetaColumnList = new ArrayList<MetadataColumn>();
        for (int i = 0; i < inputList.size(); i++) {
            IMetadataColumn imc = new MetadataColumn();
            DefaultElement de = (DefaultElement) inputList.get(i);
            Element nameElement = de.element("Name");
            imc.setLabel(nameElement.getData().toString());
            Element lengthElement = de.element("Length");
            if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) {
                imc.setLength(Integer.parseInt(lengthElement.getData().toString()));
            }
            Element typeElement = de.element("Type");
            JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString());
            if (javaType != null) {
                imc.setTalendType(javaType.getId());
            } else {
                imc.setTalendType(JavaTypesManager.STRING.getId());
            }
            inputMetaColumnList.add(imc);
        }
        inputMetaCopy.setListColumns(inputMetaColumnList);
        List outputList = document.selectNodes("//Job//Lines//Line//Steps//Output//Targets//Target//Format//Fields//Field");
        List outputMetaColumnList = new ArrayList<MetadataColumn>();
        for (int i = 0; i < outputList.size(); i++) {
            IMetadataColumn imc = new MetadataColumn();
            DefaultElement de = (DefaultElement) outputList.get(i);
            Element nameElement = de.element("Name");
            imc.setLabel(nameElement.getData().toString());
            Element lengthElement = de.element("Length");
            if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) {
                imc.setLength(Integer.parseInt(lengthElement.getData().toString()));
            }
            Element typeElement = de.element("Type");
            JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString());
            if (javaType != null) {
                imc.setTalendType(javaType.getId());
            } else {
                imc.setTalendType(JavaTypesManager.STRING.getId());
            }
            outputMetaColumnList.add(imc);
        }
        outputMetaCopy.setListColumns(outputMetaColumnList);
        // set advanced setting info
        DefaultElement de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//FieldSeparator");
        int separator = Integer.parseInt(de.getData().toString());
        node.getElementParameter("IN_FIELD_SEP").setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//HeaderRecordCount");
        node.getElementParameter("IN_HEADER_COUNT").setValue(de.getData().toString());
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//Directory");
        node.getElementParameter("IN_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//FileName");
        node.getElementParameter("IN_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation");
        node.getElementParameter("IN_MODE").setValue(de.attribute("Mode").getValue());
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//FieldSeparator");
        separator = Integer.parseInt(de.getData().toString());
        node.getElementParameter("OUT_FIELD_SEP").setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//HeaderRecordCount");
        node.getElementParameter("OUT_HEADER_COUNT").setValue(de.getData().toString());
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//Directory");
        node.getElementParameter("OUT_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//FileName");
        node.getElementParameter("OUT_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString()));
        de = (DefaultElement) document.selectObject("//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation");
        node.getElementParameter("OUT_MODE").setValue(de.attribute("Mode").getValue());
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        try {
            a.closeConnection();
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    CompoundCommand cc = new CompoundCommand();
    cc.add(new ChangeMetadataCommand(node, param, inputMeta, inputMetaCopy));
    cc.add(new ChangeMetadataCommand(node, param, outputMeta, outputMetaCopy));
    return cc;
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) SAXReader(org.dom4j.io.SAXReader) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Document(org.dom4j.Document) IOException(java.io.IOException) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) JavaType(org.talend.core.model.metadata.types.JavaType) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) AutoApi(org.talend.uniserv.AutoApi) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

DefaultElement (org.dom4j.tree.DefaultElement)9 Element (org.dom4j.Element)8 IQ (org.xmpp.packet.IQ)3 Attribute (org.dom4j.Attribute)2 Document (org.dom4j.Document)2 DefaultAttribute (org.dom4j.tree.DefaultAttribute)2 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)1 Modifications (com.thoughtworks.go.domain.materials.Modifications)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 QName (org.dom4j.QName)1 SAXReader (org.dom4j.io.SAXReader)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 IdMappingData (org.hibernate.envers.internal.entities.IdMappingData)1 EmbeddedIdMapper (org.hibernate.envers.internal.entities.mapper.id.EmbeddedIdMapper)1