List of usage examples for org.jdom2 Element getName
public String getName()
From source file:com.ohnosequences.xml.model.util.XMLWrapperClass.java
License:Open Source License
public XMLWrapperClass(Element elem) throws XMLElementException { super(elem);/*from w w w . j ava 2 s. c o m*/ if (!elem.getName().equals(TAG_NAME)) { throw new XMLElementException(XMLElementException.WRONG_TAG_NAME, new XMLElement(elem)); } }
From source file:com.ohnosequences.xml.model.util.XMLWrapperClassCreator.java
License:Open Source License
public static void main(String[] args) { if (args.length != 1) { System.out.println("El programa espera un parametro: \n" + "1. Nombre del archivo xml con la descripcion de la clase \n"); } else {//from w w w .j a v a2s. c o m File inFile = new File(args[0]); try { BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; StringBuilder stBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { stBuilder.append(line); } reader.close(); XMLElement classes = new XMLElement(stBuilder.toString()); List<Element> list = classes.getRoot().getChildren(XMLWrapperClass.TAG_NAME); for (Element elem : list) { XMLWrapperClass wrapper = new XMLWrapperClass(elem); //primero creo los directorios del package String[] packageSplit = wrapper.getPackage().split("\\."); String currentFolder = "./"; for (int i = 0; i < packageSplit.length; i++) { String string = packageSplit[i]; currentFolder += string; System.out.println("currentFolder = " + currentFolder); File tempFile = new File(currentFolder); if (!tempFile.exists()) { tempFile.mkdir(); System.out.println("no existe: tempFile = " + tempFile); } else { System.out.println("existe: tempFile = " + tempFile); } currentFolder += "/"; } BufferedWriter outBuff = new BufferedWriter( new FileWriter(new File(currentFolder + wrapper.getClassName() + ".java"))); outBuff.write("package " + wrapper.getPackage() + ";\n\n"); outBuff.write(NECESSARY_IMPORTS); outBuff.write("public class " + wrapper.getClassName() + " extends XMLElement{\n\n"); outBuff.write("public static final String TAG_NAME = \"" + wrapper.getTagName() + "\";\n\n"); HashMap<String, String> varsDeclarationNames = new HashMap<String, String>(); HashMap<String, String> varsTypes = new HashMap<String, String>(); List<Element> vars = wrapper.getVars().getChildren(); for (Element element : vars) { outBuff.write(VARS_PREFIX + " "); String varName = element.getText(); String varDeclarationName = ""; for (int i = 0; i < varName.length(); i++) { char c = varName.charAt(i); if (Character.isUpperCase(c)) { varDeclarationName += "_" + c; } else { varDeclarationName += ("" + c).toUpperCase(); } } varDeclarationName = varDeclarationName + "_TAG_NAME"; varsDeclarationNames.put(varName, varDeclarationName); varsTypes.put(varName, element.getName()); //En este ciclo cambio la mayuscula del nombre de la variable por '_' String tempTagName = ""; for (int i = 0; i < varName.length(); i++) { char c = varName.charAt(i); if (Character.isUpperCase(c)) { tempTagName += "_" + ("" + c).toLowerCase(); } else { tempTagName += "" + c; } } outBuff.write(varDeclarationName + " = \"" + tempTagName + "\";\n"); } //Ahora la parte de los constructores outBuff.write( "\n" + CONSTRUCTORS_STR.replaceAll(CLASS_NAME_CONSTRUCTOR_VAR, wrapper.getClassName())); Set<String> varsKeySet = varsDeclarationNames.keySet(); //A rellenar los getters! outBuff.write("\n" + GETTERS_STR); for (String key : varsKeySet) { String varType = varsTypes.get(key); String getStr = " get" + key.substring(0, 1).toUpperCase() + key.substring(1); outBuff.write("\npublic " + varType + getStr + "(){\treturn "); if (varType.equals("int")) { outBuff.write("Integer.parseInt(getNodeText(" + varsDeclarationNames.get(key) + "));}"); } else if (varType.equals("double")) { outBuff.write( "Double.parseDouble(getNodeText(" + varsDeclarationNames.get(key) + "));}"); } else if (varType.equals("float")) { outBuff.write("Float.parseFloat(getNodeText(" + varsDeclarationNames.get(key) + "));}"); } else if (varType.equals("String")) { outBuff.write("getNodeText(" + varsDeclarationNames.get(key) + ");}"); } else if (varType.equals("boolean")) { outBuff.write( "Boolean.parseBoolean(getNodeText(" + varsDeclarationNames.get(key) + "));}"); } } //A rellenar los setters! outBuff.write("\n" + SETTERS_STR); for (String key : varsKeySet) { String varType = varsTypes.get(key); String setStr = " set" + key.substring(0, 1).toUpperCase() + key.substring(1); outBuff.write("\npublic void " + setStr + "(" + varType + " value){\t setNodeText(" + varsDeclarationNames.get(key) + ", "); if (varType.equals("String")) { outBuff.write("value"); } else { outBuff.write("String.valueOf(value)"); } outBuff.write(");}"); } //Llave que cierra la clase outBuff.write("\n}\n"); outBuff.close(); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.ohnosequences.xml.model.wip.Region.java
License:Open Source License
public Region(Element elem) throws XMLElementException { super(elem);// w ww . jav a2 s . c o m if (!elem.getName().equals(TAG_NAME)) { throw new XMLElementException(XMLElementException.WRONG_TAG_NAME, new XMLElement(elem)); } }
From source file:com.ohnosequences.xml.model.wip.WipPosition.java
License:Open Source License
public WipPosition(Element elem) throws XMLElementException { super(elem);/*from www. j a va 2s. c o m*/ if (!elem.getName().equals(TAG_NAME)) { throw new XMLElementException(XMLElementException.WRONG_TAG_NAME, new XMLElement(elem)); } }
From source file:com.ohnosequences.xml.model.wip.WipResult.java
License:Open Source License
public WipResult(Element elem) throws XMLElementException { super(elem);/*from w w w .j av a 2s . c o m*/ if (!elem.getName().equals(TAG_NAME)) { throw new XMLElementException(XMLElementException.WRONG_TAG_NAME, new XMLElement(elem)); } }
From source file:com.rhythm.louie.email.MailProperties.java
License:Apache License
public static void processProperties(Element email) { for (Element prop : email.getChildren()) { String propName = prop.getName().toLowerCase(); if (null != propName) { switch (propName) { case JNDI: jndi = prop.getText().trim(); break; case CUSTOM: for (Element customProp : prop.getChildren()) { props.put(customProp.getName(), customProp.getTextTrim()); }/* w w w . j a v a2s .co m*/ break; default: LoggerFactory.getLogger(MailProperties.class).warn("Unknown Mail Element:{}", propName); break; } } } }
From source file:com.rhythm.louie.jms.MessagingProperties.java
License:Apache License
public static void processMessaging(Element messaging) { for (Element prop : messaging.getChildren()) { String propName = prop.getName().toLowerCase(); if (null != propName) { switch (propName) { case JMSADAPTER: adapterClass = prop.getAttributeValue(CLASS, getAdapterClass()); host = prop.getAttributeValue(JmsAdapter.HOST_KEY, getHost()); port = prop.getAttributeValue(JmsAdapter.PORT_KEY, getPort()); failover = prop.getAttributeValue(JmsAdapter.FAILOVER_KEY, getFailover()); break; case SERVER: serverPrefix = prop.getAttributeValue(PREFIX, getServerPrefix()); serverType = prop.getAttributeValue(TYPE, getServerType()); break; case CLIENT: clientPrefix = prop.getAttributeValue(PREFIX, getClientPrefix()); clientType = prop.getAttributeValue(TYPE, getClientType()); break; case UPDATE: updatePrefix = prop.getAttributeValue(PREFIX, getUpdatePrefix()); updateType = prop.getAttributeValue(TYPE, getUpdateType()); break; case CUSTOM: for (Element customProp : prop.getChildren()) { String customName = customProp.getName().toLowerCase(); CustomProperty custom = new CustomProperty(customName); for (Element child : customProp.getChildren()) { custom.setProperty(child.getName(), child.getText().trim()); }//w w w .j a v a 2 s. c o m customProperties.put(customName, custom); } break; default: LoggerFactory.getLogger(MessagingProperties.class).warn("Unknown Message Property:{}", propName); break; } } } }
From source file:com.rhythm.louie.server.AlertProperties.java
License:Apache License
public static void processProperties(Element alerts) { for (Element child : alerts.getChildren()) { String alert = child.getName(); AlertProperties prop = new AlertProperties(); properties.put(alert, prop);/*w ww. jav a2 s. c o m*/ for (Element grandchild : child.getChildren()) { String propName = grandchild.getName(); String value = grandchild.getTextTrim(); switch (propName) { case EMAIL: prop.setEmail(value); break; case REQUEST_DURATION: prop.setDuration(Long.parseLong(value)); break; case MONITOR_CYCLE: prop.setMonitorPollCycle(Integer.parseInt(value)); break; case SUMMARY_HOUR: prop.setSummaryHour(Integer.parseInt(value)); break; case PERCENTAGE: int capture = Integer.parseInt(value); double adjusted = (double) capture / 100; prop.setPercentThreshold(adjusted); break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected alert property {}", propName); break; } } } }
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
public static void processProperties(URL configs, String contextGateway) throws Exception { loadInternals(); //this code organization is weird but it's from iterations of design if (contextGateway != null) { //Overrides a default set by internal properties Server.setDefaultGateway(contextGateway); }/*from w ww. j a va 2s . c o m*/ Document properties = loadDocument(configs); if (properties == null) { return; } Element louie = properties.getRootElement(); //Check for alternate loading point boolean resetRoot = false; for (Element elem : louie.getChildren()) { if (ALT_PATH.equalsIgnoreCase(elem.getName())) { String altPath = elem.getTextTrim(); LoggerFactory.getLogger(LouieProperties.class).info("Loading Louie configs from alternate file: {}", altPath); //overwrite document with values from alternate config properties = loadDocument(new File(altPath).toURI().toURL()); if (properties == null) return; resetRoot = true; } } if (resetRoot) { //reset root to new properties obj root louie = properties.getRootElement(); } Element groups = louie.getChild(GROUPS); if (groups != null) { AccessManager.loadGroups(groups); } boolean serversConfigured = false; for (Element elem : louie.getChildren()) { String elemName = elem.getName().toLowerCase(); if (null != elemName) switch (elemName) { case ALT_PATH: LoggerFactory.getLogger(LouieProperties.class) .warn("Extra config_path alternate loading point specified. " + "Only one file-switch can be performed.\n" + " Please verify what is specified in the embedded xml file.\n" + " Found: {}", elem.getText()); break; case SERVER_PARENT: processServers(elem); serversConfigured = true; break; case SERVICE_PARENT: processServices(elem, false); break; case MESSAGING: MessagingProperties.processMessaging(elem); break; case MAIL: MailProperties.processProperties(elem); break; case SCHEDULER: TaskSchedulerProperties.processProperties(elem); break; case ALERTS: AlertProperties.processProperties(elem); break; case CUSTOM: processCustomProperties(elem); break; case GROUPS: break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected top level property {}", elemName); break; } } if (!serversConfigured) processServers(null); //ugly bootstrapping workflow }
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void processServers(Element servers) { List<Server> serverList = new ArrayList<>(); if (servers == null) { List<Server> empty = Collections.emptyList(); Server.processServers(empty);//from w w w .jav a2 s .co m return; } for (Element server : servers.getChildren()) { if (!SERVER.equals(server.getName().toLowerCase())) continue; String name = null; for (Attribute attr : server.getAttributes()) { if (NAME.equals(attr.getName().toLowerCase())) name = attr.getValue(); } if (name == null) { LoggerFactory.getLogger(LouieProperties.class) .error("A server was missing it's 'name' attribute and will be skipped!"); continue; } Server prop = new Server(name); for (Element serverProp : server.getChildren()) { String propName = serverProp.getName().toLowerCase(); String propValue = serverProp.getTextTrim(); if (null != propName) switch (propName) { case HOST: prop.setHost(propValue); break; case DISPLAY: prop.setDisplay(propValue); break; case LOCATION: prop.setLocation(propValue); break; case GATEWAY: prop.setGateway(propValue); break; case IP: prop.setIp(propValue); break; case EXTERNAL_IP: prop.setExternalIp(propValue); break; case CENTRAL_AUTH: prop.setCentralAuth(Boolean.parseBoolean(propValue)); break; case PORT: prop.setPort(Integer.parseInt(propValue)); break; case SECURE: prop.setSecure(Boolean.parseBoolean(propValue)); break; case TIMEZONE: prop.setTimezone(propValue); break; case CUSTOM: for (Element child : serverProp.getChildren()) { prop.addCustomProperty(child.getName(), child.getTextTrim()); } break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property {}:{}", propName, propValue); break; } } serverList.add(prop); } Server.processServers(serverList); }