Search in sources :

Example 26 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class DefaultSignalMastLogicManagerXml method store.

@Override
public Element store(Object o) {
    Element signalMastLogic = new Element("signalmastlogics");
    setStoreElementClass(signalMastLogic);
    SignalMastLogicManager smlm = (SignalMastLogicManager) o;
    signalMastLogic.addContent(new Element("logicDelay").addContent(Long.toString(smlm.getSignalLogicDelay())));
    ArrayList<SignalMastLogic> sml = smlm.getSignalMastLogicList();
    for (int i = 0; i < sml.size(); i++) {
        SignalMastLogic sm = sml.get(i);
        Element source = new Element("signalmastlogic");
        // added purely to make human reading of the xml easier
        source.setAttribute("source", sm.getSourceMast().getDisplayName());
        source.addContent(new Element("sourceSignalMast").addContent(sm.getSourceMast().getDisplayName()));
        ArrayList<SignalMast> destination = sm.getDestinationList();
        if (destination.size() != 0) {
            for (int k = 0; k < destination.size(); k++) {
                SignalMast dest = destination.get(k);
                if (sml.get(i).getStoreState(dest) != SignalMastLogic.STORENONE) {
                    Element elem = new Element("destinationMast");
                    // added purely to make human reading of the xml easier
                    elem.setAttribute("destination", dest.getDisplayName());
                    elem.addContent(new Element("destinationSignalMast").addContent(dest.getDisplayName()));
                    elem.addContent(new Element("comment").addContent(sm.getComment(dest)));
                    if (sm.isEnabled(dest)) {
                        elem.addContent(new Element("enabled").addContent("yes"));
                    } else {
                        elem.addContent(new Element("enabled").addContent("no"));
                    }
                    if (sm.allowAutoMaticSignalMastGeneration(dest)) {
                        elem.addContent(new Element("allowAutoMaticSignalMastGeneration").addContent("yes"));
                    } else {
                        elem.addContent(new Element("allowAutoMaticSignalMastGeneration").addContent("no"));
                    }
                    if (sm.useLayoutEditor(dest)) {
                        elem.addContent(new Element("useLayoutEditor").addContent("yes"));
                    } else {
                        elem.addContent(new Element("useLayoutEditor").addContent("no"));
                    }
                    if (sm.useLayoutEditorTurnouts(dest)) {
                        elem.addContent(new Element("useLayoutEditorTurnouts").addContent("yes"));
                    } else {
                        elem.addContent(new Element("useLayoutEditorTurnouts").addContent("no"));
                    }
                    if (sm.useLayoutEditorBlocks(dest)) {
                        elem.addContent(new Element("useLayoutEditorBlocks").addContent("yes"));
                    } else {
                        elem.addContent(new Element("useLayoutEditorBlocks").addContent("no"));
                    }
                    if (sm.getAssociatedSection(dest) != null) {
                        elem.addContent(new Element("associatedSection").addContent(sm.getAssociatedSection(dest).getDisplayName()));
                    }
                    if (sm.isTurnoutLockAllowed(dest)) {
                        elem.addContent(new Element("lockTurnouts").addContent("yes"));
                    } else {
                        elem.addContent(new Element("lockTurnouts").addContent("no"));
                    }
                    if (sml.get(i).getStoreState(dest) == SignalMastLogic.STOREALL) {
                        ArrayList<Block> blocks = sm.getBlocks(dest);
                        if (blocks.size() > 0) {
                            Element blockElement = new Element("blocks");
                            for (int j = 0; j < blocks.size(); j++) {
                                Element bloc = new Element("block");
                                bloc.addContent(new Element("blockName").addContent(blocks.get(j).getDisplayName()));
                                String blkState = "anyState";
                                if (sm.getBlockState(blocks.get(j), dest) == Block.OCCUPIED) {
                                    blkState = "occupied";
                                } else if (sm.getBlockState(blocks.get(j), dest) == Block.UNOCCUPIED) {
                                    blkState = "unoccupied";
                                }
                                bloc.addContent(new Element("blockState").addContent(blkState));
                                blockElement.addContent(bloc);
                            }
                            elem.addContent(blockElement);
                        }
                        ArrayList<NamedBeanHandle<Turnout>> turnouts = sm.getNamedTurnouts(dest);
                        if (turnouts.size() > 0) {
                            Element turnoutElement = new Element("turnouts");
                            for (int j = 0; j < turnouts.size(); j++) {
                                Element turn = new Element("turnout");
                                turn.addContent(new Element("turnoutName").addContent(turnouts.get(j).getName()));
                                String turnState = "thrown";
                                if (sm.getTurnoutState(turnouts.get(j).getBean(), dest) == Turnout.CLOSED) {
                                    turnState = "closed";
                                }
                                turn.addContent(new Element("turnoutState").addContent(turnState));
                                turnoutElement.addContent(turn);
                            }
                            elem.addContent(turnoutElement);
                        }
                        ArrayList<NamedBeanHandle<Sensor>> sensors = sm.getNamedSensors(dest);
                        if (sensors.size() > 0) {
                            Element sensorElement = new Element("sensors");
                            for (int j = 0; j < sensors.size(); j++) {
                                Element sensor = new Element("sensor");
                                sensor.addContent(new Element("sensorName").addContent(sensors.get(j).getName()));
                                String sensorState = "inActive";
                                if (sm.getSensorState(sensors.get(j).getBean(), dest) == Sensor.ACTIVE) {
                                    sensorState = "active";
                                }
                                sensor.addContent(new Element("sensorState").addContent(sensorState));
                                sensorElement.addContent(sensor);
                            }
                            elem.addContent(sensorElement);
                        }
                        ArrayList<SignalMast> masts = sm.getSignalMasts(dest);
                        if (masts.size() > 0) {
                            Element mastElement = new Element("masts");
                            for (int j = 0; j < masts.size(); j++) {
                                Element mast = new Element("mast");
                                mast.addContent(new Element("mastName").addContent(masts.get(j).getDisplayName()));
                                mast.addContent(new Element("mastState").addContent(sm.getSignalMastState(masts.get(j), dest)));
                                mastElement.addContent(mast);
                            }
                            elem.addContent(mastElement);
                        }
                    }
                    source.addContent(elem);
                }
            }
            signalMastLogic.addContent(source);
        }
    }
    return signalMastLogic;
}
Also used : Element(org.jdom2.Element) SignalMastLogicManager(jmri.SignalMastLogicManager) SignalMastLogic(jmri.SignalMastLogic) SignalMast(jmri.SignalMast) Block(jmri.Block) NamedBeanHandle(jmri.NamedBeanHandle)

