/** * Reads the payload of a tag, given the name and type. * * @param type The type. * @param name The name. * @param depth The depth. * @return The tag. * @throws IOException if an I/O error occurs. */ private Tag readTagPayload(int type, String name, int depth) throws IOException { switch (type) { case NBTConstants.TYPE_END: if (depth == 0) { throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it."); } else { return new EndTag(); } case NBTConstants.TYPE_BYTE: return new ByteTag(name, is.readByte()); case NBTConstants.TYPE_SHORT: return new ShortTag(name, is.readShort()); case NBTConstants.TYPE_INT: return new IntTag(name, is.readInt()); case NBTConstants.TYPE_LONG: return new LongTag(name, is.readLong()); case NBTConstants.TYPE_FLOAT: return new FloatTag(name, is.readFloat()); case NBTConstants.TYPE_DOUBLE: return new DoubleTag(name, is.readDouble()); case NBTConstants.TYPE_BYTE_ARRAY: int length = is.readInt(); byte[] bytes = new byte[length]; is.readFully(bytes); return new ByteArrayTag(name, bytes); case NBTConstants.TYPE_STRING: length = is.readShort(); bytes = new byte[length]; is.readFully(bytes); return new StringTag(name, new String(bytes, NBTConstants.CHARSET)); case NBTConstants.TYPE_LIST: int childType = is.readByte(); length = is.readInt(); List<Tag> tagList = new ArrayList<Tag>(); for (int i = 0; i < length; i++) { Tag tag = readTagPayload(childType, "", depth + 1); if (tag instanceof EndTag) { throw new IOException("TAG_End not permitted in a list."); } tagList.add(tag); } return new ListTag(name, NBTUtils.getTypeClass(childType), tagList); case NBTConstants.TYPE_COMPOUND: Map<String, Tag> tagMap = new HashMap<String, Tag>(); while (true) { Tag tag = readTag(depth + 1); if (tag instanceof EndTag) { break; } else { tagMap.put(tag.getName(), tag); } } return new CompoundTag(name, tagMap); default: throw new IOException("Invalid tag type: " + type + "."); } }
// save // tag///////////////////////////////////////////////////////////////////////////////////////// public static int saveTag(Tag tag) { int insertId = -1; if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) Log.d("CoCoin", "recordManager.saveTag: " + tag.toString()); } boolean duplicatedName = false; for (Tag t : TAGS) { if (t.getName().equals(tag.getName())) { duplicatedName = true; break; } } if (duplicatedName) { return SAVE_TAG_ERROR_DUPLICATED_NAME; } insertId = db.saveTag(tag); if (insertId == -1) { if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) Log.d("CoCoin", "Save the above tag FAIL!"); return SAVE_TAG_ERROR_DATABASE_ERROR; } } else { if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) Log.d("CoCoin", "Save the above tag SUCCESSFULLY!"); } TAGS.add(tag); TAG_NAMES.put(tag.getId(), tag.getName()); sortTAGS(); } return insertId; }
@Override @Secured public TestExecution updateTestExecution(TestExecution testExecution) throws ServiceException { TestExecution execEntity = testExecutionDAO.get(testExecution.getId()); if (execEntity == null) { throw new ServiceException("serviceException.testExecutionNotFound", testExecution.getName()); } // this is what can be updated here execEntity.setName(testExecution.getName()); execEntity.setStarted(testExecution.getStarted()); execEntity.setComment(testExecution.getComment()); execEntity.setTags(new ArrayList<>()); for (Tag tag : testExecution.getTags()) { Tag tagEntity = tagDAO.findByName(tag.getName()); if (tagEntity == null) { Tag newTag = new Tag(); newTag.setName(tag.getName()); tagEntity = tagDAO.create(newTag); } Collection<TestExecution> tagTestExecutions = tagEntity.getTestExecutions(); if (tagTestExecutions == null) { tagEntity.setTestExecutions(new ArrayList<>()); } tagEntity.getTestExecutions().add(execEntity); execEntity.getTags().add(tagEntity); } TestExecution execClone = cloneAndFetch(execEntity, true, true, true, true, true); return execClone; }
@Override public int compare(Tag tag, Tag tag2) { if (!TextUtils.equals(tag.getCategory(), tag2.getCategory())) { return Config.Tags.CATEGORY_DISPLAY_ORDERS.get(tag.getCategory()) - Config.Tags.CATEGORY_DISPLAY_ORDERS.get(tag2.getCategory()); } else if (tag.getOrderInCategory() != tag2.getOrderInCategory()) { return tag.getOrderInCategory() - tag2.getOrderInCategory(); } return tag.getName().compareTo(tag2.getName()); }
/** * Perform the action of the plugin. * * @param document the current document. */ public boolean perform(Document document) throws IOException { // Interact with the user to get the layer tag/ Tag layerTag = getLayerTagFromUser(document); if (layerTag == null) return false; // User cancled. Tag endTag = new Tag(layerTag.getName(), false); // Get the output stream to hold the new document text. PrintWriter out = new PrintWriter(document.getOutput()); // Create a lexical stream to tokenize the old document text. LexicalStream in = new LexicalStream(new SelectedHTMLReader(document.getInput(), out)); for (; ; ) { // Get the next token of the document. Token token = in.next(); if (token == null) break; // Null means we've finished the document. else if (token instanceof Comment) { Comment comment = (Comment) token; if (comment.isSelectionStart()) { out.print(layerTag); } else if (comment.isSelectionEnd()) { out.print(comment); out.print(endTag); continue; // So comment isn't printed twice. } } out.print(token); } out.close(); return true; }
/** * Writes all exemplar of this tag and all his nodes recursively to files. One file to exemplar * (exemplar is text, representing tag with attribute - fn, replaced by fn value) * * @param tag - written tag */ public void writeAllXml(Tag tag, String prefix, boolean toOutStream) { // initialise path in begin of export path = new ArrayList<>(); XMLStreamWriter current; int n = tag.attrSizes(); String extension = tag.getName(); // if tag size > m, _trim it_ if (limit >= 0 && limit < n) { n = limit; } // if tag size > WARNING_QUANTITY, ask user. // This tag is root tag of export, so quantity of files equals to its size if (n > WARNING_QUANTITY) { System.out.println("Write " + n + " files? y/n"); try { int yn = System.in.read(); if (yn != yCharCode) { System.out.println("Writing canceled\n Exit"); System.exit(0); } } catch (IOException e) { Util.handleException(e); } } // if must be one file, export it if (n <= 1) { // if to out, print if (toOutStream) { writeExemplarXML(getXmlStreamWriter(null), tag, 0, 0); } else { // if to file, export current = getXmlStreamWriter(prefix + "." + extension); writeExemplarXML(current, tag, 0, 0); writeVersion(current); } // if files many, } else { // if to out,print all if (toOutStream) { for (int i = 0; i < n; i++) { writeExemplarXML(getXmlStreamWriter(null), tag, i, 0); } } else { // if to files, export all appended with __[№] for (int i = 0; i < n; i++) { current = getXmlStreamWriter( prefix + "__(" + tag.getNameWithAttr(i).replace(" ", "_") + ")." + extension); writeExemplarXML(current, tag, i, 0); writeVersion(current); } } } // delete path in end of exort path = null; }
// getInstance////////////////////////////////////////////////////////////////////////////////////// public static synchronized RecordManager getInstance(Context context) { if (RECORDS == null || TAGS == null || TAG_NAMES == null || SUM == null || recordManager == null) { SUM = 0; RECORDS = new LinkedList<>(); TAGS = new LinkedList<>(); TAG_NAMES = new HashMap<>(); recordManager = new RecordManager(context); db.getData(); if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) Log.d("CoCoin", "Load " + RECORDS.size() + " records S"); if (BuildConfig.DEBUG) Log.d("CoCoin", "Load " + TAGS.size() + " tags S"); } TAGS.add(0, new Tag(-1, "Sum Histogram", -4)); TAGS.add(0, new Tag(-2, "Sum Pie", -5)); for (Tag tag : TAGS) TAG_NAMES.put(tag.getId(), tag.getName()); sortTAGS(); } return recordManager; }
void load(DataInput dis) throws IOException { tags.clear(); Tag tag; while ((tag = Tag.readNamedTag(dis)).getId() != Tag.TAG_End) { tags.put(tag.getName(), tag); } }
public static boolean isTagAndValue(String Name, String Value) { for (Tag tag : PiritaProtect.Plugin.Tags) { if (tag.getName().equalsIgnoreCase(Name) && tag.getValues().contains(Value.toLowerCase())) { return true; } } return false; }
public static boolean isTag(String Name) { for (Tag tag : PiritaProtect.Plugin.Tags) { if (tag.getName().equalsIgnoreCase(Name)) { return true; } } return false; }
@Override public List<String> getTagsByPrefix(String prefix) { List<String> tags = new ArrayList<String>(); for (Tag tag : tagDAO.findByPrefix(prefix)) { tags.add(tag.getName()); } return tags; }
protected void assertTagEquals( Tag expected, Tag source, final List<String> ignoreAttr, final List<String> ignoreTag) { if (!expected.getName().equals(source.getName())) { throw new ComparisonFailure( "Tags not equal: ", expected.getName().toString(), source.getName().toString()); } assertAttributesEquals( expected.getName(), expected.getAttributes(), source.getAttributes(), ignoreAttr); assertAttributesEquals( expected.getName(), source.getAttributes(), expected.getAttributes(), ignoreAttr); if (!StringUtils.isEmpty(expected.getText()) && !expected.getText().equals(source.getText())) { throw new ComparisonFailure("Text not equal: ", expected.getText(), source.getText()); } if (!expected.getTags().isEmpty()) { for (Tag expectedTag : expected.getTags()) { if (ignoreTag.contains(expectedTag.getName().getLocalPart()) && expectedTag.getTags().isEmpty()) { continue; } Tag sourceTag = getFromSource(source, expectedTag); if (sourceTag == null) { throw new AssertionError( "\n" + expected.toString() + " is missing in the source file:" + "\n" + source.toString()); } assertTagEquals(expectedTag, sourceTag, ignoreAttr, ignoreTag); } } }
private boolean matchInTag(String needle) { needle = needle.toLowerCase(Locale.US); for (Tag tag : getTags()) { if (tag.getName().toLowerCase(Locale.US).contains(needle)) { return true; } } return false; }
public AtributoAutofocus(Tag tag) { this.tag = tag; Class c = (Class) tag.getClass(); if (!AgregadorAtributos.class.isAssignableFrom(c)) { type = tag.getName(); } else { AgregadorAtributos temp = (AgregadorAtributos) tag; type = temp.getType(); } }
public boolean assertXmlEquals( final File expected, final File source, final List<String> ignoreAttr) throws Exception { List<Tag> expectedTags = ToolsStaxUtils.getTags(expected); List<Tag> sourceTags = ToolsStaxUtils.getTags(source); Iterator<Tag> iterator = sourceTags.iterator(); for (Tag expectedTag : expectedTags) { Tag sourceTag = iterator.next(); if (!expectedTag.getName().equals(sourceTag.getName())) { throw new ComparisonFailure( "Tags not equal: ", expectedTag.getName().toString(), sourceTag.getName().toString()); } for (Map.Entry<QName, String> attr : expectedTag.getAttributes().entrySet()) { if (ignoreAttr.contains(attr.getKey().getLocalPart())) { continue; } if (sourceTag.getAttributes().containsKey(attr.getKey())) { if (!sourceTag.getAttributes().get(attr.getKey()).equals(attr.getValue())) { throw new ComparisonFailure( "Attributes not equal: ", attr.getKey() + ":" + attr.getValue(), attr.getKey() + ":" + sourceTag.getAttributes().get(attr.getKey())); } } else { throw new AssertionError("Attribute: " + attr + " is missing in the source file."); } } if (!StringUtils.isEmpty(expectedTag.getText()) && !expectedTag.getText().equals(sourceTag.getText())) { throw new ComparisonFailure("Text not equal: ", expectedTag.getText(), sourceTag.getText()); } } return true; }
private void putTag(final String key, final Tag tag) { final String[] parts = (String[]) Iterables.toArray( Splitter.on('.').split((CharSequence) this.createRelativeKey(key)), (Class) String.class); Map<String, Tag> parent = NBTStorage.this.root; for (int i = 0; i < parts.length - 1; ++i) { if (!parent.containsKey(parts[i]) || !(parent.get(parts[i]) instanceof CompoundTag)) { parent.put(parts[i], new CompoundTag(parts[i])); } parent = parent.get(parts[i]).getValue(); } parent.put(tag.getName(), tag); }
/** * Writes a tag. * * @param tag The tag to write. * @throws IOException if an I/O error occurs. */ public void writeTag(Tag tag) throws IOException { int type = NBTUtils.getTypeCode(tag.getClass()); String name = tag.getName(); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); os.writeByte(type); os.writeShort(nameBytes.length); os.write(nameBytes); if (type == NBTConstants.TYPE_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
private static boolean renameWorld(String worldname, String newname) { if (isLoaded(worldname)) return false; Tag t = getData(worldname); if (t == null) return false; t = t.findTagByName("Data"); if (t == null || t.getType() != Type.TAG_Compound) return false; int i = 0; for (Tag tt : (Tag[]) t.getValue()) { if (tt.getName().equals("LevelName")) { t.removeTag(i); t.insertTag(new Tag(Type.TAG_String, "LevelName", newname), i); break; } i++; } return setData(worldname, t); }
public String getTagsString() { if (getTags().isEmpty()) { return "ไม่มีป้ายกำกับ"; } String tgs = ""; String splitor = ", "; for (Tag tag : getTags()) { tgs = tgs + splitor + tag.getName(); } if (tgs.startsWith(splitor)) { return tgs.substring(splitor.length()); } return tgs; }
@Override @SuppressWarnings("unchecked") public void loadTag(T entity, Tag tag) { String name = tag.getName(); if (name.equals("Dir")) { entity.setDirection(((ByteTag) tag).getValue()); } else if (name.equals("Motive")) { entity.setArt(((StringTag) tag).getValue()); } else if (name.equals("TileX")) { entity.getBlockCoordinates().setX(((IntTag) tag).getValue()); } else if (name.equals("TileY")) { entity.getBlockCoordinates().setY(((IntTag) tag).getValue()); } else if (name.equals("TileZ")) { entity.getBlockCoordinates().setZ(((IntTag) tag).getValue()); } else { super.loadTag(entity, tag); } }
@Override public void removeTagsFromTestExecutions( Collection<String> tags, Collection<TestExecution> testExecutions) { for (TestExecution testExecutionItem : testExecutions) { TestExecution testExecution = testExecutionDAO.get(testExecutionItem.getId()); if (testExecution == null) { continue; } for (Tag tag : testExecution.getTags()) { if (tags.contains(tag.getName())) { testExecution.getTags().remove(tag); } } testExecutionDAO.update(testExecution); } }
@Override public View getChildView( int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if (convertView == null) { convertView = layoutInflater.inflate(R.layout.item_expandble_list, parent, false); } TagsCategory category = (TagsCategory) getGroup(groupPosition); TextView tagName = (TextView) convertView.findViewById(R.id.elementsItemName); Tag tag = category.get(childPosition); tagName.setText(tag.getName()); if (search.isChosen(tag)) { convertView.setBackgroundColor(Color.GRAY); } else { convertView.setBackgroundColor(Color.LTGRAY); } return convertView; }
@Override @Secured public TestExecution createTestExecution(TestExecution testExecution) throws ServiceException { // The test referred by test execution has to be an existing test Test test = testDAO.get(testExecution.getTest().getId()); testExecution.setTest(test); TestExecution storedTestExecution = testExecutionDAO.create(testExecution); // execution params if (testExecution.getParameters() != null && testExecution.getParameters().size() > 0) { for (TestExecutionParameter param : testExecution.getParameters()) { param.setTestExecution(storedTestExecution); testExecutionParameterDAO.create(param); } } // tags if (testExecution.getTags() != null && testExecution.getTags().size() > 0) { for (Tag teg : testExecution.getTags()) { Tag tag = tagDAO.findByName(teg.getName()); if (tag == null) { tag = tagDAO.create(teg); } Collection<TestExecution> tagTestExecutions = tag.getTestExecutions(); if (tagTestExecutions == null) { tag.setTestExecutions(new ArrayList<>()); } tag.getTestExecutions().add(storedTestExecution); } } // values if (testExecution.getValues() != null && !testExecution.getValues().isEmpty()) { for (Value value : testExecution.getValues()) { value.setTestExecution(storedTestExecution); if (value.getMetricName() == null) { throw new IllegalArgumentException("Metric name is mandatory"); } Metric metric = test.getMetrics() .stream() .filter(m -> m.getName().equals(value.getMetricName())) .findFirst() .get(); if (metric == null) { throw new ServiceException( "serviceException.metricNotInTest", test.getName(), test.getId().toString(), value.getMetricName()); } value.setMetric(metric); valueDAO.create(value); if (value.getParameters() != null && value.getParameters().size() > 0) { for (ValueParameter vp : value.getParameters()) { vp.setValue(value); valueParameterDAO.create(vp); } } } } TestExecution clone = cloneAndFetch(storedTestExecution, true, true, true, true, true); log.debug("Created new test execution " + clone.getId()); alertingService.processAlerts(clone); return clone; }
/** Builds the document header of the swagger model */ private void overview() { Info info = swagger.getInfo(); this.markupDocBuilder.documentTitle(info.getTitle()); this.markupDocBuilder.sectionTitleLevel1(OVERVIEW); if (isNotBlank(info.getDescription())) { this.markupDocBuilder.textLine(info.getDescription()); } if (isNotBlank(info.getVersion())) { this.markupDocBuilder.sectionTitleLevel2(CURRENT_VERSION); this.markupDocBuilder.textLine(VERSION + info.getVersion()); } Contact contact = info.getContact(); if (contact != null) { this.markupDocBuilder.sectionTitleLevel2(CONTACT_INFORMATION); if (isNotBlank(contact.getName())) { this.markupDocBuilder.textLine(CONTACT_NAME + contact.getName()); } if (isNotBlank(contact.getEmail())) { this.markupDocBuilder.textLine(CONTACT_EMAIL + contact.getEmail()); } } License license = info.getLicense(); if (license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) { this.markupDocBuilder.sectionTitleLevel2(LICENSE_INFORMATION); if (isNotBlank(license.getName())) { this.markupDocBuilder.textLine(LICENSE + license.getName()); } if (isNotBlank(license.getUrl())) { this.markupDocBuilder.textLine(LICENSE_URL + license.getUrl()); } } if (isNotBlank(info.getTermsOfService())) { this.markupDocBuilder.textLine(TERMS_OF_SERVICE + info.getTermsOfService()); } if (isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) { this.markupDocBuilder.sectionTitleLevel2(URI_SCHEME); if (isNotBlank(swagger.getHost())) { this.markupDocBuilder.textLine(HOST + swagger.getHost()); } if (isNotBlank(swagger.getBasePath())) { this.markupDocBuilder.textLine(BASE_PATH + swagger.getBasePath()); } if (isNotEmpty(swagger.getSchemes())) { List<String> schemes = new ArrayList<>(); for (Scheme scheme : swagger.getSchemes()) { schemes.add(scheme.toString()); } this.markupDocBuilder.textLine(SCHEMES + join(schemes, ", ")); } } if (isNotEmpty(swagger.getTags())) { this.markupDocBuilder.sectionTitleLevel2(TAGS); List<String> tags = new ArrayList<>(); for (Tag tag : swagger.getTags()) { String name = tag.getName(); String description = tag.getDescription(); if (isNoneBlank(description)) { tags.add(name + ": " + description); } else { tags.add(name); } } this.markupDocBuilder.unorderedList(tags); } if (isNotEmpty(swagger.getConsumes())) { this.markupDocBuilder.sectionTitleLevel2(CONSUMES); this.markupDocBuilder.unorderedList(swagger.getConsumes()); } if (isNotEmpty(swagger.getProduces())) { this.markupDocBuilder.sectionTitleLevel2(PRODUCES); this.markupDocBuilder.unorderedList(swagger.getProduces()); } }
private void writeExemplarXML(XMLStreamWriter xmlStreamWriter, Tag tag, int n, int tabs) { String string; Map<String, StringFacadeIF> map; // add this tag to end of path path.add(tag); // filtr exemplar by EXIST, EXIST0, ONENODE (and m.b. something else in future) if (tag.isExemplarWritten(n)) { map = tag.getStringFacadeMap(); try { // "\t" * tabs tabs(xmlStreamWriter, tabs); // <tag> xmlStreamWriter.writeStartElement(tag.getName()); // replace attr with "..." by same without dots d and vice versa // and export it for (String s : tag.getAttributeNames()) { if (s.endsWith("...")) { string = s.replace("...", ""); if (tag.getAttributeNames().contains(string)) { xmlStreamWriter.writeAttribute(string, map.get(s).getValue(null, n)); } else { Util.printErrorAndExit("\"" + s + "\" has not pair. Exit"); } } else { string = s.concat("..."); if (tag.getAttributeNames().contains(string)) { xmlStreamWriter.writeAttribute(string, map.get(s).getValue(null, n)); } else { xmlStreamWriter.writeAttribute(s, map.get(s).getValue(null, n)); } } } // if not <tag></tag>, \n if (!tag.isEmpty()) { xmlStreamWriter.writeCharacters("\n"); } // export nodes with "\t" * (tabs + 1) if (!tag.oneNode()) { tag.getNodes().stream().forEach(t -> writeAllXml(xmlStreamWriter, t, tabs + 1)); } else { if (tag.nodeSizes() > -1) { tag.getNodes().stream().forEach(t -> writeExemplarXML(xmlStreamWriter, t, n, tabs + 1)); } } // text if (tag.getText() != null) { tabs(xmlStreamWriter, tabs + 1); xmlStreamWriter.writeCharacters(tag.getText().getValue(null, n)); xmlStreamWriter.writeCharacters("\n"); } // if not <tag></tag>, "\t" * (tabs) if (!tag.isEmpty()) { tabs(xmlStreamWriter, tabs); } // </tag> xmlStreamWriter.writeEndElement(); // \n xmlStreamWriter.writeCharacters("\n"); // print only exception name, not stackTrace (if catch this exception) } catch (XMLStreamException e) { Util.handleException(e); } } // remove this tag from path getPath().remove(getPath().size() - 1); }