Example 27 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class DecoderFileTest method setupDecoder.

// provide a test document in the above static variables
public void setupDecoder() {
    // create a JDOM tree with just some elements
    root = new Element("decoder-config");
    doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    // add some elements
    root.addContent(decoder = new Element("decoder").addContent(new Element("family").setAttribute("family", "DH142 etc").setAttribute("mfg", "Digitrax").setAttribute("defnVersion", "242").setAttribute("comment", "DH142 decoder: FX, transponding")).addContent(new Element("programming").setAttribute("direct", "byteOnly").setAttribute("paged", "yes").setAttribute("register", "yes").setAttribute("ops", "yes")).addContent(new Element("variables").addContent(new Element("variable").setAttribute("label", "Address").setAttribute("CV", "1").setAttribute("minFn", "4").setAttribute("mask", "VVVVVVVV").setAttribute("readOnly", "no").addContent(new Element("decVal").setAttribute("max", "127"))).addContent(new Element("variable").setAttribute("label", "Acceleration rate").setAttribute("CV", "3").setAttribute("minOut", "2").setAttribute("mask", "VVVVVVVV").setAttribute("readOnly", "no").addContent(new Element("decVal").setAttribute("max", "127"))).addContent(new Element("variable").setAttribute("label", "Normal direction of motion").setAttribute("CV", "29").setAttribute("minFn", "2").setAttribute("minOut", "5").setAttribute("mask", "XXXXXXXV").setAttribute("readOnly", "no").addContent(new Element("enumVal").addContent(new Element("enumChoice").setAttribute("choice", "forward")).addContent(new Element("enumChoice").setAttribute("choice", "reverse"))))));
    return;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 28 with Comment

use of org.jdom2.Comment in project JMRI by JMRI.

the class DecoderIndexFileTest method setupDoc.

// provide a test document in the above static variables
void setupDoc() {
    // create a JDOM tree with just some elements
    root = new Element("decoderIndex-config");
    doc = new Document(root);
    doc.setDocType(new DocType("decoderIndex-config", "decoderIndex-config.dtd"));
    // add some elements
    root.addContent(decoderIndexElement = new Element("decoderIndex").addContent(new Element("mfgList").addContent(new Element("manufacturer").setAttribute("mfg", "NMRA")).addContent(new Element("manufacturer").setAttribute("mfg", "Digitrax").setAttribute("mfgID", "129"))).addContent(new Element("familyList").addContent(family1 = new Element("family").setAttribute("mfg", "NMRA").setAttribute("name", "NMRA S&RP definitions").setAttribute("file", "NMRA.xml").addContent(new Element("model").setAttribute("model", "full set").setAttribute("comment", "all CVs in RP 9.2.1")).addContent(new Element("model").setAttribute("model", "required set").setAttribute("comment", "required CVs in RP 9.2.1"))).addContent(family2 = new Element("family").setAttribute("mfg", "Digitrax").setAttribute("name", "FX2 family").setAttribute("file", "DH142.xml").addContent(new Element("model").setAttribute("model", "DH142").setAttribute("numFns", "4").setAttribute("numOuts", "2").setAttribute("lowVersionID", "21")).addContent(new Element("model").setAttribute("model", "DN142").setAttribute("numFns", "5").setAttribute("numOuts", "1").addContent(new Element("versionCV").setAttribute("lowVersionID", "22").setAttribute("highVersionID", "24"))))));
    return;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 29 with Comment

use of org.jdom2.Comment in project gocd by gocd.

the class CommandSnippetXmlParser method parse.

public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) {
    try {
        Document document = buildXmlDocument(xmlContent, CommandSnippet.class.getResource("command-snippet.xsd"));
        CommandSnippetComment comment = getComment(document);
        Element execTag = document.getRootElement();
        String commandName = execTag.getAttributeValue("command");
        List<String> arguments = new ArrayList<>();
        for (Object child : execTag.getChildren()) {
            Element element = (Element) child;
            arguments.add(element.getValue());
        }
        return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath);
    } catch (Exception e) {
        String errorMessage = String.format("Reason: %s", e.getMessage());
        LOGGER.info(String.format("Could not load command '%s'. %s", fileName, errorMessage));
        return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment());
    }
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument) Document(org.jdom2.Document)

Example 30 with Comment

use of org.jdom2.Comment in project Douya by DreaminginCodeZH.

the class CommentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final Comment comment = getItem(position);
    ImageUtils.loadAvatar(holder.avatarImage, comment.author.avatar);
    final Context context = RecyclerViewUtils.getContext(holder);
    holder.avatarImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            context.startActivity(ProfileActivity.makeIntent(comment.author, context));
        }
    });
    holder.nameText.setText(comment.author.name);
    holder.timeText.setDoubanTime(comment.createdAt);
    holder.textText.setText(comment.getContentWithEntities(context));
}
Also used : Context(android.content.Context) Comment(me.zhanghai.android.douya.network.api.info.apiv2.Comment) TimeTextView(me.zhanghai.android.douya.ui.TimeTextView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

Element (org.jdom2.Element)33 Attribute (org.jdom2.Attribute)10 Document (org.jdom2.Document)6 ArrayList (java.util.ArrayList)4 File (java.io.File)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ProcessingInstruction (org.jdom2.ProcessingInstruction)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 BindView (butterknife.BindView)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 JButton (javax.swing.JButton)2 Block (jmri.Block)2 NamedBeanHandle (jmri.NamedBeanHandle)2 SignalGroup (jmri.SignalGroup)2 SignalGroupManager (jmri.SignalGroupManager)2 SignalMast (jmri.SignalMast)2 SignalMastLogic (jmri.SignalMastLogic)2